diff --git a/homeassistant/components/xiaomi_miio/select.py b/homeassistant/components/xiaomi_miio/select.py index 118f3cd5c77..9b5f0f50a06 100644 --- a/homeassistant/components/xiaomi_miio/select.py +++ b/homeassistant/components/xiaomi_miio/select.py @@ -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()