Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 8 additions & 7 deletions custom_components/panasonic_cc/aquarea/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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}"
Expand Down Expand Up @@ -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):
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions custom_components/panasonic_cc/aquarea/water_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions custom_components/panasonic_cc/compat.py
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions custom_components/panasonic_cc/hws/water_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -71,15 +72,15 @@ 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
schedule (or PV signal / holiday mode), so the entity exposes the tank
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__(
Expand All @@ -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]
Expand Down
11 changes: 6 additions & 5 deletions custom_components/panasonic_cc/panasonic/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
56 changes: 56 additions & 0 deletions tests/test_compat.py
Original file line number Diff line number Diff line change
@@ -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
Loading