-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdevice.go
34 lines (31 loc) · 1.08 KB
/
device.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
package gotado
import (
"context"
"fmt"
)
// GetTemperatureOffset returns the temperature offsets of the device
func (d *Device) GetTemperatureOffset(ctx context.Context) (float32, error) {
temperatureOffset := &TemperatureOffset{}
if err := d.client.get(ctx, apiURL("devices/%s/temperatureOffset", d.SerialNo), &temperatureOffset); err != nil {
return 0, err
}
switch d.home.TemperatureUnit {
case TemperatureUnitCelsius:
return temperatureOffset.Celsius, nil
case TemperatureUnitFahrenheit:
return temperatureOffset.Fahrenheit, nil
default:
return 0, fmt.Errorf("unknown temperature unit: %s", d.home.TemperatureUnit)
}
}
// SetTemperatureOffset updates the temperature offsets of the device
func (d *Device) SetTemperatureOffset(ctx context.Context, temperatureOffset float32) error {
offset := &TemperatureOffset{}
switch d.home.TemperatureUnit {
case TemperatureUnitCelsius:
offset.Celsius = temperatureOffset
case TemperatureUnitFahrenheit:
offset.Fahrenheit = temperatureOffset
}
return d.client.put(ctx, apiURL("devices/%s/temperatureOffset", d.SerialNo), offset)
}