From 769661adc37576d5202eda9af3ee288edba9a85b Mon Sep 17 00:00:00 2001 From: Marvin Wichmann Date: Sat, 20 Nov 2021 16:34:59 +0100 Subject: [PATCH] KNX christmas cleaning #2 - remove old migrations (#60026) * Remove old migrations from KNX integration * Remove cover migration --- homeassistant/components/knx/climate.py | 45 +--------------- homeassistant/components/knx/cover.py | 30 ----------- homeassistant/components/knx/light.py | 72 +------------------------ 3 files changed, 2 insertions(+), 145 deletions(-) diff --git a/homeassistant/components/knx/climate.py b/homeassistant/components/knx/climate.py index 791e897f4d3728..8517eed7ace847 100644 --- a/homeassistant/components/knx/climate.py +++ b/homeassistant/components/knx/climate.py @@ -6,7 +6,6 @@ from xknx import XKNX from xknx.devices import Climate as XknxClimate, ClimateMode as XknxClimateMode from xknx.dpt.dpt_hvac_mode import HVACControllerMode, HVACOperationMode -from xknx.telegram.address import parse_device_group_address from homeassistant import config_entries from homeassistant.components.climate import ClimateEntity @@ -24,8 +23,7 @@ CONF_NAME, TEMP_CELSIUS, ) -from homeassistant.core import HomeAssistant, callback -from homeassistant.helpers import entity_registry as er +from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType @@ -56,50 +54,9 @@ async def async_setup_entry( SupportedPlatforms.CLIMATE.value ] - _async_migrate_unique_id(hass, config) async_add_entities(KNXClimate(xknx, entity_config) for entity_config in config) -@callback -def _async_migrate_unique_id( - hass: HomeAssistant, platform_config: list[ConfigType] -) -> None: - """Change unique_ids used in 2021.4 to include target_temperature GA.""" - entity_registry = er.async_get(hass) - for entity_config in platform_config: - # normalize group address strings - ga_temperature_state was the old uid - ga_temperature_state = parse_device_group_address( - entity_config[ClimateSchema.CONF_TEMPERATURE_ADDRESS][0] - ) - old_uid = str(ga_temperature_state) - - entity_id = entity_registry.async_get_entity_id("climate", DOMAIN, old_uid) - if entity_id is None: - continue - ga_target_temperature_state = parse_device_group_address( - entity_config[ClimateSchema.CONF_TARGET_TEMPERATURE_STATE_ADDRESS][0] - ) - target_temp = entity_config.get(ClimateSchema.CONF_TARGET_TEMPERATURE_ADDRESS) - ga_target_temperature = ( - parse_device_group_address(target_temp[0]) - if target_temp is not None - else None - ) - setpoint_shift = entity_config.get(ClimateSchema.CONF_SETPOINT_SHIFT_ADDRESS) - ga_setpoint_shift = ( - parse_device_group_address(setpoint_shift[0]) - if setpoint_shift is not None - else None - ) - new_uid = ( - f"{ga_temperature_state}_" - f"{ga_target_temperature_state}_" - f"{ga_target_temperature}_" - f"{ga_setpoint_shift}" - ) - entity_registry.async_update_entity(entity_id, new_unique_id=new_uid) - - def _create_climate(xknx: XKNX, config: ConfigType) -> XknxClimate: """Return a KNX Climate device to be used within XKNX.""" climate_mode = XknxClimateMode( diff --git a/homeassistant/components/knx/cover.py b/homeassistant/components/knx/cover.py index 62fd3a1ba08e22..8b00f6232f341a 100644 --- a/homeassistant/components/knx/cover.py +++ b/homeassistant/components/knx/cover.py @@ -7,7 +7,6 @@ from xknx import XKNX from xknx.devices import Cover as XknxCover, Device as XknxDevice -from xknx.telegram.address import parse_device_group_address from homeassistant import config_entries from homeassistant.components.cover import ( @@ -26,7 +25,6 @@ ) from homeassistant.const import CONF_DEVICE_CLASS, CONF_ENTITY_CATEGORY, CONF_NAME from homeassistant.core import HomeAssistant, callback -from homeassistant.helpers import entity_registry as er from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.event import async_track_utc_time_change from homeassistant.helpers.typing import ConfigType @@ -47,37 +45,9 @@ async def async_setup_entry( SupportedPlatforms.COVER.value ] - _async_migrate_unique_id(hass, config) async_add_entities(KNXCover(xknx, entity_config) for entity_config in config) -@callback -def _async_migrate_unique_id( - hass: HomeAssistant, platform_config: list[ConfigType] -) -> None: - """Change unique_ids used in 2021.4 to include position_target GA.""" - entity_registry = er.async_get(hass) - for entity_config in platform_config: - # normalize group address strings - ga_updown was the old uid but is optional - updown_addresses = entity_config.get(CoverSchema.CONF_MOVE_LONG_ADDRESS) - if updown_addresses is None: - continue - ga_updown = parse_device_group_address(updown_addresses[0]) - old_uid = str(ga_updown) - - entity_id = entity_registry.async_get_entity_id("cover", DOMAIN, old_uid) - if entity_id is None: - continue - position_target_addresses = entity_config.get(CoverSchema.CONF_POSITION_ADDRESS) - ga_position_target = ( - parse_device_group_address(position_target_addresses[0]) - if position_target_addresses is not None - else None - ) - new_uid = f"{ga_updown}_{ga_position_target}" - entity_registry.async_update_entity(entity_id, new_unique_id=new_uid) - - class KNXCover(KnxEntity, CoverEntity): """Representation of a KNX cover.""" diff --git a/homeassistant/components/knx/light.py b/homeassistant/components/knx/light.py index f9223d69d74d33..0403b658221297 100644 --- a/homeassistant/components/knx/light.py +++ b/homeassistant/components/knx/light.py @@ -5,7 +5,6 @@ from xknx import XKNX from xknx.devices.light import Light as XknxLight, XYYColor -from xknx.telegram.address import parse_device_group_address from homeassistant import config_entries from homeassistant.components.light import ( @@ -25,8 +24,7 @@ LightEntity, ) from homeassistant.const import CONF_ENTITY_CATEGORY, CONF_NAME -from homeassistant.core import HomeAssistant, callback -from homeassistant.helpers import entity_registry as er +from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType import homeassistant.util.color as color_util @@ -53,77 +51,9 @@ async def async_setup_entry( SupportedPlatforms.LIGHT.value ] - _async_migrate_unique_id(hass, config) async_add_entities(KNXLight(xknx, entity_config) for entity_config in config) -@callback -def _async_migrate_unique_id( - hass: HomeAssistant, platform_config: list[ConfigType] -) -> None: - """Change unique_ids used in 2021.4 to exchange individual color switch address for brightness address.""" - entity_registry = er.async_get(hass) - for entity_config in platform_config: - individual_colors_config = entity_config.get(LightSchema.CONF_INDIVIDUAL_COLORS) - if individual_colors_config is None: - continue - try: - ga_red_switch = individual_colors_config[LightSchema.CONF_RED][KNX_ADDRESS][ - 0 - ] - ga_green_switch = individual_colors_config[LightSchema.CONF_GREEN][ - KNX_ADDRESS - ][0] - ga_blue_switch = individual_colors_config[LightSchema.CONF_BLUE][ - KNX_ADDRESS - ][0] - except KeyError: - continue - # normalize group address strings - ga_red_switch = parse_device_group_address(ga_red_switch) - ga_green_switch = parse_device_group_address(ga_green_switch) - ga_blue_switch = parse_device_group_address(ga_blue_switch) - # white config is optional so it has to be checked for `None` extra - white_config = individual_colors_config.get(LightSchema.CONF_WHITE) - white_switch = ( - white_config.get(KNX_ADDRESS) if white_config is not None else None - ) - ga_white_switch = ( - parse_device_group_address(white_switch[0]) - if white_switch is not None - else None - ) - - old_uid = ( - f"{ga_red_switch}_" - f"{ga_green_switch}_" - f"{ga_blue_switch}_" - f"{ga_white_switch}" - ) - entity_id = entity_registry.async_get_entity_id("light", DOMAIN, old_uid) - if entity_id is None: - continue - - ga_red_brightness = parse_device_group_address( - individual_colors_config[LightSchema.CONF_RED][ - LightSchema.CONF_BRIGHTNESS_ADDRESS - ][0] - ) - ga_green_brightness = parse_device_group_address( - individual_colors_config[LightSchema.CONF_GREEN][ - LightSchema.CONF_BRIGHTNESS_ADDRESS - ][0] - ) - ga_blue_brightness = parse_device_group_address( - individual_colors_config[LightSchema.CONF_BLUE][ - LightSchema.CONF_BRIGHTNESS_ADDRESS - ][0] - ) - - new_uid = f"{ga_red_brightness}_{ga_green_brightness}_{ga_blue_brightness}" - entity_registry.async_update_entity(entity_id, new_unique_id=new_uid) - - def _create_light(xknx: XKNX, config: ConfigType) -> XknxLight: """Return a KNX Light device to be used within XKNX."""