mirror of
https://github.com/nikdoof/hapz2m.git
synced 2026-01-30 15:08:19 +00:00
"Initial" working version, after cleanup.
This commit is contained in:
53
s_climate_sensors.go
Normal file
53
s_climate_sensors.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package hapz2m
|
||||
|
||||
import (
|
||||
"github.com/brutella/hap/accessory"
|
||||
"github.com/brutella/hap/service"
|
||||
)
|
||||
|
||||
func createClimateServices(dev *Device) (byte, []*service.S, []*ExposeMapping, error) {
|
||||
var svcs []*service.S
|
||||
var exposes []*ExposeMapping
|
||||
|
||||
for _, exp := range dev.Definition.Exposes {
|
||||
if exp.Ignored() {
|
||||
continue
|
||||
}
|
||||
|
||||
// climate sensors are numeric only
|
||||
if exp.Type != "numeric" {
|
||||
continue
|
||||
}
|
||||
|
||||
exp := exp // create a copy
|
||||
|
||||
switch {
|
||||
case exp.Name == "temperature":
|
||||
s := service.NewTemperatureSensor()
|
||||
|
||||
// doesn't do anything, since the Home app seem to round values to 0.25 increments regardless
|
||||
// https://developer.apple.com/forums/thread/674461
|
||||
// https://github.com/home-assistant/core/issues/45332
|
||||
s.CurrentTemperature.SetStepValue(0.01)
|
||||
|
||||
svcs = append(svcs, s.S)
|
||||
exposes = append(exposes, &ExposeMapping{&exp, s.CurrentTemperature.C, nil})
|
||||
|
||||
case exp.Name == "humidity":
|
||||
s := service.NewHumiditySensor()
|
||||
s.CurrentRelativeHumidity.SetStepValue(0.01) // ditto, but 1% increments
|
||||
svcs = append(svcs, s.S)
|
||||
exposes = append(exposes, &ExposeMapping{&exp, s.CurrentRelativeHumidity.C, nil})
|
||||
|
||||
case exp.Name == "pressure":
|
||||
// TODO looks like pressure is not standard in HomeKit
|
||||
// Eve has custom UUIDs: https://gist.github.com/simont77/3f4d4330fa55b83f8ca96388d9004e7d
|
||||
}
|
||||
}
|
||||
|
||||
return accessory.TypeSensor, svcs, exposes, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
RegisterCreateServiceHandler(createClimateServices)
|
||||
}
|
||||
Reference in New Issue
Block a user