forked from calaos/calaos-homekit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemperature.go
45 lines (35 loc) · 923 Bytes
/
temperature.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
41
42
43
44
45
package main
import (
"strconv"
"github.com/brutella/hap/accessory"
)
type Temp struct {
*accessory.Thermometer
}
const TypeTemperatureSensor = "8A"
func NewTemperatureSensor(cio CalaosIO, id uint64) *Temp {
acc := Temp{}
info := accessory.Info{
Name: cio.Name,
SerialNumber: cio.ID,
Manufacturer: "Calaos",
Model: cio.IoType,
}
acc.Thermometer = accessory.NewTemperatureSensor(info)
acc.Thermometer.Id = id
acc.Thermometer.TempSensor.CurrentTemperature.SetMinValue(-50)
acc.Thermometer.TempSensor.CurrentTemperature.SetMaxValue(50)
acc.Thermometer.TempSensor.CurrentTemperature.SetStepValue(0.1)
acc.Update(&cio)
return &acc
}
func (acc *Temp) Update(cio *CalaosIO) error {
t, err := strconv.ParseFloat(cio.State, 32)
if err == nil {
acc.TempSensor.CurrentTemperature.SetValue(t)
}
return err
}
func (acc *Temp) AccessoryGet() *accessory.A {
return acc.Thermometer.A
}