Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """Support for an Intergas boiler via an InComfort/Intouch Lan2RF gateway."""
2 
3 from __future__ import annotations
4 
5 from aiohttp import ClientResponseError
6 from incomfortclient import IncomfortError, InvalidHeaterList
7 import voluptuous as vol
8 
9 from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
10 from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME, Platform
11 from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
12 from homeassistant.data_entry_flow import FlowResultType
13 from homeassistant.exceptions import ConfigEntryAuthFailed
14 from homeassistant.helpers import config_validation as cv, issue_registry as ir
15 from homeassistant.helpers.typing import ConfigType
16 
17 from .const import DOMAIN
18 from .coordinator import InComfortDataCoordinator, async_connect_gateway
19 from .errors import InConfortTimeout, InConfortUnknownError, NoHeaters, NotFound
20 
21 CONFIG_SCHEMA = vol.Schema(
22  {
23  DOMAIN: vol.Schema(
24  {
25  vol.Required(CONF_HOST): cv.string,
26  vol.Inclusive(CONF_USERNAME, "credentials"): cv.string,
27  vol.Inclusive(CONF_PASSWORD, "credentials"): cv.string,
28  }
29  )
30  },
31  extra=vol.ALLOW_EXTRA,
32 )
33 
34 PLATFORMS = (
35  Platform.WATER_HEATER,
36  Platform.BINARY_SENSOR,
37  Platform.SENSOR,
38  Platform.CLIMATE,
39 )
40 
41 INTEGRATION_TITLE = "Intergas InComfort/Intouch Lan2RF gateway"
42 
43 type InComfortConfigEntry = ConfigEntry[InComfortDataCoordinator]
44 
45 
46 async def _async_import(hass: HomeAssistant, config: ConfigType) -> None:
47  """Import config entry from configuration.yaml."""
48  if not hass.config_entries.async_entries(DOMAIN):
49  # Start import flow
50  result = await hass.config_entries.flow.async_init(
51  DOMAIN, context={"source": SOURCE_IMPORT}, data=config
52  )
53  if result["type"] == FlowResultType.ABORT:
54  ir.async_create_issue(
55  hass,
56  DOMAIN,
57  f"deprecated_yaml_import_issue_{result['reason']}",
58  breaks_in_ha_version="2025.1.0",
59  is_fixable=False,
60  issue_domain=DOMAIN,
61  severity=ir.IssueSeverity.WARNING,
62  translation_key=f"deprecated_yaml_import_issue_{result['reason']}",
63  translation_placeholders={
64  "domain": DOMAIN,
65  "integration_title": INTEGRATION_TITLE,
66  },
67  )
68  return
69 
70  ir.async_create_issue(
71  hass,
72  HOMEASSISTANT_DOMAIN,
73  f"deprecated_yaml_{DOMAIN}",
74  breaks_in_ha_version="2025.1.0",
75  is_fixable=False,
76  issue_domain=DOMAIN,
77  severity=ir.IssueSeverity.WARNING,
78  translation_key="deprecated_yaml",
79  translation_placeholders={
80  "domain": DOMAIN,
81  "integration_title": INTEGRATION_TITLE,
82  },
83  )
84 
85 
86 async def async_setup(hass: HomeAssistant, hass_config: ConfigType) -> bool:
87  """Create an Intergas InComfort/Intouch system."""
88  if config := hass_config.get(DOMAIN):
89  hass.async_create_task(_async_import(hass, config))
90  return True
91 
92 
93 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
94  """Set up a config entry."""
95  try:
96  data = await async_connect_gateway(hass, dict(entry.data))
97  for heater in data.heaters:
98  await heater.update()
99  except InvalidHeaterList as exc:
100  raise NoHeaters from exc
101  except IncomfortError as exc:
102  if isinstance(exc.message, ClientResponseError):
103  if exc.message.status == 401:
104  raise ConfigEntryAuthFailed("Incorrect credentials") from exc
105  if exc.message.status == 404:
106  raise NotFound from exc
107  raise InConfortUnknownError from exc
108  except TimeoutError as exc:
109  raise InConfortTimeout from exc
110 
111  coordinator = InComfortDataCoordinator(hass, data)
112  entry.runtime_data = coordinator
113  await coordinator.async_config_entry_first_refresh()
114 
115  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
116  return True
117 
118 
119 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
120  """Unload config entry."""
121  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
InComfortData async_connect_gateway(HomeAssistant hass, dict[str, Any] entry_data)
Definition: coordinator.py:37
None _async_import(HomeAssistant hass, ConfigType config)
Definition: __init__.py:46
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:93
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:119
bool async_setup(HomeAssistant hass, ConfigType hass_config)
Definition: __init__.py:86