Home Assistant Unofficial Reference 2024.12.1
climate.py
Go to the documentation of this file.
1 """Support for Genius Hub climate devices."""
2 
3 from __future__ import annotations
4 
6  PRESET_ACTIVITY,
7  PRESET_BOOST,
8  ClimateEntity,
9  ClimateEntityFeature,
10  HVACAction,
11  HVACMode,
12 )
13 from homeassistant.core import HomeAssistant
14 from homeassistant.helpers.entity_platform import AddEntitiesCallback
15 
16 from . import GeniusHubConfigEntry
17 from .entity import GeniusHeatingZone
18 
19 # GeniusHub Zones support: Off, Timer, Override/Boost, Footprint & Linked modes
20 HA_HVAC_TO_GH = {HVACMode.OFF: "off", HVACMode.HEAT: "timer"}
21 GH_HVAC_TO_HA = {v: k for k, v in HA_HVAC_TO_GH.items()}
22 
23 HA_PRESET_TO_GH = {PRESET_ACTIVITY: "footprint", PRESET_BOOST: "override"}
24 GH_PRESET_TO_HA = {v: k for k, v in HA_PRESET_TO_GH.items()}
25 
26 GH_ZONES = ["radiator", "wet underfloor"]
27 
28 
30  hass: HomeAssistant,
31  entry: GeniusHubConfigEntry,
32  async_add_entities: AddEntitiesCallback,
33 ) -> None:
34  """Set up the Genius Hub climate entities."""
35 
36  broker = entry.runtime_data
37 
39  GeniusClimateZone(broker, z)
40  for z in broker.client.zone_objs
41  if z.data.get("type") in GH_ZONES
42  )
43 
44 
46  """Representation of a Genius Hub climate device."""
47 
48  _attr_supported_features = (
49  ClimateEntityFeature.TARGET_TEMPERATURE
50  | ClimateEntityFeature.PRESET_MODE
51  | ClimateEntityFeature.TURN_OFF
52  | ClimateEntityFeature.TURN_ON
53  )
54  _enable_turn_on_off_backwards_compatibility = False
55 
56  def __init__(self, broker, zone) -> None:
57  """Initialize the climate device."""
58  super().__init__(broker, zone)
59 
60  self._max_temp_max_temp = 28.0
61  self._min_temp_min_temp = 4.0
62 
63  @property
64  def icon(self) -> str:
65  """Return the icon to use in the frontend UI."""
66  return "mdi:radiator"
67 
68  @property
69  def hvac_mode(self) -> HVACMode:
70  """Return hvac operation ie. heat, cool mode."""
71  return GH_HVAC_TO_HA.get(self._zone_zone.data["mode"], HVACMode.HEAT)
72 
73  @property
74  def hvac_modes(self) -> list[HVACMode]:
75  """Return the list of available hvac operation modes."""
76  return list(HA_HVAC_TO_GH)
77 
78  @property
79  def hvac_action(self) -> HVACAction | None:
80  """Return the current running hvac operation if supported."""
81  if "_state" in self._zone_zone.data: # only for v3 API
82  if self._zone_zone.data["output"] == 1:
83  return HVACAction.HEATING
84  if not self._zone_zone.data["_state"].get("bIsActive"):
85  return HVACAction.OFF
86  return HVACAction.IDLE
87  return None
88 
89  @property
90  def preset_mode(self) -> str | None:
91  """Return the current preset mode, e.g., home, away, temp."""
92  return GH_PRESET_TO_HA.get(self._zone_zone.data["mode"])
93 
94  @property
95  def preset_modes(self) -> list[str] | None:
96  """Return a list of available preset modes."""
97  if "occupied" in self._zone_zone.data: # if has a movement sensor
98  return [PRESET_ACTIVITY, PRESET_BOOST]
99  return [PRESET_BOOST]
100 
101  async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
102  """Set a new hvac mode."""
103  await self._zone_zone.set_mode(HA_HVAC_TO_GH.get(hvac_mode))
104 
105  async def async_set_preset_mode(self, preset_mode: str) -> None:
106  """Set a new preset mode."""
107  await self._zone_zone.set_mode(HA_PRESET_TO_GH.get(preset_mode, "timer"))
web.Response get(self, web.Request request, str config_key)
Definition: view.py:88
None async_setup_entry(HomeAssistant hass, GeniusHubConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: climate.py:33