Do not create a number LED brightness entity for Xiaomi Miio devices that do not support it (#62819)

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
Maciej Bieniek
2022-01-04 14:08:32 -08:00
committed by Paulus Schoutsen
co-authored by Paulus Schoutsen
parent e3d2993d98
commit 76d5e2ea90
@@ -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.const import DEGREE, ENTITY_CATEGORY_CONFIG, TIME_MINUTES
from homeassistant.core import callback
@@ -248,6 +249,15 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
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