Skip to content

Commit

Permalink
Fix #521: Floodlight scale is from 1-100, instead of 1-5 on some cameras
Browse files Browse the repository at this point in the history
  • Loading branch information
JurajNyiri committed Jul 21, 2024
1 parent d2530aa commit 16de4e4
Showing 5 changed files with 78 additions and 4 deletions.
2 changes: 1 addition & 1 deletion custom_components/tapo_control/const.py
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 2 additions & 2 deletions custom_components/tapo_control/manifest.json
Original file line number Diff line number Diff line change
@@ -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",
58 changes: 58 additions & 0 deletions custom_components/tapo_control/number.py
Original file line number Diff line number Diff line change
@@ -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")
5 changes: 4 additions & 1 deletion custom_components/tapo_control/select.py
Original file line number Diff line number Diff line change
@@ -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,
13 changes: 13 additions & 0 deletions custom_components/tapo_control/utils.py
Original file line number Diff line number Diff line change
@@ -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:

0 comments on commit 16de4e4

Please sign in to comment.