Skip to content

Commit

Permalink
still wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pipiche38 committed Oct 15, 2023
1 parent ef020cf commit 6d3a256
Showing 1 changed file with 8 additions and 43 deletions.
51 changes: 8 additions & 43 deletions Modules/actuators.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,23 +221,6 @@ def get_all_transition_mode( self, Nwkid):
transitionHue = "%04x" % int(self.ListOfDevices[Nwkid]["Param"]["moveToHueSatu"])
return transitionMoveLevel , transitionRGB , transitionMoveLevel ,transitionHue , transitionTemp

def rgb_to_hsv(r, g, b):
r, g, b = r/255.0, g/255.0, b/255.0
mx = max(r, g, b)
mn = min(r, g, b)
df = mx-mn
if mx == mn:
h = 0
elif mx == r:
h = (60 * ((g-b)/df) + 360) % 360
elif mx == g:
h = (60 * ((b-r)/df) + 120) % 360
elif mx == b:
h = (60 * ((r-g)/df) + 240) % 360
s = 0 if mx == 0 else (df/mx)*100
v = mx*100
return int(h), int(s), int(v)

def actuator_setcolor(self, nwkid, EPout, value, Color):

Hue_List = json.loads(Color)
Expand All @@ -259,30 +242,14 @@ def actuator_setcolor(self, nwkid, EPout, value, Color):
if ( "Param" in self.ListOfDevices[nwkid] and "moveToLevel" in self.ListOfDevices[nwkid]["Param"] ):
transitionMoveLevel = "%04x" % int(self.ListOfDevices[nwkid]["Param"]["moveToLevel"])

#if Hue_List["m"] or Hue_List["m"] != 9998:
# value = lightning_percentage_to_analog( value )
# self.log.logging("Command", "Debug", "---------- Set Level: %s" % (value), nwkid)
# actuator_setlevel(self, nwkid, EPout, value, "Light", transitionMoveLevel)


force_color_command = get_deviceconf_parameter_value(self, self.ListOfDevices[nwkid]["Model"], "FORCE_COLOR_COMMAND", return_default=None)
#if force_color_command == "MovetoHueandSaturation":
# # "FORCE_COLOR_COMMAND": "MovetoHueandSaturation",
# transitionMoveLevel , transitionRGB , _ , _ , _ = get_all_transition_mode( self, nwkid)
# r = int(Hue_List["r"])
# g = int(Hue_List["g"])
# b = int(Hue_List["b"])
# hue, saturation, brightness = rgb_to_hsv( r, g, b )
# self.log.logging("Command", "Debug", "MovetoHueandSaturation (%s,%s,%s) Set Hue X: %s Saturation: %s Brightness: %s" % (
# r, g, b, hue, saturation, brightness), nwkid)
# zcl_move_hue_and_saturation(self, nwkid, EPout, Hex_Format(2, hue), Hex_Format(2, saturation), transitionRGB)

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

elif Hue_List["m"] == 3 and force_color_command == "MovetoHueandSaturation":
handle_color_mode_9998( self, nwkid, EPout, Hue_List)
handle_color_mode_9998( self, nwkid, EPout, Hue_List, value)

# ColorModeRGB = 3 // Color. Valid fields: r, g, b.
elif Hue_List["m"] == 3:
Expand All @@ -294,7 +261,7 @@ def actuator_setcolor(self, nwkid, EPout, value, Color):

# With saturation and hue, not seen in domoticz but present on zigate, and some device need it
elif Hue_List["m"] == 9998:
handle_color_mode_9998( self, nwkid, EPout, Hue_List)
handle_color_mode_9998( self, nwkid, EPout, Hue_List, value)

def handle_color_mode_2(self, nwkid, EPout, Hue_List):
# Value is in mireds (not kelvin)
Expand All @@ -304,9 +271,9 @@ def handle_color_mode_2(self, nwkid, EPout, Hue_List):
TempMired = 1000000 // TempKelvin
self.log.logging( "Command", "Debug", "handle_color_mode_2 Set Temp Kelvin: %s-%s" % (TempMired, Hex_Format(4, TempMired)), nwkid )
transitionMoveLevel , transitionRGB , transitionMoveLevel , transitionHue , transitionTemp = get_all_transition_mode( self, nwkid)
zcl_move_to_colour_temperature( self, nwkid, EPout, Hex_Format(4, TempMired), transitionTemp)
if get_deviceconf_parameter_value(self, self.ListOfDevices[nwkid]["Model"], "TUYA_Color_Control_Command_fe", return_default=None):
tuya_color_control_command_fe( self, nwkid, "00")
zcl_move_to_colour_temperature( self, nwkid, EPout, Hex_Format(4, TempMired), transitionTemp)


def handle_color_mode_3(self, nwkid, EPout, Hue_List):
Expand All @@ -332,10 +299,9 @@ def handle_color_mode_4(self, nwkid, EPout, Hue_List ):
TempMired = 1000000 // TempKelvin
self.log.logging( "Command", "Log", "handle_color_mode_4 Set Temp Kelvin: %s-%s" % (
TempMired, Hex_Format(4, TempMired)), nwkid )
zcl_move_to_colour_temperature( self, nwkid, EPout, Hex_Format(4, TempMired), transitionTemp)
if get_deviceconf_parameter_value(self, self.ListOfDevices[nwkid]["Model"], "TUYA_Color_Control_Command_fe", return_default=None):
tuya_color_control_command_fe( self, nwkid, "00")

zcl_move_to_colour_temperature( self, nwkid, EPout, Hex_Format(4, TempMired), transitionTemp)

# Process Colour
_h, _s, _l = rgb_to_hsl((int(Hue_List["r"]), int(Hue_List["g"]), int(Hue_List["b"])))
Expand All @@ -346,11 +312,11 @@ def handle_color_mode_4(self, nwkid, EPout, Hue_List ):

self.log.logging("Command", "Log", "handle_color_mode_4 Set Hue X: %s Saturation: %s" % (
hue, saturation), nwkid)
zcl_move_hue_and_saturation(self, nwkid, EPout, Hex_Format(2, hue), Hex_Format(2, saturation), transitionRGB)
if get_deviceconf_parameter_value(self, self.ListOfDevices[nwkid]["Model"], "TUYA_Color_Control_Command_fe", return_default=None):
tuya_color_control_command_fe( self, nwkid, "01")
zcl_move_hue_and_saturation(self, nwkid, EPout, Hex_Format(2, hue), Hex_Format(2, saturation), transitionRGB)

def handle_color_mode_9998( self, nwkid, EPout, Hue_List):
def handle_color_mode_9998( self, nwkid, EPout, Hue_List, value):
transitionMoveLevel , transitionRGB , transitionMoveLevel , transitionHue , transitionTemp = get_all_transition_mode( self, nwkid)
_h, _s, _l = rgb_to_hsl((int(Hue_List["r"]), int(Hue_List["g"]), int(Hue_List["b"])))
saturation = _s * 100 # 0 > 100
Expand All @@ -359,12 +325,11 @@ def handle_color_mode_9998( self, nwkid, EPout, Hue_List):
hue = int(hue * 254 // 360)

self.log.logging("Command", "Debug", "handle_color_mode_9998 Set Hue X: %s Saturation: %s" % (hue, saturation), nwkid)
zcl_move_hue_and_saturation(self, nwkid, EPout, Hex_Format(2, hue), Hex_Format(2, saturation), transitionRGB)
if get_deviceconf_parameter_value(self, self.ListOfDevices[nwkid]["Model"], "TUYA_Color_Control_Command_fe", return_default=None):
tuya_color_control_command_fe( self, nwkid, "01")
zcl_move_hue_and_saturation(self, nwkid, EPout, Hex_Format(2, hue), Hex_Format(2, saturation), transitionRGB)

value = int(_l * 254 // 100)
OnOff = "01"
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)

Expand Down

0 comments on commit 6d3a256

Please sign in to comment.