From 595a794df18b936bed33adc6b355d1ea793c4c38 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sun, 12 Feb 2023 17:18:07 +0100 Subject: [PATCH 01/17] Add floodlight mode select entity --- .coveragerc | 1 + homeassistant/components/reolink/__init__.py | 2 +- homeassistant/components/reolink/select.py | 93 ++++++++++++++++++++ 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 homeassistant/components/reolink/select.py diff --git a/.coveragerc b/.coveragerc index 2bbbb93cda5e7c..da6a390686da4a 100644 --- a/.coveragerc +++ b/.coveragerc @@ -969,6 +969,7 @@ omit = homeassistant/components/reolink/entity.py homeassistant/components/reolink/host.py homeassistant/components/reolink/number.py + homeassistant/components/reolink/select.py homeassistant/components/repetier/__init__.py homeassistant/components/repetier/sensor.py homeassistant/components/rest/notify.py diff --git a/homeassistant/components/reolink/__init__.py b/homeassistant/components/reolink/__init__.py index 0ff0861f65f2ff..1936786f14cd3c 100644 --- a/homeassistant/components/reolink/__init__.py +++ b/homeassistant/components/reolink/__init__.py @@ -23,7 +23,7 @@ _LOGGER = logging.getLogger(__name__) -PLATFORMS = [Platform.BINARY_SENSOR, Platform.CAMERA, Platform.NUMBER] +PLATFORMS = [Platform.BINARY_SENSOR, Platform.CAMERA, Platform.NUMBER, Platfrom.SELECT] DEVICE_UPDATE_INTERVAL = 60 diff --git a/homeassistant/components/reolink/select.py b/homeassistant/components/reolink/select.py new file mode 100644 index 00000000000000..b2355c56c8c493 --- /dev/null +++ b/homeassistant/components/reolink/select.py @@ -0,0 +1,93 @@ +"""This component provides support for Reolink select entities.""" +from __future__ import annotations + +from collections.abc import Callable +from dataclasses import dataclass +from typing import Any + +from reolink_aio.api import Host, SpotlightModeEnum + +from homeassistant.components.select import (SelectEntity, SelectEntityDescription) +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity_platform import AddEntitiesCallback + +from . import ReolinkData +from .const import DOMAIN +from .entity import ReolinkCoordinatorEntity + + +@dataclass +class ReolinkSelectEntityDescriptionMixin: + """Mixin values for Reolink select entities.""" + + value: Callable[[Host, int | None], bool] + method: Callable[[Host, int | None, float], Any] + + +@dataclass +class ReolinkSelectEntityDescription( + SelectEntityDescription, ReolinkSelectEntityDescriptionMixin +): + """A class that describes select entities.""" + + supported: Callable[[Host, int | None], bool] = lambda api, ch: True + + +SELECT_ENTITIES = ( + ReolinkSelectEntityDescription( + key="floodlight mode", + name="Floodlight mode", + icon="mdi:spotlight-beam", + options=[mode.name for mode in SpotlightModeEnum], + supported=lambda api, ch: api.supported(ch, "floodLight"), + value=lambda api, ch: SpotlightModeEnum(api.whiteled_mode(ch)).name, + method=lambda api, ch, value: api.set_whiteled(ch, mode=value), + ), +) + + +async def async_setup_entry( + hass: HomeAssistant, + config_entry: ConfigEntry, + async_add_entities: AddEntitiesCallback, +) -> None: + """Set up a Reolink select entities.""" + reolink_data: ReolinkData = hass.data[DOMAIN][config_entry.entry_id] + + async_add_entities( + ReolinkSelectEntity(reolink_data, channel, entity_description) + for entity_description in SELECT_ENTITIES + for channel in reolink_data.host.api.channels + if entity_description.supported(reolink_data.host.api, channel) + ) + + +class ReolinkSelectEntity(ReolinkCoordinatorEntity, SelectEntity): + """Base select entity class for Reolink IP cameras.""" + + _attr_has_entity_name = True + entity_description: ReolinkSelectEntityDescription + + def __init__( + self, + reolink_data: ReolinkData, + channel: int, + entity_description: ReolinkSelectEntityDescription, + ) -> None: + """Initialize Reolink select entity.""" + super().__init__(reolink_data, channel) + self.entity_description = entity_description + + self._attr_unique_id = ( + f"{self._host.unique_id}_{self._channel}_{entity_description.key}" + ) + + @property + def current_option(self) -> str: + """The current select option.""" + return self.entity_description.value(self._host.api, self._channel) + + async def async_select_option(self, option: str) -> None: + """Change the selected option.""" + await self.entity_description.method(self._host.api, self._channel, option) From e0ec07e6baf157ff6ba91fefb6a274faafc41c1c Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sun, 12 Feb 2023 17:20:11 +0100 Subject: [PATCH 02/17] fix typo --- homeassistant/components/reolink/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/reolink/__init__.py b/homeassistant/components/reolink/__init__.py index 1936786f14cd3c..6fb8809bbe860c 100644 --- a/homeassistant/components/reolink/__init__.py +++ b/homeassistant/components/reolink/__init__.py @@ -23,7 +23,7 @@ _LOGGER = logging.getLogger(__name__) -PLATFORMS = [Platform.BINARY_SENSOR, Platform.CAMERA, Platform.NUMBER, Platfrom.SELECT] +PLATFORMS = [Platform.BINARY_SENSOR, Platform.CAMERA, Platform.NUMBER, Platform.SELECT] DEVICE_UPDATE_INTERVAL = 60 From 756a7254343b381b056f4e5b9c4a14edabef6c6a Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sun, 12 Feb 2023 17:21:22 +0100 Subject: [PATCH 03/17] fix types --- homeassistant/components/reolink/select.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/reolink/select.py b/homeassistant/components/reolink/select.py index b2355c56c8c493..efb769b15bf972 100644 --- a/homeassistant/components/reolink/select.py +++ b/homeassistant/components/reolink/select.py @@ -21,8 +21,8 @@ class ReolinkSelectEntityDescriptionMixin: """Mixin values for Reolink select entities.""" - value: Callable[[Host, int | None], bool] - method: Callable[[Host, int | None, float], Any] + value: Callable[[Host, int | None], str] + method: Callable[[Host, int | None, str], Any] @dataclass From 55b31a6d1310c7edf848c49a89cd4df5b20a0327 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sun, 12 Feb 2023 17:23:23 +0100 Subject: [PATCH 04/17] fix styling --- homeassistant/components/reolink/select.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/reolink/select.py b/homeassistant/components/reolink/select.py index efb769b15bf972..78089fcea18f44 100644 --- a/homeassistant/components/reolink/select.py +++ b/homeassistant/components/reolink/select.py @@ -7,7 +7,7 @@ from reolink_aio.api import Host, SpotlightModeEnum -from homeassistant.components.select import (SelectEntity, SelectEntityDescription) +from homeassistant.components.select import SelectEntity, SelectEntityDescription from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback From 307d8130fbc0421b70f48b7f22194d5a098f9b98 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sun, 12 Feb 2023 17:40:24 +0100 Subject: [PATCH 05/17] Add DayNight mode support --- homeassistant/components/reolink/select.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/reolink/select.py b/homeassistant/components/reolink/select.py index 78089fcea18f44..6359cabb59f9dc 100644 --- a/homeassistant/components/reolink/select.py +++ b/homeassistant/components/reolink/select.py @@ -5,7 +5,7 @@ from dataclasses import dataclass from typing import Any -from reolink_aio.api import Host, SpotlightModeEnum +from reolink_aio.api import DayNightEnum, Host, SpotlightModeEnum from homeassistant.components.select import SelectEntity, SelectEntityDescription from homeassistant.config_entries import ConfigEntry @@ -36,7 +36,7 @@ class ReolinkSelectEntityDescription( SELECT_ENTITIES = ( ReolinkSelectEntityDescription( - key="floodlight mode", + key="floodlight_mode", name="Floodlight mode", icon="mdi:spotlight-beam", options=[mode.name for mode in SpotlightModeEnum], @@ -44,6 +44,15 @@ class ReolinkSelectEntityDescription( value=lambda api, ch: SpotlightModeEnum(api.whiteled_mode(ch)).name, method=lambda api, ch, value: api.set_whiteled(ch, mode=value), ), + ReolinkSelectEntityDescription( + key="day_night_mode", + name="Day night mode", + icon="mdi:theme-light-dark", + options=[mode.value for mode in DayNightEnum], + supported=lambda api, ch: api.supported(ch, "dayNight"), + value=lambda api, ch: api.daynight_state(ch), + method=lambda api, ch, value: api.set_daynight(ch, value), + ), ) From e71d453d9d35b993bcd1248d88ca3198b5475e0c Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sun, 12 Feb 2023 19:18:06 +0100 Subject: [PATCH 06/17] fix docstring --- homeassistant/components/reolink/select.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/reolink/select.py b/homeassistant/components/reolink/select.py index 6359cabb59f9dc..0f4af4f2c62044 100644 --- a/homeassistant/components/reolink/select.py +++ b/homeassistant/components/reolink/select.py @@ -94,7 +94,7 @@ def __init__( @property def current_option(self) -> str: - """The current select option.""" + """Return the current option.""" return self.entity_description.value(self._host.api, self._channel) async def async_select_option(self, option: str) -> None: From 08b7167b76d1f7fa89bb4bc0810f7117a83c67de Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Mon, 13 Feb 2023 10:02:41 +0100 Subject: [PATCH 07/17] Add select translation keys --- homeassistant/components/reolink/select.py | 2 ++ homeassistant/components/reolink/strings.json | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/homeassistant/components/reolink/select.py b/homeassistant/components/reolink/select.py index 0f4af4f2c62044..1a8c53301962d0 100644 --- a/homeassistant/components/reolink/select.py +++ b/homeassistant/components/reolink/select.py @@ -39,6 +39,7 @@ class ReolinkSelectEntityDescription( key="floodlight_mode", name="Floodlight mode", icon="mdi:spotlight-beam", + translation_key="floodlight_mode", options=[mode.name for mode in SpotlightModeEnum], supported=lambda api, ch: api.supported(ch, "floodLight"), value=lambda api, ch: SpotlightModeEnum(api.whiteled_mode(ch)).name, @@ -48,6 +49,7 @@ class ReolinkSelectEntityDescription( key="day_night_mode", name="Day night mode", icon="mdi:theme-light-dark", + translation_key="day_night_mode", options=[mode.value for mode in DayNightEnum], supported=lambda api, ch: api.supported(ch, "dayNight"), value=lambda api, ch: api.daynight_state(ch), diff --git a/homeassistant/components/reolink/strings.json b/homeassistant/components/reolink/strings.json index cc609488762b17..df2ac2ec5e045a 100644 --- a/homeassistant/components/reolink/strings.json +++ b/homeassistant/components/reolink/strings.json @@ -43,5 +43,23 @@ "title": "Reolink webhook URL uses HTTPS (SSL)", "description": "Reolink products can not push motion events to an HTTPS address (SSL), please configure a (local) HTTP address under \"Home Assistant URL\" in the [network settings]({network_link}). The current (local) address is: `{base_url}`" } + }, + "entity": { + "select": { + "floodlight_mode": { + "state": { + "Off": "Off", + "Auto": "Auto", + "Schedule": "Schedule" + } + }, + "day_night_mode": { + "state": { + "Auto": "Auto", + "Color": "Color", + "Black&White": "Black&White" + } + } + } } } From f22780faa2964d1f2a2ab82bff01f07ad59afea0 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Mon, 13 Feb 2023 10:21:46 +0100 Subject: [PATCH 08/17] Do not use capital letters in options --- homeassistant/components/reolink/select.py | 8 ++++---- homeassistant/components/reolink/strings.json | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/reolink/select.py b/homeassistant/components/reolink/select.py index 1a8c53301962d0..d92a44e11c02df 100644 --- a/homeassistant/components/reolink/select.py +++ b/homeassistant/components/reolink/select.py @@ -43,17 +43,17 @@ class ReolinkSelectEntityDescription( options=[mode.name for mode in SpotlightModeEnum], supported=lambda api, ch: api.supported(ch, "floodLight"), value=lambda api, ch: SpotlightModeEnum(api.whiteled_mode(ch)).name, - method=lambda api, ch, value: api.set_whiteled(ch, mode=value), + method=lambda api, ch, name: api.set_whiteled(ch, mode=name), ), ReolinkSelectEntityDescription( key="day_night_mode", name="Day night mode", icon="mdi:theme-light-dark", translation_key="day_night_mode", - options=[mode.value for mode in DayNightEnum], + options=[mode.name for mode in DayNightEnum], supported=lambda api, ch: api.supported(ch, "dayNight"), - value=lambda api, ch: api.daynight_state(ch), - method=lambda api, ch, value: api.set_daynight(ch, value), + value=lambda api, ch: DayNightEnum(api.daynight_state(ch)).name, + method=lambda api, ch, name: api.set_daynight(ch, DayNightEnum[name].value), ), ) diff --git a/homeassistant/components/reolink/strings.json b/homeassistant/components/reolink/strings.json index df2ac2ec5e045a..f4cb8a904ffd79 100644 --- a/homeassistant/components/reolink/strings.json +++ b/homeassistant/components/reolink/strings.json @@ -48,16 +48,16 @@ "select": { "floodlight_mode": { "state": { - "Off": "Off", - "Auto": "Auto", - "Schedule": "Schedule" + "off": "Off", + "auto": "Auto", + "schedule": "Schedule" } }, "day_night_mode": { "state": { - "Auto": "Auto", - "Color": "Color", - "Black&White": "Black&White" + "auto": "Auto", + "color": "Color", + "blackwhite": "Black&White" } } } From 81e73f4c939942ac5267d44dceff734787c7be6c Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Wed, 22 Feb 2023 19:38:31 +0100 Subject: [PATCH 09/17] fix styling --- homeassistant/components/reolink/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/reolink/__init__.py b/homeassistant/components/reolink/__init__.py index d27d5147cc819b..4c0cf6d56f208e 100644 --- a/homeassistant/components/reolink/__init__.py +++ b/homeassistant/components/reolink/__init__.py @@ -23,7 +23,13 @@ _LOGGER = logging.getLogger(__name__) -PLATFORMS = [Platform.BINARY_SENSOR, Platform.CAMERA, Platform.NUMBER, Platform.SELECT, Platform.UPDATE] +PLATFORMS = [ + Platform.BINARY_SENSOR, + Platform.CAMERA, + Platform.NUMBER, + Platform.SELECT, + Platform.UPDATE, +] DEVICE_UPDATE_INTERVAL = timedelta(seconds=60) FIRMWARE_UPDATE_INTERVAL = timedelta(hours=12) From 784e14b12f35c0d3056af6fbc20724dd1da89b71 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Wed, 22 Feb 2023 23:57:26 +0100 Subject: [PATCH 10/17] Add PTZ preset support --- homeassistant/components/reolink/select.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/reolink/select.py b/homeassistant/components/reolink/select.py index d92a44e11c02df..addb1a0d388628 100644 --- a/homeassistant/components/reolink/select.py +++ b/homeassistant/components/reolink/select.py @@ -21,7 +21,6 @@ class ReolinkSelectEntityDescriptionMixin: """Mixin values for Reolink select entities.""" - value: Callable[[Host, int | None], str] method: Callable[[Host, int | None, str], Any] @@ -32,6 +31,8 @@ class ReolinkSelectEntityDescription( """A class that describes select entities.""" supported: Callable[[Host, int | None], bool] = lambda api, ch: True + value: Callable[[Host, int | None], str] | None = None + get_options: Callable[[Host, int | None], Any] | None = None SELECT_ENTITIES = ( @@ -55,6 +56,14 @@ class ReolinkSelectEntityDescription( value=lambda api, ch: DayNightEnum(api.daynight_state(ch)).name, method=lambda api, ch, name: api.set_daynight(ch, DayNightEnum[name].value), ), + ReolinkSelectEntityDescription( + key="ptz_preset", + name="PTZ preset", + icon="mdi:pan", + get_options=lambda api, ch: list(api.ptz_presets(ch).keys()), + supported=lambda api, ch: api.supported(ch, "ptz_presets"), + method=lambda api, ch, name: api.set_ptz_command(ch, preset=name), + ), ) @@ -94,9 +103,17 @@ def __init__( f"{self._host.unique_id}_{self._channel}_{entity_description.key}" ) + if entity_description.get_options is not None: + self._attr_options = entity_description.get_options( + self._host.api, self._channel + ) + @property - def current_option(self) -> str: + def current_option(self) -> str | None: """Return the current option.""" + if self.entity_description.value is None: + return None + return self.entity_description.value(self._host.api, self._channel) async def async_select_option(self, option: str) -> None: From af9471ce73cf5772b6d6956a443c22e3a4dd2166 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Thu, 23 Feb 2023 22:16:50 +0100 Subject: [PATCH 11/17] remove duplicate const --- homeassistant/components/reolink/select.py | 1 - 1 file changed, 1 deletion(-) diff --git a/homeassistant/components/reolink/select.py b/homeassistant/components/reolink/select.py index addb1a0d388628..48b94871978d38 100644 --- a/homeassistant/components/reolink/select.py +++ b/homeassistant/components/reolink/select.py @@ -86,7 +86,6 @@ async def async_setup_entry( class ReolinkSelectEntity(ReolinkCoordinatorEntity, SelectEntity): """Base select entity class for Reolink IP cameras.""" - _attr_has_entity_name = True entity_description: ReolinkSelectEntityDescription def __init__( From 39038a72cc8a0f59c8529107f76d954dcbf3b930 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Fri, 3 Mar 2023 11:16:00 +0100 Subject: [PATCH 12/17] require channel --- homeassistant/components/reolink/select.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/reolink/select.py b/homeassistant/components/reolink/select.py index 48b94871978d38..eec27c4cfaea16 100644 --- a/homeassistant/components/reolink/select.py +++ b/homeassistant/components/reolink/select.py @@ -21,7 +21,7 @@ class ReolinkSelectEntityDescriptionMixin: """Mixin values for Reolink select entities.""" - method: Callable[[Host, int | None, str], Any] + method: Callable[[Host, int, str], Any] @dataclass @@ -30,9 +30,9 @@ class ReolinkSelectEntityDescription( ): """A class that describes select entities.""" - supported: Callable[[Host, int | None], bool] = lambda api, ch: True - value: Callable[[Host, int | None], str] | None = None - get_options: Callable[[Host, int | None], Any] | None = None + supported: Callable[[Host, int], bool] = lambda api, ch: True + value: Callable[[Host, int], str] | None = None + get_options: Callable[[Host, int], Any] | None = None SELECT_ENTITIES = ( From 525e97a5da89ebd2f93c8d90f205eda170450939 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sat, 4 Mar 2023 13:41:09 +0100 Subject: [PATCH 13/17] Adjust docstring --- homeassistant/components/reolink/select.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/reolink/select.py b/homeassistant/components/reolink/select.py index eec27c4cfaea16..9bc7e1fb2afc61 100644 --- a/homeassistant/components/reolink/select.py +++ b/homeassistant/components/reolink/select.py @@ -1,4 +1,4 @@ -"""This component provides support for Reolink select entities.""" +"""Component providing support for Reolink select entities.""" from __future__ import annotations from collections.abc import Callable From 0a5391fb455b848ca5d0449f1eb8c4224dc3fd11 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sat, 4 Mar 2023 14:02:47 +0100 Subject: [PATCH 14/17] make get_options required --- homeassistant/components/reolink/select.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/reolink/select.py b/homeassistant/components/reolink/select.py index 9bc7e1fb2afc61..686344ff113b32 100644 --- a/homeassistant/components/reolink/select.py +++ b/homeassistant/components/reolink/select.py @@ -22,6 +22,7 @@ class ReolinkSelectEntityDescriptionMixin: """Mixin values for Reolink select entities.""" method: Callable[[Host, int, str], Any] + get_options: list[str] | Callable[[Host, int], list[str]] @dataclass @@ -32,7 +33,6 @@ class ReolinkSelectEntityDescription( supported: Callable[[Host, int], bool] = lambda api, ch: True value: Callable[[Host, int], str] | None = None - get_options: Callable[[Host, int], Any] | None = None SELECT_ENTITIES = ( @@ -41,7 +41,7 @@ class ReolinkSelectEntityDescription( name="Floodlight mode", icon="mdi:spotlight-beam", translation_key="floodlight_mode", - options=[mode.name for mode in SpotlightModeEnum], + get_options=[mode.name for mode in SpotlightModeEnum], supported=lambda api, ch: api.supported(ch, "floodLight"), value=lambda api, ch: SpotlightModeEnum(api.whiteled_mode(ch)).name, method=lambda api, ch, name: api.set_whiteled(ch, mode=name), @@ -51,7 +51,7 @@ class ReolinkSelectEntityDescription( name="Day night mode", icon="mdi:theme-light-dark", translation_key="day_night_mode", - options=[mode.name for mode in DayNightEnum], + get_options=[mode.name for mode in DayNightEnum], supported=lambda api, ch: api.supported(ch, "dayNight"), value=lambda api, ch: DayNightEnum(api.daynight_state(ch)).name, method=lambda api, ch, name: api.set_daynight(ch, DayNightEnum[name].value), @@ -102,10 +102,12 @@ def __init__( f"{self._host.unique_id}_{self._channel}_{entity_description.key}" ) - if entity_description.get_options is not None: + if callable(entity_description.get_options): self._attr_options = entity_description.get_options( self._host.api, self._channel ) + else: + self._attr_options = entity_description.get_options @property def current_option(self) -> str | None: From 584bf3c77798cd941680f0894b4185775191746a Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sat, 4 Mar 2023 23:57:58 +0100 Subject: [PATCH 15/17] Add EntityCategory --- homeassistant/components/reolink/select.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/reolink/select.py b/homeassistant/components/reolink/select.py index 686344ff113b32..f9048a38ed1867 100644 --- a/homeassistant/components/reolink/select.py +++ b/homeassistant/components/reolink/select.py @@ -9,6 +9,7 @@ from homeassistant.components.select import SelectEntity, SelectEntityDescription from homeassistant.config_entries import ConfigEntry +from homeassistant.const import EntityCategory from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -40,6 +41,7 @@ class ReolinkSelectEntityDescription( key="floodlight_mode", name="Floodlight mode", icon="mdi:spotlight-beam", + entity_category=EntityCategory.CONFIG, translation_key="floodlight_mode", get_options=[mode.name for mode in SpotlightModeEnum], supported=lambda api, ch: api.supported(ch, "floodLight"), @@ -50,6 +52,7 @@ class ReolinkSelectEntityDescription( key="day_night_mode", name="Day night mode", icon="mdi:theme-light-dark", + entity_category=EntityCategory.CONFIG, translation_key="day_night_mode", get_options=[mode.name for mode in DayNightEnum], supported=lambda api, ch: api.supported(ch, "dayNight"), @@ -99,12 +102,12 @@ def __init__( self.entity_description = entity_description self._attr_unique_id = ( - f"{self._host.unique_id}_{self._channel}_{entity_description.key}" + f"{self._host.unique_id}_{channel}_{entity_description.key}" ) if callable(entity_description.get_options): self._attr_options = entity_description.get_options( - self._host.api, self._channel + self._host.api, channel ) else: self._attr_options = entity_description.get_options From f51f50df9d58d2ca4ee0a8de424c12aa19197b28 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sat, 4 Mar 2023 23:58:40 +0100 Subject: [PATCH 16/17] fix styling --- homeassistant/components/reolink/select.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/homeassistant/components/reolink/select.py b/homeassistant/components/reolink/select.py index f9048a38ed1867..8a64d84acf645b 100644 --- a/homeassistant/components/reolink/select.py +++ b/homeassistant/components/reolink/select.py @@ -106,9 +106,7 @@ def __init__( ) if callable(entity_description.get_options): - self._attr_options = entity_description.get_options( - self._host.api, channel - ) + self._attr_options = entity_description.get_options(self._host.api, channel) else: self._attr_options = entity_description.get_options From ec2ae904be3271688798d8f0be6ab962b83f2a50 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sun, 5 Mar 2023 22:34:30 +0100 Subject: [PATCH 17/17] Update homeassistant/components/reolink/select.py Co-authored-by: Franck Nijhof --- homeassistant/components/reolink/select.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/reolink/select.py b/homeassistant/components/reolink/select.py index 8a64d84acf645b..8df4afba735dff 100644 --- a/homeassistant/components/reolink/select.py +++ b/homeassistant/components/reolink/select.py @@ -63,7 +63,7 @@ class ReolinkSelectEntityDescription( key="ptz_preset", name="PTZ preset", icon="mdi:pan", - get_options=lambda api, ch: list(api.ptz_presets(ch).keys()), + get_options=lambda api, ch: list(api.ptz_presets(ch)), supported=lambda api, ch: api.supported(ch, "ptz_presets"), method=lambda api, ch, name: api.set_ptz_command(ch, preset=name), ),