diff --git a/custom_components/tapo_control/const.py b/custom_components/tapo_control/const.py index fd7e548..1414d55 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.22" +PYTAPO_REQUIRED_VERSION = "3.3.23" 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 5326827..37bfa19 100644 --- a/custom_components/tapo_control/manifest.json +++ b/custom_components/tapo_control/manifest.json @@ -6,9 +6,9 @@ "codeowners": [ "@JurajNyiri" ], - "version": "5.4.19", + "version": "5.4.26", "requirements": [ - "pytapo==3.3.22" + "pytapo==3.3.23" ], "dependencies": [ "ffmpeg", diff --git a/custom_components/tapo_control/switch.py b/custom_components/tapo_control/switch.py index 95e97d3..fa238fb 100644 --- a/custom_components/tapo_control/switch.py +++ b/custom_components/tapo_control/switch.py @@ -138,6 +138,29 @@ async def setupEntities(entry): LOGGER.debug("Adding tapoMicrophoneNoiseCancellationSwitch...") switches.append(tapoMicrophoneNoiseCancellationSwitch) + if ( + "videoCapability" in entry["camData"] + and entry["camData"]["videoCapability"] is not None + and "video_capability" in entry["camData"]["videoCapability"] + and "main" in entry["camData"]["videoCapability"]["video_capability"] + and "hdrs" + in entry["camData"]["videoCapability"]["video_capability"]["main"] + and "videoQualities" in entry["camData"] + and "video" in entry["camData"]["videoQualities"] + and "main" in entry["camData"]["videoQualities"]["video"] + and "hdr" in entry["camData"]["videoQualities"]["video"]["main"] + ): + tapoHDRSwitch = await check_and_create( + entry, + hass, + TapoHDRSwitch, + "getVideoQualities", + config_entry, + ) + if tapoHDRSwitch: + LOGGER.debug("Adding tapoHDRSwitch...") + switches.append(tapoHDRSwitch) + return switches switches = await setupEntities(entry) @@ -152,6 +175,54 @@ async def setupEntities(entry): LOGGER.debug("No switch entities available.") +class TapoHDRSwitch(TapoSwitchEntity): + def __init__(self, entry: dict, hass: HomeAssistant, config_entry): + TapoSwitchEntity.__init__( + self, + "HDR", + entry, + hass, + config_entry, + "mdi:hdr", + ) + + async def async_update(self) -> None: + await self._coordinator.async_request_refresh() + + async def async_turn_on(self) -> None: + result = await self._hass.async_add_executor_job( + self._controller.setHDR, + True, + ) + if "error_code" not in result or result["error_code"] == 0: + self._attr_state = "on" + self.async_write_ha_state() + await self._coordinator.async_request_refresh() + + async def async_turn_off(self) -> None: + result = await self._hass.async_add_executor_job( + self._controller.setHDR, + False, + ) + if "error_code" not in result or result["error_code"] == 0: + self._attr_state = "off" + self.async_write_ha_state() + await self._coordinator.async_request_refresh() + + def updateTapo(self, camData): + if ( + not camData + or "videoQualities" not in camData + or "video" not in camData["videoQualities"] + or "main" not in camData["videoQualities"]["video"] + or "hdr" not in camData["videoQualities"]["video"]["main"] + ): + self._attr_state = STATE_UNAVAILABLE + else: + self._attr_is_on = camData["videoQualities"]["video"]["main"]["hdr"] == "1" + self._attr_state = "on" if self._attr_is_on else "off" + + class TapoRecordingPlanSwitch(TapoSwitchEntity): def __init__(self, entry: dict, hass: HomeAssistant, config_entry): TapoSwitchEntity.__init__( diff --git a/custom_components/tapo_control/utils.py b/custom_components/tapo_control/utils.py index 577860a..0f3b940 100644 --- a/custom_components/tapo_control/utils.py +++ b/custom_components/tapo_control/utils.py @@ -1087,6 +1087,18 @@ async def getCamData(hass, controller): connectionInformation = None camData["connectionInformation"] = connectionInformation + try: + videoCapability = data["getVideoCapability"][0] + except Exception: + videoCapability = None + camData["videoCapability"] = videoCapability + + try: + videoQualities = data["getVideoQualities"][0] + except Exception: + videoQualities = None + camData["videoQualities"] = videoQualities + LOGGER.debug("getCamData - done") LOGGER.debug("Processed update data:") LOGGER.debug(camData) @@ -1348,6 +1360,10 @@ def pytapoFunctionMap(pytapoFunctionName): return ["getFirmwareAutoUpgradeConfig"] elif pytapoFunctionName == "getSirenTypeList": return ["getSirenTypeList"] + elif pytapoFunctionName == "getVideoQualities": + return ["getVideoQualities"] + elif pytapoFunctionName == "getVideoCapability": + return ["getVideoCapability"] return []