-
Notifications
You must be signed in to change notification settings - Fork 9
/
rf_device.py
63 lines (46 loc) · 1.82 KB
/
rf_device.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
"""Handling of the Becker USB device."""
import logging
import voluptuous as vol
from pybecker.becker import Becker
from .const import CONF_CHANNEL, CONF_UNIT, DEFAULT_CONF_USB_STICK_PATH, DOMAIN
_LOGGER = logging.getLogger(__name__)
PAIR_SCHEMA = vol.Schema(
{
vol.Required(CONF_CHANNEL): vol.All(int, vol.Range(min=1, max=7)),
vol.Optional(CONF_UNIT): vol.All(int, vol.Range(min=1, max=5)),
}
)
class PyBecker:
"""Manages a (single, global) pybecker Becker instance."""
becker = None
@classmethod
def setup(cls, stick_path=None):
"""Initiate becker instance."""
if not stick_path:
stick_path = DEFAULT_CONF_USB_STICK_PATH
cls.becker = Becker(stick_path, True)
@classmethod
async def async_register_services(cls, hass):
"""Register component services."""
hass.services.async_register(DOMAIN, "pair", cls.handle_pair, PAIR_SCHEMA)
hass.services.async_register(DOMAIN, "log_units", cls.handle_log_units)
@classmethod
async def handle_pair(cls, call):
"""Service to pair with a cover receiver."""
channel = call.data.get(CONF_CHANNEL)
unit = call.data.get(CONF_UNIT, 1)
await cls.becker.pair(f"{unit}:{channel}")
@classmethod
async def handle_log_units(cls, call):
"""Service that logs all paired units."""
units = await cls.becker.list_units()
# Apparently the SQLite results are implicitly returned in unit id
# order. This seems pretty dirty to rely on.
unit_id = 1
_LOGGER.info("Configured Becker centronic units:")
for row in units:
unit_code, increment = row[0:2]
_LOGGER.info(
"Unit id %d, unit code %s, increment %d", unit_id, unit_code, increment
)
unit_id += 1