-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
46 lines (36 loc) · 1.52 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""The nymea integration."""
from __future__ import annotations
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from . import maveo_box
from .const import DOMAIN
from .thing import Thing
from .maveo_stick import MaveoStick
PLATFORMS: list[str] = ["cover", "sensor", "binary_sensor"]
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up nymea from a config entry."""
nymea_hub = maveo_box.MaveoBox(
hass, entry.data["host"], entry.data["port"], entry.data["token"]
)
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = nymea_hub
try:
await nymea_hub.init_connection()
# await nymea_hub.nymea.init_connection()
except Exception as ex:
raise ConfigEntryNotReady(
f"Error while connecting to {entry.data["host"]}"
) from ex
await MaveoStick.add(nymea_hub)
await Thing.add(nymea_hub)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
# This is called when an entry/configured device is to be removed. The class
# needs to unload itself, and remove callbacks. See the classes for further
# details
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
if unload_ok:
hass.data[DOMAIN].pop(entry.entry_id)
return unload_ok