Skip to content

Commit

Permalink
luxwslang: Parse "---" as value zero
Browse files Browse the repository at this point in the history
When there is no demand for heat, the circulation pump stops pumping
water around. The heat pump UI shows "--- l/h" as the flow rate (liters
per hour).

Fixes #3.
  • Loading branch information
hansmi committed Mar 27, 2022
1 parent df6ce4d commit 599ff66
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions luxwslang/terminology.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ func (*Terminology) ParseMeasurement(text string) (float64, string, error) {
}
}

if !ok {
for _, format := range []string{"--- %s\n", "---%s\n"} {
if n, err := fmt.Sscanf(text, format, &unit); err == nil && n == 1 {
value = 0
ok = true
break
}
}
}

if ok {
switch unit {
case "K", "bar", "l/h", "kWh", "rpm", "V", "kW", "Hz", "mA", "s", "m³/h":
Expand Down
2 changes: 2 additions & 0 deletions luxwslang/terminology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ func TestParseMeasurement(t *testing.T) {
{terms: English, input: "3600s", want: 3600, wantUnit: "s"},
{terms: English, input: "36 m³/h", want: 36, wantUnit: "m³/h"},
{terms: English, input: "18 min", want: 18 * 60, wantUnit: "s"},
{terms: Dutch, input: "--- l/h", want: 0, wantUnit: "l/h"},
{terms: English, input: "---rpm", want: 0, wantUnit: "rpm"},
} {
t.Run(tc.terms.ID+" "+tc.input, func(t *testing.T) {
got, gotUnit, err := tc.terms.ParseMeasurement(tc.input)
Expand Down

0 comments on commit 599ff66

Please sign in to comment.