From 0d237a3da10dd241f25d12afedd39ae09b87ab40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Harald=20=C3=98ymyr?= Date: Thu, 17 Feb 2022 23:38:16 +0100 Subject: [PATCH] Improved support for window covering devices and whitelisted Aqara Roller Shade Driver E1 --- src/conbee/types.go | 1 + src/utils/utils.go | 2 ++ src/zigbee/fimp-to-conbee.go | 13 ++++++------- src/zigbee/net-service.go | 25 +++++++++++++++++++++++-- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/conbee/types.go b/src/conbee/types.go index 3507afb..807ff1c 100644 --- a/src/conbee/types.go +++ b/src/conbee/types.go @@ -3,6 +3,7 @@ package conbee const ( DeviceTypeWindowCoveringController = "Window covering controller" DeviceTypeWindowCoveringDevice = "Window covering device" + WindowCoveringDeviceWhitelist = "lumi.curtain.acn002" ) type FullState struct { diff --git a/src/utils/utils.go b/src/utils/utils.go index e322bed..111a89c 100644 --- a/src/utils/utils.go +++ b/src/utils/utils.go @@ -2,8 +2,10 @@ package utils import ( "fmt" + "github.com/alivinco/conbee-ad/conbee" "io" "os" + "strings" ) func FileExists(filename string) bool { diff --git a/src/zigbee/fimp-to-conbee.go b/src/zigbee/fimp-to-conbee.go index b78c17a..07630e5 100644 --- a/src/zigbee/fimp-to-conbee.go +++ b/src/zigbee/fimp-to-conbee.go @@ -3,6 +3,7 @@ package zigbee import ( "github.com/alivinco/conbee-ad/conbee" "github.com/alivinco/conbee-ad/model" + "github.com/alivinco/conbee-ad/utils" "github.com/futurehomeno/fimpgo" "github.com/futurehomeno/fimpgo/edgeapp" log "github.com/sirupsen/logrus" @@ -63,7 +64,7 @@ func (fc *FimpToConbeeRouter) routeFimpMessage(newMsg *fimpgo.Message) { val,_ := newMsg.Payload.GetBoolValue() dev := fc.conbeeClient.GetLightById(addr) var req interface{} - if dev.Type == conbee.DeviceTypeWindowCoveringController || dev.Type == conbee.DeviceTypeWindowCoveringDevice { + if utils.IsWindowCoveringType(dev) { req = conbee.WindowCoveringRequest{Open: &val} }else { req = conbee.ConnbeeLightRequest{On:val} @@ -75,7 +76,7 @@ func (fc *FimpToConbeeRouter) routeFimpMessage(newMsg *fimpgo.Message) { if err != nil { log.Error("Response error ",err) }else { - if dev.Type == conbee.DeviceTypeWindowCoveringController || dev.Type == conbee.DeviceTypeWindowCoveringDevice { + if utils.IsWindowCoveringType(dev) { msg := fimpgo.NewBoolMessage("evt.binary.report", "out_lvl_switch", val, nil, nil, nil) adr := &fimpgo.Address{MsgType: fimpgo.MsgTypeEvt, ResourceType: fimpgo.ResourceTypeDevice, ResourceName: "conbee", ResourceAddress: fc.configs.InstanceAddress, ServiceName: "out_lvl_switch", ServiceAddress: newMsg.Addr.ServiceAddress} fc.mqt.Publish(adr, msg) @@ -89,7 +90,7 @@ func (fc *FimpToConbeeRouter) routeFimpMessage(newMsg *fimpgo.Message) { //x = A * 100 / 255 var req interface{} dev := fc.conbeeClient.GetLightById(addr) - if dev.Type == conbee.DeviceTypeWindowCoveringController || dev.Type == conbee.DeviceTypeWindowCoveringDevice { + if utils.IsWindowCoveringType(dev) { lvl := int(val) req = conbee.WindowCoveringRequest{Lift: &lvl} }else { @@ -101,7 +102,7 @@ func (fc *FimpToConbeeRouter) routeFimpMessage(newMsg *fimpgo.Message) { if err != nil { log.Error("Response error ",err) }else { - if dev.Type == conbee.DeviceTypeWindowCoveringController || dev.Type == conbee.DeviceTypeWindowCoveringDevice { + if utils.IsWindowCoveringType(dev) { msg := fimpgo.NewIntMessage("evt.lvl.report", "out_lvl_switch", val, nil, nil, nil) adr := &fimpgo.Address{MsgType: fimpgo.MsgTypeEvt, ResourceType: fimpgo.ResourceTypeDevice, ResourceName: "conbee", ResourceAddress: fc.configs.InstanceAddress, ServiceName: "out_lvl_switch", ServiceAddress: newMsg.Addr.ServiceAddress} fc.mqt.Publish(adr, msg) @@ -109,7 +110,7 @@ func (fc *FimpToConbeeRouter) routeFimpMessage(newMsg *fimpgo.Message) { } case "cmd.lvl.stop": dev := fc.conbeeClient.GetLightById(addr) - if dev.Type == conbee.DeviceTypeWindowCoveringController || dev.Type == conbee.DeviceTypeWindowCoveringDevice { + if utils.IsWindowCoveringType(dev) { state := true req := conbee.WindowCoveringRequest{Stop: &state} var resp interface{} @@ -284,5 +285,3 @@ func (fc *FimpToConbeeRouter) routeFimpMessage(newMsg *fimpgo.Message) { } } - - diff --git a/src/zigbee/net-service.go b/src/zigbee/net-service.go index be2aff1..8c9974c 100644 --- a/src/zigbee/net-service.go +++ b/src/zigbee/net-service.go @@ -258,6 +258,21 @@ func (ns *NetworkService) SendInclusionReport(deviceType, deviceId string) error Interfaces: outLvlSwitchInterfaces, } + windowCoveringService := fimptype.Service{ + Name: "out_lvl_switch", + Alias: "Light control", + Address: "/rt:dev/rn:conbee/ad:1/sv:out_lvl_switch/ad:", + Enabled: true, + Groups: []string{"ch_0"}, + Props: map[string]interface{}{ + "max_lvl": 100, + "min_lvl": 0, + }, + Tags: nil, + PropSetReference: "", + Interfaces: outLvlSwitchInterfaces, + } + tempSensorService := fimptype.Service{ Name: "sensor_temp", Alias: "Temperature sensor", @@ -350,8 +365,14 @@ func (ns *NetworkService) SendInclusionReport(deviceType, deviceId string) error swVersion = lightDeviceDescriptor.Swversion serialNr = lightDeviceDescriptor.Uniqueid serviceAddres := "l"+deviceId+"_0" - outLvlSwitchService.Address = outLvlSwitchService.Address + serviceAddres - services = append(services,outLvlSwitchService) + + if !utils.IsWindowCoveringType(lightDeviceDescriptor) { + outLvlSwitchService.Address = outLvlSwitchService.Address + serviceAddres + services = append(services, outLvlSwitchService) + } else { + windowCoveringService.Address = windowCoveringService.Address + serviceAddres + services = append(services, windowCoveringService) + } } powerSource = "ac" deviceId = "l"+deviceId