From fb06014dcf2246a9cb64bacbc9fe19dcc6be890e Mon Sep 17 00:00:00 2001 From: marcosngomezi <92400610+marcosngomezi@users.noreply.github.com> Date: Sat, 20 Jul 2024 14:03:20 -0300 Subject: [PATCH 1/2] not-supported-cached --- custom_components/tapo_control/utils.py | 93 +++++++++++++------------ 1 file changed, 48 insertions(+), 45 deletions(-) diff --git a/custom_components/tapo_control/utils.py b/custom_components/tapo_control/utils.py index a6d19d6..3c51166 100644 --- a/custom_components/tapo_control/utils.py +++ b/custom_components/tapo_control/utils.py @@ -1397,55 +1397,58 @@ def pytapoFunctionMap(pytapoFunctionName): def isCacheSupported(check_function, rawData): rawFunctions = pytapoFunctionMap(check_function) for function in rawFunctions: - if function in rawData and rawData[function][0]: - if check_function == "getForceWhitelampState": - return ( - "image" in rawData["getLdc"][0] - and "switch" in rawData["getLdc"][0]["image"] - and "force_wtl_state" in rawData["getLdc"][0]["image"]["switch"] - ) - elif check_function == "getDayNightMode": - return ( - "image" in rawData["getLightFrequencyInfo"][0] - and "common" in rawData["getLightFrequencyInfo"][0]["image"] - and "inf_type" - in rawData["getLightFrequencyInfo"][0]["image"]["common"] - ) - elif check_function == "getImageFlipVertical": - return ( - "image" in rawData["getLdc"][0] - and "switch" in rawData["getLdc"][0]["image"] - and "flip_type" in rawData["getLdc"][0]["image"]["switch"] - ) or ( - "image" in rawData["getRotationStatus"][0] - and "switch" in rawData["getRotationStatus"][0]["image"] - and "flip_type" - in rawData["getRotationStatus"][0]["image"]["switch"] - ) - elif check_function == "getLensDistortionCorrection": - return ( - "image" in rawData["getLdc"][0] - and "switch" in rawData["getLdc"][0]["image"] - and "ldc" in rawData["getLdc"][0]["image"]["switch"] - ) - return True + if function in rawData: + if rawData[function][0]: + if check_function == "getForceWhitelampState": + return ( + "image" in rawData["getLdc"][0] + and "switch" in rawData["getLdc"][0]["image"] + and "force_wtl_state" in rawData["getLdc"][0]["image"]["switch"] + ) + elif check_function == "getDayNightMode": + return ( + "image" in rawData["getLightFrequencyInfo"][0] + and "common" in rawData["getLightFrequencyInfo"][0]["image"] + and "inf_type" + in rawData["getLightFrequencyInfo"][0]["image"]["common"] + ) + elif check_function == "getImageFlipVertical": + return ( + "image" in rawData["getLdc"][0] + and "switch" in rawData["getLdc"][0]["image"] + and "flip_type" in rawData["getLdc"][0]["image"]["switch"] + ) or ( + "image" in rawData["getRotationStatus"][0] + and "switch" in rawData["getRotationStatus"][0]["image"] + and "flip_type" + in rawData["getRotationStatus"][0]["image"]["switch"] + ) + elif check_function == "getLensDistortionCorrection": + return ( + "image" in rawData["getLdc"][0] + and "switch" in rawData["getLdc"][0]["image"] + and "ldc" in rawData["getLdc"][0]["image"]["switch"] + ) + return True + else: + raise Exception(f"Capability {check_function} (raw:{rawFunctions}) cached but not supported.") return False async def check_and_create(entry, hass, cls, check_function, config_entry): - if isCacheSupported(check_function, entry["camData"]["raw"]): - LOGGER.debug( - f"Found cached capability {check_function}, creating {cls.__name__}" - ) - return cls(entry, hass, config_entry) - else: - LOGGER.debug(f"Capability {check_function} not found, querying again...") - try: + try: + if isCacheSupported(check_function, entry["camData"]["raw"]): + LOGGER.debug( + f"Found cached capability {check_function}, creating {cls.__name__}" + ) + return cls(entry, hass, config_entry) + else: + LOGGER.debug(f"Capability {check_function} not found, querying again...") await hass.async_add_executor_job( getattr(entry["controller"], check_function) ) - except Exception: - LOGGER.info(f"Camera does not support {cls.__name__}") - return None - LOGGER.debug(f"Creating {cls.__name__}") - return cls(entry, hass, config_entry) + LOGGER.debug(f"Creating {cls.__name__}") + return cls(entry, hass, config_entry) + except Exception as err: + LOGGER.info(f"Camera does not support {cls.__name__}: {err}") + return None From eee6a2bc763f76fec79da018c20809d56e67a10d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20G=C3=B3mez?= <92400610+marcosngomezi@users.noreply.github.com> Date: Sat, 20 Jul 2024 20:15:29 -0300 Subject: [PATCH 2/2] review-change --- custom_components/tapo_control/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/tapo_control/utils.py b/custom_components/tapo_control/utils.py index 3c51166..2143f50 100644 --- a/custom_components/tapo_control/utils.py +++ b/custom_components/tapo_control/utils.py @@ -1431,7 +1431,7 @@ def isCacheSupported(check_function, rawData): ) return True else: - raise Exception(f"Capability {check_function} (raw:{rawFunctions}) cached but not supported.") + raise Exception(f"Capability {check_function} (mapped to:{function}) cached but not supported.") return False