diff --git a/homeassistant/components/reolink/entity.py b/homeassistant/components/reolink/entity.py index 29c1e95be81..53a81f2b162 100644 --- a/homeassistant/components/reolink/entity.py +++ b/homeassistant/components/reolink/entity.py @@ -89,11 +89,17 @@ class ReolinkHostCoordinatorEntity(ReolinkBaseCoordinatorEntity[None]): async def async_added_to_hass(self) -> None: """Entity created.""" await super().async_added_to_hass() - if ( - self.entity_description.cmd_key is not None - and self.entity_description.cmd_key not in self._host.update_cmd_list - ): - self._host.update_cmd_list.append(self.entity_description.cmd_key) + cmd_key = self.entity_description.cmd_key + if cmd_key is not None: + self._host.async_register_update_cmd(cmd_key) + + async def async_will_remove_from_hass(self) -> None: + """Entity removed.""" + cmd_key = self.entity_description.cmd_key + if cmd_key is not None: + self._host.async_unregister_update_cmd(cmd_key) + + await super().async_will_remove_from_hass() class ReolinkChannelCoordinatorEntity(ReolinkHostCoordinatorEntity): @@ -128,3 +134,18 @@ class ReolinkChannelCoordinatorEntity(ReolinkHostCoordinatorEntity): sw_version=self._host.api.camera_sw_version(dev_ch), configuration_url=self._conf_url, ) + + async def async_added_to_hass(self) -> None: + """Entity created.""" + await super().async_added_to_hass() + cmd_key = self.entity_description.cmd_key + if cmd_key is not None: + self._host.async_register_update_cmd(cmd_key, self._channel) + + async def async_will_remove_from_hass(self) -> None: + """Entity removed.""" + cmd_key = self.entity_description.cmd_key + if cmd_key is not None: + self._host.async_unregister_update_cmd(cmd_key, self._channel) + + await super().async_will_remove_from_hass() diff --git a/homeassistant/components/reolink/host.py b/homeassistant/components/reolink/host.py index fe8b1596e74..b1a1a9adf0f 100644 --- a/homeassistant/components/reolink/host.py +++ b/homeassistant/components/reolink/host.py @@ -3,6 +3,7 @@ from __future__ import annotations import asyncio +from collections import defaultdict from collections.abc import Mapping import logging from typing import Any, Literal @@ -21,7 +22,7 @@ from homeassistant.const import ( CONF_PROTOCOL, CONF_USERNAME, ) -from homeassistant.core import CALLBACK_TYPE, HassJob, HomeAssistant +from homeassistant.core import CALLBACK_TYPE, HassJob, HomeAssistant, callback from homeassistant.helpers import issue_registry as ir from homeassistant.helpers.device_registry import format_mac from homeassistant.helpers.dispatcher import async_dispatcher_send @@ -67,7 +68,9 @@ class ReolinkHost: timeout=DEFAULT_TIMEOUT, ) - self.update_cmd_list: list[str] = [] + self._update_cmd: defaultdict[str, defaultdict[int | None, int]] = defaultdict( + lambda: defaultdict(int) + ) self.webhook_id: str | None = None self._onvif_push_supported: bool = True @@ -84,6 +87,20 @@ class ReolinkHost: self._long_poll_task: asyncio.Task | None = None self._lost_subscription: bool = False + @callback + def async_register_update_cmd(self, cmd: str, channel: int | None = None) -> None: + """Register the command to update the state.""" + self._update_cmd[cmd][channel] += 1 + + @callback + def async_unregister_update_cmd(self, cmd: str, channel: int | None = None) -> None: + """Unregister the command to update the state.""" + self._update_cmd[cmd][channel] -= 1 + if not self._update_cmd[cmd][channel]: + del self._update_cmd[cmd][channel] + if not self._update_cmd[cmd]: + del self._update_cmd[cmd] + @property def unique_id(self) -> str: """Create the unique ID, base for all entities.""" @@ -320,7 +337,7 @@ class ReolinkHost: async def update_states(self) -> None: """Call the API of the camera device to update the internal states.""" - await self._api.get_states(cmd_list=self.update_cmd_list) + await self._api.get_states(cmd_list=self._update_cmd) async def disconnect(self) -> None: """Disconnect from the API, so the connection will be released.""" diff --git a/homeassistant/components/reolink/manifest.json b/homeassistant/components/reolink/manifest.json index f9050ee73c4..36bc8731925 100644 --- a/homeassistant/components/reolink/manifest.json +++ b/homeassistant/components/reolink/manifest.json @@ -18,5 +18,5 @@ "documentation": "https://www.home-assistant.io/integrations/reolink", "iot_class": "local_push", "loggers": ["reolink_aio"], - "requirements": ["reolink-aio==0.8.11"] + "requirements": ["reolink-aio==0.9.1"] } diff --git a/homeassistant/components/reolink/select.py b/homeassistant/components/reolink/select.py index 13757e7bb22..907cc90b8af 100644 --- a/homeassistant/components/reolink/select.py +++ b/homeassistant/components/reolink/select.py @@ -109,12 +109,14 @@ SELECT_ENTITIES = ( ReolinkSelectEntityDescription( key="status_led", cmd_key="GetPowerLed", - translation_key="status_led", + translation_key="doorbell_led", entity_category=EntityCategory.CONFIG, - get_options=[state.name for state in StatusLedEnum], + get_options=lambda api, ch: api.doorbell_led_list(ch), supported=lambda api, ch: api.supported(ch, "doorbell_led"), value=lambda api, ch: StatusLedEnum(api.doorbell_led(ch)).name, - method=lambda api, ch, name: api.set_status_led(ch, StatusLedEnum[name].value), + method=lambda api, ch, name: ( + api.set_status_led(ch, StatusLedEnum[name].value, doorbell=True) + ), ), ) diff --git a/homeassistant/components/reolink/strings.json b/homeassistant/components/reolink/strings.json index 8191f51d7ef..d1fa0f4426b 100644 --- a/homeassistant/components/reolink/strings.json +++ b/homeassistant/components/reolink/strings.json @@ -463,8 +463,8 @@ "pantiltfirst": "Pan/tilt first" } }, - "status_led": { - "name": "Status LED", + "doorbell_led": { + "name": "Doorbell LED", "state": { "stayoff": "Stay off", "auto": "Auto", diff --git a/requirements_all.txt b/requirements_all.txt index 0a49a7c58b7..54aee2cdafd 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2454,7 +2454,7 @@ renault-api==0.2.3 renson-endura-delta==1.7.1 # homeassistant.components.reolink -reolink-aio==0.8.11 +reolink-aio==0.9.1 # homeassistant.components.idteck_prox rfk101py==0.0.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 2c79fa6c046..1198fee3cac 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1915,7 +1915,7 @@ renault-api==0.2.3 renson-endura-delta==1.7.1 # homeassistant.components.reolink -reolink-aio==0.8.11 +reolink-aio==0.9.1 # homeassistant.components.rflink rflink==0.0.66