mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Reolink fix unknown value in select enums (#99012)
This commit is contained in:
parent
da9fc495ca
commit
bab7d289a6
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from reolink_aio.api import (
|
from reolink_aio.api import (
|
||||||
@ -23,6 +24,8 @@ from . import ReolinkData
|
|||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .entity import ReolinkChannelCoordinatorEntity
|
from .entity import ReolinkChannelCoordinatorEntity
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ReolinkSelectEntityDescriptionMixin:
|
class ReolinkSelectEntityDescriptionMixin:
|
||||||
@ -135,6 +138,7 @@ class ReolinkSelectEntity(ReolinkChannelCoordinatorEntity, SelectEntity):
|
|||||||
"""Initialize Reolink select entity."""
|
"""Initialize Reolink select entity."""
|
||||||
super().__init__(reolink_data, channel)
|
super().__init__(reolink_data, channel)
|
||||||
self.entity_description = entity_description
|
self.entity_description = entity_description
|
||||||
|
self._log_error = True
|
||||||
|
|
||||||
self._attr_unique_id = (
|
self._attr_unique_id = (
|
||||||
f"{self._host.unique_id}_{channel}_{entity_description.key}"
|
f"{self._host.unique_id}_{channel}_{entity_description.key}"
|
||||||
@ -151,7 +155,16 @@ class ReolinkSelectEntity(ReolinkChannelCoordinatorEntity, SelectEntity):
|
|||||||
if self.entity_description.value is None:
|
if self.entity_description.value is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return self.entity_description.value(self._host.api, self._channel)
|
try:
|
||||||
|
option = self.entity_description.value(self._host.api, self._channel)
|
||||||
|
except ValueError:
|
||||||
|
if self._log_error:
|
||||||
|
_LOGGER.exception("Reolink '%s' has an unknown value", self.name)
|
||||||
|
self._log_error = False
|
||||||
|
return None
|
||||||
|
|
||||||
|
self._log_error = True
|
||||||
|
return option
|
||||||
|
|
||||||
async def async_select_option(self, option: str) -> None:
|
async def async_select_option(self, option: str) -> None:
|
||||||
"""Change the selected option."""
|
"""Change the selected option."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user