Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """Support for Danfoss Air HRV."""
2 
3 from datetime import timedelta
4 import logging
5 
6 from pydanfossair.commands import ReadCommand
7 from pydanfossair.danfossclient import DanfossClient
8 import voluptuous as vol
9 
10 from homeassistant.const import CONF_HOST, Platform
11 from homeassistant.core import HomeAssistant
12 from homeassistant.helpers import discovery
14 from homeassistant.helpers.typing import ConfigType
15 from homeassistant.util import Throttle
16 
17 _LOGGER = logging.getLogger(__name__)
18 
19 PLATFORMS = [Platform.BINARY_SENSOR, Platform.SENSOR, Platform.SWITCH]
20 DOMAIN = "danfoss_air"
21 
22 MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
23 
24 CONFIG_SCHEMA = vol.Schema(
25  {DOMAIN: vol.Schema({vol.Required(CONF_HOST): cv.string})}, extra=vol.ALLOW_EXTRA
26 )
27 
28 
29 def setup(hass: HomeAssistant, config: ConfigType) -> bool:
30  """Set up the Danfoss Air component."""
31  conf = config[DOMAIN]
32 
33  hass.data[DOMAIN] = DanfossAir(conf[CONF_HOST])
34 
35  for platform in PLATFORMS:
36  discovery.load_platform(hass, platform, DOMAIN, {}, config)
37 
38  return True
39 
40 
41 class DanfossAir:
42  """Handle all communication with Danfoss Air CCM unit."""
43 
44  def __init__(self, host):
45  """Initialize the Danfoss Air CCM connection."""
46  self._data_data = {}
47 
48  self._client_client = DanfossClient(host)
49 
50  def get_value(self, item):
51  """Get value for sensor."""
52  return self._data_data.get(item)
53 
54  def update_state(self, command, state_command):
55  """Send update command to Danfoss Air CCM."""
56  self._data_data[state_command] = self._client_client.command(command)
57 
58  @Throttle(MIN_TIME_BETWEEN_UPDATES)
59  def update(self):
60  """Use the data from Danfoss Air API."""
61  _LOGGER.debug("Fetching data from Danfoss Air CCM module")
62 
63  self._data_data[ReadCommand.exhaustTemperature] = self._client_client.command(
64  ReadCommand.exhaustTemperature
65  )
66  self._data_data[ReadCommand.outdoorTemperature] = self._client_client.command(
67  ReadCommand.outdoorTemperature
68  )
69  self._data_data[ReadCommand.supplyTemperature] = self._client_client.command(
70  ReadCommand.supplyTemperature
71  )
72  self._data_data[ReadCommand.extractTemperature] = self._client_client.command(
73  ReadCommand.extractTemperature
74  )
75  self._data_data[ReadCommand.humidity] = round(
76  self._client_client.command(ReadCommand.humidity), 2
77  )
78  self._data_data[ReadCommand.filterPercent] = round(
79  self._client_client.command(ReadCommand.filterPercent), 2
80  )
81  self._data_data[ReadCommand.bypass] = self._client_client.command(ReadCommand.bypass)
82  self._data_data[ReadCommand.fan_step] = self._client_client.command(ReadCommand.fan_step)
83  self._data_data[ReadCommand.supply_fan_speed] = self._client_client.command(
84  ReadCommand.supply_fan_speed
85  )
86  self._data_data[ReadCommand.exhaust_fan_speed] = self._client_client.command(
87  ReadCommand.exhaust_fan_speed
88  )
89  self._data_data[ReadCommand.away_mode] = self._client_client.command(ReadCommand.away_mode)
90  self._data_data[ReadCommand.boost] = self._client_client.command(ReadCommand.boost)
91  self._data_data[ReadCommand.battery_percent] = self._client_client.command(
92  ReadCommand.battery_percent
93  )
94  self._data_data[ReadCommand.bypass] = self._client_client.command(ReadCommand.bypass)
95  self._data_data[ReadCommand.automatic_bypass] = self._client_client.command(
96  ReadCommand.automatic_bypass
97  )
98 
99  _LOGGER.debug("Done fetching data from Danfoss Air CCM module")
def update_state(self, command, state_command)
Definition: __init__.py:54
web.Response get(self, web.Request request, str config_key)
Definition: view.py:88
bool setup(HomeAssistant hass, ConfigType config)
Definition: __init__.py:29