Files
hapz2m/s_contact_sensor.go
2023-04-26 23:20:07 +08:00

38 lines
868 B
Go

package hapz2m
import (
"github.com/brutella/hap/accessory"
"github.com/brutella/hap/characteristic"
"github.com/brutella/hap/service"
)
func createContactServices(dev *Device) (byte, []*service.S, []*ExposeMapping, error) {
var svcs []*service.S
var exposes []*ExposeMapping
for _, exp := range dev.Definition.Exposes {
if exp.Ignored() {
continue
}
switch {
case exp.Type == "binary" && exp.Name == "contact":
exp := exp // create a copy
s := service.NewContactSensor()
svcs = append(svcs, s.S)
exposes = append(exposes, &ExposeMapping{&exp, s.ContactSensorState.C,
&BoolTranslator{
characteristic.ContactSensorStateContactNotDetected,
characteristic.ContactSensorStateContactDetected}})
}
}
return accessory.TypeSensor, svcs, exposes, nil
}
func init() {
RegisterCreateServiceHandler(createContactServices)
}