Home Assistant Unofficial Reference 2024.12.1
climate.py
Go to the documentation of this file.
1 """Intellifire Climate Entities."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
8  ClimateEntity,
9  ClimateEntityDescription,
10  ClimateEntityFeature,
11  HVACMode,
12 )
13 from homeassistant.config_entries import ConfigEntry
14 from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
15 from homeassistant.core import HomeAssistant
16 from homeassistant.helpers.entity_platform import AddEntitiesCallback
17 
18 from . import IntellifireDataUpdateCoordinator
19 from .const import DEFAULT_THERMOSTAT_TEMP, DOMAIN, LOGGER
20 from .entity import IntellifireEntity
21 
22 INTELLIFIRE_CLIMATES: tuple[ClimateEntityDescription, ...] = (
23  ClimateEntityDescription(key="climate", name="Thermostat"),
24 )
25 
26 
28  hass: HomeAssistant,
29  entry: ConfigEntry,
30  async_add_entities: AddEntitiesCallback,
31 ) -> None:
32  """Configure the fan entry.."""
33  coordinator: IntellifireDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
34 
35  if coordinator.data.has_thermostat:
38  coordinator=coordinator,
39  description=description,
40  )
41  for description in INTELLIFIRE_CLIMATES
42  )
43 
44 
46  """Intellifire climate entity."""
47 
48  entity_description: ClimateEntityDescription
49 
50  _attr_hvac_modes = [HVACMode.HEAT, HVACMode.OFF]
51  _attr_min_temp = 0
52  _attr_max_temp = 37
53  _attr_supported_features = (
54  ClimateEntityFeature.TARGET_TEMPERATURE
55  | ClimateEntityFeature.TURN_OFF
56  | ClimateEntityFeature.TURN_ON
57  )
58  _attr_target_temperature_step = 1.0
59  _attr_temperature_unit = UnitOfTemperature.CELSIUS
60  last_temp = DEFAULT_THERMOSTAT_TEMP
61  _enable_turn_on_off_backwards_compatibility = False
62 
63  def __init__(
64  self,
65  coordinator: IntellifireDataUpdateCoordinator,
66  description: ClimateEntityDescription,
67  ) -> None:
68  """Configure climate entry - and override last_temp if the thermostat is currently on."""
69  super().__init__(coordinator, description)
70 
71  if coordinator.data.thermostat_on:
72  self.last_templast_temp = int(coordinator.data.thermostat_setpoint_c)
73 
74  @property
75  def hvac_mode(self) -> HVACMode:
76  """Return current hvac mode."""
77  if self.coordinator.read_api.data.thermostat_on:
78  return HVACMode.HEAT
79  return HVACMode.OFF
80 
81  async def async_set_temperature(self, **kwargs: Any) -> None:
82  """Turn on thermostat by setting a target temperature."""
83  raw_target_temp = kwargs[ATTR_TEMPERATURE]
84  self.last_templast_temp = int(raw_target_temp)
85  LOGGER.debug(
86  "Setting target temp to %sc %sf",
87  int(raw_target_temp),
88  (raw_target_temp * 9 / 5) + 32,
89  )
90  await self.coordinator.control_api.set_thermostat_c(
91  temp_c=self.last_templast_temp,
92  )
93 
94  @property
95  def current_temperature(self) -> float:
96  """Return the current temperature."""
97  return float(self.coordinator.read_api.data.temperature_c)
98 
99  @property
100  def target_temperature(self) -> float:
101  """Return target temperature."""
102  return float(self.coordinator.read_api.data.thermostat_setpoint_c)
103 
104  async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
105  """Set HVAC mode to normal or thermostat control."""
106  LOGGER.debug(
107  "Setting mode to [%s] - using last temp: %s", hvac_mode, self.last_templast_temp
108  )
109 
110  if hvac_mode == HVACMode.OFF:
111  await self.coordinator.control_api.turn_off_thermostat()
112  return
113 
114  # hvac_mode == HVACMode.HEAT
115  # 1) Set the desired target temp
116  await self.coordinator.control_api.set_thermostat_c(
117  temp_c=self.last_templast_temp,
118  )
119 
120  # 2) Make sure the fireplace is on!
121  if not self.coordinator.read_api.data.is_on:
122  await self.coordinator.control_api.flame_on()
None __init__(self, IntellifireDataUpdateCoordinator coordinator, ClimateEntityDescription description)
Definition: climate.py:67
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: climate.py:31