Home Assistant Unofficial Reference 2024.12.1
water_heater.py
Go to the documentation of this file.
1 """Support for hive water heaters."""
2 
3 from datetime import timedelta
4 from typing import Any
5 
6 import voluptuous as vol
7 
9  STATE_ECO,
10  WaterHeaterEntity,
11  WaterHeaterEntityFeature,
12 )
13 from homeassistant.config_entries import ConfigEntry
14 from homeassistant.const import STATE_OFF, STATE_ON, UnitOfTemperature
15 from homeassistant.core import HomeAssistant
16 from homeassistant.helpers import config_validation as cv, entity_platform
17 from homeassistant.helpers.entity_platform import AddEntitiesCallback
18 
19 from . import refresh_system
20 from .const import (
21  ATTR_ONOFF,
22  ATTR_TIME_PERIOD,
23  DOMAIN,
24  SERVICE_BOOST_HOT_WATER,
25  WATER_HEATER_MODES,
26 )
27 from .entity import HiveEntity
28 
29 HOTWATER_NAME = "Hot Water"
30 PARALLEL_UPDATES = 0
31 SCAN_INTERVAL = timedelta(seconds=15)
32 HIVE_TO_HASS_STATE = {
33  "SCHEDULE": STATE_ECO,
34  "ON": STATE_ON,
35  "OFF": STATE_OFF,
36 }
37 
38 HASS_TO_HIVE_STATE = {
39  STATE_ECO: "SCHEDULE",
40  STATE_ON: "MANUAL",
41  STATE_OFF: "OFF",
42 }
43 
44 SUPPORT_WATER_HEATER = [STATE_ECO, STATE_ON, STATE_OFF]
45 
46 
48  hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
49 ) -> None:
50  """Set up Hive thermostat based on a config entry."""
51 
52  hive = hass.data[DOMAIN][entry.entry_id]
53  devices = hive.session.deviceList.get("water_heater")
54  if devices:
55  async_add_entities((HiveWaterHeater(hive, dev) for dev in devices), True)
56 
57  platform = entity_platform.async_get_current_platform()
58 
59  platform.async_register_entity_service(
60  SERVICE_BOOST_HOT_WATER,
61  {
62  vol.Optional(ATTR_TIME_PERIOD, default="00:30:00"): vol.All(
63  cv.time_period,
64  cv.positive_timedelta,
65  lambda td: td.total_seconds() // 60,
66  ),
67  vol.Required(ATTR_ONOFF): vol.In(WATER_HEATER_MODES),
68  },
69  "async_hot_water_boost",
70  )
71 
72 
74  """Hive Water Heater Device."""
75 
76  _attr_supported_features = WaterHeaterEntityFeature.OPERATION_MODE
77  _attr_temperature_unit = UnitOfTemperature.CELSIUS
78  _attr_operation_list = SUPPORT_WATER_HEATER
79 
80  @refresh_system
81  async def async_turn_on(self, **kwargs: Any) -> None:
82  """Turn on hotwater."""
83  await self.hivehive.hotwater.setMode(self.devicedevicedevice, "MANUAL")
84 
85  @refresh_system
86  async def async_turn_off(self, **kwargs: Any) -> None:
87  """Turn on hotwater."""
88  await self.hivehive.hotwater.setMode(self.devicedevicedevice, "OFF")
89 
90  @refresh_system
91  async def async_set_operation_mode(self, operation_mode: str) -> None:
92  """Set operation mode."""
93  new_mode = HASS_TO_HIVE_STATE[operation_mode]
94  await self.hivehive.hotwater.setMode(self.devicedevicedevice, new_mode)
95 
96  @refresh_system
97  async def async_hot_water_boost(self, time_period: int, on_off: str) -> None:
98  """Handle the service call."""
99  if on_off == "on":
100  await self.hivehive.hotwater.setBoostOn(self.devicedevicedevice, time_period)
101  elif on_off == "off":
102  await self.hivehive.hotwater.setBoostOff(self.devicedevicedevice)
103 
104  async def async_update(self) -> None:
105  """Update all Node data from Hive."""
106  await self.hivehive.session.updateData(self.devicedevicedevice)
107  self.devicedevicedevice = await self.hivehive.hotwater.getWaterHeater(self.devicedevicedevice)
108  self._attr_available_attr_available = self.devicedevicedevice["deviceData"].get("online")
109  if self._attr_available_attr_available:
110  self._attr_current_operation_attr_current_operation = HIVE_TO_HASS_STATE[
111  self.devicedevicedevice["status"]["current_operation"]
112  ]
None async_hot_water_boost(self, int time_period, str on_off)
Definition: water_heater.py:97
web.Response get(self, web.Request request, str config_key)
Definition: view.py:88
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: water_heater.py:49