-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhap-python.py
More file actions
33 lines (24 loc) · 1014 Bytes
/
hap-python.py
File metadata and controls
33 lines (24 loc) · 1014 Bytes
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
"""An example of how to setup and start a ThermoBeacon Bridge.
This is:
1. Create AccessoryDriver Object.
2. Create the ThermoBeacon object and add it to an AccessoryDriver
"""
import logging
import os, signal
from pyhap.accessory_driver import AccessoryDriver
from ThermoBeacon import ThermoBeaconBridge
logging.basicConfig(level=logging.INFO, format="[%(module)s] %(message)s")
service_dir = '~/.hap-python/'
# Start the accessory on port 51826
driver = AccessoryDriver(port=51826,
persist_file = service_dir + '.accessory.state',
pincode=b'123-12-123')
bridge = ThermoBeaconBridge(driver,
config_file = os.path.expanduser(service_dir + 'beacons.json'))
#Run a Bridge
driver.add_accessory(accessory=bridge)
# We want SIGTERM (terminate) to be handled by the driver itself,
# so that it can gracefully stop the accessory, server and advertising.
signal.signal(signal.SIGTERM, driver.signal_handler)
# Start it!
driver.start()