Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare 7.1.006 ( December release) #1670

Merged
merged 81 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
06ed3cd
prevent handling a group message when group is not yet ready ( https:…
pipiche38 Nov 18, 2023
2296092
makes possible to disable the Tuya Magic Read for all Tuya mac@
pipiche38 Nov 19, 2023
5930e44
make it ready for python3.12
pipiche38 Nov 20, 2023
839cc94
upgrade zigpy radio, and deconz to allow ConBeeIII
pipiche38 Nov 20, 2023
c36669c
fix synctax issues
pipiche38 Nov 20, 2023
83f5532
Firmware version fix
pipiche38 Nov 20, 2023
c3b86db
Modules/pluginModels.py: Add LIDL plug model A2
thertp Nov 12, 2023
7cb9edb
Danfoss eTRV0100: Fix "window open" status
thertp Jun 5, 2023
027cb2b
Danfoss eTRV0100: Add "External Open Window Detected" support
thertp Nov 3, 2023
9577403
Modules/input.py: Decode8095: Fix fallback MsgCmd
thertp Jun 5, 2023
6f27721
Decode0110: fix decoding loop
thertp Jun 5, 2023
5d00770
Merge pull request #1673 from thertp/etrv100
pipiche38 Nov 21, 2023
075fa5a
Merge pull request #1674 from thertp/lidl-plug-a2
pipiche38 Nov 21, 2023
cf34715
Merge pull request #1676 from thertp/decode0110_loop
pipiche38 Nov 21, 2023
d448ee1
Merge pull request #1675 from thertp/decode8095-fallback-msgcmd
pipiche38 Nov 21, 2023
9a1a3d2
Prevent call TOUCH() too often and limit to lastupdate + 30 seconds
pipiche38 Nov 21, 2023
4dcb9f7
Merge remote-tracking branch 'refs/remotes/origin/wip-stable-7.1.6' i…
pipiche38 Nov 21, 2023
96b54ec
update the lohg messages
pipiche38 Nov 22, 2023
5e2450a
refactor is_manufacturer_specific_cluster, and fix an issue as it mig…
pipiche38 Nov 22, 2023
2c1853a
provide Stack Trace for Errors, refactor zigpy_loggin configuration
pipiche38 Nov 23, 2023
9a235ee
refactor is_manufacturer_specific_cluster() , and fix issue found on …
pipiche38 Nov 23, 2023
c5582e5
Refactor is_manufacturer_specific_cluster
pipiche38 Nov 24, 2023
d580b7f
fix stack trace
pipiche38 Nov 24, 2023
252b0cc
latest zigpy libarries
pipiche38 Nov 24, 2023
33aa713
Merge branch 'wip-stable-7.1.6' into zigpy/deconz-conbeeIII
pipiche38 Nov 24, 2023
30b8506
refactor the way to get stack trace, as traceback.format_exc() is onl…
pipiche38 Nov 24, 2023
49ef797
remove unnecessary log
pipiche38 Nov 24, 2023
992ba0b
Merge pull request #1672 from zigbeefordomoticz/zigpy/deconz-conbeeIII
pipiche38 Nov 24, 2023
c4bf151
fix a major issue with certain device/firmware which are requesting a…
pipiche38 Nov 25, 2023
1f85b79
refactor some of the OTA functions
pipiche38 Nov 25, 2023
6852052
cleanup
pipiche38 Nov 25, 2023
3c5d944
Merge pull request #1677 from zigbeefordomoticz/refactor/OTA
pipiche38 Nov 25, 2023
f7ff7cd
Refacor Modules/input.py and breakdown into specialized unit (#1678)
pipiche38 Nov 28, 2023
b7aeb27
Replace references to Devices[ unit ] by DomoticzAbstract api (#1671)
pipiche38 Nov 29, 2023
91a3b9e
fix indentation issue
pipiche38 Nov 29, 2023
db29d43
fix device_id_ieee name
pipiche38 Nov 29, 2023
7e7837a
fixing retrieve_data_from_current whcih should return nvalue and svalue
pipiche38 Nov 29, 2023
f98f44c
fixing teh usage of retrieve_data_from_current
pipiche38 Nov 29, 2023
c1a3156
several fixes to make it working
pipiche38 Nov 29, 2023
9ccbc5b
correctly handle Signed data (very true for cold temperature nowadays
pipiche38 Nov 30, 2023
55bd8c6
move a log to debug
pipiche38 Nov 30, 2023
9d7cc48
Move log to debug
pipiche38 Nov 30, 2023
147da76
fix number of arguments when calling check_set_meter_widget
pipiche38 Nov 30, 2023
1ae3745
provide an abstract api for Domoticz.Log
pipiche38 Nov 30, 2023
80c00d1
no need to have self
pipiche38 Nov 30, 2023
3f01f4d
one more Log to Debug
pipiche38 Nov 30, 2023
14d368e
log cleanup
pipiche38 Nov 30, 2023
14da4eb
update the update_firmware method
pipiche38 Nov 30, 2023
f278112
fix issue when brand name are not provided
pipiche38 Nov 30, 2023
cea0ba3
fix the firmware_update api
pipiche38 Nov 30, 2023
f94c8c5
fixing reporting of Firmware version
pipiche38 Dec 3, 2023
bfc3a3e
Refactoring of Decode8010
pipiche38 Dec 3, 2023
4997dac
remove space after (
pipiche38 Dec 4, 2023
5f040fe
fix access to Topology Reports
pipiche38 Dec 4, 2023
6b6617a
Make pyserial-asyncio-fast available for zigpy ( https://github.com/z…
pipiche38 Dec 4, 2023
56862db
move some plugin helpers function to a specific module
pipiche38 Dec 4, 2023
7e8cf88
Possibility to print the list of all imported modules and there versi…
pipiche38 Dec 4, 2023
6c1979b
move from Log to debug
pipiche38 Dec 4, 2023
e2cb31d
Fix an issue with Sensor delivering only Temp+Humi
pipiche38 Dec 5, 2023
060a86e
Update Copyright dates
pipiche38 Dec 5, 2023
6dc770d
remaining issue in retrieve_data_from_current()
pipiche38 Dec 5, 2023
7fec9c8
remaining issue in retrieve_data_from_current()
pipiche38 Dec 5, 2023
5d8dfd5
Support of Dresden Elektronic Conbee III (thanks for Dresden sponosrs…
pipiche38 Dec 6, 2023
3b8a51a
refactor and upgrade to the latest zigpy radio libs
pipiche38 Dec 8, 2023
f3291d2
upgrade to the latest zigpy radio libs
pipiche38 Dec 8, 2023
6e26442
refactor
pipiche38 Dec 8, 2023
0ae0857
Device/remote legrand toggle (#1679)
pipiche38 Dec 9, 2023
cca108e
Refactor domMaj and remove Devices[Unit].xxxx (#1681)
pipiche38 Dec 10, 2023
f7377ae
Log to Debug
pipiche38 Dec 10, 2023
f800aed
Log to Debug
pipiche38 Dec 10, 2023
822a8e4
Update domoMaj.py (#1682)
SylvainPer Dec 13, 2023
dbf5b4e
Provide a function to query SWITCH_SELECTOR matrix and get the nValue…
pipiche38 Dec 13, 2023
ea24dde
Merge remote-tracking branch 'refs/remotes/origin/wip-stable-7.1.6' i…
pipiche38 Dec 13, 2023
42fefa2
Move Decode8100 from IAS to ReadAttributeRsp
pipiche38 Dec 13, 2023
bfb7416
do the righ test
pipiche38 Dec 14, 2023
dedc56c
adding debug
pipiche38 Dec 14, 2023
685b652
remove obsolete conf files
pipiche38 Dec 15, 2023
7e364f0
add a read attribute function for Sonoff 0xfc11 TRV cluster
pipiche38 Dec 15, 2023
f14fe73
latest zigpy radio libs
pipiche38 Dec 15, 2023
bd7a87b
preparing Release 7.1.006
pipiche38 Dec 16, 2023
78e78ad
CodeFactor multi-space correction
pipiche38 Dec 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
237 changes: 124 additions & 113 deletions Classes/LoggingManagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

"""

import inspect
import json
import logging
import os
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 +45,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 +79,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 @@ -83,6 +96,7 @@ def loggingUpdatePluginVersion(self, Version):
):
self.LogErrorHistory[str(self.LogErrorHistory["LastLog"])]["PluginVersion"] = Version


def loggingUpdateFirmware(self, FirmwareVersion, FirmwareMajorVersion):
if self.FirmwareVersion and self.FirmwareMajorVersion:
return
Expand All @@ -97,51 +111,12 @@ 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):
self.open_logging_mode()
self.open_log_history()


def open_logging_mode(self):
import sys

Expand Down Expand Up @@ -195,7 +170,6 @@ def open_logging_mode(self):
os.chmod(_logfilename, self.pluginconf.pluginConf["PluginLogMode"])



def open_log_history(self):
_pluginlogs = Path( self.pluginconf.pluginConf["pluginLogs"] )
jsonLogHistory = _pluginlogs / ( LOG_ERROR_HISTORY + "%02d.json" % self.HardwareID)
Expand All @@ -222,6 +196,7 @@ def open_log_history(self):

handle.close()


def closeLogFile(self):
if self.logging_thread is None:
Domoticz.Error("closeLogFile - logging_thread is None")
Expand All @@ -245,6 +220,7 @@ def closeLogFile(self):
loggingWriteErrorHistory(self)
Domoticz.Log("Logging Thread shutdown")


def loggingCleaningErrorHistory(self):
if len(self.LogErrorHistory) > 1:
idx = list(self.LogErrorHistory.keys())[1]
Expand All @@ -262,10 +238,12 @@ def loggingCleaningErrorHistory(self):
if len(self.LogErrorHistory) == 1:
self.LogErrorHistory.clear()


def loggingClearErrorHistory(self):
self.LogErrorHistory.clear()
self._newError = False


def logging(self, module, logType, message, nwkid=None, context=None):
#Domoticz.Log("%s %s %s %s %s %s %s" % (module, logType, message, nwkid, context, self.logging_thread, self.logging_queue))
# Set python3 modules logging if required
Expand All @@ -277,6 +255,12 @@ def logging(self, module, logType, message, nwkid=None, context=None):
except AttributeError:
thread_id = 0

if logType == "Error":
if context:
context["StackTrace"] = get_stack_trace()
else:
context = { "StackTrace": get_stack_trace() }

if self.logging_thread and self.logging_queue:
logging_tuple = [
str(time.time()),
Expand Down Expand Up @@ -395,30 +379,40 @@ def loggingError(self, thread_name, module, message, nwkid, context):
loggingWriteErrorHistory(self)


def loggingBuildContext(self, thread_name, module, message, nwkid, context):
def get_stack_trace():
# Get the current stack frame
current_frame = inspect.currentframe()

if not self.PluginHealth:
_txt = "Not Started"
if "Txt" not in self.PluginHealth:
_txt = "Not Started"
else:
_txt = self.PluginHealth["Txt"]
# Get the call stack ( -2 to exclude the get_stack_trace() and logging()
stack = traceback.extract_stack(current_frame)[:-2]

# Format the stack trace
stack_trace = traceback.format_list(stack)

# Alternatively, you can return the formatted stack trace as a string
return ''.join(stack_trace)


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

_txt = self.PluginHealth.get("Txt", "Not Started")

_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,
}
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 +495,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")
Loading
Loading