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 22:43:22 +01:00 committed by GitHub
parent f0acbabd48
commit 626ae7be9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,6 +4,7 @@ from __future__ import annotations
from dataclasses import dataclass from dataclasses import dataclass
from homeassistant.components.number import NumberEntity, NumberEntityDescription 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.config_entries import ConfigEntry
from homeassistant.const import DEGREE, TIME_MINUTES from homeassistant.const import DEGREE, TIME_MINUTES
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
@ -252,6 +253,15 @@ async def async_setup_entry(
return return
for feature, description in NUMBER_TYPES.items(): 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 feature & features:
if ( if (
description.key == ATTR_OSCILLATION_ANGLE description.key == ATTR_OSCILLATION_ANGLE