Skip to content

Commit

Permalink
Merge pull request #618 from JurajNyiri/hdr
Browse files Browse the repository at this point in the history
Add: HDR switch
  • Loading branch information
JurajNyiri authored Jul 4, 2024
2 parents 7b3df46 + 7e77f43 commit ab850c0
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 3 deletions.
2 changes: 1 addition & 1 deletion custom_components/tapo_control/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions custom_components/tapo_control/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
71 changes: 71 additions & 0 deletions custom_components/tapo_control/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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__(
Expand Down
16 changes: 16 additions & 0 deletions custom_components/tapo_control/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 []


Expand Down

0 comments on commit ab850c0

Please sign in to comment.