From 626ae7be9b8c48fc2877bd6deb95ae00acc62083 Mon Sep 17 00:00:00 2001 From: Maciej Bieniek Date: Tue, 4 Jan 2022 22:43:22 +0100 Subject: [PATCH] Do not create a number LED brightness entity for Xiaomi Miio devices that do not support it (#62819) Co-authored-by: Paulus Schoutsen --- homeassistant/components/xiaomi_miio/number.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/homeassistant/components/xiaomi_miio/number.py b/homeassistant/components/xiaomi_miio/number.py index b2a3f4e9f5e..22e6b8da55f 100644 --- a/homeassistant/components/xiaomi_miio/number.py +++ b/homeassistant/components/xiaomi_miio/number.py @@ -4,6 +4,7 @@ from __future__ import annotations from dataclasses import dataclass from homeassistant.components.number import NumberEntity, NumberEntityDescription +from homeassistant.components.number.const import DOMAIN as PLATFORM_DOMAIN from homeassistant.config_entries import ConfigEntry from homeassistant.const import DEGREE, TIME_MINUTES from homeassistant.core import HomeAssistant, callback @@ -252,6 +253,15 @@ async def async_setup_entry( return for feature, description in NUMBER_TYPES.items(): + if feature == FEATURE_SET_LED_BRIGHTNESS and model != MODEL_FAN_ZA5: + # Delete LED bightness entity created by mistake if it exists + entity_reg = hass.helpers.entity_registry.async_get() + entity_id = entity_reg.async_get_entity_id( + PLATFORM_DOMAIN, DOMAIN, f"{description.key}_{config_entry.unique_id}" + ) + if entity_id: + entity_reg.async_remove(entity_id) + continue if feature & features: if ( description.key == ATTR_OSCILLATION_ANGLE