]> git.giacomolli.uk - onehouse/blob - driver/alamo/reported_control_test.go
Poll and command shared Alamo thermostats
[onehouse] / driver / alamo / reported_control_test.go
1 package alamo
2
3 import (
4 "encoding/json"
5 "testing"
6
7 "github.com/stretchr/testify/require"
8 )
9
10 func TestReportedControlPreservesReadbackAndLocalHeatingMeaning(t *testing.T) {
11 testCases := []struct {
12 name string
13 power bool
14 active bool
15 mode string
16 action string
17 }{
18 {
19 name: "powered off has no heating action",
20 mode: "off",
21 action: "off",
22 },
23 {
24 name: "powered thermostat can be idle",
25 power: true,
26 mode: "heat",
27 action: "idle",
28 },
29 {
30 name: "active thermostat reports local heating",
31 power: true,
32 active: true,
33 mode: "heat",
34 action: "heating",
35 },
36 }
37
38 for _, tc := range testCases {
39 t.Run(tc.name, func(t *testing.T) {
40 state := testState()
41 state.Power = tc.power
42 state.Active = tc.active
43 state.Locked = true
44 reported := newReportedControl(state)
45 require.Equal(t, tc.mode, reported.Settings.Mode)
46 require.Equal(t, tc.action, reported.Action)
47
48 data, err := json.Marshal(reported)
49 require.NoError(t, err)
50 require.Contains(t, string(data), `"current_temperature":19.5`)
51 require.Contains(t, string(data), `"floor_temperature":23`)
52 require.Contains(t, string(data), `"target_temperature":20`)
53 require.Contains(t, string(data), `"locked":true`)
54 })
55 }
56 }