-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
41 lines (27 loc) · 1 KB
/
main.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
"""Homebridge addon for Candle Controller."""
# You will need to change the name in this file in two places, marked below:
from os import path
import functools
import signal
import sys
import time
sys.path.append(path.join(path.dirname(path.abspath(__file__)), 'lib'))
# Change this to reflect your addon's adapter class. It should be the same as the name in the:
from pkg.homebridge_adapter import HomebridgeAdapter # noqa
_DEBUG = False
_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__':
signal.signal(signal.SIGINT, cleanup)
signal.signal(signal.SIGTERM, cleanup)
# Change this to the correct name too:
_ADAPTER = HomebridgeAdapter(verbose=_DEBUG)
# Wait until the proxy stops running, indicating that the gateway shut us
# down.
while _ADAPTER.proxy_running():
time.sleep(2)