-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path__init__.py
56 lines (41 loc) · 1.86 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
47
48
49
50
51
52
53
54
55
56
"""The CentralControl integration."""
from __future__ import annotations
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, CONF_TOKEN
from homeassistant.core import HomeAssistant
from .central_control import CentralControl
from .const import PLATFORMS
type CentralControlConfigEntry = ConfigEntry[CentralControl] # noqa: F821
async def async_setup_entry(
hass: HomeAssistant, entry: CentralControlConfigEntry
) -> bool:
"""Set up CentralControl from a config entry."""
address = entry.data[CONF_HOST]
cookie = entry.data.get(CONF_TOKEN, None)
# shortName = "" # short name of the central control device (login to gw.b-tronic.net, connect to a box and check the URL)
central_control = CentralControl(
address=address,
# address="https://gw.b-tronic.net/cc{}/cgi-bin/cc51rpc.cgi".format(shortName), # Connect through the gateway. Not recommended.
cookie=cookie,
)
entry.runtime_data = central_control
item_list: dict
try:
item_list = await central_control.get_item_list(item_type="group")
except TimeoutError:
return False
# # Run zeroconf discovery, in case no address was supplied?
# aiozc = await zeroconf.async_get_async_instance(hass)
# discovery = CentralControlDiscovery()
# await aiozc.async_add_service_listener("_http._tcp.local.", discovery)
if item_list.get("result") is None:
return False
if item_list["result"].get("item_list") is None:
return False
if item_list["result"]["item_list"] is False:
return False
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."""
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)