Files
hapz2m/s_contact_sensor.go
Darell Tan d4daef7bce Introduce constructors for ExposeMapping
This should allow the ExposeMapping struct to be changed without
constantly impacting its callers.
2024-11-24 15:25:17 +08:00

38 lines
880 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, NewTranslatedExposeMapping(&exp, s.ContactSensorState.C,
&BoolTranslator{
characteristic.ContactSensorStateContactNotDetected,
characteristic.ContactSensorStateContactDetected}))
}
}
return accessory.TypeSensor, svcs, exposes, nil
}
func init() {
RegisterCreateServiceHandler(createContactServices)
}