-
Notifications
You must be signed in to change notification settings - Fork 0
/
thermostat.go
40 lines (36 loc) · 1.07 KB
/
thermostat.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package devices
import (
"github.com/galenliu/gateway/pkg/addon/properties"
)
type Thermostat struct {
*Device
Temperature properties.NumberEntity
TargetTemperature properties.NumberEntity
HeatingCooling properties.StringEntity
ThermostatMode properties.StringEntity
}
func NewThermostat(id string, opts ...Option) *OnOffSwitch {
device := NewDevice(DeviceDescription{
Id: id,
AtType: []Capability{CapabilityThermostat},
}, opts...)
if device == nil {
return nil
}
return &OnOffSwitch{Device: device}
}
func (device *Thermostat) AddProperties(props ...properties.Entity) {
for _, p := range props {
switch p.GetAtType() {
case properties.TypeTemperatureProperty:
device.Temperature = p.(properties.NumberEntity)
case properties.TypeTargetTemperatureProperty:
device.Temperature = p.(properties.NumberEntity)
case properties.TypeHeatingCoolingProperty:
device.HeatingCooling = p.(properties.StringEntity)
case properties.TypeThermostatModeProperty:
device.ThermostatMode = p.(properties.StringEntity)
}
device.Device.AddProperty(p)
}
}