From 2ef37f01b1c6e26f3a462c64eef69a6bb085f2a3 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Sun, 8 Sep 2024 14:23:24 +0200 Subject: [PATCH] Deprecate aux_heat from Nexia climate entity, implement switch (#125250) * Remove deprecated aux_heat from nexia * Add back aux_heat * Raise issue --- homeassistant/components/nexia/climate.py | 22 ++++++++++++++ homeassistant/components/nexia/strings.json | 13 +++++++++ homeassistant/components/nexia/switch.py | 32 ++++++++++++++++++++- 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/nexia/climate.py b/homeassistant/components/nexia/climate.py index a4bcc03c210723..9b22607d5a8d4e 100644 --- a/homeassistant/components/nexia/climate.py +++ b/homeassistant/components/nexia/climate.py @@ -35,6 +35,7 @@ from homeassistant.helpers import entity_platform import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback +from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue from homeassistant.helpers.typing import VolDictType from .const import ( @@ -42,6 +43,7 @@ ATTR_DEHUMIDIFY_SETPOINT, ATTR_HUMIDIFY_SETPOINT, ATTR_RUN_MODE, + DOMAIN, ) from .coordinator import NexiaDataUpdateCoordinator from .entity import NexiaThermostatZoneEntity @@ -378,11 +380,31 @@ async def async_set_preset_mode(self, preset_mode: str) -> None: async def async_turn_aux_heat_off(self) -> None: """Turn Aux Heat off.""" + async_create_issue( + self.hass, + DOMAIN, + "migrate_aux_heat", + breaks_in_ha_version="2025.4.0", + is_fixable=True, + is_persistent=True, + translation_key="migrate_aux_heat", + severity=IssueSeverity.WARNING, + ) await self._thermostat.set_emergency_heat(False) self._signal_thermostat_update() async def async_turn_aux_heat_on(self) -> None: """Turn Aux Heat on.""" + async_create_issue( + self.hass, + DOMAIN, + "migrate_aux_heat", + breaks_in_ha_version="2025.4.0", + is_fixable=True, + is_persistent=True, + translation_key="migrate_aux_heat", + severity=IssueSeverity.WARNING, + ) await self._thermostat.set_emergency_heat(True) self._signal_thermostat_update() diff --git a/homeassistant/components/nexia/strings.json b/homeassistant/components/nexia/strings.json index 9e49f4bb793864..acb57352d244f7 100644 --- a/homeassistant/components/nexia/strings.json +++ b/homeassistant/components/nexia/strings.json @@ -96,5 +96,18 @@ } } } + }, + "issues": { + "migrate_aux_heat": { + "title": "Migration of Nexia set_aux_heat action", + "fix_flow": { + "step": { + "confirm": { + "description": "The Nexia `set_aux_heat` action has been migrated. A new `aux_heat_only` switch entity is available for each thermostat.\n\nUpdate any automations to use the new Emergency heat switch entity. When this is done, press submit to fix this issue.", + "title": "[%key:component::nexia::issues::migrate_aux_heat::title%]" + } + } + } + } } } diff --git a/homeassistant/components/nexia/switch.py b/homeassistant/components/nexia/switch.py index 0a874ba18173dc..f92443517c8641 100644 --- a/homeassistant/components/nexia/switch.py +++ b/homeassistant/components/nexia/switch.py @@ -25,12 +25,14 @@ async def async_setup_entry( """Set up switches for a Nexia device.""" coordinator = config_entry.runtime_data nexia_home = coordinator.nexia_home - entities: list[NexiaHoldSwitch] = [] + entities: list[NexiaHoldSwitch | NexiaEmergencyHeatSwitch] = [] for thermostat_id in nexia_home.get_thermostat_ids(): thermostat: NexiaThermostat = nexia_home.get_thermostat_by_id(thermostat_id) for zone_id in thermostat.get_zone_ids(): zone: NexiaThermostatZone = thermostat.get_zone_by_id(zone_id) entities.append(NexiaHoldSwitch(coordinator, zone)) + if thermostat.has_emergency_heat(): + entities.append(NexiaEmergencyHeatSwitch(coordinator, zone)) async_add_entities(entities) @@ -64,3 +66,31 @@ async def async_turn_off(self, **kwargs: Any) -> None: """Disable permanent hold.""" await self._zone.call_return_to_schedule() self._signal_zone_update() + + +class NexiaEmergencyHeatSwitch(NexiaThermostatZoneEntity, SwitchEntity): + """Provides Nexia emergency heat switch support.""" + + _attr_translation_key = "emergency_heat" + + def __init__( + self, coordinator: NexiaDataUpdateCoordinator, zone: NexiaThermostatZone + ) -> None: + """Initialize the emergency heat mode switch.""" + zone_id = zone.zone_id + super().__init__(coordinator, zone, zone_id) + + @property + def is_on(self) -> bool: + """Return if the zone is in hold mode.""" + return self._thermostat.is_emergency_heat_active() + + async def async_turn_on(self, **kwargs: Any) -> None: + """Enable permanent hold.""" + await self._thermostat.set_emergency_heat(True) + self._signal_thermostat_update() + + async def async_turn_off(self, **kwargs: Any) -> None: + """Disable permanent hold.""" + await self._thermostat.set_emergency_heat(False) + self._signal_thermostat_update()