From d0e48abed36c118f4e7b1d76e17191c2f983219d Mon Sep 17 00:00:00 2001 From: Patrick Pichon Date: Sat, 17 Feb 2024 13:11:51 +0100 Subject: [PATCH] resilience on handling the onoff_poweron settings --- Modules/onoff_settings.py | 13 +++++++++---- Modules/tools.py | 8 ++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Modules/onoff_settings.py b/Modules/onoff_settings.py index 952935695..d471fab24 100644 --- a/Modules/onoff_settings.py +++ b/Modules/onoff_settings.py @@ -14,7 +14,8 @@ from Modules.enki import is_enky_device from Modules.philips import is_philips_device from Modules.readAttributes import ReadAttributeRequest_0006_400x -from Modules.tools import get_deviceconf_parameter_value, getListOfEpForCluster +from Modules.tools import (get_deviceconf_parameter_value, + getListOfEpForCluster, is_int) from Modules.tuya import (get_tuya_attribute, is_tuya_switch_relay, tuya_switch_relay_status) from Modules.zigateConsts import ZIGATE_EP @@ -67,9 +68,13 @@ def onoff_startup_onoff_mode(self, nwkid, ep, value): self.log.logging( "onoffSettings", "Debug", f"onoff_startup_onoff_mode for {nwkid}/{ep} - value: {value}", nwkid ) if isinstance(value, str): - old_value = value - value = int(value) - self.log.logging( "onoffSettings", "Log", f"onoff_startup_onoff_mode for {nwkid}/{ep} - value: {old_value} converted to {value}", nwkid ) + if is_int(value): + old_value = value + value = int(value) + self.log.logging( "onoffSettings", "Log", f"onoff_startup_onoff_mode for {nwkid}/{ep} - value: {old_value} converted to {value}", nwkid ) + else: + self.log.logging( "onoffSettings", "Error", f"onoff_startup_onoff_mode for {nwkid}/{ep} - value error {value}", nwkid ) + return write_attribute( self, diff --git a/Modules/tools.py b/Modules/tools.py index f90cff3b1..f9920e1a0 100644 --- a/Modules/tools.py +++ b/Modules/tools.py @@ -26,10 +26,14 @@ from Modules.pluginDbAttributes import STORE_CONFIGURE_REPORTING from Modules.zigateConsts import HEARTBEAT +HEX_DIGIT = "0123456789abcdefABCDEF" +INT_DIGIT = "0123456789" def is_hex(s): - hex_digits = set("0123456789abcdefABCDEF") - return all(char in hex_digits for char in s) + return all(char in HEX_DIGIT for char in s) + +def is_int(s): + return all(char in INT_DIGIT for char in s) def returnlen(taille, value): while len(value) < taille: