-
Notifications
You must be signed in to change notification settings - Fork 3
/
humidity.go
44 lines (35 loc) · 902 Bytes
/
humidity.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
package main
import (
"strconv"
"github.com/brutella/hap/accessory"
"github.com/brutella/hap/service"
)
type Humidity struct {
*accessory.A
HumiditySensor *service.HumiditySensor
}
func NewHumiditySensor(cio CalaosIO, id uint64) *Humidity {
acc := Humidity{}
// info := accessory.Info{
// Name: cio.Name,
// SerialNumber: cio.ID,
// Manufacturer: "Calaos",
// Model: cio.IoType,
// }
// acc.A = accessory.NewHumidifier(info).A
acc.HumiditySensor = service.NewHumiditySensor()
acc.HumiditySensor.Id = id
acc.Update(&cio)
return &acc
}
func (acc *Humidity) Update(cio *CalaosIO) error {
if h, err := strconv.ParseFloat(cio.State, 32); err == nil {
acc.HumiditySensor.CurrentRelativeHumidity.SetValue(h)
} else {
acc.HumiditySensor.CurrentRelativeHumidity.SetValue(0.0)
}
return nil
}
func (acc *Humidity) AccessoryGet() *accessory.A {
return acc.A
}