Do not crash on non-existing enum values in xiaomi_miio.select (#82625)
fixes undefinedpull/82661/head
parent
3b0a42f8f4
commit
e4fbbdfa05
|
@ -2,6 +2,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
import logging
|
||||
from typing import NamedTuple
|
||||
|
||||
from miio.fan_common import LedBrightness as FanLedBrightness
|
||||
|
@ -66,6 +67,9 @@ ATTR_LED_BRIGHTNESS = "led_brightness"
|
|||
ATTR_PTC_LEVEL = "ptc_level"
|
||||
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@dataclass
|
||||
class XiaomiMiioSelectDescription(SelectEntityDescription):
|
||||
"""A class that describes select entities."""
|
||||
|
@ -248,11 +252,17 @@ class XiaomiGenericSelector(XiaomiSelector):
|
|||
@callback
|
||||
def _handle_coordinator_update(self):
|
||||
"""Fetch state from the device."""
|
||||
attr = self._enum_class(
|
||||
self._extract_value_from_attribute(
|
||||
try:
|
||||
value = self._extract_value_from_attribute(
|
||||
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:
|
||||
self._current_attr = attr
|
||||
self.async_write_ha_state()
|
||||
|
|
Loading…
Reference in New Issue