generated from rmcguire/go-server-with-otel
add ui, new config opts
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package econetclient
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// sampleGen5 is a trimmed but faithful slice of a real getUserDataForApp
|
||||
// equipment block for a Rheem Gen5 heat-pump water heater (see the values in
|
||||
// the field decoders it exercises: @TYPE, @MODE enumText incl. "Electric/Gas",
|
||||
// @HOTWATER "_v2" icon, @SETPOINT limits, @ENABLED, @NAME).
|
||||
const sampleGen5 = `{
|
||||
"@TYPE":"heatpumpWaterHeaterGen5",
|
||||
"@CONNECTED":true,
|
||||
"@ENABLED":{"constraints":{"enumText":["Disabled","Enabled "],"lowerLimit":0,"upperLimit":1},"status":"Enabled ","value":1},
|
||||
"@MODE":{"constraints":{"enumText":["Off ","Energy Saver ","Heat Pump ","High Demand ","Electric/Gas ","Vacation "],"lowerLimit":0,"upperLimit":5},"status":"Energy Saver ","value":1},
|
||||
"@HOTWATER":"ic_tank_hundread_percent_v2.png",
|
||||
"@SETPOINT":{"constraints":{"lowerLimit":110,"upperLimit":140},"value":135},
|
||||
"@NAME":{"constraints":{"stringLength":64},"value":"Heat Pump Water Heater"},
|
||||
"@RUNNING":"",
|
||||
"@ALERTCOUNT":0,
|
||||
"device_name":"3224625639131449",
|
||||
"device_type":"WH",
|
||||
"serial_number":"04-17-1a-0d-22-11-25-c0-01"
|
||||
}`
|
||||
|
||||
func TestNewDeviceGen5(t *testing.T) {
|
||||
var info map[string]json.RawMessage
|
||||
if err := json.Unmarshal([]byte(sampleGen5), &info); err != nil {
|
||||
t.Fatalf("bad sample: %v", err)
|
||||
}
|
||||
d := newDevice(info, time.Now())
|
||||
|
||||
if d.SerialNumber != "04-17-1a-0d-22-11-25-c0-01" {
|
||||
t.Errorf("serial = %q", d.SerialNumber)
|
||||
}
|
||||
if d.GenericType != "heatpumpWaterHeaterGen5" {
|
||||
t.Errorf("genericType = %q", d.GenericType)
|
||||
}
|
||||
if d.FriendlyName != "Heat Pump Water Heater" {
|
||||
t.Errorf("friendlyName = %q", d.FriendlyName)
|
||||
}
|
||||
if !d.Enabled {
|
||||
t.Errorf("enabled = false, want true")
|
||||
}
|
||||
if d.Mode != "energy-saving" {
|
||||
t.Errorf("mode = %q, want energy-saving", d.Mode)
|
||||
}
|
||||
if d.Setpoint != 135 || d.SetpointMin != 110 || d.SetpointMax != 140 {
|
||||
t.Errorf("setpoint = %d [%d,%d], want 135 [110,140]", d.Setpoint, d.SetpointMin, d.SetpointMax)
|
||||
}
|
||||
if d.HotWaterAvailability != 100 {
|
||||
t.Errorf("hotWater = %d, want 100", d.HotWaterAvailability)
|
||||
}
|
||||
if len(d.Raw) == 0 {
|
||||
t.Errorf("raw payload not retained")
|
||||
}
|
||||
|
||||
// "Electric/Gas" must map to a real, settable mode (not dropped as unknown).
|
||||
want := []string{"off", "energy-saving", "heat-pump", "high-demand", "electric-gas", "vacation"}
|
||||
if got := d.SupportedModes(); !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("supportedModes = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user