From a7a219b99bb4057b57c7b58ed2f28d6ab94bf0ba Mon Sep 17 00:00:00 2001 From: G Johansson Date: Sun, 8 Sep 2024 14:24:39 +0200 Subject: [PATCH] Deprecate aux_heat in econet (#125365) * Deprecate aux_heat in econet * strings * Use generator --- homeassistant/components/econet/__init__.py | 1 + homeassistant/components/econet/climate.py | 21 ++++++++ homeassistant/components/econet/strings.json | 13 +++++ homeassistant/components/econet/switch.py | 57 ++++++++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 homeassistant/components/econet/switch.py diff --git a/homeassistant/components/econet/__init__.py b/homeassistant/components/econet/__init__.py index 84e636e660b861..4aba79f779fab2 100644 --- a/homeassistant/components/econet/__init__.py +++ b/homeassistant/components/econet/__init__.py @@ -31,6 +31,7 @@ Platform.BINARY_SENSOR, Platform.CLIMATE, Platform.SENSOR, + Platform.SWITCH, Platform.WATER_HEATER, ] PUSH_UPDATE = "econet.push_update" diff --git a/homeassistant/components/econet/climate.py b/homeassistant/components/econet/climate.py index f6bd52c97022e6..1d6cefc96455c1 100644 --- a/homeassistant/components/econet/climate.py +++ b/homeassistant/components/econet/climate.py @@ -20,6 +20,7 @@ from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback +from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue from . import EcoNetEntity from .const import DOMAIN, EQUIPMENT @@ -203,10 +204,30 @@ def set_fan_mode(self, fan_mode: str) -> None: def turn_aux_heat_on(self) -> None: """Turn auxiliary heater 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, + ) self._econet.set_mode(ThermostatOperationMode.EMERGENCY_HEAT) def turn_aux_heat_off(self) -> None: """Turn auxiliary heater 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, + ) self._econet.set_mode(ThermostatOperationMode.HEATING) @property diff --git a/homeassistant/components/econet/strings.json b/homeassistant/components/econet/strings.json index 6e81085a9bfdaa..83d66dde1448a4 100644 --- a/homeassistant/components/econet/strings.json +++ b/homeassistant/components/econet/strings.json @@ -18,5 +18,18 @@ } } } + }, + "issues": { + "migrate_aux_heat": { + "title": "Migration of EcoNet set_aux_heat action", + "fix_flow": { + "step": { + "confirm": { + "description": "The EcoNet `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 `aux_heat_only` switch entity. When this is done, Press submit to fix this issue.", + "title": "[%key:component::econet::issues::migrate_aux_heat::title%]" + } + } + } + } } } diff --git a/homeassistant/components/econet/switch.py b/homeassistant/components/econet/switch.py new file mode 100644 index 00000000000000..107cd7dc586bf1 --- /dev/null +++ b/homeassistant/components/econet/switch.py @@ -0,0 +1,57 @@ +"""Support for using switch with ecoNet thermostats.""" + +from __future__ import annotations + +import logging +from typing import Any + +from pyeconet.equipment import EquipmentType +from pyeconet.equipment.thermostat import ThermostatOperationMode + +from homeassistant.components.switch import SwitchEntity +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity_platform import AddEntitiesCallback + +from . import EcoNetEntity +from .const import DOMAIN, EQUIPMENT + +_LOGGER = logging.getLogger(__name__) + + +async def async_setup_entry( + hass: HomeAssistant, + entry: ConfigEntry, + async_add_entities: AddEntitiesCallback, +) -> None: + """Set up the ecobee thermostat switch entity.""" + equipment = hass.data[DOMAIN][EQUIPMENT][entry.entry_id] + async_add_entities( + EcoNetSwitchAuxHeatOnly(thermostat) + for thermostat in equipment[EquipmentType.THERMOSTAT] + ) + + +class EcoNetSwitchAuxHeatOnly(EcoNetEntity, SwitchEntity): + """Representation of a aux_heat_only EcoNet switch.""" + + def __init__(self, thermostat) -> None: + """Initialize EcoNet ventilator platform.""" + super().__init__(thermostat) + self._attr_name = f"{thermostat.device_name} emergency heat" + self._attr_unique_id = ( + f"{thermostat.device_id}_{thermostat.device_name}_auxheat" + ) + + def turn_on(self, **kwargs: Any) -> None: + """Set the hvacMode to auxHeatOnly.""" + self._econet.set_mode(ThermostatOperationMode.EMERGENCY_HEAT) + + def turn_off(self, **kwargs: Any) -> None: + """Set the hvacMode back to the prior setting.""" + self._econet.set_mode(ThermostatOperationMode.HEATING) + + @property + def is_on(self) -> bool: + """Return true if auxHeatOnly mode is active.""" + return self._econet.mode == ThermostatOperationMode.EMERGENCY_HEAT