Skip to content

Commit

Permalink
Take into account @Bl34 sniff. Use MovetoHueSaturation (with a bright…
Browse files Browse the repository at this point in the history
…ness at the end ???)
  • Loading branch information
pipiche38 committed Oct 22, 2023
1 parent cc31b01 commit 64c968c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
5 changes: 3 additions & 2 deletions Conf/Local-Devices/TS0505A.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@
"0019": [],
"0300": [ "f002", "f00d", "0000", "0001", "0003", "0004", "0007", "0008", "000f" ]
},
"TUYA_REGISTRATION": 19,
"TUYA_REGISTRATION": 13,
"TuyaCommandF0": true,
"TUYAColorControlRgbMode": true,
"Param": {
"moveToColourTemp": "0010",
"moveToColourRGB": "0010",
"moveToHueSatu": "0010"
"moveToHueSatu": "0000"
}
}
27 changes: 23 additions & 4 deletions Modules/actuators.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from Modules.tools import (Hex_Format, get_deviceconf_parameter_value,
getAttributeValue, rgb_to_hsl, rgb_to_xy)
from Modules.tuya import (tuya_color_control_rgbMode,
tuya_Move_To_Hue_Saturation,
tuya_Move_To_Hue_Saturation_Brightness)
from Modules.zigateConsts import ZIGATE_EP
from Zigbee.zclCommands import (zcl_identify_send, zcl_identify_trigger_effect,
Expand Down Expand Up @@ -249,14 +250,13 @@ def actuator_setcolor(self, nwkid, EPout, value, Color):

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)



if Hue_List["m"] == 2:
# ColorModeTemp = 2 // White with color temperature. Valid fields: t
handle_color_mode_2(self, nwkid, EPout, Hue_List)

elif Hue_List["m"] == 3 and force_color_command == "TuyaMovetoHueandSaturation":
handle_color_mode_4( self, nwkid, EPout, Hue_List)
handle_color_mode_tuya( self, nwkid, EPout, Hue_List)

elif Hue_List["m"] == 3:
# ColorModeRGB = 3 // Color. Valid fields: r, g, b.
Expand Down Expand Up @@ -338,13 +338,32 @@ def handle_color_mode_9998( self, nwkid, EPout, Hue_List, value):
tuya_color_control_rgbMode( self, nwkid, "01")

if get_deviceconf_parameter_value(self, self.ListOfDevices[nwkid]["Model"], "FORCE_COLOR_COMMAND", return_default=None) == "TuyaMovetoHueandSaturation":
tuya_Move_To_Hue_Saturation_Brightness( self, nwkid, hue, saturation, value)
tuya_Move_To_Hue_Saturation( self, nwkid, hue, saturation, value)
else:
zcl_move_hue_and_saturation(self, nwkid, EPout, Hex_Format(2, hue), Hex_Format(2, saturation), transitionRGB)
value = lightning_percentage_to_analog( value )
self.log.logging( "Command", "Debug", "handle_color_mode_9998 Set Level: %s instead of Level: %s" % (value, value), nwkid)
actuator_setlevel(self, nwkid, EPout, value, "Light", transitionMoveLevel)


def handle_color_mode_tuya( self, nwkid, EPout, Hue_List, value):

self.log.logging("Command", "Debug", "handle_color_mode_tuya Hue_list: %s Value: %s" % (
Hue_List, value), nwkid)

transitionMoveLevel , transitionRGB , transitionMoveLevel , transitionHue , transitionTemp = get_all_transition_mode( self, nwkid)
_h, _s, brightness = rgb_to_hsl((int(Hue_List["r"]), int(Hue_List["g"]), int(Hue_List["b"])))
saturation = _s * 100 # 0 > 100
saturation = int(saturation * 254 // 100)
hue = _h * 360 # 0 > 360
hue = int(hue * 254 // 360)

self.log.logging("Command", "Log", "handle_color_mode_tuya Set Hue X: %s Saturation: %s Brightness: %s Value: %s" % (
hue, saturation, brightness, value), nwkid)
if get_deviceconf_parameter_value(self, self.ListOfDevices[nwkid]["Model"], "TUYAColorControlRgbMode", return_default=None):
tuya_color_control_rgbMode( self, nwkid, "01")
tuya_Move_To_Hue_Saturation_Brightness( self, nwkid, EPout, hue, saturation, transitionHue, brightness)

def actuator_identify(self, nwkid, ep, value=None):

if value is None:
Expand Down
8 changes: 6 additions & 2 deletions Modules/pairingProcess.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,8 @@ def handle_device_specific_needs(self, Devices, NWKID):

elif self.ListOfDevices[NWKID]["Model"] in ( "TS0222", "TS0002_relay_switch", "TS0003_relay_switch", 'TS0601-motion'):
tuya_command_f0( self, NWKID )



elif self.ListOfDevices[NWKID]["Model"] in (
"TS0601-Energy",
"TS0601-switch",
Expand Down Expand Up @@ -692,7 +693,10 @@ def handle_device_specific_needs(self, Devices, NWKID):
elif self.ListOfDevices[NWKID]["Model"] == "lumi.remote.b28ac1":
enable_click_mode_aqara( self, NWKID )
enableOppleSwitch( self, NWKID )


if get_deviceconf_parameter_value( self, NWKID, "TuyaCommandF0"):
tuya_command_f0( self, NWKID )

if get_deviceconf_parameter_value(self, self.ListOfDevices[NWKID]["Model"], "LightingColorControl", return_default=None):
tuya_lighting_color_control(self, NWKID)

Expand Down
16 changes: 14 additions & 2 deletions Modules/tuya.py
Original file line number Diff line number Diff line change
Expand Up @@ -1535,9 +1535,21 @@ def tuya_color_control_rgbMode( self, NwkId, mode):
payload = "11" + sqn + "f0" + mode
raw_APS_request(self, NwkId, "01", "0300", "0104", payload, zigpyzqn=sqn, zigate_ep=ZIGATE_EP, ackIsDisabled=False)

def tuya_Move_To_Hue_Saturation( self, NwkId, hue, saturation, transition, brightness):
# Command 0x06
self.log.logging("Tuya", "Debug", "tuya_Move_To_Hue_Saturation", NwkId)

hue = "%04x" % struct.unpack("H", struct.pack(">H", hue, ))[0]
saturation = "%04x" % struct.unpack("H", struct.pack(">H", saturation))[0]
transition = "%04x" % struct.unpack("H", struct.pack(">H", transition, ))[0]
brightness = "%02x" % brightness
sqn = get_and_inc_ZCL_SQN(self, NwkId)
payload = "11" + sqn + "06" + hue + saturation + + transition + brightness

raw_APS_request(self, NwkId, "01", "0300", "0104", payload, zigpyzqn=sqn, zigate_ep=ZIGATE_EP, ackIsDisabled=False)


def tuya_Move_To_Hue_Saturation_Brightness( self, NwkId, hue, saturation, brightness):
def tuya_Move_To_Hue_Saturation_Brightness( self, NwkId, epout, hue, saturation, brightness):
# Command 0xe1
self.log.logging("Tuya", "Debug", "tuya_Move_To_Hue_Saturation_Brightness", NwkId)

Expand All @@ -1547,4 +1559,4 @@ def tuya_Move_To_Hue_Saturation_Brightness( self, NwkId, hue, saturation, bright
sqn = get_and_inc_ZCL_SQN(self, NwkId)
payload = "11" + sqn + "e1" + hue + saturation + brightness

raw_APS_request(self, NwkId, "01", "0300", "0104", payload, zigpyzqn=sqn, zigate_ep=ZIGATE_EP, ackIsDisabled=False)
raw_APS_request(self, NwkId, epout, "0300", "0104", payload, zigpyzqn=sqn, zigate_ep=ZIGATE_EP, ackIsDisabled=False)

0 comments on commit 64c968c

Please sign in to comment.