Skip to content
Snippets Groups Projects
Commit 6fcdc0de authored by KERDREUX Jerome's avatar KERDREUX Jerome
Browse files

New devices

- Added motion sensors
- Added Luxmeter
parent bc72b239
No related branches found
No related tags found
No related merge requests found
...@@ -53,6 +53,14 @@ type ButtonRemote struct { ...@@ -53,6 +53,14 @@ type ButtonRemote struct {
XAALDevice XAALDevice
} }
type Motion struct {
XAALDevice
}
type LuxMeter struct {
XAALDevice
}
type XAALDeviceInterface interface { type XAALDeviceInterface interface {
update(map[string]interface{}) update(map[string]interface{})
GetXAALDevice() *xaal.Device GetXAALDevice() *xaal.Device
...@@ -445,3 +453,36 @@ func (dev *ButtonRemote) getButtons(xaal.MessageBody) *xaal.MessageBody { ...@@ -445,3 +453,36 @@ func (dev *ButtonRemote) getButtons(xaal.MessageBody) *xaal.MessageBody {
} }
return &body return &body
} }
// =============================================================================
// Motion
// =============================================================================
func NewMotion(addr uuid.UUID, zDev *Z2MDevice, exp *Expose) XAALDeviceInterface {
dev := &Motion{XAALDevice{schemas.NewMotion(addr), zDev, exp}}
dev.setup()
return dev
}
func (dev *Motion) update(payload map[string]interface{}) {
value, exists := payload[dev.Expose.Name].(bool)
if exists {
dev.GetAttribute("presence").SetValue(value)
}
}
// =============================================================================
// LuxMeter
// =============================================================================
func NewLuxMeter(addr uuid.UUID, zDev *Z2MDevice, exp *Expose) XAALDeviceInterface {
dev := &LuxMeter{XAALDevice{schemas.NewLuxmeter(addr), zDev, exp}}
dev.GetAttribute("illuminance").Value = 0 // override
dev.setup()
return dev
}
func (dev *LuxMeter) update(payload map[string]interface{}) {
lux, err := convertToInt(payload[dev.Expose.Name])
if err == nil {
dev.GetAttribute("illuminance").SetValue(lux)
}
}
...@@ -111,6 +111,8 @@ func (zDev *Z2MDevice) FindXAALDevices(gw *Gateway) { ...@@ -111,6 +111,8 @@ func (zDev *Z2MDevice) FindXAALDevices(gw *Gateway) {
"action": NewButtonRemote, "action": NewButtonRemote,
"switch": NewPowerRelay, "switch": NewPowerRelay,
"light": NewLamp, "light": NewLamp,
"occupancy": NewMotion,
"illuminance": NewLuxMeter,
} }
// Search a matching expose name // Search a matching expose name
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment