1 """Platform to control a Zehnder ComfoAir Q350/450/600 ventilation unit."""
3 from __future__
import annotations
9 from pycomfoconnect
import (
16 SENSOR_FAN_SPEED_MODE,
17 SENSOR_OPERATING_MODE_BIS,
26 percentage_to_ranged_value,
27 ranged_value_to_percentage,
31 from .
import DOMAIN, SIGNAL_COMFOCONNECT_UPDATE_RECEIVED, ComfoConnectBridge
33 _LOGGER = logging.getLogger(__name__)
38 2: CMD_FAN_MODE_MEDIUM,
44 PRESET_MODE_AUTO =
"auto"
45 PRESET_MODES = [PRESET_MODE_AUTO]
51 add_entities: AddEntitiesCallback,
52 discovery_info: DiscoveryInfoType |
None =
None,
54 """Set up the ComfoConnect fan platform."""
55 ccb = hass.data[DOMAIN]
61 """Representation of the ComfoConnect fan platform."""
63 _attr_icon =
"mdi:air-conditioner"
64 _attr_should_poll =
False
65 _attr_supported_features = (
66 FanEntityFeature.SET_SPEED
67 | FanEntityFeature.PRESET_MODE
68 | FanEntityFeature.TURN_OFF
69 | FanEntityFeature.TURN_ON
71 _enable_turn_on_off_backwards_compatibility =
False
72 _attr_preset_modes = PRESET_MODES
73 current_speed: float |
None =
None
75 def __init__(self, ccb: ComfoConnectBridge) ->
None:
76 """Initialize the ComfoConnect fan."""
83 """Register for sensor updates."""
84 _LOGGER.debug(
"Registering for fan speed")
88 SIGNAL_COMFOCONNECT_UPDATE_RECEIVED.format(SENSOR_FAN_SPEED_MODE),
95 SIGNAL_COMFOCONNECT_UPDATE_RECEIVED.format(SENSOR_OPERATING_MODE_BIS),
99 await self.
hasshass.async_add_executor_job(
100 self.
_ccb_ccb.comfoconnect.register_sensor, SENSOR_FAN_SPEED_MODE
102 await self.
hasshass.async_add_executor_job(
103 self.
_ccb_ccb.comfoconnect.register_sensor, SENSOR_OPERATING_MODE_BIS
107 """Handle update callbacks."""
109 "Handle update for fan speed (%d): %s", SENSOR_FAN_SPEED_MODE, value
115 """Handle update callbacks."""
117 "Handle update for operating mode (%d): %s",
118 SENSOR_OPERATING_MODE_BIS,
121 self.
_attr_preset_mode_attr_preset_mode = PRESET_MODE_AUTO
if value == -1
else None
126 """Return the current speed percentage."""
133 """Return the number of speeds the fan supports."""
138 percentage: int |
None =
None,
139 preset_mode: str |
None =
None,
142 """Turn on the fan."""
147 if percentage
is None:
153 """Turn off the fan (to away)."""
157 """Set fan speed percentage."""
158 _LOGGER.debug(
"Changing fan speed percentage to %s", percentage)
161 cmd = CMD_FAN_MODE_AWAY
164 cmd = CMD_MAPPING[speed]
166 self.
_ccb_ccb.comfoconnect.cmd_rmi_request(cmd)
169 """Set new preset mode."""
171 raise ValueError(f
"Invalid preset mode: {preset_mode}")
173 _LOGGER.debug(
"Changing preset mode to %s", preset_mode)
174 if preset_mode == PRESET_MODE_AUTO:
176 self.
_ccb_ccb.comfoconnect.cmd_rmi_request(CMD_MODE_MANUAL)
178 self.
_ccb_ccb.comfoconnect.cmd_rmi_request(CMD_MODE_AUTO)
None _handle_mode_update(self, int value)
None __init__(self, ComfoConnectBridge ccb)
None _handle_speed_update(self, float value)
None turn_on(self, int|None percentage=None, str|None preset_mode=None, **Any kwargs)
None async_added_to_hass(self)
None turn_off(self, **Any kwargs)
None set_percentage(self, int percentage)
None set_preset_mode(self, str preset_mode)
int|None percentage(self)
None set_preset_mode(self, str preset_mode)
None set_percentage(self, int percentage)
list[str]|None preset_modes(self)
None async_on_remove(self, CALLBACK_TYPE func)
None schedule_update_ha_state(self, bool force_refresh=False)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)
float percentage_to_ranged_value(tuple[float, float] low_high_range, float percentage)
int ranged_value_to_percentage(tuple[float, float] low_high_range, float value)
int int_states_in_range(tuple[float, float] low_high_range)