mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Do not crash on non-existing enum values in xiaomi_miio.select (#82625)
fixes undefined
This commit is contained in:
parent
3b0a42f8f4
commit
e4fbbdfa05
@ -2,6 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
|
import logging
|
||||||
from typing import NamedTuple
|
from typing import NamedTuple
|
||||||
|
|
||||||
from miio.fan_common import LedBrightness as FanLedBrightness
|
from miio.fan_common import LedBrightness as FanLedBrightness
|
||||||
@ -66,6 +67,9 @@ ATTR_LED_BRIGHTNESS = "led_brightness"
|
|||||||
ATTR_PTC_LEVEL = "ptc_level"
|
ATTR_PTC_LEVEL = "ptc_level"
|
||||||
|
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class XiaomiMiioSelectDescription(SelectEntityDescription):
|
class XiaomiMiioSelectDescription(SelectEntityDescription):
|
||||||
"""A class that describes select entities."""
|
"""A class that describes select entities."""
|
||||||
@ -248,11 +252,17 @@ class XiaomiGenericSelector(XiaomiSelector):
|
|||||||
@callback
|
@callback
|
||||||
def _handle_coordinator_update(self):
|
def _handle_coordinator_update(self):
|
||||||
"""Fetch state from the device."""
|
"""Fetch state from the device."""
|
||||||
attr = self._enum_class(
|
try:
|
||||||
self._extract_value_from_attribute(
|
value = self._extract_value_from_attribute(
|
||||||
self.coordinator.data, self.entity_description.attr_name
|
self.coordinator.data, self.entity_description.attr_name
|
||||||
)
|
)
|
||||||
)
|
attr = self._enum_class(value)
|
||||||
|
except ValueError: # if the value does not exist in
|
||||||
|
_LOGGER.debug(
|
||||||
|
"Value '%s' does not exist in enum %s", value, self._enum_class
|
||||||
|
)
|
||||||
|
attr = None
|
||||||
|
|
||||||
if attr is not None:
|
if attr is not None:
|
||||||
self._current_attr = attr
|
self._current_attr = attr
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user