-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·28 lines (22 loc) · 943 Bytes
/
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
#!/usr/bin/env python3
import logging, signal, os, time, sys
from pyhap.accessory import Bridge
from pyhap.accessory_driver import AccessoryDriver
import ClassExample
from pyhap.loader import Loader as Loader
logging.basicConfig(level=logging.INFO, format="[%(module)s] %(message)s")
persist_file = 'devices.state'
loader = Loader(path_char='CharacteristicDefinition.json',path_service='ServiceDefinition.json')
def get_bridge(driver):
bridge = Bridge(driver, 'HAPBridge')
Weather = ClassExample.Weather(driver, 'Weather')
bridge.add_accessory(Weather)
return bridge
try:
driver = AccessoryDriver(port=51826, persist_file= persist_file, loader=loader)
driver.add_accessory(accessory=get_bridge(driver))
signal.signal(signal.SIGTERM, driver.signal_handler)
driver.start()
except Exception as e:
logging.info('**** Could connect HAP Service: {0}'.format(e))
os.kill(os.getpid(), signal.SIGKILL)