-
Notifications
You must be signed in to change notification settings - Fork 9
/
__init__.py
69 lines (54 loc) · 2.08 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
"""The becker component."""
from itertools import chain
import logging
from homeassistant.const import MATCH_ALL
from .rf_device import PyBecker
_LOGGER = logging.getLogger(__name__)
def initialise_templates(hass, templates, attribute_templates=None):
"""Initialise templates and attribute templates."""
if attribute_templates is None:
attribute_templates = dict()
for template in chain(templates.values(), attribute_templates.values()):
if template is None:
continue
template.hass = hass
def extract_entities(
device_name, device_type, manual_entity_ids, templates, attribute_templates=None
):
"""Extract entity ids from templates and attribute templates."""
if attribute_templates is None:
attribute_templates = dict()
entity_ids = set()
if manual_entity_ids is None:
invalid_templates = []
for template_name, template in chain(
templates.items(), attribute_templates.items()
):
if template is None:
continue
template_entity_ids = template.extract_entities()
if template_entity_ids != MATCH_ALL:
entity_ids |= set(template_entity_ids)
else:
invalid_templates.append(template_name.replace("_template", ""))
if invalid_templates:
entity_ids = MATCH_ALL
_LOGGER.warning(
"Template %s '%s' has no entity ids configured to track nor"
" were we able to extract the entities to track from the %s "
"template(s). This entity will only be able to be updated "
"manually.",
device_type,
device_name,
", ".join(invalid_templates),
)
else:
entity_ids = list(entity_ids)
else:
entity_ids = manual_entity_ids
return entity_ids
async def async_setup(hass, config):
"""Initiate becker component for home assistant."""
# Register this component's services
await PyBecker.async_register_services(hass)
return True