-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.go
35 lines (29 loc) · 864 Bytes
/
settings.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
package homlet
import "github.com/pkg/errors"
// DeviceSettings represents settings for a specific device
type DeviceSettings struct {
ID int // device id
Room string // room where device is located
Sensors []*SensorSettings
}
// SensorSettings represents settings for a specific sensor
type SensorSettings struct {
Name string
Correction float64 // correction to apply to sensor value
Disable bool // disable that sensor
Domoticz int // domoticz idx
}
// Sensor returns sensor settings
func (ds *DeviceSettings) Sensor(sensor Sensor) (*SensorSettings, error) {
for _, sensorSettings := range ds.Sensors {
s, err := SensorString(sensorSettings.Name)
if err != nil {
return nil, errors.Wrap(err, "unexpected sensor name")
}
if s == sensor {
return sensorSettings, nil
}
}
// not found
return nil, nil
}