mirror of
https://github.com/nikdoof/hapz2m.git
synced 2026-01-30 02:18:22 +00:00
This should allow the ExposeMapping struct to be changed without constantly impacting its callers.
37 lines
831 B
Go
37 lines
831 B
Go
package hapz2m
|
|
|
|
import (
|
|
"github.com/brutella/hap/accessory"
|
|
"github.com/brutella/hap/service"
|
|
)
|
|
|
|
// there isn't a distinction between motion and occupancy sensors in z2m,
|
|
// but most sensors are PIR, so they are technically motion sensors
|
|
|
|
func createMotionServices(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 == "occupancy":
|
|
exp := exp // create a copy
|
|
|
|
s := service.NewMotionSensor()
|
|
|
|
svcs = append(svcs, s.S)
|
|
exposes = append(exposes, NewExposeMapping(&exp, s.MotionDetected.C))
|
|
}
|
|
}
|
|
|
|
return accessory.TypeSensor, svcs, exposes, nil
|
|
}
|
|
|
|
func init() {
|
|
RegisterCreateServiceHandler(createMotionServices)
|
|
}
|