diff --git a/custom_components/tapo_control/const.py b/custom_components/tapo_control/const.py index 51d0b9e..ebb5570 100644 --- a/custom_components/tapo_control/const.py +++ b/custom_components/tapo_control/const.py @@ -5,7 +5,7 @@ from homeassistant.helpers import config_validation as cv -PYTAPO_REQUIRED_VERSION = "3.3.27" +PYTAPO_REQUIRED_VERSION = "3.3.29" DOMAIN = "tapo_control" BRAND = "TP-Link" ALARM_MODE = "alarm_mode" diff --git a/custom_components/tapo_control/manifest.json b/custom_components/tapo_control/manifest.json index 6dbe336..a56505f 100644 --- a/custom_components/tapo_control/manifest.json +++ b/custom_components/tapo_control/manifest.json @@ -6,9 +6,9 @@ "codeowners": [ "@JurajNyiri" ], - "version": "5.4.31", + "version": "5.4.34", "requirements": [ - "pytapo==3.3.27" + "pytapo==3.3.29" ], "dependencies": [ "ffmpeg", diff --git a/custom_components/tapo_control/number.py b/custom_components/tapo_control/number.py index cf90747..1b03478 100644 --- a/custom_components/tapo_control/number.py +++ b/custom_components/tapo_control/number.py @@ -91,6 +91,18 @@ async def setupEntities(entry): LOGGER.debug("Adding TapoSirenDuration...") numbers.append(tapoSirenDuration) + if entry["camData"]["whitelampConfigIntensity"] is not None: + tapoSpotlightIntensity = await check_and_create( + entry, + hass, + TapoSpotlightIntensity, + "getNightVisionCapability", + config_entry, + ) + if tapoSpotlightIntensity: + LOGGER.debug("Adding tapoSpotlightIntensity...") + numbers.append(tapoSpotlightIntensity) + return numbers numbers = await setupEntities(entry) @@ -344,6 +356,52 @@ def updateTapo(self, camData): self.alarm_mode = camData["alarm_config"]["mode"] +class TapoSpotlightIntensity(TapoNumberEntity): + def __init__(self, entry: dict, hass: HomeAssistant, config_entry): + LOGGER.debug("TapoSpotlightIntensity - init - start") + self._attr_min_value = 1 + self._attr_native_min_value = 1 + self._attr_max_value = 100 + self._attr_native_max_value = 100 + self._attr_step = 1 + self._hass = hass + self._attr_native_value = entry["camData"]["whitelampConfigIntensity"] + self._attr_state = entry["camData"]["whitelampConfigIntensity"] + + TapoNumberEntity.__init__( + self, + "Spotlight Intensity", + entry, + hass, + config_entry, + "mdi:lightbulb-on-50", + ) + LOGGER.debug("TapoSpotlightIntensity - init - end") + + async def async_update(self) -> None: + await self._coordinator.async_request_refresh() + + @property + def entity_category(self): + return EntityCategory.CONFIG + + async def async_set_native_value(self, value: float) -> None: + result = await self._hass.async_add_executor_job( + self._controller.setWhitelampConfig, False, int(value) + ) + if "error_code" not in result or result["error_code"] == 0: + self._attr_state = value + self.async_write_ha_state() + await self._coordinator.async_request_refresh() + + def updateTapo(self, camData): + if not camData: + self._attr_state = STATE_UNAVAILABLE + else: + self._attr_native_value = int(camData["whitelampConfigIntensity"]) + self._attr_state = camData["whitelampConfigIntensity"] + + class TapoSirenDuration(TapoNumberEntity): def __init__(self, entry: dict, hass: HomeAssistant, config_entry): LOGGER.debug("TapoSirenDuration - init - start") diff --git a/custom_components/tapo_control/select.py b/custom_components/tapo_control/select.py index c5eab26..64a887e 100644 --- a/custom_components/tapo_control/select.py +++ b/custom_components/tapo_control/select.py @@ -144,7 +144,10 @@ async def setupEntities(entry): LOGGER.debug("Adding TapoWhitelampForceTimeSelect...") selects.append(tapoWhitelampForceTimeSelect) - if entry["camData"]["whitelampConfigIntensity"] is not None: + if ( + entry["camData"]["whitelampConfigIntensity"] is not None + and entry["camData"]["nightVisionCapability"] is None + ): tapoWhitelampIntensityLevelSelect = await check_and_create( entry, hass, diff --git a/custom_components/tapo_control/utils.py b/custom_components/tapo_control/utils.py index 7434e03..4e53d9d 100644 --- a/custom_components/tapo_control/utils.py +++ b/custom_components/tapo_control/utils.py @@ -1077,6 +1077,19 @@ async def getCamData(hass, controller): camData["alarm_is_hubSiren"] = hubSiren camData["alarm_siren_type_list"] = alarmSirenTypeList + try: + if ( + "image_capability" in data["getNightVisionCapability"][0] + and "supplement_lamp" + in data["getNightVisionCapability"][0]["image_capability"] + ): + nightVisionCapability = data["getNightVisionCapability"][0][ + "image_capability" + ]["supplement_lamp"] + except Exception: + nightVisionCapability = None + camData["nightVisionCapability"] = nightVisionCapability + try: led = data["getLedStatus"][0]["led"]["config"]["enabled"] except Exception: