Skip to content

Commit

Permalink
Merge branch 'wip-stable7-1-005' into stable7
Browse files Browse the repository at this point in the history
  • Loading branch information
pipiche38 committed Nov 16, 2023
2 parents e1179aa + 991cd5e commit 9239e0c
Show file tree
Hide file tree
Showing 37 changed files with 864 additions and 448 deletions.
62 changes: 41 additions & 21 deletions Classes/GroupMgtv2/GrpDomoticz.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from Classes.GroupMgtv2.GrpCommands import (set_hue_saturation,
set_kelvin_color, set_rgb_color)
from Classes.GroupMgtv2.GrpDatabase import update_due_to_nwk_id_change
from Modules.tools import Hex_Format
from Modules.tools import Hex_Format, is_hex
from Modules.zigateConsts import ADDRESS_MODE, LEGRAND_REMOTES, ZIGATE_EP
from Zigbee.zclCommands import (zcl_group_level_move_to_level,
zcl_group_move_to_level_with_onoff,
Expand All @@ -19,6 +19,7 @@
zcl_group_onoff_on,
zcl_group_window_covering_off,
zcl_group_window_covering_on,
zcl_group_move_to_level_stop,
zcl_group_window_covering_stop)

WIDGET_STYLE = {
Expand Down Expand Up @@ -185,6 +186,7 @@ def best_group_widget(self, GroupId):
# }

GroupWidgetType = None
GroupWidgetStyle = None

self.logging("Debug", "best_group_widget Device - %s" % str(self.ListOfGroups[GroupId]["Devices"]))
for NwkId, devEp, iterIEEE in self.ListOfGroups[GroupId]["Devices"]:
Expand All @@ -194,7 +196,7 @@ def best_group_widget(self, GroupId):
if NwkId == "0000":
continue

self.logging("debug", "bestGroupWidget - Group: %s processing %s" % (GroupId, NwkId))
self.logging("Debug", "bestGroupWidget - Group: %s processing %s" % (GroupId, NwkId))
if NwkId not in self.ListOfDevices:
# We have some inconsistency !
continue
Expand All @@ -207,9 +209,13 @@ def best_group_widget(self, GroupId):
WidgetType = self.ListOfDevices[NwkId]["Ep"][devEp]["ClusterType"][DomoDeviceUnit]
self.logging("Debug", "------------ GroupWidget: %s WidgetType: %s" % (GroupWidgetType, WidgetType))

if WidgetType == "LvlControl" and "Blind" in self.ListOfDevices[NwkId]["Type"]:
GroupWidgetStyle = "BlindPercentInverted"

if WidgetType in ("VenetianInverted", "VanneInverted", "CurtainInverted"):
# Those widgets are commanded via cluster Level Control
GroupWidgetType = "LvlControl"
GroupWidgetStyle = "VenetianInverted"
continue

if GroupWidgetType is None and WidgetType in WIDGET_STYLE:
Expand Down Expand Up @@ -245,7 +251,6 @@ def best_group_widget(self, GroupId):
GroupWidgetType = WidgetType
continue


if WidgetType in ("Venetian", "WindowCovering", "BlindPercentInverted"):
GroupWidgetType = WidgetType

Expand Down Expand Up @@ -281,13 +286,13 @@ def best_group_widget(self, GroupId):
else:
self.ListOfGroups[GroupId]["Cluster"] = ""

self.logging(
"Debug",
"best_group_widget for GroupId: %s Found WidgetType: %s Widget: %s"
% (GroupId, GroupWidgetType, WIDGET_STYLE.get(GroupWidgetType, WIDGET_STYLE["ColorControlFull"])),
)
self.logging( "Debug", "best_group_widget for GroupId: %s Found WidgetType: %s Widget: %s" % (
GroupId, GroupWidgetType, WIDGET_STYLE.get(GroupWidgetType, WIDGET_STYLE["ColorControlFull"])), )

return WIDGET_STYLE.get(GroupWidgetType, WIDGET_STYLE["ColorControlFull"])
if GroupWidgetStyle is None:
GroupWidgetStyle = GroupWidgetType

return WIDGET_STYLE.get(GroupWidgetStyle, WIDGET_STYLE["ColorControlFull"])


def update_domoticz_group_device(self, GroupId):
Expand Down Expand Up @@ -317,7 +322,7 @@ def update_domoticz_group_device(self, GroupId):
if "Cluster" in self.ListOfGroups[GroupId]:
Cluster = self.ListOfGroups[GroupId]["Cluster"]

countOn = countOff = 0
countStop = countOn = countOff = 0
nValue = 0 if self.pluginconf.pluginConf["OnIfOneOn"] else 1
sValue = level = None
for NwkId, Ep, IEEE in self.ListOfGroups[GroupId]["Devices"]:
Expand Down Expand Up @@ -347,11 +352,13 @@ def update_domoticz_group_device(self, GroupId):
and Cluster in ("0006", "0008", "0300")
and "0006" in self.ListOfDevices[NwkId]["Ep"][Ep]
and "0000" in self.ListOfDevices[NwkId]["Ep"][Ep]["0006"]
and str(self.ListOfDevices[NwkId]["Ep"][Ep]["0006"]["0000"]).isdigit()
and is_hex( str(self.ListOfDevices[NwkId]["Ep"][Ep]["0006"]["0000"]) )
):
self.logging( "Debug", "update_domoticz_group_device - Cluster ON/OFF Group: %s NwkId: %s Ep: %s Value: %s" %(
GroupId, NwkId, Ep, self.ListOfDevices[NwkId]["Ep"][Ep]["0006"]["0000"]))
if int(self.ListOfDevices[NwkId]["Ep"][Ep]["0006"]["0000"]) != 0:
if str(self.ListOfDevices[NwkId]["Ep"][Ep]["0006"]["0000"]) == "f0":
countStop += 1
elif int(self.ListOfDevices[NwkId]["Ep"][Ep]["0006"]["0000"]) != 0:
countOn += 1
else:
countOff += 1
Expand Down Expand Up @@ -381,23 +388,31 @@ def update_domoticz_group_device(self, GroupId):
level = lvl_value if level is None else (level + lvl_value) // 2
nValue, sValue = ValuesForVenetian(level)

self.logging( "Debug", "update_domoticz_group_device - Processing: Group: %s %s/%s On: %s, Off: %s level: %s" % (
GroupId, NwkId, Ep, countOn, countOff, level), )
self.logging( "Debug", "update_domoticz_group_device - Processing: Group: %s %s/%s On: %s, Off: %s Stop: %s, level: %s" % (
GroupId, NwkId, Ep, countOn, countOff, countStop, level), )

if self.pluginconf.pluginConf["OnIfOneOn"]:
if countStop > 0:
nValue = 17
elif self.pluginconf.pluginConf["OnIfOneOn"]:
if countOn > 0:
nValue = 1
elif countOff > 0:
nValue = 0
self.logging( "Debug", "update_domoticz_group_device - Processing: Group: %s == > nValue: %s, level: %s" % (
GroupId, nValue, level), )


# At that stage
# nValue == 0 if Off
# nValue == 1 if Open/On
# nValue == 17 if Stop
# level is None, so we use nValue/sValue
# level is not None; so we have a LvlControl
if sValue is None and level:
if nValue == 17:
# Stop
sValue = "0"

elif sValue is None and level:
if self.Devices[unit].SwitchType not in (13, 14, 15, 16):
# Not a Shutter/Blind
analogValue = level
Expand Down Expand Up @@ -439,11 +454,8 @@ def update_domoticz_group_device(self, GroupId):
else:
sValue = "On"

self.logging(
"Debug",
"update_domoticz_group_device - Processing: Group: %s == > from %s:%s to %s:%s"
% (GroupId, self.Devices[unit].nValue, self.Devices[unit].sValue, nValue, sValue),
)
self.logging( "Debug", "update_domoticz_group_device - Processing: Group: %s == > from %s:%s to %s:%s" % (
GroupId, self.Devices[unit].nValue, self.Devices[unit].sValue, nValue, sValue), )
if nValue != self.Devices[unit].nValue or sValue != self.Devices[unit].sValue:
self.logging("Log", "UpdateGroup - (%15s) %s:%s" % (self.Devices[unit].Name, nValue, sValue))
self.Devices[unit].Update(nValue, sValue)
Expand Down Expand Up @@ -680,6 +692,14 @@ def processCommand(self, unit, GrpId, Command, Level, Color_):
sValue = "On"
self.Devices[unit].Update(nValue=int(nValue), sValue=str(sValue))

elif Command in ( "Stop",) and self.ListOfGroups[GrpId]["Cluster"] == "0102":
# Windowscovering Stop
zcl_group_window_covering_stop(self, GrpId, "01", EPout)

elif Command in ( "Stop",) and self.ListOfGroups[GrpId]["Cluster"] == "0008":
# SetLevel Off
zcl_group_move_to_level_stop(self, GrpId, EPout)

elif Command == "Set Level":
# Level: % value of move
# Converted to value , raw value from 0 to 255
Expand Down
1 change: 1 addition & 0 deletions Classes/PluginConf.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@
"ThreadWriter": {"type": "bool","default": 0,"current": None,"restart": 0,"hidden": False,"Advanced": True,},
"ThreadCommunication": {"type": "bool","default": 0,"current": None,"restart": 0,"hidden": False,"Advanced": True,},
"ZLinky": {"type": "bool","default": 0,"current": None,"restart": 0,"hidden": False,"Advanced": True,},
"Garbage": {"type": "bool","default": 0,"current": None,"restart": 0,"hidden": True,"Advanced": True,},
},
},
# Others
Expand Down
8 changes: 6 additions & 2 deletions Classes/ZigpyTransport/AppBellows.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env python3btt.
# coding: utf-8 -*-
#
# Author: deufo, badz & pipiche38
Expand All @@ -8,6 +8,7 @@

import bellows.config as bellows_conf
import bellows.types as t
import zigpy.types as zigpy_t
import bellows.zigbee.application
import zigpy.config as zigpy_conf
import zigpy.device
Expand Down Expand Up @@ -148,6 +149,9 @@ def handle_leave(self, nwk, ieee):
def get_zigpy_version(self):
return Classes.ZigpyTransport.AppGeneric.get_zigpy_version(self)

def packet_received(self, packet: zigpy_t.ZigbeePacket) -> None:
return Classes.ZigpyTransport.AppGeneric.packet_received(self,packet)

def handle_message(
self,
sender: zigpy.device.Device,
Expand All @@ -160,7 +164,7 @@ def handle_message(
dst_addressing=None,
)->None:
return Classes.ZigpyTransport.AppGeneric.handle_message(self,sender,profile,cluster,src_ep,dst_ep,message, dst_addressing=dst_addressing)

async def set_zigpy_tx_power(self, power):
# EmberConfigTxPowerMode - EZSP_CONFIG_TX_POWER_MODE in EzspConfigId
# 0x00: Normal mode
Expand Down
3 changes: 3 additions & 0 deletions Classes/ZigpyTransport/AppDeconz.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ def get_device_ieee(self, nwk):
def handle_leave(self, nwk, ieee):
Classes.ZigpyTransport.AppGeneric.handle_leave(self, nwk, ieee)

def packet_received(self, packet: t.ZigbeePacket) -> None:
return Classes.ZigpyTransport.AppGeneric.packet_received(self,packet)

def handle_message(
self,
sender: zigpy.device.Device,
Expand Down
Loading

0 comments on commit 9239e0c

Please sign in to comment.