Skip to content

Commit

Permalink
Add support for outdoor_temperature in Thermostat cluster (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
zagor authored Sep 11, 2024
1 parent c99237f commit f2e1a00
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,26 @@ async def test_climate_local_temperature(
assert entity.state["current_temperature"] == 21.0


async def test_climate_outdoor_temperature(
device_climate: Device,
zha_gateway: Gateway,
) -> None:
"""Test outdoor temperature."""

thrm_cluster = device_climate.device.endpoints[1].thermostat
entity: ThermostatEntity = get_entity(
device_climate, platform=Platform.CLIMATE, entity_type=ThermostatEntity
)
assert entity.state["outdoor_temperature"] is None

await send_attributes_report(
zha_gateway,
thrm_cluster,
{Thermostat.AttributeDefs.outdoor_temperature.id: 2150},
)
assert entity.state["outdoor_temperature"] == 21.5


async def test_climate_hvac_action_running_state(
device_climate_sinope: Device,
zha_gateway: Gateway,
Expand Down
8 changes: 8 additions & 0 deletions zha/application/platforms/climate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def state(self) -> dict[str, Any]:

response = super().state
response["current_temperature"] = self.current_temperature
response["outdoor_temperature"] = self.outdoor_temperature
response["target_temperature"] = self.target_temperature
response["target_temperature_high"] = self.target_temperature_high
response["target_temperature_low"] = self.target_temperature_low
Expand Down Expand Up @@ -179,6 +180,13 @@ def current_temperature(self):
return None
return self._thermostat_cluster_handler.local_temperature / ZCL_TEMP

@property
def outdoor_temperature(self):
"""Return the outdoor temperature."""
if self._thermostat_cluster_handler.outdoor_temperature is None:
return None
return self._thermostat_cluster_handler.outdoor_temperature / ZCL_TEMP

@property
def fan_mode(self) -> str | None:
"""Return current FAN mode."""
Expand Down
5 changes: 5 additions & 0 deletions zha/zigbee/cluster_handlers/hvac.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ def local_temperature(self) -> int | None:
"""Thermostat temperature."""
return self.cluster.get(Thermostat.AttributeDefs.local_temperature.name)

@property
def outdoor_temperature(self) -> int | None:
"""Thermostat outdoor temperature."""
return self.cluster.get(Thermostat.AttributeDefs.outdoor_temperature.name)

@property
def occupancy(self) -> int | None:
"""Is occupancy detected."""
Expand Down

0 comments on commit f2e1a00

Please sign in to comment.