Fix Xiaomi humidifier name migration (#53738)
This commit is contained in:
parent
96b02153b9
commit
1e33017db8
7 changed files with 8 additions and 35 deletions
|
@ -21,7 +21,6 @@ from .const import (
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
KEY_COORDINATOR,
|
KEY_COORDINATOR,
|
||||||
KEY_DEVICE,
|
KEY_DEVICE,
|
||||||
KEY_MIGRATE_ENTITY_NAME,
|
|
||||||
MODELS_AIR_MONITOR,
|
MODELS_AIR_MONITOR,
|
||||||
MODELS_FAN,
|
MODELS_FAN,
|
||||||
MODELS_HUMIDIFIER,
|
MODELS_HUMIDIFIER,
|
||||||
|
@ -112,12 +111,13 @@ async def async_create_miio_device_and_coordinator(
|
||||||
else:
|
else:
|
||||||
device = AirHumidifier(host, token, model=model)
|
device = AirHumidifier(host, token, model=model)
|
||||||
|
|
||||||
# Removing fan platform entity for humidifiers and cache the name and entity name for migration
|
# Removing fan platform entity for humidifiers and migrate the name to the config entry for migration
|
||||||
entity_registry = er.async_get(hass)
|
entity_registry = er.async_get(hass)
|
||||||
entity_id = entity_registry.async_get_entity_id("fan", DOMAIN, entry.unique_id)
|
entity_id = entity_registry.async_get_entity_id("fan", DOMAIN, entry.unique_id)
|
||||||
if entity_id:
|
if entity_id:
|
||||||
# This check is entities that have a platform migration only and should be removed in the future
|
# This check is entities that have a platform migration only and should be removed in the future
|
||||||
migrate_entity_name = entity_registry.async_get(entity_id).name
|
migrate_entity_name = entity_registry.async_get(entity_id).name
|
||||||
|
hass.config_entries.async_update_entry(entry, title=migrate_entity_name)
|
||||||
entity_registry.async_remove(entity_id)
|
entity_registry.async_remove(entity_id)
|
||||||
|
|
||||||
async def async_update_data():
|
async def async_update_data():
|
||||||
|
@ -142,8 +142,6 @@ async def async_create_miio_device_and_coordinator(
|
||||||
KEY_DEVICE: device,
|
KEY_DEVICE: device,
|
||||||
KEY_COORDINATOR: coordinator,
|
KEY_COORDINATOR: coordinator,
|
||||||
}
|
}
|
||||||
if migrate_entity_name:
|
|
||||||
hass.data[DOMAIN][entry.entry_id][KEY_MIGRATE_ENTITY_NAME] = migrate_entity_name
|
|
||||||
|
|
||||||
# Trigger first data fetch
|
# Trigger first data fetch
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
|
@ -18,7 +18,6 @@ CONF_CLOUD_SUBDEVICES = "cloud_subdevices"
|
||||||
# Keys
|
# Keys
|
||||||
KEY_COORDINATOR = "coordinator"
|
KEY_COORDINATOR = "coordinator"
|
||||||
KEY_DEVICE = "device"
|
KEY_DEVICE = "device"
|
||||||
KEY_MIGRATE_ENTITY_NAME = "migrate_entity_name"
|
|
||||||
|
|
||||||
# Attributes
|
# Attributes
|
||||||
ATTR_AVAILABLE = "available"
|
ATTR_AVAILABLE = "available"
|
||||||
|
|
|
@ -24,7 +24,6 @@ from .const import (
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
KEY_COORDINATOR,
|
KEY_COORDINATOR,
|
||||||
KEY_DEVICE,
|
KEY_DEVICE,
|
||||||
KEY_MIGRATE_ENTITY_NAME,
|
|
||||||
MODEL_AIRHUMIDIFIER_CA1,
|
MODEL_AIRHUMIDIFIER_CA1,
|
||||||
MODEL_AIRHUMIDIFIER_CA4,
|
MODEL_AIRHUMIDIFIER_CA4,
|
||||||
MODEL_AIRHUMIDIFIER_CB1,
|
MODEL_AIRHUMIDIFIER_CB1,
|
||||||
|
@ -52,10 +51,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
model = config_entry.data[CONF_MODEL]
|
model = config_entry.data[CONF_MODEL]
|
||||||
unique_id = config_entry.unique_id
|
unique_id = config_entry.unique_id
|
||||||
coordinator = hass.data[DOMAIN][config_entry.entry_id][KEY_COORDINATOR]
|
coordinator = hass.data[DOMAIN][config_entry.entry_id][KEY_COORDINATOR]
|
||||||
if KEY_MIGRATE_ENTITY_NAME in hass.data[DOMAIN][config_entry.entry_id]:
|
name = config_entry.title
|
||||||
name = hass.data[DOMAIN][config_entry.entry_id][KEY_MIGRATE_ENTITY_NAME]
|
|
||||||
else:
|
|
||||||
name = config_entry.title
|
|
||||||
|
|
||||||
if model in MODELS_HUMIDIFIER_MIOT:
|
if model in MODELS_HUMIDIFIER_MIOT:
|
||||||
air_humidifier = hass.data[DOMAIN][config_entry.entry_id][KEY_DEVICE]
|
air_humidifier = hass.data[DOMAIN][config_entry.entry_id][KEY_DEVICE]
|
||||||
|
|
|
@ -13,7 +13,6 @@ from .const import (
|
||||||
FEATURE_SET_MOTOR_SPEED,
|
FEATURE_SET_MOTOR_SPEED,
|
||||||
KEY_COORDINATOR,
|
KEY_COORDINATOR,
|
||||||
KEY_DEVICE,
|
KEY_DEVICE,
|
||||||
KEY_MIGRATE_ENTITY_NAME,
|
|
||||||
MODEL_AIRHUMIDIFIER_CA4,
|
MODEL_AIRHUMIDIFIER_CA4,
|
||||||
)
|
)
|
||||||
from .device import XiaomiCoordinatedMiioEntity
|
from .device import XiaomiCoordinatedMiioEntity
|
||||||
|
@ -58,10 +57,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
model = config_entry.data[CONF_MODEL]
|
model = config_entry.data[CONF_MODEL]
|
||||||
device = hass.data[DOMAIN][config_entry.entry_id][KEY_DEVICE]
|
device = hass.data[DOMAIN][config_entry.entry_id][KEY_DEVICE]
|
||||||
coordinator = hass.data[DOMAIN][config_entry.entry_id][KEY_COORDINATOR]
|
coordinator = hass.data[DOMAIN][config_entry.entry_id][KEY_COORDINATOR]
|
||||||
if KEY_MIGRATE_ENTITY_NAME in hass.data[DOMAIN][config_entry.entry_id]:
|
|
||||||
name = hass.data[DOMAIN][config_entry.entry_id][KEY_MIGRATE_ENTITY_NAME]
|
|
||||||
else:
|
|
||||||
name = config_entry.title
|
|
||||||
|
|
||||||
if model not in [MODEL_AIRHUMIDIFIER_CA4]:
|
if model not in [MODEL_AIRHUMIDIFIER_CA4]:
|
||||||
return
|
return
|
||||||
|
@ -69,7 +64,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
for number in NUMBER_TYPES.values():
|
for number in NUMBER_TYPES.values():
|
||||||
entities.append(
|
entities.append(
|
||||||
XiaomiAirHumidifierNumber(
|
XiaomiAirHumidifierNumber(
|
||||||
f"{name} {number.name}",
|
f"{config_entry.title} {number.name}",
|
||||||
device,
|
device,
|
||||||
config_entry,
|
config_entry,
|
||||||
f"{number.short_name}_{config_entry.unique_id}",
|
f"{number.short_name}_{config_entry.unique_id}",
|
||||||
|
|
|
@ -16,7 +16,6 @@ from .const import (
|
||||||
FEATURE_SET_LED_BRIGHTNESS,
|
FEATURE_SET_LED_BRIGHTNESS,
|
||||||
KEY_COORDINATOR,
|
KEY_COORDINATOR,
|
||||||
KEY_DEVICE,
|
KEY_DEVICE,
|
||||||
KEY_MIGRATE_ENTITY_NAME,
|
|
||||||
MODEL_AIRHUMIDIFIER_CA1,
|
MODEL_AIRHUMIDIFIER_CA1,
|
||||||
MODEL_AIRHUMIDIFIER_CA4,
|
MODEL_AIRHUMIDIFIER_CA4,
|
||||||
MODEL_AIRHUMIDIFIER_CB1,
|
MODEL_AIRHUMIDIFIER_CB1,
|
||||||
|
@ -67,10 +66,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
model = config_entry.data[CONF_MODEL]
|
model = config_entry.data[CONF_MODEL]
|
||||||
device = hass.data[DOMAIN][config_entry.entry_id][KEY_DEVICE]
|
device = hass.data[DOMAIN][config_entry.entry_id][KEY_DEVICE]
|
||||||
coordinator = hass.data[DOMAIN][config_entry.entry_id][KEY_COORDINATOR]
|
coordinator = hass.data[DOMAIN][config_entry.entry_id][KEY_COORDINATOR]
|
||||||
if KEY_MIGRATE_ENTITY_NAME in hass.data[DOMAIN][config_entry.entry_id]:
|
|
||||||
name = hass.data[DOMAIN][config_entry.entry_id][KEY_MIGRATE_ENTITY_NAME]
|
|
||||||
else:
|
|
||||||
name = config_entry.title
|
|
||||||
|
|
||||||
if model in [MODEL_AIRHUMIDIFIER_CA1, MODEL_AIRHUMIDIFIER_CB1]:
|
if model in [MODEL_AIRHUMIDIFIER_CA1, MODEL_AIRHUMIDIFIER_CB1]:
|
||||||
entity_class = XiaomiAirHumidifierSelector
|
entity_class = XiaomiAirHumidifierSelector
|
||||||
|
@ -84,7 +79,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
for selector in SELECTOR_TYPES.values():
|
for selector in SELECTOR_TYPES.values():
|
||||||
entities.append(
|
entities.append(
|
||||||
entity_class(
|
entity_class(
|
||||||
f"{name} {selector.name}",
|
f"{config_entry.title} {selector.name}",
|
||||||
device,
|
device,
|
||||||
config_entry,
|
config_entry,
|
||||||
f"{selector.short_name}_{config_entry.unique_id}",
|
f"{selector.short_name}_{config_entry.unique_id}",
|
||||||
|
|
|
@ -45,7 +45,6 @@ from .const import (
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
KEY_COORDINATOR,
|
KEY_COORDINATOR,
|
||||||
KEY_DEVICE,
|
KEY_DEVICE,
|
||||||
KEY_MIGRATE_ENTITY_NAME,
|
|
||||||
MODELS_HUMIDIFIER_MIOT,
|
MODELS_HUMIDIFIER_MIOT,
|
||||||
)
|
)
|
||||||
from .device import XiaomiCoordinatedMiioEntity, XiaomiMiioEntity
|
from .device import XiaomiCoordinatedMiioEntity, XiaomiMiioEntity
|
||||||
|
@ -190,11 +189,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
model = config_entry.data[CONF_MODEL]
|
model = config_entry.data[CONF_MODEL]
|
||||||
device = None
|
device = None
|
||||||
sensors = []
|
sensors = []
|
||||||
if KEY_MIGRATE_ENTITY_NAME in hass.data[DOMAIN][config_entry.entry_id]:
|
|
||||||
name = hass.data[DOMAIN][config_entry.entry_id][KEY_MIGRATE_ENTITY_NAME]
|
|
||||||
else:
|
|
||||||
name = config_entry.title
|
|
||||||
|
|
||||||
if model in MODELS_HUMIDIFIER_MIOT:
|
if model in MODELS_HUMIDIFIER_MIOT:
|
||||||
device = hass.data[DOMAIN][config_entry.entry_id][KEY_DEVICE]
|
device = hass.data[DOMAIN][config_entry.entry_id][KEY_DEVICE]
|
||||||
coordinator = hass.data[DOMAIN][config_entry.entry_id][KEY_COORDINATOR]
|
coordinator = hass.data[DOMAIN][config_entry.entry_id][KEY_COORDINATOR]
|
||||||
|
@ -205,6 +199,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
sensors = HUMIDIFIER_SENSORS
|
sensors = HUMIDIFIER_SENSORS
|
||||||
else:
|
else:
|
||||||
unique_id = config_entry.unique_id
|
unique_id = config_entry.unique_id
|
||||||
|
name = config_entry.title
|
||||||
_LOGGER.debug("Initializing with host %s (token %s...)", host, token[:5])
|
_LOGGER.debug("Initializing with host %s (token %s...)", host, token[:5])
|
||||||
|
|
||||||
device = AirQualityMonitor(host, token)
|
device = AirQualityMonitor(host, token)
|
||||||
|
@ -214,7 +209,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
for sensor in sensors:
|
for sensor in sensors:
|
||||||
entities.append(
|
entities.append(
|
||||||
XiaomiGenericSensor(
|
XiaomiGenericSensor(
|
||||||
f"{name} {sensor.replace('_', ' ').title()}",
|
f"{config_entry.title} {sensor.replace('_', ' ').title()}",
|
||||||
device,
|
device,
|
||||||
config_entry,
|
config_entry,
|
||||||
f"{sensor}_{config_entry.unique_id}",
|
f"{sensor}_{config_entry.unique_id}",
|
||||||
|
|
|
@ -41,7 +41,6 @@ from .const import (
|
||||||
FEATURE_SET_DRY,
|
FEATURE_SET_DRY,
|
||||||
KEY_COORDINATOR,
|
KEY_COORDINATOR,
|
||||||
KEY_DEVICE,
|
KEY_DEVICE,
|
||||||
KEY_MIGRATE_ENTITY_NAME,
|
|
||||||
MODEL_AIRHUMIDIFIER_CA1,
|
MODEL_AIRHUMIDIFIER_CA1,
|
||||||
MODEL_AIRHUMIDIFIER_CA4,
|
MODEL_AIRHUMIDIFIER_CA4,
|
||||||
MODEL_AIRHUMIDIFIER_CB1,
|
MODEL_AIRHUMIDIFIER_CB1,
|
||||||
|
@ -235,10 +234,6 @@ async def async_setup_coordinated_entry(hass, config_entry, async_add_entities):
|
||||||
unique_id = config_entry.unique_id
|
unique_id = config_entry.unique_id
|
||||||
device = hass.data[DOMAIN][config_entry.entry_id][KEY_DEVICE]
|
device = hass.data[DOMAIN][config_entry.entry_id][KEY_DEVICE]
|
||||||
coordinator = hass.data[DOMAIN][config_entry.entry_id][KEY_COORDINATOR]
|
coordinator = hass.data[DOMAIN][config_entry.entry_id][KEY_COORDINATOR]
|
||||||
if KEY_MIGRATE_ENTITY_NAME in hass.data[DOMAIN][config_entry.entry_id]:
|
|
||||||
name = hass.data[DOMAIN][config_entry.entry_id][KEY_MIGRATE_ENTITY_NAME]
|
|
||||||
else:
|
|
||||||
name = config_entry.title
|
|
||||||
|
|
||||||
if DATA_KEY not in hass.data:
|
if DATA_KEY not in hass.data:
|
||||||
hass.data[DATA_KEY] = {}
|
hass.data[DATA_KEY] = {}
|
||||||
|
@ -256,7 +251,7 @@ async def async_setup_coordinated_entry(hass, config_entry, async_add_entities):
|
||||||
if feature & device_features:
|
if feature & device_features:
|
||||||
entities.append(
|
entities.append(
|
||||||
XiaomiGenericCoordinatedSwitch(
|
XiaomiGenericCoordinatedSwitch(
|
||||||
f"{name} {switch.name}",
|
f"{config_entry.title} {switch.name}",
|
||||||
device,
|
device,
|
||||||
config_entry,
|
config_entry,
|
||||||
f"{switch.short_name}_{unique_id}",
|
f"{switch.short_name}_{unique_id}",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue