-
-
Notifications
You must be signed in to change notification settings - Fork 38.2k
Reolink add select platform #87946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Reolink add select platform #87946
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
595a794
Add floodlight mode select entity
starkillerOG e0ec07e
fix typo
starkillerOG 756a725
fix types
starkillerOG 55b31a6
fix styling
starkillerOG 307d813
Add DayNight mode support
starkillerOG e71d453
fix docstring
starkillerOG 08b7167
Add select translation keys
starkillerOG f22780f
Do not use capital letters in options
starkillerOG 8af4666
Merge branch 'dev' into reolink_select
starkillerOG 11e35cf
Merge branch 'dev' into reolink_select
starkillerOG af688b5
Merge branch 'dev' into reolink_select
starkillerOG 81e73f4
fix styling
starkillerOG 784e14b
Add PTZ preset support
starkillerOG 1cd944f
Merge remote-tracking branch 'upstream/dev' into reolink_select
starkillerOG af9471c
remove duplicate const
starkillerOG 39038a7
require channel
starkillerOG 525e97a
Adjust docstring
starkillerOG 0a5391f
make get_options required
starkillerOG 584bf3c
Add EntityCategory
starkillerOG f51f50d
fix styling
starkillerOG ec2ae90
Update homeassistant/components/reolink/select.py
starkillerOG c110421
Merge branch 'dev' into reolink_select
starkillerOG File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| """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 DayNightEnum, 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.""" | ||
|
|
||
| method: Callable[[Host, int, str], Any] | ||
|
|
||
|
|
||
| @dataclass | ||
| class ReolinkSelectEntityDescription( | ||
| SelectEntityDescription, ReolinkSelectEntityDescriptionMixin | ||
| ): | ||
| """A class that describes select entities.""" | ||
|
|
||
| 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 = ( | ||
| 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, | ||
| 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.name for mode in DayNightEnum], | ||
|
starkillerOG marked this conversation as resolved.
Outdated
|
||
| 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), | ||
| ), | ||
| ReolinkSelectEntityDescription( | ||
| key="ptz_preset", | ||
| name="PTZ preset", | ||
| icon="mdi:pan", | ||
| get_options=lambda api, ch: list(api.ptz_presets(ch).keys()), | ||
|
starkillerOG marked this conversation as resolved.
Outdated
|
||
| supported=lambda api, ch: api.supported(ch, "ptz_presets"), | ||
| method=lambda api, ch, name: api.set_ptz_command(ch, preset=name), | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| 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.""" | ||
|
|
||
| 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}" | ||
| ) | ||
|
|
||
| if entity_description.get_options is not None: | ||
|
starkillerOG marked this conversation as resolved.
Outdated
|
||
| self._attr_options = entity_description.get_options( | ||
| self._host.api, self._channel | ||
| ) | ||
|
|
||
| @property | ||
| 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: | ||
| """Change the selected option.""" | ||
| await self.entity_description.method(self._host.api, self._channel, option) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.