Skip to content

Commit

Permalink
update and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pipiche38 committed Jan 13, 2025
1 parent 9b29278 commit 116ebd1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
10 changes: 5 additions & 5 deletions DevicesModules/custom_zlinky.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,10 @@ def zlinky_set_color_based_on_counter(self, domoticz_devices, nwkid, ep, cluster
"""
def update_color(nwkid, previous_color, new_color):
"""Update the device color if it has changed."""
if new_color != previous_color:
self.log.logging("ZLinky", "Status", f"Updating ZLinky color from {previous_color} to {new_color}", nwkid)
MajDomoDevice(self, domoticz_devices, nwkid, "01", "0009", new_color, Attribute_="0020")
zlinky_color_tarif(self, nwkid, new_color)
ReadAttributeReq_Scheduled_ZLinky(self, nwkid)
self.log.logging("ZLinky", "Status", f"Updating ZLinky color from {previous_color} to {new_color}", nwkid)
MajDomoDevice(self, domoticz_devices, nwkid, "01", "0009", new_color, Attribute_="0020")
zlinky_color_tarif(self, nwkid, new_color)
ReadAttributeReq_Scheduled_ZLinky(self, nwkid)

def get_new_color(attribut, op_tarifiare):
"""Determine the new color based on the attribute and tariff type."""
Expand Down Expand Up @@ -157,6 +156,7 @@ def handle_attribut_value(attribut, store_keys=None, update_color=False, totaliz
MajDomoDevice(self, domoticz_devices, nwkid, maj_ep, cluster, str(value), Attribute_=attribut)

if attribut == "0020":
MajDomoDevice(self, domoticz_devices, nwkid, "01", "0009", value, Attribute_="0020")
zlinky_color_tarif(self, nwkid, str(value))

if update_color:
Expand Down
26 changes: 17 additions & 9 deletions Modules/zlinky.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,17 @@
def convert_kva_to_ampere( kva ):
return ( kva * 1000) / 200


def zlinky_color_tarif(self, MsgSrcAddr, color):
if "ZLinky" not in self.ListOfDevices[MsgSrcAddr]:
self.ListOfDevices[MsgSrcAddr]["ZLinky"] = {}
self.ListOfDevices[MsgSrcAddr]["ZLinky"]["Color"] = color
self.ListOfDevices.setdefault(MsgSrcAddr, {}).setdefault("ZLinky", {})["Color"] = color

def store_ZLinky_infos( self, nwkid, command_tic, value):

def store_ZLinky_infos( self, nwkid, command_tic, value):
if 'ZLinky' not in self.ListOfDevices[ nwkid ]:
self.ListOfDevices[ nwkid ][ 'ZLinky' ] = {}
self.ListOfDevices[ nwkid ][ 'ZLinky' ][ command_tic ] = value


def get_ISOUSC( self, nwkid ):

if (
Expand Down Expand Up @@ -155,12 +155,20 @@ def get_OPTARIF( self, nwkid):

return "BASE"

def get_instant_power( self, nwkid ):
return round(float(self.ListOfDevices[nwkid]["Ep"]["01"]["0b04"]["050f"]), 2) if "0b04" in self.ListOfDevices[nwkid]["Ep"]["01"] and "050f" in self.ListOfDevices[nwkid]["Ep"]["01"]["0b04"] else 0
def get_instant_power(self, nwkid):
try:
device = self.ListOfDevices.get(nwkid, {})
ep = device.get("Ep", {}).get("01", {})
cluster = ep.get("0b04", {})
power = cluster.get("050f")
return round(float(power), 2) if power is not None else 0
except (ValueError, TypeError):
return 0


def get_tarif_color(self, nwkid):
return self.ListOfDevices.get(nwkid, {}).get("ZLinky", {}).get("Color")

def get_tarif_color( self, nwkid ):
return self.ListOfDevices[nwkid]["ZLinky"]["Color"] if "ZLinky" in self.ListOfDevices[nwkid] and "Color" in self.ListOfDevices[nwkid]["ZLinky"] else None


def zlinky_check_alarm(self, Devices, MsgSrcAddr, MsgSrcEp, value):

Expand Down

0 comments on commit 116ebd1

Please sign in to comment.