-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy path__init__.py
100 lines (79 loc) · 2.81 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"""Platform for the Daikin AC."""
import asyncio
from datetime import timedelta
import logging
from pymadoka import Controller, discover_devices, force_device_disconnect
import voluptuous as vol
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONF_DEVICE,
CONF_DEVICES,
CONF_FORCE_UPDATE,
CONF_SCAN_INTERVAL,
)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import HomeAssistantType
from . import config_flow # noqa: F401
from .const import CONTROLLERS, DOMAIN
PARALLEL_UPDATES = 0
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
COMPONENT_TYPES = ["climate"]
_LOGGER = logging.getLogger(__name__)
CONFIG_SCHEMA = vol.Schema(
vol.All(
cv.deprecated(DOMAIN),
{
DOMAIN: vol.Schema(
{
vol.Required(CONF_DEVICES, default=[]): vol.All(
cv.ensure_list, [cv.string]
),
vol.Optional(CONF_FORCE_UPDATE, default=True): bool,
vol.Optional(CONF_DEVICE, default="hci0"): cv.string,
vol.Optional(CONF_SCAN_INTERVAL, default=5): cv.positive_int,
}
)
},
),
extra=vol.ALLOW_EXTRA,
)
async def async_setup(hass, config):
"""Set up the component."""
hass.data.setdefault(DOMAIN, {})
return True
async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
"""Pass conf to all the components."""
controllers = {}
for device in entry.data[CONF_DEVICES]:
if entry.data[CONF_FORCE_UPDATE]:
await force_device_disconnect(device)
controllers[device] = Controller(device, adapter=entry.data[CONF_DEVICE])
await discover_devices(
adapter=entry.data[CONF_DEVICE], timeout=entry.data[CONF_SCAN_INTERVAL]
)
for device, controller in controllers.items():
try:
await asyncio.wait_for(controller.start(),timeout=10)
except ConnectionAbortedError as connection_aborted_error:
_LOGGER.error(
"Could not connect to device %s: %s",
device,
str(connection_aborted_error),
)
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.entry_id] = {CONTROLLERS: controllers}
for component in COMPONENT_TYPES:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, component)
)
return True
async def async_unload_entry(hass, config_entry):
"""Unload a config entry."""
await asyncio.wait(
[
hass.async_create_task(hass.config_entries.async_forward_entry_unload(config_entry, component))
for component in COMPONENT_TYPES
]
)
hass.data[DOMAIN].pop(config_entry.entry_id)
return True