mirror of
https://github.com/nikdoof/hapz2m.git
synced 2026-01-30 19:48:26 +00:00
"Initial" working version, after cleanup.
This commit is contained in:
37
s_contact_sensor.go
Normal file
37
s_contact_sensor.go
Normal file
@@ -0,0 +1,37 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user