Skip to content

Commit

Permalink
Merge branch 'wip-stable-7.1.6' into zigpy/deconz-conbeeIII
Browse files Browse the repository at this point in the history
  • Loading branch information
pipiche38 committed Nov 24, 2023
2 parents 252b0cc + d580b7f commit 33aa713
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 155 deletions.
211 changes: 99 additions & 112 deletions Classes/LoggingManagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import os.path
import threading
import time
import traceback
from logging.handlers import RotatingFileHandler, TimedRotatingFileHandler
from pathlib import Path
from queue import PriorityQueue, Queue
Expand Down Expand Up @@ -43,15 +44,19 @@ def __init__(self, pluginconf, PluginHealth, HardwareID, ListOfDevices, permitTo
self._startTime = int(time.time())

self.debugzigpy = False
zigpy_loging_mode("warning")
self.debugZNP = False
zigpy_logging_znp("warning")
self.debugEZSP = False
zigpy_logging_ezsp("warning")
self.debugZigate = False
zigpy_logging_zigate("warning")
self.debugdeconz = False
zigpy_logging_deconz("warning")

configure_zigpy_loggers("warning")
configure_zigpy_znp_loggers("warning")
configure_zigpy_ezsp_loggers("warning")
configure_zigpy_zigate_loggers("warning")
configure_zigpy_deconz_loggers("warning")




self.zigpy_login()

Expand All @@ -73,6 +78,13 @@ def reset_new_error(self):
def is_new_error(self):
return bool(self._newError and bool(self.LogErrorHistory))

def zigpy_login(self):
_configure_debug_mode(self, self.debugzigpy, "Zigpy", configure_zigpy_loggers)
_configure_debug_mode(self, self.debugZNP, "ZigpyZNP", configure_zigpy_znp_loggers)
_configure_debug_mode(self, self.debugEZSP, "ZigpyEZSP", configure_zigpy_ezsp_loggers)
_configure_debug_mode(self, self.debugZigate, "ZigpyZigate", configure_zigpy_zigate_loggers)
_configure_debug_mode(self, self.debugdeconz, "ZigpydeCONZ", configure_zigpy_deconz_loggers)

def loggingUpdatePluginVersion(self, Version):
self.PluginVersion = Version
if (
Expand All @@ -97,45 +109,6 @@ def loggingUpdateFirmware(self, FirmwareVersion, FirmwareMajorVersion):
self.LogErrorHistory[str(self.LogErrorHistory["LastLog"])]["FirmwareVersion"] = FirmwareVersion
self.LogErrorHistory[str(self.LogErrorHistory["LastLog"])]["FirmwareMajorVersion"] = FirmwareMajorVersion

def zigpy_login(self):
if not self.debugzigpy and self.pluginconf.pluginConf["Zigpy"]:
self.debugzigpy = True
zigpy_loging_mode("debug")
elif self.debugzigpy and not self.pluginconf.pluginConf["Zigpy"]:
self.debugzigpy = False
zigpy_loging_mode("warning")

# Debug ZNP
if not self.debugZNP and self.pluginconf.pluginConf["ZigpyZNP"]:
self.debugZNP = True
zigpy_logging_znp("debug")
elif self.debugZNP and not self.pluginconf.pluginConf["ZigpyZNP"]:
self.debugZNP = False
zigpy_logging_znp("warning")

# Debug Bellows/Ezsp
if not self.debugEZSP and self.pluginconf.pluginConf["ZigpyEZSP"]:
self.debugEZSP = True
zigpy_logging_ezsp("debug")
elif self.debugEZSP and not self.pluginconf.pluginConf["ZigpyEZSP"]:
self.debugEZSP = False
zigpy_logging_ezsp("warning")

# Debug Zigate
if not self.debugZigate and self.pluginconf.pluginConf["ZigpyZigate"]:
self.debugZigate = True
zigpy_logging_zigate("debug")
elif self.debugZigate and not self.pluginconf.pluginConf["ZigpyZigate"]:
self.debugZigate = False
zigpy_logging_zigate("warning")

# Debug deConz
if not self.debugdeconz and self.pluginconf.pluginConf["ZigpydeCONZ"]:
self.debugdeconz = True
zigpy_logging_deconz("debug")
elif self.debugdeconz and not self.pluginconf.pluginConf["ZigpydeCONZ"]:
self.debugdeconz = False
zigpy_logging_deconz("warning")


def openLogFile(self):
Expand Down Expand Up @@ -394,31 +367,28 @@ def loggingError(self, thread_name, module, message, nwkid, context):

loggingWriteErrorHistory(self)

def loggingBuildContext(self, thread_name, module, message, nwkid, context=None):

def loggingBuildContext(self, thread_name, module, message, nwkid, context):

if not self.PluginHealth:
_txt = "Not Started"
if "Txt" not in self.PluginHealth:
_txt = "Not Started"
else:
_txt = self.PluginHealth["Txt"]
_txt = self.PluginHealth.get("Txt", "Not Started")
_stacktrace = str(traceback.format_exc())

_context = {
"Time": int(time.time()),
"Module": module,
"nwkid": nwkid,
"PluginHealth": _txt,
"message": message,
"PermitToJoin": self.permitTojoin,
"PluginHealth": _txt,
"Thread": thread_name,
"nwkid": nwkid,
"Module": module,
"message": message,
"Stack Trace": _stacktrace
}
if nwkid and nwkid in self.ListOfDevices:
_context["DeviceInfos"] = dict(self.ListOfDevices[nwkid])

if nwkid in self.ListOfDevices:
_context["DeviceInfos"] = dict(self.ListOfDevices.get(nwkid, {}))

if context is not None:
if isinstance(context, dict):
_context["context"] = context.copy()
elif isinstance(context, (str, int)):
_context["context"] = str(context)
_context["context"] = context.copy() if isinstance(context, dict) else str(context)

return _context


Expand Down Expand Up @@ -501,56 +471,73 @@ def logging_thread(self):
Domoticz.Error("logging_thread unexpected tuple %s" % (str(logging_tuple)))
Domoticz.Log("logging_thread - ended")


def zigpy_loging_mode(mode):
def configure_loggers(logger_names, mode):
#Domoticz.Log(f"configure_loggers({logger_names} with {_set_logging_level})")
_set_logging_level = logging.DEBUG if mode == "debug" else logging.WARNING
Domoticz.Log( "zigpy_login_mode(%s)" %_set_logging_level)
logging.getLogger("zigpy.application").setLevel(_set_logging_level)
logging.getLogger("zigpy").setLevel(_set_logging_level)
logging.getLogger("zigpy.zdo").setLevel(_set_logging_level)
logging.getLogger("zigpy.zcl").setLevel(_set_logging_level)
logging.getLogger("zigpy.profiles").setLevel(_set_logging_level)
logging.getLogger("zigpy.quirks").setLevel(_set_logging_level)
logging.getLogger("zigpy.ota").setLevel(_set_logging_level)
logging.getLogger("zigpy.appdb_schemas").setLevel(_set_logging_level)
logging.getLogger("zigpy.backups").setLevel(_set_logging_level)
logging.getLogger("zigpy.device").setLevel(_set_logging_level)
logging.getLogger("zigpy.application").setLevel(_set_logging_level)
logging.getLogger("zigpy.appdb").setLevel(_set_logging_level)
logging.getLogger("zigpy.endpoint").setLevel(_set_logging_level)
logging.getLogger("zigpy.group").setLevel(_set_logging_level)
logging.getLogger("zigpy.neighbor").setLevel(_set_logging_level)
logging.getLogger("zigpy.topology").setLevel(_set_logging_level)

for logger_name in logger_names:
logging.getLogger(logger_name).setLevel(_set_logging_level)

def zigpy_logging_znp(mode):
_set_logging_level = logging.DEBUG if mode == "debug" else logging.WARNING
logging.getLogger("zigpy_znp").setLevel(_set_logging_level)
logging.getLogger("zigpy_znp.zigbee").setLevel(_set_logging_level)
logging.getLogger("zigpy_znp.zigbee.application").setLevel(_set_logging_level)
logging.getLogger("zigpy_znp.zigbee.device").setLevel(_set_logging_level)
logging.getLogger("Classes.ZigpyTransport.AppZnp").setLevel(_set_logging_level)
logging.getLogger("Classes.ZigpyTransport.AppGeneric").setLevel(_set_logging_level)


def zigpy_logging_ezsp(mode):
_set_logging_level = logging.DEBUG if mode == "debug" else logging.WARNING
logging.getLogger("bellows").setLevel(_set_logging_level)
logging.getLogger("bellows.zigbee").setLevel(_set_logging_level)
logging.getLogger("bellows.zigbee.application").setLevel(_set_logging_level)
logging.getLogger("bellows.zigbee.device").setLevel(_set_logging_level)
logging.getLogger("bellows.uart").setLevel(_set_logging_level)
logging.getLogger("Classes.ZigpyTransport.AppBellows").setLevel(_set_logging_level)
logging.getLogger("Classes.ZigpyTransport.AppGeneric").setLevel(_set_logging_level)


def zigpy_logging_zigate(mode):
_set_logging_level = logging.DEBUG if mode == "debug" else logging.WARNING
logging.getLogger("zigpy_zigate").setLevel(_set_logging_level)
logging.getLogger("Classes.ZigpyTransport.AppZigate").setLevel(_set_logging_level)


def zigpy_logging_deconz(mode):
_set_logging_level = logging.DEBUG if mode == "debug" else logging.WARNING
logging.getLogger("zigpy_deconz").setLevel(_set_logging_level)
logging.getLogger("Classes.ZigpyTransport.AppDeconz").setLevel(_set_logging_level)

# Loggers configurations
def configure_zigpy_loggers(mode):
logger_names = [
"zigpy.application", "zigpy", "zigpy.zdo", "zigpy.zcl",
"zigpy.profiles", "zigpy.quirks", "zigpy.ota",
"zigpy.appdb_schemas", "zigpy.backups", "zigpy.device",
"zigpy.application", "zigpy.appdb", "zigpy.endpoint",
"zigpy.group", "zigpy.neighbor", "zigpy.topology"
]
configure_loggers(logger_names, mode)


def configure_zigpy_znp_loggers(mode):
logger_names = [
"zigpy_znp",
"zigpy_znp.zigbee",
"zigpy_znp.zigbee.application",
"zigpy_znp.zigbee.device",
"Classes.ZigpyTransport.AppZnp",
"Classes.ZigpyTransport.AppGeneric"
]
configure_loggers(logger_names, mode)


def configure_zigpy_ezsp_loggers(mode):
logger_names = [
"bellows",
"bellows.zigbee",
"bellows.zigbee.application",
"bellows.zigbee.device",
"bellows.uart",
"Classes.ZigpyTransport.AppBellows",
"Classes.ZigpyTransport.AppGeneric"
]
configure_loggers(logger_names, mode)


def configure_zigpy_zigate_loggers(mode):
logger_names = [
"zigpy_zigate",
"Classes.ZigpyTransport.AppZigate"
]
configure_loggers(logger_names, mode)


def configure_zigpy_deconz_loggers(mode):
logger_names = [
"zigpy_deconz",
"Classes.ZigpyTransport.AppDeconz"
]
configure_loggers(logger_names, mode)


# Main configuration function

def _configure_debug_mode(self, debug_flag, config_name, config_function):
if not debug_flag and self.pluginconf.pluginConf[config_name]:
debug_flag = True
config_function("debug")
elif debug_flag and not self.pluginconf.pluginConf[config_name]:
debug_flag = False
config_function("warning")
24 changes: 12 additions & 12 deletions DevicesModules/custom_zlinky.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def zlinky_cluster_electrical_measurement(self, Devices, nwkid, ep, cluster, att

elif attribut == "050b": # Active Power

self.log.logging("Cluster", "Debug", "ReadCluster %s - %s/%s Power %s" % (cluster, nwkid, ep, value))
self.log.logging("Cluster", "Debug", "zlinky_cluster_electrical_measurement %s - %s/%s Power %s" % (cluster, nwkid, ep, value))
checkAndStoreAttributeValue(self, nwkid, ep, cluster, attribut, value)
MajDomoDevice(self, Devices, nwkid, ep, cluster, str(value))
store_ZLinky_infos( self, nwkid, 'CCASN', value)
Expand All @@ -206,7 +206,7 @@ def zlinky_cluster_electrical_measurement(self, Devices, nwkid, ep, cluster, att
store_ZLinky_infos( self, nwkid, 'CCASN-1',value)

elif attribut in ("0505", "0905", "0a05"): # RMS Voltage
self.log.logging("Cluster", "Debug", "ReadCluster %s - %s/%s Voltage %s" % (cluster, nwkid, ep, value))
self.log.logging("Cluster", "Debug", "zlinky_cluster_electrical_measurement %s - %s/%s Voltage %s" % (cluster, nwkid, ep, value))
if value == 0xFFFF:
return
checkAndStoreAttributeValue(self, nwkid, ep, cluster, attribut, value)
Expand All @@ -224,7 +224,7 @@ def zlinky_cluster_electrical_measurement(self, Devices, nwkid, ep, cluster, att
elif attribut == "0508": # RMSCurrent
if value == 0xFFFF:
return
self.log.logging( "ZLinky", "Debug", "ReadCluster %s - %s/%s %s Current L1 %s" % (
self.log.logging( "ZLinky", "Debug", "zlinky_cluster_electrical_measurement %s - %s/%s %s Current L1 %s" % (
cluster, nwkid, ep, attribut, value), nwkid, )

# from random import randrange
Expand Down Expand Up @@ -277,7 +277,7 @@ def zlinky_cluster_electrical_measurement(self, Devices, nwkid, ep, cluster, att
store_ZLinky_infos( self, nwkid, 'SMAXN', value)

else:
self.log.logging( "ZLinky", "Error", "=====> ReadCluster %s - %s/%s Unexpected %s/%s linkyMode: %s" % (
self.log.logging( "ZLinky", "Error", "=====> zlinky_cluster_electrical_measurement %s - %s/%s Unexpected %s/%s linkyMode: %s" % (
cluster, nwkid, ep, attribut, value, _linkyMode ), nwkid, )
return

Expand All @@ -301,14 +301,14 @@ def zlinky_cluster_electrical_measurement(self, Devices, nwkid, ep, cluster, att

elif attribut in ( "050f", "0306",) : # Apparent Power - 0x0306 is for tri-phased
if value >= 0xFFFF:
self.log.logging( "ZLinky", "Error", "=====> ReadCluster %s - %s/%s Apparent Power %s out of range !!!" % (cluster, nwkid, ep, value), nwkid, )
self.log.logging( "ZLinky", "Error", "=====> zlinky_cluster_electrical_measurement %s - %s/%s Apparent Power %s out of range !!!" % (cluster, nwkid, ep, value), nwkid, )
return
checkAndStoreAttributeValue(self, nwkid, ep, cluster, attribut, value)

self.log.logging( "ZLinky", "Debug", "=====> ReadCluster %s - %s/%s Apparent Power %s" % (cluster, nwkid, ep, value), nwkid, )
self.log.logging( "ZLinky", "Debug", "=====> zlinky_cluster_electrical_measurement %s - %s/%s Apparent Power %s" % (cluster, nwkid, ep, value), nwkid, )
# ApparentPower (Represents the single phase or Phase A, current demand of apparent (Square root of active and reactive power) power, in VA.)

self.log.logging( "ZLinky", "Debug", "=====> ReadCluster %s - %s/%s Apparent Power %s" % (cluster, nwkid, ep, value), nwkid, )
self.log.logging( "ZLinky", "Debug", "=====> zlinky_cluster_electrical_measurement %s - %s/%s Apparent Power %s" % (cluster, nwkid, ep, value), nwkid, )

_linkyMode = linky_mode( self, nwkid, protocol=True )

Expand All @@ -330,7 +330,7 @@ def zlinky_cluster_electrical_measurement(self, Devices, nwkid, ep, cluster, att
store_ZLinky_infos( self, nwkid, 'SINSTS', value)

else:
self.log.logging( "ZLinky", "Error", "=====> ReadCluster %s - %s/%s Unexpected %s/%s linkyMode: %s" % (
self.log.logging( "ZLinky", "Error", "=====> zlinky_cluster_electrical_measurement %s - %s/%s Unexpected %s/%s linkyMode: %s" % (
cluster, nwkid, ep, attribut, value, _linkyMode ), nwkid, )
return

Expand All @@ -355,7 +355,7 @@ def zlinky_cluster_electrical_measurement(self, Devices, nwkid, ep, cluster, att
else:
MajDomoDevice(self, Devices, nwkid, "01", cluster, str(value), Attribute_=attribut)

self.log.logging( "ZLinky", "Debug", "ReadCluster %s - %s/%s Apparent Power %s" % (cluster, nwkid, ep, value), nwkid, )
self.log.logging( "ZLinky", "Debug", "zlinky_cluster_electrical_measurement %s - %s/%s Apparent Power %s" % (cluster, nwkid, ep, value), nwkid, )

elif attribut in ( "090f", ):
store_ZLinky_infos( self, nwkid, 'SINSTS2', value)
Expand All @@ -372,12 +372,12 @@ def zlinky_cluster_electrical_measurement(self, Devices, nwkid, ep, cluster, att
MajDomoDevice(self, Devices, nwkid, ep, cluster, str(value), Attribute_=attribut)
# Check if Intensity is below subscription level
if attribut == "0908":
self.log.logging("Cluster", "Debug", "ReadCluster %s - %s/%s %s Current L2 %s" % (cluster, nwkid, ep, attribut, value), nwkid)
self.log.logging("Cluster", "Debug", "zlinky_cluster_electrical_measurement %s - %s/%s %s Current L2 %s" % (cluster, nwkid, ep, attribut, value), nwkid)
MajDomoDevice( self, Devices, nwkid, "f2", "0009", zlinky_check_alarm(self, Devices, nwkid, ep, value), Attribute_="0005", )
store_ZLinky_infos( self, nwkid, 'IRMS2', value)

elif attribut == "0a08":
self.log.logging("Cluster", "Debug", "ReadCluster %s - %s/%s %s Current L3 %s" % (cluster, nwkid, ep, attribut, value), nwkid)
self.log.logging("Cluster", "Debug", "zlinky_cluster_electrical_measurement %s - %s/%s %s Current L3 %s" % (cluster, nwkid, ep, attribut, value), nwkid)
MajDomoDevice( self, Devices, nwkid, "f3", "0009", zlinky_check_alarm(self, Devices, nwkid, ep, value), Attribute_="0005", )
store_ZLinky_infos( self, nwkid, 'IRMS3', value)

Expand Down Expand Up @@ -605,7 +605,7 @@ def zlinky_cluster_lixee_private(self, Devices, nwkid, ep, cluster, attribut, va
self.log.logging( "ZLinky", "Log", "STGE Value: %s" % ( value ))
stge = value

self.log.logging( "ZLinky", "Log", "STGE decoded %s : %s" % ( stge, decode_STEG( stge ) ))
self.log.logging( "ZLinky", "Log", "STGE decoded %s : %s" % ( stge, decode_STEG( stge ) ))
store_ZLinky_infos( self, nwkid, "STGE", decode_STEG( stge ))
checkAndStoreAttributeValue(self, nwkid, ep, cluster, attribut, stge)

Expand Down
11 changes: 9 additions & 2 deletions Modules/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
tuya_lidl_set_mode, tuya_trv_brt100_set_mode,
tuya_trv_mode, tuya_trv_onoff,
tuya_trv_switch_onoff)
from Modules.danfoss import danfoss_on_off
from Modules.tuyaTS0601 import ts0601_actuator, ts0601_extract_data_point_infos
from Modules.zigateConsts import (THERMOSTAT_LEVEL_2_MODE,
THERMOSTAT_LEVEL_3_MODE, ZIGATE_EP)
Expand Down Expand Up @@ -504,7 +505,10 @@ def mgtCommand(self, Devices, Unit, Command, Level, Color):

elif DeviceType == "ThermoOnOff":
self.log.logging("Command", "Debug", "ThermoOnOff - requested Off", NWKID)
tuya_trv_onoff(self, NWKID, 0x00)
if "Model" in self.ListOfDevices[NWKID] and self.ListOfDevices[NWKID]["Model"] in ("eTRV0100"):
danfoss_on_off(self, NWKID, 0x00)
else:
tuya_trv_onoff(self, NWKID, 0x00)
UpdateDevice_v2(self, Devices, Unit, 0, "Off", BatteryLevel, SignalLevel, ForceUpdate_=forceUpdateDev)

elif DeviceType == "ShutterCalibration":
Expand Down Expand Up @@ -689,7 +693,10 @@ def mgtCommand(self, Devices, Unit, Command, Level, Color):
thermostat_Mode(self, NWKID, "Heat")

elif DeviceType == "ThermoOnOff":
tuya_trv_onoff(self, NWKID, 0x01)
if "Model" in self.ListOfDevices[NWKID] and self.ListOfDevices[NWKID]["Model"] in ("eTRV0100"):
danfoss_on_off(self, NWKID, 0x01)
else:
tuya_trv_onoff(self, NWKID, 0x01)
UpdateDevice_v2(self, Devices, Unit, 1, "On", BatteryLevel, SignalLevel, ForceUpdate_=forceUpdateDev)

elif DeviceType == "ShutterCalibration":
Expand Down
Loading

0 comments on commit 33aa713

Please sign in to comment.