/
xknx_module.py
47 lines (31 loc) · 1.12 KB
/
xknx_module.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
import threading
import logging
import asyncio
import xknx
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
from .xknx_config import XKNXConfig
_LOGGER = logging.getLogger(__name__)
class XKNXModule(object):
"""Representation of XKNX Object."""
def __init__(self, hass, config):
xknx_config = XKNXConfig(hass, config)
self.xknx = xknx.XKNX(loop=hass.loop, start=False)
self.initialized = False
self.lock = threading.Lock()
self.hass = hass
self.config_file = xknx_config.config_file()
@staticmethod
def telegram_received_callback(xknx, device, telegram):
#print("{0}".format(device.name))
pass
@asyncio.coroutine
def start(self):
xknx.Config(self.xknx).read(file=self.config_file)
yield from self.xknx.async_start(
state_updater=True,
telegram_received_callback=self.telegram_received_callback)
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self.stop)
self.initialized = True
@asyncio.coroutine
def stop(self, event):
yield from self.xknx.async_stop()