From 62e74fd96af436293a1b6c76fa2826128cea39f2 Mon Sep 17 00:00:00 2001 From: Jimmy Everling Date: Sat, 21 Nov 2026 16:59:42 +0100 Subject: [PATCH] Migrate temperature attributes to the native_* API with old-release compat Home Assistant 2026.11 moved climate and water heater temperatures to the native_* API, so entities now set _attr_native_* attributes instead of _attr_*. Add a NativeTemperatureCompat mixin in compat.py that serves the native attributes through the legacy temperature properties on older releases, and mix it into the Aquarea/Panasonic climate and HWS/Aquarea water heater entities. Add tests covering the compat mixin and its use across all four entities. --- .../panasonic_cc/aquarea/climate.py | 15 ++--- .../panasonic_cc/aquarea/water_heater.py | 9 +-- custom_components/panasonic_cc/compat.py | 42 ++++++++++++++ .../panasonic_cc/hws/water_heater.py | 7 ++- .../panasonic_cc/panasonic/climate.py | 11 ++-- tests/test_compat.py | 56 +++++++++++++++++++ 6 files changed, 121 insertions(+), 19 deletions(-) create mode 100644 custom_components/panasonic_cc/compat.py create mode 100644 tests/test_compat.py diff --git a/custom_components/panasonic_cc/aquarea/climate.py b/custom_components/panasonic_cc/aquarea/climate.py index e2edd5b..6262d98 100644 --- a/custom_components/panasonic_cc/aquarea/climate.py +++ b/custom_components/panasonic_cc/aquarea/climate.py @@ -27,6 +27,7 @@ from aio_panasonic_comfort_cloud.models.aquarea import AquareaZoneStatus from ..const import DOMAIN, PRESET_ECO, PRESET_NONE +from ..compat import NativeTemperatureCompat from .base import AquareaDataEntity from .coordinator import AquareaDeviceCoordinator from .const import AQUAREA_COORDINATORS, AQUAREA_CLIMATE_DELAY_SHORT, AQUAREA_CLIMATE_DELAY_LONG @@ -109,7 +110,7 @@ def _get_hvac_action_from_device_direction( return HVACAction.IDLE -class AquareaClimateEntity(AquareaDataEntity, ClimateEntity): +class AquareaClimateEntity(NativeTemperatureCompat, AquareaDataEntity, ClimateEntity): """Representation of an Aquarea Climate Device.""" entity_description: AquareaClimateEntityDescription @@ -124,7 +125,7 @@ def __init__( """Initialize the climate entity.""" super().__init__(coordinator, description.key) self.entity_description = description - self._attr_temperature_unit = UnitOfTemperature.CELSIUS + self._attr_native_temperature_unit = UnitOfTemperature.CELSIUS zone = self.coordinator.device.parameters.get_zone(description.zone_id) self._attr_name = zone.name if zone else None self._attr_unique_id = f"{super().unique_id}_climate_{description.zone_id}" @@ -157,12 +158,12 @@ def _async_update_attrs(self) -> None: zone = params.get_zone(self.entity_description.zone_id) # The zone temperature is reported even when the zone is off - self._attr_current_temperature = zone.temperature if zone is not None else None + self._attr_native_current_temperature = zone.temperature if zone is not None else None if zone is None or zone.operation_status == AquareaOperationStatus.Off: self._attr_hvac_mode = HVACMode.OFF self._attr_hvac_action = HVACAction.OFF - self._attr_target_temperature = None + self._attr_native_target_temperature = None self._attr_min_temp = 5 self._attr_max_temp = 65 if zone is not None and zone_supports_special_status(zone): @@ -183,11 +184,11 @@ def _async_update_attrs(self) -> None: AquareaOperationMode.Heat, AquareaOperationMode.AutoHeat, ): - self._attr_target_temperature = zone.heat_set + self._attr_native_target_temperature = zone.heat_set self._attr_min_temp = zone.heat_min if zone.heat_min is not None else 5 self._attr_max_temp = zone.heat_max if zone.heat_max is not None else 65 else: - self._attr_target_temperature = zone.cool_set + self._attr_native_target_temperature = zone.cool_set self._attr_min_temp = zone.cool_min if zone.cool_min is not None else 5 self._attr_max_temp = zone.cool_max if zone.cool_max is not None else 65 @@ -281,7 +282,7 @@ async def async_set_temperature(self, **kwargs: Any) -> None: int(target_temp), mode=mode, ) - self._attr_target_temperature = target_temp + self._attr_native_target_temperature = target_temp state_changed = True if mode := kwargs.get("hvac_mode"): await self.async_set_hvac_mode(mode) diff --git a/custom_components/panasonic_cc/aquarea/water_heater.py b/custom_components/panasonic_cc/aquarea/water_heater.py index 18177ba..7ec349d 100644 --- a/custom_components/panasonic_cc/aquarea/water_heater.py +++ b/custom_components/panasonic_cc/aquarea/water_heater.py @@ -17,6 +17,7 @@ from aio_panasonic_comfort_cloud.constants import AquareaOperationStatus from ..const import DOMAIN +from ..compat import NativeTemperatureCompat from .base import AquareaDataEntity from .coordinator import AquareaDeviceCoordinator from .const import AQUAREA_COORDINATORS @@ -47,10 +48,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry, async_add_e async_add_entities(entities) -class AquareaWaterHeater(AquareaDataEntity, WaterHeaterEntity): +class AquareaWaterHeater(NativeTemperatureCompat, AquareaDataEntity, WaterHeaterEntity): """Representation of a Aquarea Water Tank.""" - _attr_temperature_unit = UnitOfTemperature.CELSIUS + _attr_native_temperature_unit = UnitOfTemperature.CELSIUS _attr_supported_features = WaterHeaterEntityFeature.TARGET_TEMPERATURE | WaterHeaterEntityFeature.OPERATION_MODE _attr_operation_list = [STATE_HEAT_PUMP, STATE_OFF] _attr_precision = PRECISION_WHOLE @@ -79,8 +80,8 @@ def _async_update_attrs(self) -> None: self._attr_min_temp = tank.heat_min if tank.heat_max is not None: self._attr_max_temp = tank.heat_max - self._attr_target_temperature = tank.heat_set - self._attr_current_temperature = tank.temperature + self._attr_native_target_temperature = tank.heat_set + self._attr_native_current_temperature = tank.temperature if tank.operation_status == AquareaOperationStatus.Off: self._attr_current_operation = STATE_OFF diff --git a/custom_components/panasonic_cc/compat.py b/custom_components/panasonic_cc/compat.py new file mode 100644 index 0000000..81dd93e --- /dev/null +++ b/custom_components/panasonic_cc/compat.py @@ -0,0 +1,42 @@ +"""Compatibility helpers for older Home Assistant releases.""" +from __future__ import annotations + +from homeassistant.components.climate import ClimateEntity +from homeassistant.components.water_heater import WaterHeaterEntity + +# Home Assistant 2026.11 moved climate and water heater temperatures to the +# native_* API. Entities set the _attr_native_* attributes; on older releases +# the mixin below serves them through the old property names. +# Remove once the minimum supported version is 2026.11 or newer. +HAS_NATIVE_TEMPERATURE_API = hasattr( + ClimateEntity, "native_temperature_unit" +) and hasattr(WaterHeaterEntity, "native_temperature_unit") + +if HAS_NATIVE_TEMPERATURE_API: + + class NativeTemperatureCompat: + """Nothing to do, Home Assistant reads the native attributes itself.""" + +else: + + class NativeTemperatureCompat: # type: ignore[no-redef] + """Serve the native temperature attributes through the old properties.""" + + _attr_native_temperature_unit: str + _attr_native_current_temperature: float | None = None + _attr_native_target_temperature: float | None = None + + @property + def temperature_unit(self) -> str: + """Return the unit of measurement.""" + return self._attr_native_temperature_unit + + @property + def current_temperature(self) -> float | None: + """Return the current temperature.""" + return self._attr_native_current_temperature + + @property + def target_temperature(self) -> float | None: + """Return the target temperature.""" + return self._attr_native_target_temperature diff --git a/custom_components/panasonic_cc/hws/water_heater.py b/custom_components/panasonic_cc/hws/water_heater.py index b815341..2b97613 100644 --- a/custom_components/panasonic_cc/hws/water_heater.py +++ b/custom_components/panasonic_cc/hws/water_heater.py @@ -19,6 +19,7 @@ from aio_panasonic_comfort_cloud.exceptions import DeviceIsNotReadyError from ..const import DOMAIN +from ..compat import NativeTemperatureCompat from .base import HwsDataEntity from .coordinator import HwsDeviceCoordinator from .const import HWS_COORDINATORS, HWS_WATER_HEATER_DELAY @@ -71,7 +72,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry, async_add_e async_add_entities(entities) -class HwsWaterHeater(HwsDataEntity, WaterHeaterEntity): +class HwsWaterHeater(NativeTemperatureCompat, HwsDataEntity, WaterHeaterEntity): """Representation of an HWS hot water tank. The API has no tank setpoint to write; heating is driven by the weekly @@ -79,7 +80,7 @@ class HwsWaterHeater(HwsDataEntity, WaterHeaterEntity): temperature, the operation mode and the schedule itself. """ - _attr_temperature_unit = UnitOfTemperature.CELSIUS + _attr_native_temperature_unit = UnitOfTemperature.CELSIUS _attr_precision = PRECISION_WHOLE def __init__( @@ -96,7 +97,7 @@ def _async_update_attrs(self) -> None: """Update attributes.""" device = self.coordinator.device params = device.parameters - self._attr_current_temperature = params.tank_temperature + self._attr_native_current_temperature = params.tank_temperature modes = _supported_operation_modes(device) self._attr_operation_list = [OPERATION_MODE_REVERSE_LOOKUP[mode] for mode in modes] diff --git a/custom_components/panasonic_cc/panasonic/climate.py b/custom_components/panasonic_cc/panasonic/climate.py index 0a79ba0..12f0c14 100644 --- a/custom_components/panasonic_cc/panasonic/climate.py +++ b/custom_components/panasonic_cc/panasonic/climate.py @@ -23,6 +23,7 @@ DEFAULT_USE_PANASONIC_PRESET_NAMES, DOMAIN, ) +from ..compat import NativeTemperatureCompat from .base import PanasonicDataEntity from .coordinator import PanasonicDeviceCoordinator from .const import ( @@ -128,12 +129,12 @@ def convert_state_to_hvac_action(state: PanasonicDeviceParameters) -> HVACAction ) -class PanasonicClimateEntity(PanasonicDataEntity, ClimateEntity): +class PanasonicClimateEntity(NativeTemperatureCompat, PanasonicDataEntity, ClimateEntity): """Representation of a Panasonic Climate Device.""" entity_description: PanasonicClimateEntityDescription - _attr_temperature_unit = UnitOfTemperature.CELSIUS + _attr_native_temperature_unit = UnitOfTemperature.CELSIUS _attr_target_temperature_step = 0.5 _attr_min_temp = 16 _attr_max_temp = 30 @@ -217,9 +218,9 @@ def _async_update_attrs(self) -> None: ) self._set_temp_range() - self._attr_current_temperature = state.inside_temperature + self._attr_native_current_temperature = state.inside_temperature # Clothes drying runs with temperatureSet 0, which isn't a real setpoint. - self._attr_target_temperature = ( + self._attr_native_target_temperature = ( None if state.mode == constants.OperationMode.ClothesDrying else state.target_temperature @@ -258,7 +259,7 @@ def _update_attributes(self, builder: ChangeRequestBuilder) -> None: self._attr_hvac_mode = HVACMode.OFF default_preset = PRESET_NONE if builder.target_temperature: - self._attr_target_temperature = builder.target_temperature + self._attr_native_target_temperature = builder.target_temperature if builder.target_temperature > 15 and self._attr_preset_mode == PRESET_8_15: self._attr_preset_mode = default_preset elif builder.target_temperature < 15 and self._attr_preset_mode != PRESET_8_15: diff --git a/tests/test_compat.py b/tests/test_compat.py new file mode 100644 index 0000000..5336cb1 --- /dev/null +++ b/tests/test_compat.py @@ -0,0 +1,56 @@ +"""Tests for the native temperature compatibility mixin.""" +from __future__ import annotations + +from homeassistant.components.climate import ClimateEntity +from homeassistant.components.water_heater import WaterHeaterEntity +from homeassistant.const import UnitOfTemperature + +from custom_components.panasonic_cc.aquarea.climate import AquareaClimateEntity +from custom_components.panasonic_cc.aquarea.water_heater import AquareaWaterHeater +from custom_components.panasonic_cc.compat import NativeTemperatureCompat +from custom_components.panasonic_cc.hws.water_heater import HwsWaterHeater +from custom_components.panasonic_cc.panasonic.climate import PanasonicClimateEntity + + +class _Climate(NativeTemperatureCompat, ClimateEntity): + _attr_native_temperature_unit = UnitOfTemperature.CELSIUS + + +class _WaterHeater(NativeTemperatureCompat, WaterHeaterEntity): + _attr_native_temperature_unit = UnitOfTemperature.CELSIUS + + +def _native_values(entity) -> tuple: + """Read the temperatures the way the running Home Assistant does.""" + if hasattr(entity, "native_temperature_unit"): + return ( + entity.native_temperature_unit, + entity.native_current_temperature, + entity.native_target_temperature, + ) + return entity.temperature_unit, entity.current_temperature, entity.target_temperature + + +def test_climate_serves_native_temperatures() -> None: + entity = _Climate() + assert _native_values(entity) == (UnitOfTemperature.CELSIUS, None, None) + entity._attr_native_current_temperature = 21.5 + entity._attr_native_target_temperature = 23 + assert _native_values(entity) == (UnitOfTemperature.CELSIUS, 21.5, 23) + + +def test_water_heater_serves_native_temperatures() -> None: + entity = _WaterHeater() + entity._attr_native_current_temperature = 48 + entity._attr_native_target_temperature = 50 + assert _native_values(entity) == (UnitOfTemperature.CELSIUS, 48, 50) + + +def test_entities_use_the_mixin() -> None: + for cls in ( + PanasonicClimateEntity, + AquareaClimateEntity, + AquareaWaterHeater, + HwsWaterHeater, + ): + assert cls.__mro__[1] is NativeTemperatureCompat