1 """Support for Fibaro thermostats."""
3 from __future__
import annotations
5 from contextlib
import suppress
9 from pyfibaro.fibaro_device
import DeviceModel
25 from .
import FibaroController
26 from .const
import DOMAIN
27 from .entity
import FibaroEntity
29 PRESET_RESUME =
"resume"
30 PRESET_MOIST =
"moist"
31 PRESET_FURNACE =
"furnace"
32 PRESET_CHANGEOVER =
"changeover"
33 PRESET_ECO_HEAT =
"eco_heat"
34 PRESET_ECO_COOL =
"eco_cool"
35 PRESET_FORCE_OPEN =
"force_open"
37 _LOGGER = logging.getLogger(__name__)
49 7:
"humidity_circulation",
56 HA_FANMODES = {v: k
for k, v
in FANMODES.items()}
65 10: PRESET_CHANGEOVER,
70 31: PRESET_FORCE_OPEN,
73 HA_OPMODES_PRESET = {v: k
for k, v
in OPMODES_PRESET.items()}
103 TARGET_TEMP_ACTIONS = (
105 "setThermostatSetpoint",
106 "setHeatingThermostatSetpoint",
109 OP_MODE_ACTIONS = (
"setMode",
"setOperatingMode",
"setThermostatMode")
115 async_add_entities: AddEntitiesCallback,
117 """Perform the setup for Fibaro controller devices."""
118 controller: FibaroController = hass.data[DOMAIN][entry.entry_id]
122 for device
in controller.fibaro_devices[Platform.CLIMATE]
129 """Representation of a Fibaro Thermostat."""
131 _enable_turn_on_off_backwards_compatibility =
False
133 def __init__(self, fibaro_device: DeviceModel) ->
None:
134 """Initialize the Fibaro device."""
142 siblings = fibaro_device.fibaro_controller.get_siblings(fibaro_device)
143 _LOGGER.debug(
"%s siblings: %s", fibaro_device.ha_id, siblings)
145 for device
in siblings:
148 if device.type ==
"com.fibaro.temperatureSensor" or (
151 and (device.value.has_value
or device.has_heating_thermostat_setpoint)
152 and device.unit
in (
"C",
"F")
155 tempunit = device.unit
158 action
for action
in TARGET_TEMP_ACTIONS
if action
in device.actions
161 self._attr_supported_features |= ClimateEntityFeature.TARGET_TEMPERATURE
163 tempunit = device.unit
165 if any(action
for action
in OP_MODE_ACTIONS
if action
in device.actions):
167 self._attr_supported_features |= ClimateEntityFeature.PRESET_MODE
169 if "setFanMode" in device.actions:
171 self._attr_supported_features |= ClimateEntityFeature.FAN_MODE
179 fan_modes = self.
_fan_mode_device_fan_mode_device.fibaro_device.supported_modes
181 for mode
in fan_modes:
182 if mode
not in FANMODES:
183 _LOGGER.warning(
"%d unknown fan mode", mode)
192 if device.has_supported_thermostat_modes:
193 for mode
in device.supported_thermostat_modes:
199 if device.has_supported_operating_modes:
200 op_modes = device.supported_operating_modes
202 op_modes = device.supported_modes
203 for mode
in op_modes:
206 and (mode_ha := OPMODES_HVAC.get(mode))
210 if mode
in OPMODES_PRESET:
214 self._attr_supported_features |= (
215 ClimateEntityFeature.TURN_OFF | ClimateEntityFeature.TURN_ON
219 """Call when entity is added to hass."""
223 "- _temp_sensor_device %s\n"
224 "- _target_temp_device %s\n"
225 "- _op_mode_device %s\n"
226 "- _fan_mode_device %s"
238 for device
in siblings:
244 """Return the fan setting."""
248 return FANMODES[mode]
251 """Set new target fan mode."""
258 """Return the operating mode of the device."""
260 return HA_OPMODES_HVAC[HVACMode.AUTO]
264 if device.has_operating_mode:
265 return device.operating_mode
266 if device.has_thermostat_mode:
267 return device.thermostat_mode
272 """Return hvac operation ie. heat, cool, idle."""
274 if isinstance(fibaro_operation_mode, str):
275 with suppress(ValueError):
276 return HVACMode(fibaro_operation_mode.lower())
277 elif fibaro_operation_mode
in OPMODES_HVAC:
278 return OPMODES_HVAC[fibaro_operation_mode]
282 """Set new target operation mode."""
288 if "setOperatingMode" in self.
_op_mode_device_op_mode_device.fibaro_device.actions:
290 elif "setThermostatMode" in self.
_op_mode_device_op_mode_device.fibaro_device.actions:
292 if device.has_supported_thermostat_modes:
293 for mode
in device.supported_thermostat_modes:
294 if mode.lower() == hvac_mode:
297 elif "setMode" in self.
_op_mode_device_op_mode_device.fibaro_device.actions:
302 """Return the current running hvac operation if supported."""
307 if device.has_thermostat_operating_state:
308 with suppress(ValueError):
309 return HVACAction(device.thermostat_operating_state.lower())
315 """Return the current preset mode, e.g., home, away, temp.
317 Requires ClimateEntityFeature.PRESET_MODE.
322 if self.
_op_mode_device_op_mode_device.fibaro_device.has_thermostat_mode:
323 mode = self.
_op_mode_device_op_mode_device.fibaro_device.thermostat_mode
327 if self.
_op_mode_device_op_mode_device.fibaro_device.has_operating_mode:
328 mode = self.
_op_mode_device_op_mode_device.fibaro_device.operating_mode
332 if mode
not in OPMODES_PRESET:
334 return OPMODES_PRESET[mode]
337 """Set new preset mode."""
341 if "setThermostatMode" in self.
_op_mode_device_op_mode_device.fibaro_device.actions:
343 elif "setOperatingMode" in self.
_op_mode_device_op_mode_device.fibaro_device.actions:
345 "setOperatingMode", HA_OPMODES_PRESET[preset_mode]
347 elif "setMode" in self.
_op_mode_device_op_mode_device.fibaro_device.actions:
352 """Return the current temperature."""
355 if device.has_heating_thermostat_setpoint:
356 return device.heating_thermostat_setpoint
357 return device.value.float_value()
362 """Return the temperature we try to reach."""
365 if device.has_heating_thermostat_setpoint_future:
366 return device.heating_thermostat_setpoint_future
367 return device.target_level
371 """Set new target temperatures."""
372 temperature = kwargs.get(ATTR_TEMPERATURE)
374 if target
is not None and temperature
is not None:
375 if "setThermostatSetpoint" in target.fibaro_device.actions:
376 target.action(
"setThermostatSetpoint", self.
fibaro_op_modefibaro_op_mode, temperature)
377 elif "setHeatingThermostatSetpoint" in target.fibaro_device.actions:
378 target.action(
"setHeatingThermostatSetpoint", temperature)
380 target.action(
"setTargetLevel", temperature)
list[str]|None preset_modes(self)
str|None preset_mode(self)
HVACAction|None hvac_action(self)
str|None preset_mode(self)
None async_added_to_hass(self)
float|None current_temperature(self)
None set_fan_mode(self, str fan_mode)
float|None target_temperature(self)
None set_hvac_mode(self, HVACMode hvac_mode)
None set_preset_mode(self, str preset_mode)
None set_temperature(self, **Any kwargs)
str|int fibaro_op_mode(self)
None __init__(self, DeviceModel fibaro_device)
None action(self, str cmd, *Any args)
None _update_callback(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
def register(HomeAssistant hass, Heos controller)