Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
24 changes: 18 additions & 6 deletions zha/application/platforms/climate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from zigpy.profiles import zha
from zigpy.zcl.clusters.hvac import (
FanMode,
RunningState,
SystemMode,
Thermostat as ThermostatCluster,
Expand All @@ -35,12 +34,15 @@
ATTR_UNOCCP_COOL_SETPT,
ATTR_UNOCCP_HEAT_SETPT,
FAN_AUTO,
FAN_MODE_TO_ZCL,
FAN_ON,
HVAC_MODE_2_SYSTEM,
PRECISION_TENTHS,
SEQ_FAN_MODES,
SEQ_OF_OPERATION,
SYSTEM_MODE_2_HVAC,
ZCL_TEMP,
ZCL_TO_FAN_MODE,
ClimateEntityFeature,
HVACAction,
HVACMode,
Expand Down Expand Up @@ -332,9 +334,12 @@ def outdoor_temperature(self):
@property
def fan_mode(self) -> str | None:
"""Return current FAN mode."""
if self._fan_cluster_handler is not None:
current = self._fan_cluster_handler.fan_mode
if current is not None:
return ZCL_TO_FAN_MODE.get(current, FAN_AUTO)
if self._thermostat_cluster_handler.running_state is None:
return FAN_AUTO

if self._thermostat_cluster_handler.running_state & (
RunningState.Fan_State_On
| RunningState.Fan_2nd_Stage_On
Expand All @@ -348,7 +353,8 @@ def fan_modes(self) -> list[str] | None:
"""Return supported FAN modes."""
if not self._fan_cluster_handler:
return None
return [FAN_AUTO, FAN_ON]
seq = self._fan_cluster_handler.fan_mode_sequence
return SEQ_FAN_MODES.get(seq, [FAN_ON, FAN_AUTO])

@property
def hvac_action(self) -> HVACAction | None:
Expand Down Expand Up @@ -409,9 +415,12 @@ def hvac_mode(self) -> HVACMode | None:
@property
def hvac_modes(self) -> list[HVACMode]:
"""Return the list of available HVAC operation modes."""
return SEQ_OF_OPERATION.get(
modes = SEQ_OF_OPERATION.get(
self._thermostat_cluster_handler.ctrl_sequence_of_oper, [HVACMode.OFF]
)
if self._fan_cluster_handler is not None and HVACMode.FAN_ONLY not in modes:
modes = [*modes, HVACMode.FAN_ONLY]
return modes

@property
def preset_mode(self) -> str:
Expand Down Expand Up @@ -538,9 +547,12 @@ async def async_set_fan_mode(self, fan_mode: str) -> None:
self.warning("Unsupported '%s' fan mode", fan_mode)
return

mode = FanMode.On if fan_mode == FAN_ON else FanMode.Auto
zcl_mode = FAN_MODE_TO_ZCL.get(fan_mode)
if zcl_mode is None:
self.warning("No ZCL mapping for fan mode '%s'", fan_mode)
return

await self._fan_cluster_handler.async_set_speed(mode)
await self._fan_cluster_handler.async_set_speed(zcl_mode)

async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set new target operation mode."""
Expand Down
25 changes: 24 additions & 1 deletion zha/application/platforms/climate/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
from enum import IntFlag, StrEnum
from typing import Final

from zigpy.zcl.clusters.hvac import ControlSequenceOfOperation, RunningMode, SystemMode
from zigpy.zcl.clusters.hvac import (
ControlSequenceOfOperation,
FanMode,
RunningMode,
SystemMode,
)

ATTR_SYS_MODE: Final[str] = "system_mode"
ATTR_FAN_MODE: Final[str] = "fan_mode"
Expand Down Expand Up @@ -141,6 +146,24 @@ class HVACAction(StrEnum):
PREHEATING = "preheating"


SEQ_FAN_MODES: dict[int, list[str]] = {
0x00: [FAN_LOW, FAN_MEDIUM, FAN_HIGH],
Comment thread
puddly marked this conversation as resolved.
Outdated
0x01: [FAN_LOW, FAN_HIGH],
0x02: [FAN_LOW, FAN_MEDIUM, FAN_HIGH, FAN_AUTO],
0x03: [FAN_LOW, FAN_HIGH, FAN_AUTO],
0x04: [FAN_ON, FAN_AUTO],
}

FAN_MODE_TO_ZCL: dict[str, FanMode] = {
FAN_LOW: FanMode.Low,
FAN_MEDIUM: FanMode.Medium,
FAN_HIGH: FanMode.High,
FAN_ON: FanMode.On,
FAN_AUTO: FanMode.Auto,
}

ZCL_TO_FAN_MODE: dict[int, str] = {v: k for k, v in FAN_MODE_TO_ZCL.items()}

RUNNING_MODE = {
RunningMode.Off: HVACMode.OFF,
RunningMode.Cool: HVACMode.COOL,
Expand Down
Loading