Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 1 addition & 44 deletions homeassistant/components/knx/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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(
Expand Down
72 changes: 1 addition & 71 deletions homeassistant/components/knx/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
Expand All @@ -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."""

Expand Down