From daefce5cb0efbcea9e902739aad29f4e875a566b Mon Sep 17 00:00:00 2001 From: Patrick Pichon Date: Tue, 17 Oct 2023 18:59:30 +0200 Subject: [PATCH] Trying tweak --- Conf/Local-Devices/TS0505A.json | 6 +++- Modules/actuators.py | 52 ++++++++++++++++++++++++++++----- Modules/readAttributes.py | 7 +++++ 3 files changed, 57 insertions(+), 8 deletions(-) diff --git a/Conf/Local-Devices/TS0505A.json b/Conf/Local-Devices/TS0505A.json index 53a895f1b..7e58781c8 100644 --- a/Conf/Local-Devices/TS0505A.json +++ b/Conf/Local-Devices/TS0505A.json @@ -19,6 +19,7 @@ "000a": "", "0019": "", "1000": "", + "ef00": "", "Type": "ColorControlRGBWW" }, "f2": { @@ -39,5 +40,8 @@ "0300": [ "f002", "f00d", "0000", "0001", "0003", "0004", "0007", "0008", "000f" ] }, "TUYA_REGISTRATION": 19, - "TUYAColorControlRgbMode": true + "TUYAColorControlRgbMode": true, + "Param": { + "ResetTuyaTS0505A": 1 + } } diff --git a/Modules/actuators.py b/Modules/actuators.py index 849c99e7e..47402958e 100644 --- a/Modules/actuators.py +++ b/Modules/actuators.py @@ -10,17 +10,16 @@ """ - - - - import json from Modules.basicOutputs import set_poweron_afteroffon -from Modules.readAttributes import ReadAttributeRequest_0006_400x +from Modules.paramDevice import get_device_config_param +from Modules.readAttributes import ( + ReadAttributeRequest_0006_400x, + ReadAttributeRequest_0300_Color_Capabilities) from Modules.thermostats import thermostat_Setpoint from Modules.tools import (Hex_Format, get_deviceconf_parameter_value, - rgb_to_hsl, rgb_to_xy) + getAttributeValue, rgb_to_hsl, rgb_to_xy) from Modules.tuya import (tuya_color_control_rgbMode, tuya_Move_To_Hue_Saturation_Brightness) from Modules.zigateConsts import ZIGATE_EP @@ -249,7 +248,8 @@ def actuator_setcolor(self, nwkid, EPout, value, Color): transitionMoveLevel = "%04x" % int(self.ListOfDevices[nwkid]["Param"]["moveToLevel"]) force_color_command = get_deviceconf_parameter_value(self, self.ListOfDevices[nwkid]["Model"], "FORCE_COLOR_COMMAND", return_default=None) - + ColorCapabilitiesList = device_color_capabilities( self, nwkid, EPout) + # ColorModeTemp = 2 // White with color temperature. Valid fields: t if Hue_List["m"] == 2: handle_color_mode_2(self, nwkid, EPout, Hue_List) @@ -290,6 +290,12 @@ def handle_color_mode_3(self, nwkid, EPout, Hue_List): transitionMoveLevel , transitionRGB , transitionMoveLevel , transitionHue , transitionTemp = get_all_transition_mode( self, nwkid) if get_deviceconf_parameter_value(self, self.ListOfDevices[nwkid]["Model"], "TUYAColorControlRgbMode", return_default=None): tuya_color_control_rgbMode( self, nwkid, "01") + + + if get_device_config_param( self, nwkid, "ResetTuyaTS0505A"): + tuya_Move_To_Hue_Saturation_Brightness( self, nwkid, 300, 100, 50) + + zcl_move_to_colour(self, nwkid, EPout, Hex_Format(4, x), Hex_Format(4, y), transitionRGB) def handle_color_mode_4(self, nwkid, EPout, Hue_List ): @@ -367,3 +373,35 @@ def actuator_identify(self, nwkid, ep, value=None): color = 0x03 # Blue zcl_identify_trigger_effect( self, nwkid, ep, "%02x" % value, "%02x" % color) + + +def decode_color_capabilities(capabilities_value): + capabilities = { + "Hue and Saturation": 0b00000000_00000001, + "Enhanced Hue": 0b00000000_00000010, + "Color Loop": 0b00000000_00000100, + "XY Attributes": 0b00000000_00001000, + "Color Temperature": 0b00000000_00010000 + } + + return [ + feature + for feature, bitmask in capabilities.items() + if capabilities_value & bitmask + ] + +def device_color_capabilities( self, nwkid, ep): + self.log.logging( "Command", "Debug", "device_color_capabilities %s %s" % (nwkid, ep), nwkid) + deviceHasNoColorCapabilities = get_deviceconf_parameter_value(self, self.ListOfDevices[nwkid]["Model"], "NoColorCapabilitie", return_default=None) + colorCapabilities = getAttributeValue( self, nwkid, ep, "0300", "400a") + + self.log.logging( "Command", "Debug", "+ deviceHasColorCapabilities %s" % (deviceHasNoColorCapabilities), nwkid) + self.log.logging( "Command", "Debug", "+ colorCapabilities %s" % (colorCapabilities), nwkid) + + if colorCapabilities is None and deviceHasNoColorCapabilities: + return [] + if colorCapabilities is None or isinstance( colorCapabilities, str): + ReadAttributeRequest_0300_Color_Capabilities(self, nwkid) + return [] + + return decode_color_capabilities(colorCapabilities) \ No newline at end of file diff --git a/Modules/readAttributes.py b/Modules/readAttributes.py index 6e5a33195..5b67c4dc2 100644 --- a/Modules/readAttributes.py +++ b/Modules/readAttributes.py @@ -999,7 +999,14 @@ def ReadAttributeRequest_0300(self, key): ) ReadAttributeReq(self, key, ZIGATE_EP, EPout, "0300", listAttributes, ackIsDisabled=is_ack_tobe_disabled(self, key)) +def ReadAttributeRequest_0300_Color_Capabilities(self, key): + # Cluster 0x0300 - Color Control + self.log.logging("ReadAttributes", "Debug", "ReadAttributeRequest_0300_Color_Capabilities - Key: %s " % key, nwkid=key) + ListOfEp = getListOfEpForCluster(self, key, "0300") + for EPout in ListOfEp: + ReadAttributeReq(self, key, ZIGATE_EP, EPout, "0300", [ 0x400A], ackIsDisabled=is_ack_tobe_disabled(self, key)) + def ReadAttributeRequest_0400(self, key): self.log.logging("ReadAttributes", "Debug", "ReadAttributeRequest_0400 - Key: %s " % key, nwkid=key)