From a238cce37c13e02842e1361ec79397e1f8c2d993 Mon Sep 17 00:00:00 2001 From: Maciej Bieniek Date: Thu, 7 Oct 2021 17:44:25 +0200 Subject: [PATCH] Update led brightness select state only if valid data is available, Xiaomi Miio integration (#57197) * Update state if there is valid data * Add comment --- homeassistant/components/xiaomi_miio/select.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/xiaomi_miio/select.py b/homeassistant/components/xiaomi_miio/select.py index daa721fef95..9e9cdcec1ae 100644 --- a/homeassistant/components/xiaomi_miio/select.py +++ b/homeassistant/components/xiaomi_miio/select.py @@ -146,10 +146,14 @@ class XiaomiAirHumidifierSelector(XiaomiSelector): @callback def _handle_coordinator_update(self): """Fetch state from the device.""" - self._current_led_brightness = self._extract_value_from_attribute( + led_brightness = self._extract_value_from_attribute( self.coordinator.data, self.entity_description.key ) - self.async_write_ha_state() + # Sometimes (quite rarely) the device returns None as the LED brightness so we + # check that the value is not None before updating the state. + if led_brightness: + self._current_led_brightness = led_brightness + self.async_write_ha_state() @property def current_option(self):