-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
61 lines (50 loc) · 1.79 KB
/
main.py
File metadata and controls
61 lines (50 loc) · 1.79 KB
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
"""ConBee addon for Mozilla IoT Gateway."""
from os import path
import functools
import gateway_addon
import logging
import signal
import sys
import time
import traceback
sys.path.append(path.join(path.dirname(path.abspath(__file__)), 'lib'))
from pkg.conbee_adapter import ConBeeAdapter
_API_VERSION = {
'min': 2,
'max': 2,
}
_ADAPTER = None
print = functools.partial(print, flush=True)
def cleanup(signum, frame):
"""Clean up any resources before exiting."""
if _ADAPTER is not None:
_ADAPTER.close_proxy()
sys.exit(0)
if __name__ == '__main__':
logging.basicConfig(
level=logging.INFO,
format="%(filename)s:%(lineno)s %(levelname)s %(message)s",
stream = sys.stdout
)
logging.info('Starting Zigbee Conbee Addon')
if gateway_addon.API_VERSION < _API_VERSION['min'] or \
gateway_addon.API_VERSION > _API_VERSION['max']:
logging.error('Unsupported API version. ver: %s', gateway_addon.API_VERSION)
sys.exit(0)
try:
logging.info('Starting zigbee-conbee-adapter. gateway_addon.API_VERSION: %s', gateway_addon.API_VERSION)
logging.info('Arguments list: %s', str(sys.argv))
signal.signal(signal.SIGINT, cleanup)
signal.signal(signal.SIGTERM, cleanup)
_ADAPTER = ConBeeAdapter(verbose=True)
logging.debug('adapter created')
# Wait until proxy stops running. this indicats that the gateway has shut down.
while _ADAPTER.proxy_running():
time.sleep(2)
except Exception as ex:
print('EXECPTION')
print(ex)
print(ex.args)
print(traceback.format_exception(None, # <- type(e) by docs, but ignored
ex, ex.__traceback__), file=sys.stdout)
logging.info('STOPPED Zigbee Conbee Addon')