Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The component for STIEBEL ELTRON heat pumps with ISGWeb Modbus module."""
2 
3 from datetime import timedelta
4 import logging
5 
6 from pystiebeleltron import pystiebeleltron
7 import voluptuous as vol
8 
9 from homeassistant.const import CONF_NAME, DEVICE_DEFAULT_NAME, Platform
10 from homeassistant.core import HomeAssistant
11 from homeassistant.helpers import discovery
13 from homeassistant.helpers.typing import ConfigType
14 from homeassistant.util import Throttle
15 
16 CONF_HUB = "hub"
17 DEFAULT_HUB = "modbus_hub"
18 MODBUS_DOMAIN = "modbus"
19 DOMAIN = "stiebel_eltron"
20 
21 CONFIG_SCHEMA = vol.Schema(
22  {
23  DOMAIN: vol.Schema(
24  {
25  vol.Optional(CONF_NAME, default=DEVICE_DEFAULT_NAME): cv.string,
26  vol.Optional(CONF_HUB, default=DEFAULT_HUB): cv.string,
27  }
28  )
29  },
30  extra=vol.ALLOW_EXTRA,
31 )
32 
33 _LOGGER = logging.getLogger(__name__)
34 
35 MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=30)
36 
37 
38 def setup(hass: HomeAssistant, config: ConfigType) -> bool:
39  """Set up the STIEBEL ELTRON unit.
40 
41  Will automatically load climate platform.
42  """
43  name = config[DOMAIN][CONF_NAME]
44  modbus_client = hass.data[MODBUS_DOMAIN][config[DOMAIN][CONF_HUB]]
45 
46  hass.data[DOMAIN] = {
47  "name": name,
48  "ste_data": StiebelEltronData(name, modbus_client),
49  }
50 
51  discovery.load_platform(hass, Platform.CLIMATE, DOMAIN, {}, config)
52  return True
53 
54 
56  """Get the latest data and update the states."""
57 
58  def __init__(self, name, modbus_client):
59  """Init the STIEBEL ELTRON data object."""
60 
61  self.apiapi = pystiebeleltron.StiebelEltronAPI(modbus_client, 1)
62 
63  @Throttle(MIN_TIME_BETWEEN_UPDATES)
64  def update(self):
65  """Update unit data."""
66  if not self.apiapi.update():
67  _LOGGER.warning("Modbus read failed")
68  else:
69  _LOGGER.debug("Data updated successfully")
bool setup(HomeAssistant hass, ConfigType config)
Definition: __init__.py:38