HAP-python 1.0__tar.gz → 1.0.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {HAP-python-1.0/HAP_python.egg-info → usr/local/lib/python3.6/site-packages/HAP_python-1.0.5-py3.6.egg-info}/PKG-INFO +1 -1
- usr/local/lib/python3.6/site-packages/pyhap/__pycache__/__init__.cpython-36.pyc +0 -0
- usr/local/lib/python3.6/site-packages/pyhap/__pycache__/accessory.cpython-36.pyc +0 -0
- usr/local/lib/python3.6/site-packages/pyhap/__pycache__/accessory_driver.cpython-36.pyc +0 -0
- usr/local/lib/python3.6/site-packages/pyhap/__pycache__/characteristic.cpython-36.pyc +0 -0
- usr/local/lib/python3.6/site-packages/pyhap/__pycache__/hap_server.cpython-36.pyc +0 -0
- usr/local/lib/python3.6/site-packages/pyhap/__pycache__/hsrp.cpython-36.pyc +0 -0
- usr/local/lib/python3.6/site-packages/pyhap/__pycache__/loader.cpython-36.pyc +0 -0
- usr/local/lib/python3.6/site-packages/pyhap/__pycache__/params.cpython-36.pyc +0 -0
- usr/local/lib/python3.6/site-packages/pyhap/__pycache__/service.cpython-36.pyc +0 -0
- usr/local/lib/python3.6/site-packages/pyhap/__pycache__/tlv.cpython-36.pyc +0 -0
- usr/local/lib/python3.6/site-packages/pyhap/__pycache__/util.cpython-36.pyc +0 -0
- usr/local/lib/python3.6/site-packages/pyhap/accessories/Http.py +207 -0
- usr/local/lib/python3.6/site-packages/pyhap/accessories/__pycache__/AM2302.cpython-36.pyc +0 -0
- usr/local/lib/python3.6/site-packages/pyhap/accessories/__pycache__/BMP180.cpython-36.pyc +0 -0
- usr/local/lib/python3.6/site-packages/pyhap/accessories/__pycache__/FakeFan.cpython-36.pyc +0 -0
- usr/local/lib/python3.6/site-packages/pyhap/accessories/__pycache__/Http.cpython-36.pyc +0 -0
- usr/local/lib/python3.6/site-packages/pyhap/accessories/__pycache__/LightBulb.cpython-36.pyc +0 -0
- usr/local/lib/python3.6/site-packages/pyhap/accessories/__pycache__/MotionSensor.cpython-36.pyc +0 -0
- usr/local/lib/python3.6/site-packages/pyhap/accessories/__pycache__/ShutdownSwitch.cpython-36.pyc +0 -0
- usr/local/lib/python3.6/site-packages/pyhap/accessories/__pycache__/TSL2591.cpython-36.pyc +0 -0
- usr/local/lib/python3.6/site-packages/pyhap/accessories/__pycache__/TemperatureSensor.cpython-36.pyc +0 -0
- usr/local/lib/python3.6/site-packages/pyhap/accessories/__pycache__/__init__.cpython-36.pyc +0 -0
- {HAP-python-1.0 → usr/local/lib/python3.6/site-packages}/pyhap/accessory.py +9 -3
- {HAP-python-1.0 → usr/local/lib/python3.6/site-packages}/pyhap/accessory_driver.py +0 -0
- {HAP-python-1.0 → usr/local/lib/python3.6/site-packages}/pyhap/hap_server.py +0 -0
- HAP-python-1.0/LICENSE +0 -176
- HAP-python-1.0/MANIFEST.in +0 -2
- HAP-python-1.0/PKG-INFO +0 -18
- HAP-python-1.0/README.md +0 -214
- HAP-python-1.0/pyhap/accessories/Http.py +0 -127
- HAP-python-1.0/setup.cfg +0 -10
- HAP-python-1.0/setup.py +0 -33
- {HAP-python-1.0/HAP_python.egg-info → usr/local/lib/python3.6/site-packages/HAP_python-1.0.5-py3.6.egg-info}/SOURCES.txt +0 -0
- {HAP-python-1.0/HAP_python.egg-info → usr/local/lib/python3.6/site-packages/HAP_python-1.0.5-py3.6.egg-info}/dependency_links.txt +0 -0
- {HAP-python-1.0/HAP_python.egg-info → usr/local/lib/python3.6/site-packages/HAP_python-1.0.5-py3.6.egg-info}/requires.txt +0 -0
- {HAP-python-1.0/HAP_python.egg-info → usr/local/lib/python3.6/site-packages/HAP_python-1.0.5-py3.6.egg-info}/top_level.txt +0 -0
- {HAP-python-1.0 → usr/local/lib/python3.6/site-packages}/pyhap/__init__.py +0 -0
- {HAP-python-1.0 → usr/local/lib/python3.6/site-packages}/pyhap/accessories/AM2302.py +0 -0
- {HAP-python-1.0 → usr/local/lib/python3.6/site-packages}/pyhap/accessories/BMP180.py +0 -0
- {HAP-python-1.0 → usr/local/lib/python3.6/site-packages}/pyhap/accessories/FakeFan.py +0 -0
- {HAP-python-1.0 → usr/local/lib/python3.6/site-packages}/pyhap/accessories/LightBulb.py +0 -0
- {HAP-python-1.0 → usr/local/lib/python3.6/site-packages}/pyhap/accessories/MotionSensor.py +0 -0
- {HAP-python-1.0 → usr/local/lib/python3.6/site-packages}/pyhap/accessories/ShutdownSwitch.py +0 -0
- {HAP-python-1.0 → usr/local/lib/python3.6/site-packages}/pyhap/accessories/TSL2591.py +0 -0
- {HAP-python-1.0 → usr/local/lib/python3.6/site-packages}/pyhap/accessories/TemperatureSensor.py +0 -0
- {HAP-python-1.0 → usr/local/lib/python3.6/site-packages}/pyhap/accessories/__init__.py +0 -0
- {HAP-python-1.0 → usr/local/lib/python3.6/site-packages}/pyhap/characteristic.py +0 -0
- {HAP-python-1.0 → usr/local/lib/python3.6/site-packages}/pyhap/hsrp.py +0 -0
- {HAP-python-1.0 → usr/local/lib/python3.6/site-packages}/pyhap/loader.py +0 -0
- {HAP-python-1.0 → usr/local/lib/python3.6/site-packages}/pyhap/params.py +0 -0
- {HAP-python-1.0 → usr/local/lib/python3.6/site-packages}/pyhap/resources/characteristics.json +0 -0
- {HAP-python-1.0 → usr/local/lib/python3.6/site-packages}/pyhap/resources/services.json +0 -0
- {HAP-python-1.0 → usr/local/lib/python3.6/site-packages}/pyhap/service.py +0 -0
- {HAP-python-1.0 → usr/local/lib/python3.6/site-packages}/pyhap/tlv.py +0 -0
- {HAP-python-1.0 → usr/local/lib/python3.6/site-packages}/pyhap/util.py +0 -0
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"""This module provides HttpAccessory - an accessory that
|
|
2
|
+
allows remote devices to provide HAP services by sending POST
|
|
3
|
+
requests.
|
|
4
|
+
"""
|
|
5
|
+
import json
|
|
6
|
+
import threading
|
|
7
|
+
import logging
|
|
8
|
+
from http.server import HTTPServer, BaseHTTPRequestHandler
|
|
9
|
+
|
|
10
|
+
from pyhap.accessory import Bridge, Category
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class HttpBridgeHandler(BaseHTTPRequestHandler):
|
|
16
|
+
"""Handles requests and passes value updates to an HttpAccessory.
|
|
17
|
+
|
|
18
|
+
The POST request should contain json data with the format:
|
|
19
|
+
{ "aid": <aid>
|
|
20
|
+
"services": {
|
|
21
|
+
<service>: {
|
|
22
|
+
<characteristic>: value,
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
Example:
|
|
28
|
+
{ "aid": 2
|
|
29
|
+
"services": {
|
|
30
|
+
TemperatureSensor" : {
|
|
31
|
+
"CurrentTemperature": 20
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
def __init__(self, http_accessory, sock, client_addr, server):
|
|
38
|
+
"""Create a handler that passes updates to the given HttpAccessory.
|
|
39
|
+
"""
|
|
40
|
+
self.http_accessory = http_accessory
|
|
41
|
+
super(HttpBridgeHandler, self).__init__(sock, client_addr, server)
|
|
42
|
+
|
|
43
|
+
def respond_ok(self):
|
|
44
|
+
"""Reply with code 200 (OK) and close the connection.
|
|
45
|
+
"""
|
|
46
|
+
self.send_response(200)
|
|
47
|
+
self.send_header("Content-Type", "text/html")
|
|
48
|
+
self.send_header("Content-Length", 0)
|
|
49
|
+
self.end_headers()
|
|
50
|
+
self.close_connection = 1
|
|
51
|
+
|
|
52
|
+
def respond_err(self):
|
|
53
|
+
"""Reply with code 400 and close the connection.
|
|
54
|
+
"""
|
|
55
|
+
self.send_response(400)
|
|
56
|
+
self.send_header("Content-Type", "text/html")
|
|
57
|
+
self.send_header("Content-Length", 0)
|
|
58
|
+
self.end_headers()
|
|
59
|
+
self.close_connection = 1
|
|
60
|
+
|
|
61
|
+
def do_POST(self):
|
|
62
|
+
"""Read the payload as json and update the state of the accessory.
|
|
63
|
+
"""
|
|
64
|
+
length = int(self.headers["Content-Length"])
|
|
65
|
+
try:
|
|
66
|
+
# The below decode is necessary only for python <3.6, because loads prior 3.6
|
|
67
|
+
# doesn't know bytes/bytearray.
|
|
68
|
+
content = self.rfile.read(length).decode("utf-8")
|
|
69
|
+
data = json.loads(content)
|
|
70
|
+
except Exception as e:
|
|
71
|
+
logger.error("Bad POST request; Error was: %s", str(e))
|
|
72
|
+
self.respond_err()
|
|
73
|
+
else:
|
|
74
|
+
self.http_accessory.update_state(data)
|
|
75
|
+
self.respond_ok()
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class HttpBridge(Bridge):
|
|
79
|
+
"""An accessory that listens to HTTP requests containing characteristic updates.
|
|
80
|
+
|
|
81
|
+
Simple devices/implementations can just HTTP POST data as:
|
|
82
|
+
|
|
83
|
+
{
|
|
84
|
+
<aid>: int,
|
|
85
|
+
"services": {
|
|
86
|
+
<service1>: {
|
|
87
|
+
<characteristic1>: value
|
|
88
|
+
...
|
|
89
|
+
}
|
|
90
|
+
...
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
Then this accessory takes care of communicating this update to any HAP clients.
|
|
95
|
+
|
|
96
|
+
The way you configure a HttpBridge is by adding Accessory objects. In the
|
|
97
|
+
example below, we add three accessories to a HTTP Bridge:
|
|
98
|
+
>>> # get loaders
|
|
99
|
+
>>> service_loader = loader.get_serv_loader()
|
|
100
|
+
>>> char_loader = loader.get_char_loader()
|
|
101
|
+
>>>
|
|
102
|
+
>>> # Create an accessory with the temperature sensor service.
|
|
103
|
+
>>> temperature_acc_1 = Accessory("temp1", 2)
|
|
104
|
+
>>> temperature_acc_1.add_service(service_loader.get("TemperatureSensor"))
|
|
105
|
+
>>>
|
|
106
|
+
>>> # Create an accessory with the temperature sensor service.
|
|
107
|
+
>>> # Also, add an optional characteristic Name to the service.
|
|
108
|
+
>>> temperature_acc_2 = Accessory("temp2", 3)
|
|
109
|
+
>>> temp_service = service_loader.get("TemperatureSensor")
|
|
110
|
+
>>> temp_service.add_opt_characteristic(char_loader.get("StatusLowBattery"))
|
|
111
|
+
>>> temperature_acc_2.add_service(temp_service)
|
|
112
|
+
>>>
|
|
113
|
+
>>> # Create a lightbulb accessory.
|
|
114
|
+
>>> light_bulb_acc = Accessory("bulb", 4)
|
|
115
|
+
>>> light_bulb_acc.add_service(service_loader.get("Lightbulb"))
|
|
116
|
+
>>>
|
|
117
|
+
>>> # Finally, create the HTTP Bridge and add all accessories to it.
|
|
118
|
+
>>> http_bridge = HttpBridge("HTTP Bridge", address=("", 51111))
|
|
119
|
+
>>> for accessory in (temperature_acc_1, temperature_acc_2, light_bulb_acc):
|
|
120
|
+
... http_bridge.add_accessory(accessory)
|
|
121
|
+
>>>
|
|
122
|
+
>>> # add to an accessory driver and start as usual
|
|
123
|
+
"""
|
|
124
|
+
|
|
125
|
+
category = Category.OTHER
|
|
126
|
+
|
|
127
|
+
def __init__(self, address, *args, **kwargs):
|
|
128
|
+
"""Initialise and add the given services.
|
|
129
|
+
|
|
130
|
+
@param address: The address-port on which to listen for requests.
|
|
131
|
+
@type address: tuple(str, int)
|
|
132
|
+
|
|
133
|
+
@param accessories:
|
|
134
|
+
"""
|
|
135
|
+
super(HttpBridge, self).__init__(*args, **kwargs)
|
|
136
|
+
|
|
137
|
+
# For exclusive access to updates. Slight overkill...
|
|
138
|
+
self.update_lock = None
|
|
139
|
+
self.server_thread = None
|
|
140
|
+
self._set_server(address)
|
|
141
|
+
|
|
142
|
+
def _set_server(self, address):
|
|
143
|
+
"""Set up a HTTPServer to listen on the given address.
|
|
144
|
+
"""
|
|
145
|
+
self.server = HTTPServer(address, lambda *a: HttpBridgeHandler(self, *a))
|
|
146
|
+
self.server_thread = threading.Thread(target=self.server.serve_forever)
|
|
147
|
+
self.update_lock = threading.Lock()
|
|
148
|
+
|
|
149
|
+
def __getstate__(self):
|
|
150
|
+
"""Return the state of this instance, less the server and server thread.
|
|
151
|
+
|
|
152
|
+
Also add the server address. All this is because we cannot pickle such
|
|
153
|
+
objects and to allow to recover the server using the address.
|
|
154
|
+
"""
|
|
155
|
+
state = super(HttpBridge, self).__getstate__()
|
|
156
|
+
state["server"] = None
|
|
157
|
+
state["server_thread"] = None
|
|
158
|
+
state["update_lock"] = None
|
|
159
|
+
state["address"] = self.server.server_address
|
|
160
|
+
return state
|
|
161
|
+
|
|
162
|
+
def __setstate__(self, state):
|
|
163
|
+
"""Load the state and set up the server with the address in the state.
|
|
164
|
+
"""
|
|
165
|
+
self.__dict__.update(state)
|
|
166
|
+
self._set_server(state["address"])
|
|
167
|
+
|
|
168
|
+
def update_state(self, data):
|
|
169
|
+
"""Update the characteristics from the received data.
|
|
170
|
+
|
|
171
|
+
Expected to be called from HapHttpHandler. Updates are thread-safe.
|
|
172
|
+
|
|
173
|
+
@param data: A dict of values that should be set, e.g.:
|
|
174
|
+
{
|
|
175
|
+
<aid>: int,
|
|
176
|
+
<service1 name> : {
|
|
177
|
+
<characteristic1 name>: value
|
|
178
|
+
...
|
|
179
|
+
}
|
|
180
|
+
...
|
|
181
|
+
}
|
|
182
|
+
@type data: dict
|
|
183
|
+
"""
|
|
184
|
+
aid = data["aid"]
|
|
185
|
+
logger.debug("Got update from accessory with aid: %d", aid)
|
|
186
|
+
accessory = self.accessories[aid]
|
|
187
|
+
service_data = data["services"]
|
|
188
|
+
for service, char_data in service_data.items():
|
|
189
|
+
service_obj = accessory.get_service(service)
|
|
190
|
+
for char, value in char_data.items():
|
|
191
|
+
char_obj = service_obj.get_characteristic(char)
|
|
192
|
+
with self.update_lock:
|
|
193
|
+
char_obj.set_value(value)
|
|
194
|
+
|
|
195
|
+
def stop(self):
|
|
196
|
+
"""Stop the server.
|
|
197
|
+
"""
|
|
198
|
+
super(HttpBridge, self).stop()
|
|
199
|
+
logger.debug("Stopping HTTP bridge server.")
|
|
200
|
+
self.server.shutdown()
|
|
201
|
+
self.server.server_close()
|
|
202
|
+
|
|
203
|
+
def run(self):
|
|
204
|
+
"""Start the server - can listen for requests.
|
|
205
|
+
"""
|
|
206
|
+
logger.debug("Starting HTTP bridge server.")
|
|
207
|
+
self.server_thread.start()
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
usr/local/lib/python3.6/site-packages/pyhap/accessories/__pycache__/MotionSensor.cpython-36.pyc
ADDED
|
Binary file
|
usr/local/lib/python3.6/site-packages/pyhap/accessories/__pycache__/ShutdownSwitch.cpython-36.pyc
ADDED
|
Binary file
|
|
Binary file
|
usr/local/lib/python3.6/site-packages/pyhap/accessories/__pycache__/TemperatureSensor.cpython-36.pyc
ADDED
|
Binary file
|
|
Binary file
|
|
@@ -112,7 +112,8 @@ class Accessory(object):
|
|
|
112
112
|
mac = util.generate_mac()
|
|
113
113
|
return cls(display_name, aid=aid, mac=mac, pincode=pincode)
|
|
114
114
|
|
|
115
|
-
def __init__(self, display_name, aid=
|
|
115
|
+
def __init__(self, display_name, aid=STANDALONE_AID, mac=None, pincode=None,
|
|
116
|
+
iid_manager=None):
|
|
116
117
|
|
|
117
118
|
self.display_name = display_name
|
|
118
119
|
self.aid = aid
|
|
@@ -298,8 +299,13 @@ class Bridge(Accessory):
|
|
|
298
299
|
|
|
299
300
|
category = Category.BRIDGE
|
|
300
301
|
|
|
301
|
-
def __init__(self, display_name,
|
|
302
|
-
|
|
302
|
+
def __init__(self, display_name, mac=None, pincode=None, iid_manager=None):
|
|
303
|
+
aid = STANDALONE_AID
|
|
304
|
+
# A Bridge cannot be Bridge, hence talks directly to HAP clients.
|
|
305
|
+
# Thus, we need a mac.
|
|
306
|
+
mac = mac or util.generate_mac()
|
|
307
|
+
super(Bridge, self).__init__(display_name, aid=aid, mac=mac,
|
|
308
|
+
pincode=pincode, iid_manager=iid_manager)
|
|
303
309
|
self.accessories = {} # aid: acc
|
|
304
310
|
|
|
305
311
|
def _set_services(self):
|
|
File without changes
|
|
File without changes
|
HAP-python-1.0/LICENSE
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
HAP-python-1.0/MANIFEST.in
DELETED
HAP-python-1.0/PKG-INFO
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 1.1
|
|
2
|
-
Name: HAP-python
|
|
3
|
-
Version: 1.0
|
|
4
|
-
Summary: HomeKit Accessory Protocol implementation in python3
|
|
5
|
-
Home-page: https://github.com/ikalchev/HAP-python.git
|
|
6
|
-
Author: Ivan Kalchev
|
|
7
|
-
Author-email: UNKNOWN
|
|
8
|
-
License: Apache-2.0
|
|
9
|
-
Description-Content-Type: UNKNOWN
|
|
10
|
-
Description: UNKNOWN
|
|
11
|
-
Platform: UNKNOWN
|
|
12
|
-
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
-
Classifier: Programming Language :: Python :: 3
|
|
14
|
-
Classifier: Operating System :: OS Independent
|
|
15
|
-
Classifier: Topic :: Home Automation
|
|
16
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
|
18
|
-
Classifier: Intended Audience :: Developers
|
HAP-python-1.0/README.md
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
# HAP-python
|
|
2
|
-
|
|
3
|
-
HomeKit Accessory Protocol implementation in python 3 (tested with 3.4, 3.5 and 3.6).
|
|
4
|
-
With this project, you can integrate your own accessories and add them to your
|
|
5
|
-
iOS Home app. Since Siri is integrated with the Home app, you can start voice-control your
|
|
6
|
-
accessories right away - e.g. "What is the temperature in my bedroom." and "Turn on the
|
|
7
|
-
lights in the Dining Room."
|
|
8
|
-
|
|
9
|
-
The project was developed for a Raspberry Pi, but it should work on other platforms. You
|
|
10
|
-
can even integrate with HAP-python remotely using HTTP (see below). To kick-start things,
|
|
11
|
-
you can open `main.py`, where you can find out how to launch a mock temperature sensor.
|
|
12
|
-
Just run `python3 main.py` and you should see it in the Home app (be sure to be in the same network).
|
|
13
|
-
Stop it by hitting Ctrl+C.
|
|
14
|
-
|
|
15
|
-
There are example accessories in [the accessories folder](pyhap/accessories) (e.g. AM2302 temperature and humidity sensor).
|
|
16
|
-
|
|
17
|
-
## Table of Contents
|
|
18
|
-
1. [API](#API)
|
|
19
|
-
2. [Installation](#Installation)
|
|
20
|
-
3. [Integrating non-compatible devices](#HttpAcc)
|
|
21
|
-
4. [Run at boot (and a Switch to shutdown your device)](#AtBoot)
|
|
22
|
-
5. [Notice](#Notice)
|
|
23
|
-
|
|
24
|
-
## Installation <a name="Installation"></a>
|
|
25
|
-
|
|
26
|
-
As a prerequisite, you will need Avahi/Bonjour installed (due to zeroconf package).
|
|
27
|
-
On a Raspberry Pi, you can get it with:
|
|
28
|
-
```
|
|
29
|
-
sudo apt-get install libavahi-compat-libdnssd-dev
|
|
30
|
-
```
|
|
31
|
-
`avahi-utils` may also fit the bill. Then, to install HAP-python, you will need `setuptools` or `pip3`.
|
|
32
|
-
Just git clone this project and install it like (you will need `sudo` or `--user` for the install):
|
|
33
|
-
|
|
34
|
-
```sh
|
|
35
|
-
git clone https://github.com/ikalchev/HAP-python.git && cd HAP-python
|
|
36
|
-
python3 setup.py install
|
|
37
|
-
```
|
|
38
|
-
or
|
|
39
|
-
```
|
|
40
|
-
pip3 install .
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
This will install HAP-python in your python packages, so that you can import it as `pyhap`.
|
|
44
|
-
Alternatively, you can install only the dependencies and run with the root directory of this project in your `PYTHONPATH`.
|
|
45
|
-
|
|
46
|
-
To uninstall, just do:
|
|
47
|
-
|
|
48
|
-
```
|
|
49
|
-
pip3 uninstall HAP-python
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## API <a name="API"></a>
|
|
53
|
-
|
|
54
|
-
A typical flow for using HAP-python starts with implementing an Accessory. This is done by
|
|
55
|
-
subclassing [Accessory](pyhap/accessory.py) and putting in place a few details
|
|
56
|
-
(see below). After that, you give your accessory to an AccessoryDriver to manage. This
|
|
57
|
-
will take care of advertising it on the local network, setting a HAP server and
|
|
58
|
-
running the Accessory. Take a look at [main.py](main.py) for a quick start on that.
|
|
59
|
-
|
|
60
|
-
```python
|
|
61
|
-
from pyhap.accessory import Accessory, Category
|
|
62
|
-
import pyhap.loader as loader
|
|
63
|
-
|
|
64
|
-
class TemperatureSensor(Accessory):
|
|
65
|
-
"""Implementation of a mock temperature sensor accessory."""
|
|
66
|
-
|
|
67
|
-
category = Category.SENSOR # This is for the icon in the iOS Home app.
|
|
68
|
-
|
|
69
|
-
def __init__(self, *args, **kwargs):
|
|
70
|
-
"""Here, we just store a reference to the current temperature characteristic and
|
|
71
|
-
add a method that will be executed every time its value changes.
|
|
72
|
-
"""
|
|
73
|
-
# If overriding this method, be sure to call the super's implementation first,
|
|
74
|
-
# because it calls _set_services and performs some other important actions.
|
|
75
|
-
super(TemperatureSensor, self).__init__(*args, **kwargs)
|
|
76
|
-
|
|
77
|
-
self.temp_char = self.get_service("TemperatureSensor")\
|
|
78
|
-
.get_characteristic("CurrentTemperature")
|
|
79
|
-
# Having a callback is optional, but you can use it to add functionality.
|
|
80
|
-
self.temp_char.setter_callback = self.temperature_changed
|
|
81
|
-
|
|
82
|
-
def temperature_changed(self, value):
|
|
83
|
-
"""This will be called every time the value of the CurrentTemperature Characteristic
|
|
84
|
-
is changed. Use setter_callbacks to react to user actions, e.g. setting the
|
|
85
|
-
lights On could fire some GPIO code to turn on a LED (see pyhap/accessories/LightBulb.py).
|
|
86
|
-
|
|
87
|
-
NOTE: no need to set the value yourself, this is done for you, before the callback
|
|
88
|
-
is called.
|
|
89
|
-
"""
|
|
90
|
-
print("Temperature changed to: ", value)
|
|
91
|
-
|
|
92
|
-
def _set_services(self):
|
|
93
|
-
"""We override this method to add the services that we want our accessory to
|
|
94
|
-
support. Services have "mandatory" characteristics and optional
|
|
95
|
-
characteristics. Mandatory characteristics are automatically added
|
|
96
|
-
to your selected service, but you must add optional characteristics yourself.
|
|
97
|
-
Take a look at pyhap/accessories/FakeFan.py for an example of how to do that.
|
|
98
|
-
"""
|
|
99
|
-
super(TemperatureSensor, self)._set_services() # Adds some neccessary characteristics.
|
|
100
|
-
# A loader creates Service and Characteristic objects based on json representation
|
|
101
|
-
# such as the Apple-defined ones in pyhap/resources/.
|
|
102
|
-
temp_sensor_service = loader.get_serv_loader().get("TemperatureSensor")
|
|
103
|
-
self.add_service(temp_sensor_service)
|
|
104
|
-
|
|
105
|
-
def run(self):
|
|
106
|
-
"""We override this method to implement what the accessory will do when it is
|
|
107
|
-
started. An accessory is started and stopped from the AccessoryDriver.
|
|
108
|
-
|
|
109
|
-
It might be convenient to use the Accessory's run_sentinel, which is a
|
|
110
|
-
threading.Event object which is set when the accessory should stop running.
|
|
111
|
-
|
|
112
|
-
In this example, we wait 3 seconds to see if the run_sentinel will be set and if
|
|
113
|
-
not, we set the current temperature to a random number.
|
|
114
|
-
"""
|
|
115
|
-
while not self.run_sentinel.wait(3):
|
|
116
|
-
self.temp_char.set_value(random.randint(18, 26))
|
|
117
|
-
|
|
118
|
-
def stop(self):
|
|
119
|
-
"""We override this method to clean up any resources or perform final actions, as
|
|
120
|
-
this is called by the AccessoryDriver when the Accessory is being stopped (it is
|
|
121
|
-
called right after run_sentinel is set).
|
|
122
|
-
"""
|
|
123
|
-
print("Stopping accessory.")
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
## Integrating non-compatible devices <a name="HttpAcc"></a>
|
|
127
|
-
HAP-python may not be available for many IoT devices. For them, HAP-python allows devices
|
|
128
|
-
to be bridged by means of communicating with an HTTP server - the [Http Accessory](pyhap/accessories/Http.py).
|
|
129
|
-
|
|
130
|
-
For example, the bellow snippet creates an Http Accessory that listens on port 51800
|
|
131
|
-
for updates on the TemperatureSensor service:
|
|
132
|
-
```python
|
|
133
|
-
import pyhap.util as util
|
|
134
|
-
from pyhap.accessories.Http import Http
|
|
135
|
-
from pyhap.accessory import STANDALONE_AID
|
|
136
|
-
from pyhap.accessory_driver import AccessoryDriver
|
|
137
|
-
|
|
138
|
-
http = Http(("", 51800), ["TemperatureSensor"], "HTTP bridge",
|
|
139
|
-
aid=STANDALONE_AID, mac=util.generate_mac(), pincode=b"203-23-999")
|
|
140
|
-
driver = AccessoryDriver(http, 51826)
|
|
141
|
-
driver.start()
|
|
142
|
-
```
|
|
143
|
-
Now, remote accessories can do an HTTP POST to the address of the device where the
|
|
144
|
-
accessory is running (port 51800) with the following content:
|
|
145
|
-
```json
|
|
146
|
-
{ "TemperatureSensor" : {
|
|
147
|
-
"CurrentTemperature" : 20 }
|
|
148
|
-
}
|
|
149
|
-
```
|
|
150
|
-
This will update the value of the characteristic "CurrentTemperature" to 20 degrees C.
|
|
151
|
-
Needless to say the communication to the Http Accessory poses a security risk, so
|
|
152
|
-
keep that in mind.
|
|
153
|
-
|
|
154
|
-
## Run at boot <a name="AtBoot"></a>
|
|
155
|
-
This is a quick way to get `HAP-python` to run at boot on a Raspberry Pi. It is recommended
|
|
156
|
-
to turn on "Wait for network" in `raspi-config`. If this turns to be unreliable, see
|
|
157
|
-
[this](https://www.raspberrypi.org/forums/viewtopic.php?f=66&t=187225).
|
|
158
|
-
|
|
159
|
-
Copy the below in `/etc/systemd/system/HAP-python.service` (needs sudo).
|
|
160
|
-
```
|
|
161
|
-
[Unit]
|
|
162
|
-
Description = HAP-python daemon
|
|
163
|
-
Wants = pigpiod.service # Remove this if you don't depend on pigpiod
|
|
164
|
-
After = local-fs.target network-online.target pigpiod.service
|
|
165
|
-
|
|
166
|
-
[Service]
|
|
167
|
-
User = lesserdaemon # It's a good idea to use some unprivileged system user
|
|
168
|
-
# Script starting HAP-python, e.g. main.py
|
|
169
|
-
# Be careful to set any paths you use, e.g. for persisting the state.
|
|
170
|
-
ExecStart = /usr/bin/python3 /home/lesserdaemon/.hap-python/hap-python.py
|
|
171
|
-
|
|
172
|
-
[Install]
|
|
173
|
-
WantedBy = multi-user.target
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
Test that everything is fine by doing:
|
|
177
|
-
|
|
178
|
-
```sh
|
|
179
|
-
> sudo systemctl start HAP-python
|
|
180
|
-
> systemctl status HAP-python
|
|
181
|
-
> sudo journalctl -u HAP-python # to see the output of the start up script.
|
|
182
|
-
> sudo systemctl stop HAP-python
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
To enable or disable at boot, do:
|
|
186
|
-
|
|
187
|
-
```sh
|
|
188
|
-
> sudo systemctl enable HAP-python
|
|
189
|
-
> sudo systemctl disable HAP-python
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
### Shutdown switch
|
|
193
|
-
|
|
194
|
-
If you are running `HAP-python` on a Raspberry Pi, you may want to add a
|
|
195
|
-
[Shutdown Switch](pyhap/accessories/ShutdownSwitch.py) to your Home. This is a
|
|
196
|
-
Switch Accessory, which, when triggered, executes `sudo shutdown -h now`, i.e.
|
|
197
|
-
it shutdowns and halts the Pi. This allows you to safely unplug it.
|
|
198
|
-
|
|
199
|
-
For the above to work, you need to enable passwordless `/sbin/shutdown` to whichever
|
|
200
|
-
user is running `HAP-python`. For example, do:
|
|
201
|
-
```sh
|
|
202
|
-
$ sudo visudo # and add the line: "<hap-user> ALL=NOPASSWD: /sbin/shutdown".
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
## Notice <a name="Notice"></a>
|
|
206
|
-
|
|
207
|
-
Some HAP know-how was taken from [HAP-NodeJS by KhaosT](https://github.com/KhaosT/HAP-NodeJS).
|
|
208
|
-
|
|
209
|
-
I am not aware of any bugs, but I am more than confident that such exist. If you find any,
|
|
210
|
-
please report and I will try to fix them.
|
|
211
|
-
|
|
212
|
-
Suggestions are always welcome.
|
|
213
|
-
|
|
214
|
-
Have fun!
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"""An accessory that listens to HTTP requests containing characteristic updates.
|
|
2
|
-
|
|
3
|
-
A more simple device/implementation can just HTTP POST data as:
|
|
4
|
-
{ <service_name>: {
|
|
5
|
-
<characteristic_name>: value
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
Then this accessory takes care of communicating this update to any HAP clients.
|
|
9
|
-
"""
|
|
10
|
-
import json
|
|
11
|
-
import threading
|
|
12
|
-
import logging
|
|
13
|
-
from http.server import HTTPServer, BaseHTTPRequestHandler
|
|
14
|
-
|
|
15
|
-
from pyhap.accessory import Accessory, Category
|
|
16
|
-
import pyhap.loader as loader
|
|
17
|
-
|
|
18
|
-
logger = logging.getLogger(__name__)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class HapHttpHandler(BaseHTTPRequestHandler):
|
|
22
|
-
"""
|
|
23
|
-
Handles POST requests and passes characteristic value updates to an HttpAccessory.
|
|
24
|
-
|
|
25
|
-
The POST request should contain json data with the format:
|
|
26
|
-
{ <service_name>: {
|
|
27
|
-
<characteristic_name>: value,
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
Example:
|
|
32
|
-
{ "TemperatureSensor" : {
|
|
33
|
-
"CurrentTemperature": 20
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
"""
|
|
37
|
-
|
|
38
|
-
def __init__(self, httpAccessory, sock, client_addr, server):
|
|
39
|
-
"""
|
|
40
|
-
Creates a handler that passes updates to the given HttpAccessory.
|
|
41
|
-
"""
|
|
42
|
-
self.httpAccessory = httpAccessory
|
|
43
|
-
super(HapHttpHandler, self).__init__(sock, client_addr, server)
|
|
44
|
-
|
|
45
|
-
def respond_ok(self):
|
|
46
|
-
self.send_response(200)
|
|
47
|
-
self.send_header("Content-Type", "text/html")
|
|
48
|
-
self.send_header("Content-Length", 0)
|
|
49
|
-
self.end_headers()
|
|
50
|
-
self.close_connection = 1
|
|
51
|
-
|
|
52
|
-
def respond_err(self):
|
|
53
|
-
self.send_response(400)
|
|
54
|
-
self.send_header("Content-Type", "text/html")
|
|
55
|
-
self.send_header("Content-Length", 0)
|
|
56
|
-
self.end_headers()
|
|
57
|
-
self.close_connection = 1
|
|
58
|
-
|
|
59
|
-
def do_POST(self):
|
|
60
|
-
"""
|
|
61
|
-
Read the payload as json and update the state of the httpAccessory.
|
|
62
|
-
"""
|
|
63
|
-
length = int(self.headers["Content-Length"])
|
|
64
|
-
try:
|
|
65
|
-
# The below decode is necessary only for python <3.6, because loads prior 3.6
|
|
66
|
-
# doesn't know bytes/bytearray.
|
|
67
|
-
content = self.rfile.read(length).decode("utf-8")
|
|
68
|
-
data = json.loads(content)
|
|
69
|
-
except Exception as e:
|
|
70
|
-
logger.error("Bad POST request; Error was: %s", str(e))
|
|
71
|
-
self.respond_err()
|
|
72
|
-
else:
|
|
73
|
-
self.httpAccessory.update_state(data)
|
|
74
|
-
self.respond_ok()
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
'''TODO: should make it possible to init with {"aid" : [services]}
|
|
78
|
-
or {"addr": [services]} etc., so that this accessory can bridge several
|
|
79
|
-
other. In this way remote devices can use a simple interface and this module will do
|
|
80
|
-
the hap magic.
|
|
81
|
-
'''
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
class Http(Accessory):
|
|
85
|
-
|
|
86
|
-
category = Category.OTHER
|
|
87
|
-
|
|
88
|
-
def __init__(self, address, hapServices, *args, **kwargs):
|
|
89
|
-
self.hapServices = hapServices
|
|
90
|
-
super(Http, self).__init__(*args, **kwargs)
|
|
91
|
-
self._set_server(address)
|
|
92
|
-
|
|
93
|
-
def _set_server(self, address):
|
|
94
|
-
self.server = HTTPServer(address, lambda *a: HapHttpHandler(self, *a))
|
|
95
|
-
self.serverThread = threading.Thread(target=self.server.serve_forever)
|
|
96
|
-
|
|
97
|
-
def _set_services(self):
|
|
98
|
-
super(Http, self)._set_services()
|
|
99
|
-
ldr = loader.get_serv_loader()
|
|
100
|
-
for s in self.hapServices:
|
|
101
|
-
self.add_service(ldr.get(s))
|
|
102
|
-
|
|
103
|
-
def __getstate__(self):
|
|
104
|
-
state = super(Http, self).__getstate__()
|
|
105
|
-
state["server"] = None
|
|
106
|
-
state["serverThread"] = None
|
|
107
|
-
state["address"] = self.server.server_address
|
|
108
|
-
return state
|
|
109
|
-
|
|
110
|
-
def __setstate__(self, state):
|
|
111
|
-
self.__dict__.update(state)
|
|
112
|
-
self._set_server(state["address"])
|
|
113
|
-
|
|
114
|
-
def update_state(self, data):
|
|
115
|
-
for service, charData in data.items():
|
|
116
|
-
serviceObj = self.get_service(service)
|
|
117
|
-
for char, value in charData.items():
|
|
118
|
-
charObj = serviceObj.get_characteristic(char)
|
|
119
|
-
charObj.set_value(value)
|
|
120
|
-
|
|
121
|
-
def stop(self):
|
|
122
|
-
super(Http, self).stop()
|
|
123
|
-
self.server.shutdown()
|
|
124
|
-
self.server.server_close()
|
|
125
|
-
|
|
126
|
-
def run(self):
|
|
127
|
-
self.serverThread.start()
|
HAP-python-1.0/setup.cfg
DELETED
HAP-python-1.0/setup.py
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
from setuptools import setup
|
|
2
|
-
|
|
3
|
-
setup(
|
|
4
|
-
name="HAP-python",
|
|
5
|
-
description="HomeKit Accessory Protocol implementation in python3",
|
|
6
|
-
author="Ivan Kalchev",
|
|
7
|
-
version="1.0",
|
|
8
|
-
url="https://github.com/ikalchev/HAP-python.git",
|
|
9
|
-
classifiers=[
|
|
10
|
-
"Development Status :: 5 - Production/Stable",
|
|
11
|
-
"Programming Language :: Python :: 3",
|
|
12
|
-
"Operating System :: OS Independent",
|
|
13
|
-
"Topic :: Home Automation",
|
|
14
|
-
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
15
|
-
"License :: OSI Approved :: Apache Software License",
|
|
16
|
-
"Intended Audience :: Developers",
|
|
17
|
-
],
|
|
18
|
-
license="Apache-2.0",
|
|
19
|
-
packages=[
|
|
20
|
-
"pyhap",
|
|
21
|
-
"pyhap.accessories"
|
|
22
|
-
],
|
|
23
|
-
install_requires=[
|
|
24
|
-
"pycryptodome",
|
|
25
|
-
"tlslite-ng",
|
|
26
|
-
"ed25519",
|
|
27
|
-
"zeroconf",
|
|
28
|
-
"curve25519-donna"
|
|
29
|
-
],
|
|
30
|
-
package_data={
|
|
31
|
-
"pyhap": ["resources/*"],
|
|
32
|
-
}
|
|
33
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{HAP-python-1.0 → usr/local/lib/python3.6/site-packages}/pyhap/accessories/ShutdownSwitch.py
RENAMED
|
File without changes
|
|
File without changes
|
{HAP-python-1.0 → usr/local/lib/python3.6/site-packages}/pyhap/accessories/TemperatureSensor.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{HAP-python-1.0 → usr/local/lib/python3.6/site-packages}/pyhap/resources/characteristics.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|