Skip to content

Commit

Permalink
Skip rows without timestamp when parsing reported errors
Browse files Browse the repository at this point in the history
The table with errors encountered by the heat pump controller may
contain empty rows, denoted by "----".

Fixes #5.
  • Loading branch information
hansmi committed Apr 2, 2022
1 parent 48f3704 commit 00a4849
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
6 changes: 4 additions & 2 deletions luxws-exporter/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,13 @@ func (c *collector) collectTimetable(ch chan<- prometheus.Metric, desc *promethe
latest := map[string]time.Time{}

for _, item := range group.Items {
if item.Value == nil {
tsRaw := normalizeSpace(item.Name)

if item.Value == nil || strings.Trim(tsRaw, "-") == "" {
continue
}

ts, err := c.terms.ParseTimestamp(item.Name, c.loc)
ts, err := c.terms.ParseTimestamp(tsRaw, c.loc)
if err != nil {
return err
}
Expand Down
21 changes: 21 additions & 0 deletions luxws-exporter/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,27 @@ luxws_latest_error{reason=""} 0
# TYPE luxws_latest_error gauge
luxws_latest_error{reason="aaa"} 1296633600
luxws_latest_error{reason="bbb"} 1396566000
`,
},
{
name: "latest error with empty rows",
fn: c.collectLatestError,
input: &luxwsclient.ContentRoot{
Items: []luxwsclient.ContentItem{
{
Name: "Fehlerspeicher",
Items: []luxwsclient.ContentItem{
{Name: "----", Value: luxwsclient.String("placeholder")},
{Name: "08.11.21 21:40:09", Value: luxwsclient.String("text")},
{Name: "----", Value: luxwsclient.String("----")},
},
},
},
},
want: `
# HELP luxws_latest_error Latest error
# TYPE luxws_latest_error gauge
luxws_latest_error{reason="text"} 1636407609
`,
},
{
Expand Down

0 comments on commit 00a4849

Please sign in to comment.