HAP-python 1.0.5__tar.gz → 1.0.6__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.

Potentially problematic release.


This version of HAP-python might be problematic. Click here for more details.

Files changed (55) hide show
  1. {usr/local/lib/python3.6/site-packages/HAP_python-1.0.5-py3.6.egg-info → HAP-python-1.0.6/HAP_python.egg-info}/PKG-INFO +1 -1
  2. HAP-python-1.0.6/LICENSE +176 -0
  3. HAP-python-1.0.6/MANIFEST.in +2 -0
  4. HAP-python-1.0.6/PKG-INFO +18 -0
  5. HAP-python-1.0.6/README.md +230 -0
  6. {usr/local/lib/python3.6/site-packages → HAP-python-1.0.6}/pyhap/accessory.py +16 -1
  7. {usr/local/lib/python3.6/site-packages → HAP-python-1.0.6}/pyhap/accessory_driver.py +16 -1
  8. {usr/local/lib/python3.6/site-packages → HAP-python-1.0.6}/pyhap/hap_server.py +0 -0
  9. HAP-python-1.0.6/setup.cfg +10 -0
  10. HAP-python-1.0.6/setup.py +33 -0
  11. usr/local/lib/python3.6/site-packages/pyhap/__pycache__/__init__.cpython-36.pyc +0 -0
  12. usr/local/lib/python3.6/site-packages/pyhap/__pycache__/accessory.cpython-36.pyc +0 -0
  13. usr/local/lib/python3.6/site-packages/pyhap/__pycache__/accessory_driver.cpython-36.pyc +0 -0
  14. usr/local/lib/python3.6/site-packages/pyhap/__pycache__/characteristic.cpython-36.pyc +0 -0
  15. usr/local/lib/python3.6/site-packages/pyhap/__pycache__/hap_server.cpython-36.pyc +0 -0
  16. usr/local/lib/python3.6/site-packages/pyhap/__pycache__/hsrp.cpython-36.pyc +0 -0
  17. usr/local/lib/python3.6/site-packages/pyhap/__pycache__/loader.cpython-36.pyc +0 -0
  18. usr/local/lib/python3.6/site-packages/pyhap/__pycache__/params.cpython-36.pyc +0 -0
  19. usr/local/lib/python3.6/site-packages/pyhap/__pycache__/service.cpython-36.pyc +0 -0
  20. usr/local/lib/python3.6/site-packages/pyhap/__pycache__/tlv.cpython-36.pyc +0 -0
  21. usr/local/lib/python3.6/site-packages/pyhap/__pycache__/util.cpython-36.pyc +0 -0
  22. usr/local/lib/python3.6/site-packages/pyhap/accessories/__pycache__/AM2302.cpython-36.pyc +0 -0
  23. usr/local/lib/python3.6/site-packages/pyhap/accessories/__pycache__/BMP180.cpython-36.pyc +0 -0
  24. usr/local/lib/python3.6/site-packages/pyhap/accessories/__pycache__/FakeFan.cpython-36.pyc +0 -0
  25. usr/local/lib/python3.6/site-packages/pyhap/accessories/__pycache__/Http.cpython-36.pyc +0 -0
  26. usr/local/lib/python3.6/site-packages/pyhap/accessories/__pycache__/LightBulb.cpython-36.pyc +0 -0
  27. usr/local/lib/python3.6/site-packages/pyhap/accessories/__pycache__/MotionSensor.cpython-36.pyc +0 -0
  28. usr/local/lib/python3.6/site-packages/pyhap/accessories/__pycache__/ShutdownSwitch.cpython-36.pyc +0 -0
  29. usr/local/lib/python3.6/site-packages/pyhap/accessories/__pycache__/TSL2591.cpython-36.pyc +0 -0
  30. usr/local/lib/python3.6/site-packages/pyhap/accessories/__pycache__/TemperatureSensor.cpython-36.pyc +0 -0
  31. usr/local/lib/python3.6/site-packages/pyhap/accessories/__pycache__/__init__.cpython-36.pyc +0 -0
  32. {usr/local/lib/python3.6/site-packages/HAP_python-1.0.5-py3.6.egg-info → HAP-python-1.0.6/HAP_python.egg-info}/SOURCES.txt +0 -0
  33. {usr/local/lib/python3.6/site-packages/HAP_python-1.0.5-py3.6.egg-info → HAP-python-1.0.6/HAP_python.egg-info}/dependency_links.txt +0 -0
  34. {usr/local/lib/python3.6/site-packages/HAP_python-1.0.5-py3.6.egg-info → HAP-python-1.0.6/HAP_python.egg-info}/requires.txt +0 -0
  35. {usr/local/lib/python3.6/site-packages/HAP_python-1.0.5-py3.6.egg-info → HAP-python-1.0.6/HAP_python.egg-info}/top_level.txt +0 -0
  36. {usr/local/lib/python3.6/site-packages → HAP-python-1.0.6}/pyhap/__init__.py +0 -0
  37. {usr/local/lib/python3.6/site-packages → HAP-python-1.0.6}/pyhap/accessories/AM2302.py +0 -0
  38. {usr/local/lib/python3.6/site-packages → HAP-python-1.0.6}/pyhap/accessories/BMP180.py +0 -0
  39. {usr/local/lib/python3.6/site-packages → HAP-python-1.0.6}/pyhap/accessories/FakeFan.py +0 -0
  40. {usr/local/lib/python3.6/site-packages → HAP-python-1.0.6}/pyhap/accessories/Http.py +0 -0
  41. {usr/local/lib/python3.6/site-packages → HAP-python-1.0.6}/pyhap/accessories/LightBulb.py +0 -0
  42. {usr/local/lib/python3.6/site-packages → HAP-python-1.0.6}/pyhap/accessories/MotionSensor.py +0 -0
  43. {usr/local/lib/python3.6/site-packages → HAP-python-1.0.6}/pyhap/accessories/ShutdownSwitch.py +0 -0
  44. {usr/local/lib/python3.6/site-packages → HAP-python-1.0.6}/pyhap/accessories/TSL2591.py +0 -0
  45. {usr/local/lib/python3.6/site-packages → HAP-python-1.0.6}/pyhap/accessories/TemperatureSensor.py +0 -0
  46. {usr/local/lib/python3.6/site-packages → HAP-python-1.0.6}/pyhap/accessories/__init__.py +0 -0
  47. {usr/local/lib/python3.6/site-packages → HAP-python-1.0.6}/pyhap/characteristic.py +0 -0
  48. {usr/local/lib/python3.6/site-packages → HAP-python-1.0.6}/pyhap/hsrp.py +0 -0
  49. {usr/local/lib/python3.6/site-packages → HAP-python-1.0.6}/pyhap/loader.py +0 -0
  50. {usr/local/lib/python3.6/site-packages → HAP-python-1.0.6}/pyhap/params.py +0 -0
  51. {usr/local/lib/python3.6/site-packages → HAP-python-1.0.6}/pyhap/resources/characteristics.json +0 -0
  52. {usr/local/lib/python3.6/site-packages → HAP-python-1.0.6}/pyhap/resources/services.json +0 -0
  53. {usr/local/lib/python3.6/site-packages → HAP-python-1.0.6}/pyhap/service.py +0 -0
  54. {usr/local/lib/python3.6/site-packages → HAP-python-1.0.6}/pyhap/tlv.py +0 -0
  55. {usr/local/lib/python3.6/site-packages → HAP-python-1.0.6}/pyhap/util.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.1
2
2
  Name: HAP-python
3
- Version: 1.0.5
3
+ Version: 1.0.6
4
4
  Summary: HomeKit Accessory Protocol implementation in python3
5
5
  Home-page: https://github.com/ikalchev/HAP-python.git
6
6
  Author: Ivan Kalchev
@@ -0,0 +1,176 @@
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
@@ -0,0 +1,2 @@
1
+ include LICENSE
2
+ recursive-include pyhap/resources *
@@ -0,0 +1,18 @@
1
+ Metadata-Version: 1.1
2
+ Name: HAP-python
3
+ Version: 1.0.6
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
@@ -0,0 +1,230 @@
1
+ [![PyPI version](https://badge.fury.io/py/HAP-python.svg)](https://badge.fury.io/py/HAP-python)
2
+ # HAP-python
3
+
4
+ HomeKit Accessory Protocol implementation in python 3 (tested with 3.4, 3.5 and 3.6).
5
+ With this project, you can integrate your own accessories and add them to your
6
+ iOS Home app. Since Siri is integrated with the Home app, you can start voice-control your
7
+ accessories right away - e.g. "What is the temperature in my bedroom." and "Turn on the
8
+ lights in the Dining Room."
9
+
10
+ The project was developed for a Raspberry Pi, but it should work on other platforms. You
11
+ can even integrate with HAP-python remotely using HTTP (see below). To kick-start things,
12
+ you can open `main.py`, where you can find out how to launch a mock temperature sensor.
13
+ Just run `python3 main.py` and you should see it in the Home app (be sure to be in the same network).
14
+ Stop it by hitting Ctrl+C.
15
+
16
+ There are example accessories in [the accessories folder](pyhap/accessories) (e.g. AM2302 temperature and humidity sensor).
17
+
18
+ ## Table of Contents
19
+ 1. [API](#API)
20
+ 2. [Installation](#Installation)
21
+ 3. [Integrating non-compatible devices](#HttpAcc)
22
+ 4. [Run at boot (and a Switch to shutdown your device)](#AtBoot)
23
+ 5. [Notice](#Notice)
24
+
25
+ ## Installation <a name="Installation"></a>
26
+
27
+ As a prerequisite, you will need Avahi/Bonjour installed (due to zeroconf package).
28
+ On a Raspberry Pi, you can get it with:
29
+ ```
30
+ sudo apt-get install libavahi-compat-libdnssd-dev
31
+ ```
32
+ `avahi-utils` may also fit the bill. Then, you can install with `pip3` (you will need `sudo` or `--user` for the install):
33
+ ```sh
34
+ pip3 install HAP-python
35
+ ```
36
+
37
+ This will install HAP-python in your python packages, so that you can import it as `pyhap`. To uninstall, just do:
38
+ ```
39
+ pip3 uninstall HAP-python
40
+ ```
41
+
42
+ ## API <a name="API"></a>
43
+
44
+ A typical flow for using HAP-python starts with implementing an Accessory. This is done by
45
+ subclassing [Accessory](pyhap/accessory.py) and putting in place a few details
46
+ (see below). After that, you give your accessory to an AccessoryDriver to manage. This
47
+ will take care of advertising it on the local network, setting a HAP server and
48
+ running the Accessory. Take a look at [main.py](main.py) for a quick start on that.
49
+
50
+ ```python
51
+ from pyhap.accessory import Accessory, Category
52
+ import pyhap.loader as loader
53
+
54
+ class TemperatureSensor(Accessory):
55
+ """Implementation of a mock temperature sensor accessory."""
56
+
57
+ category = Category.SENSOR # This is for the icon in the iOS Home app.
58
+
59
+ def __init__(self, *args, **kwargs):
60
+ """Here, we just store a reference to the current temperature characteristic and
61
+ add a method that will be executed every time its value changes.
62
+ """
63
+ # If overriding this method, be sure to call the super's implementation first,
64
+ # because it calls _set_services and performs some other important actions.
65
+ super(TemperatureSensor, self).__init__(*args, **kwargs)
66
+
67
+ self.temp_char = self.get_service("TemperatureSensor")\
68
+ .get_characteristic("CurrentTemperature")
69
+ # Having a callback is optional, but you can use it to add functionality.
70
+ self.temp_char.setter_callback = self.temperature_changed
71
+
72
+ def temperature_changed(self, value):
73
+ """This will be called every time the value of the CurrentTemperature Characteristic
74
+ is changed. Use setter_callbacks to react to user actions, e.g. setting the
75
+ lights On could fire some GPIO code to turn on a LED (see pyhap/accessories/LightBulb.py).
76
+
77
+ NOTE: no need to set the value yourself, this is done for you, before the callback
78
+ is called.
79
+ """
80
+ print("Temperature changed to: ", value)
81
+
82
+ def _set_services(self):
83
+ """We override this method to add the services that we want our accessory to
84
+ support. Services have "mandatory" characteristics and optional
85
+ characteristics. Mandatory characteristics are automatically added
86
+ to your selected service, but you must add optional characteristics yourself.
87
+ Take a look at pyhap/accessories/FakeFan.py for an example of how to do that.
88
+ """
89
+ super(TemperatureSensor, self)._set_services() # Adds some neccessary characteristics.
90
+ # A loader creates Service and Characteristic objects based on json representation
91
+ # such as the Apple-defined ones in pyhap/resources/.
92
+ temp_sensor_service = loader.get_serv_loader().get("TemperatureSensor")
93
+ self.add_service(temp_sensor_service)
94
+
95
+ def run(self):
96
+ """We override this method to implement what the accessory will do when it is
97
+ started. An accessory is started and stopped from the AccessoryDriver.
98
+
99
+ It might be convenient to use the Accessory's run_sentinel, which is a
100
+ threading.Event object which is set when the accessory should stop running.
101
+
102
+ In this example, we wait 3 seconds to see if the run_sentinel will be set and if
103
+ not, we set the current temperature to a random number.
104
+ """
105
+ while not self.run_sentinel.wait(3):
106
+ self.temp_char.set_value(random.randint(18, 26))
107
+
108
+ def stop(self):
109
+ """We override this method to clean up any resources or perform final actions, as
110
+ this is called by the AccessoryDriver when the Accessory is being stopped (it is
111
+ called right after run_sentinel is set).
112
+ """
113
+ print("Stopping accessory.")
114
+ ```
115
+
116
+ ## Integrating non-compatible devices <a name="HttpAcc"></a>
117
+ HAP-python may not be available for many IoT devices. For them, HAP-python allows devices
118
+ to be bridged by means of communicating with an HTTP server - the [HttpBridge](pyhap/accessories/Http.py). You can add as many remote accessories as you like.
119
+
120
+ For example, the bellow snippet creates an Http Accessory that listens on port 51800
121
+ for updates on the TemperatureSensor service:
122
+ ```python
123
+ import pyhap.util as util
124
+ import pyhap.loader as loader
125
+ from pyhap.accessories.Http import HttpBridge
126
+ from pyhap.accessory import Accessory
127
+ from pyhap.accessory_driver import AccessoryDriver
128
+
129
+ # get loaders
130
+ service_loader = loader.get_serv_loader()
131
+ char_loader = loader.get_char_loader()
132
+
133
+ # Create an accessory with the temperature sensor service.
134
+ # Also, add an optional characteristic StatusLowBattery to that service.
135
+ remote_accessory = Accessory("foo", aid=2) # aids must be unique for each accessory.
136
+ tservice = service_loader.get("TemperatureSensor")
137
+ tservice.add_opt_characteristic(
138
+ char_loader.get("StatusLowBattery"))
139
+ remote_accessory.add_service(tservice)
140
+
141
+ # Create the HTTP Bridge and add the accessory to it.
142
+ address = ("", 51111)
143
+ http_bridge = HttpBridge(address=address,
144
+ display_name="HTTP Bridge",
145
+ pincode=b"203-23-999")
146
+ http_bridge.add_accessory(remote_accessory)
147
+
148
+ # Add to driver and run.
149
+ driver = AccessoryDriver(http_bridge, 51826)
150
+ driver.start()
151
+ ```
152
+ Now, remote accessories can do an HTTP POST to the address of the device where the
153
+ accessory is running (port 51111) with the following content:
154
+ ```json
155
+ {
156
+ "aid": 2,
157
+ "services": {
158
+ "TemperatureSensor": {
159
+ "CurrentTemperature" : 20,
160
+ "StatusLowBattery": true,
161
+ }
162
+ }
163
+ }
164
+ ```
165
+ This will update the value of the characteristic "CurrentTemperature" to 20 degrees C
166
+ and "StatusLowBattery" to `true`.
167
+ Needless to say the communication to the Http Bridge poses a security risk, so
168
+ keep that in mind.
169
+
170
+ ## Run at boot <a name="AtBoot"></a>
171
+ This is a quick way to get `HAP-python` to run at boot on a Raspberry Pi. It is recommended
172
+ to turn on "Wait for network" in `raspi-config`. If this turns to be unreliable, see
173
+ [this](https://www.raspberrypi.org/forums/viewtopic.php?f=66&t=187225).
174
+
175
+ Copy the below in `/etc/systemd/system/HAP-python.service` (needs sudo).
176
+ ```
177
+ [Unit]
178
+ Description = HAP-python daemon
179
+ Wants = pigpiod.service # Remove this if you don't depend on pigpiod
180
+ After = local-fs.target network-online.target pigpiod.service
181
+
182
+ [Service]
183
+ User = lesserdaemon # It's a good idea to use some unprivileged system user
184
+ # Script starting HAP-python, e.g. main.py
185
+ # Be careful to set any paths you use, e.g. for persisting the state.
186
+ ExecStart = /usr/bin/python3 /home/lesserdaemon/.hap-python/hap-python.py
187
+
188
+ [Install]
189
+ WantedBy = multi-user.target
190
+ ```
191
+
192
+ Test that everything is fine by doing:
193
+
194
+ ```sh
195
+ > sudo systemctl start HAP-python
196
+ > systemctl status HAP-python
197
+ > sudo journalctl -u HAP-python # to see the output of the start up script.
198
+ > sudo systemctl stop HAP-python
199
+ ```
200
+
201
+ To enable or disable at boot, do:
202
+
203
+ ```sh
204
+ > sudo systemctl enable HAP-python
205
+ > sudo systemctl disable HAP-python
206
+ ```
207
+
208
+ ### Shutdown switch
209
+
210
+ If you are running `HAP-python` on a Raspberry Pi, you may want to add a
211
+ [Shutdown Switch](pyhap/accessories/ShutdownSwitch.py) to your Home. This is a
212
+ Switch Accessory, which, when triggered, executes `sudo shutdown -h now`, i.e.
213
+ it shutdowns and halts the Pi. This allows you to safely unplug it.
214
+
215
+ For the above to work, you need to enable passwordless `/sbin/shutdown` to whichever
216
+ user is running `HAP-python`. For example, do:
217
+ ```sh
218
+ $ sudo visudo # and add the line: "<hap-user> ALL=NOPASSWD: /sbin/shutdown".
219
+ ```
220
+
221
+ ## Notice <a name="Notice"></a>
222
+
223
+ Some HAP know-how was taken from [HAP-NodeJS by KhaosT](https://github.com/KhaosT/HAP-NodeJS).
224
+
225
+ I am not aware of any bugs, but I am more than confident that such exist. If you find any,
226
+ please report and I will try to fix them.
227
+
228
+ Suggestions are always welcome.
229
+
230
+ Have fun!
@@ -146,7 +146,6 @@ class Accessory(object):
146
146
  The default implementation adds only the AccessoryInformation services
147
147
  and sets its Name characteristic to the Accessory's display name.
148
148
  """
149
- # Info service
150
149
  info_service = get_serv_loader().get("AccessoryInformation")
151
150
  info_service.get_characteristic("Name")\
152
151
  .set_value(self.display_name, False)
@@ -172,6 +171,22 @@ class Accessory(object):
172
171
  """
173
172
  self.run_sentinel = run_sentinel
174
173
 
174
+ def config_changed(self):
175
+ """Notify the accessory about configuration changes.
176
+
177
+ These include new services or updated characteristic values, e.g.
178
+ the Name of a service changed.
179
+
180
+ This method also notifies the broker about the change, so that it can
181
+ publish the changes to the world.
182
+
183
+ @note: If you are changing the configuration of a bridged accessory
184
+ (i.e. an Accessory that is contained in a Bridge),
185
+ you should call the `config_changed` method on the Bridge.
186
+ """
187
+ self.config_version += 1
188
+ self.broker.config_changed()
189
+
175
190
  def add_service(self, *servs):
176
191
  """Add the given services to this Accessory.
177
192
 
@@ -12,7 +12,8 @@ AccessoryDriver (all this happens through the publish() interface). The Accessor
12
12
  will then check if there is a client that subscribed for events from this exact
13
13
  Characteristic from this exact Accessory (remember, it could be a Bridge with more than
14
14
  one Accessory in it). If so, the event is put in a FIFO queue - the event queue. This
15
- terminates the call chain and concludes the publishing process from the Characteristic.
15
+ terminates the call chain and concludes the publishing process from the Characteristic,
16
+ the Characteristic does not block waiting for the actual send to happen.
16
17
 
17
18
  When the AccessoryDriver is started, it spawns an event dispatch thread. The purpose of
18
19
  this thread is to get events from the event queue and send them to subscribed clients.
@@ -217,6 +218,16 @@ class AccessoryDriver(object):
217
218
  self.sent_events = 0
218
219
  self.accumulated_qsize = 0
219
220
 
221
+ def config_changed(self):
222
+ """Notify the driver that the accessory's configuration has changed.
223
+
224
+ Updates the mDNS advertisment, so that iOS clients know they need to new data.
225
+ Also, persists the accessory, so that the new configuration is available on
226
+ restart.
227
+ """
228
+ self.update_advertisment()
229
+ self.persist()
230
+
220
231
  def update_advertisment(self):
221
232
  """Updates the mDNS service info for the accessory."""
222
233
  self.advertiser.unregister_service(self.mdns_service_info)
@@ -434,6 +445,10 @@ class AccessoryDriver(object):
434
445
  self.http_server.shutdown()
435
446
  self.http_server.server_close()
436
447
  self.http_server_thread.join()
448
+
449
+ logger.debug("Persisting accessory state")
450
+ self.persist()
451
+
437
452
  logger.debug("AccessoryDriver stopped successfully")
438
453
 
439
454
  def signal_handler(self, _signal, _frame):
@@ -0,0 +1,10 @@
1
+ [metadata]
2
+ description-file = README.md
3
+
4
+ [pycodestyle]
5
+ max-line-length = 90
6
+
7
+ [egg_info]
8
+ tag_build =
9
+ tag_date = 0
10
+
@@ -0,0 +1,33 @@
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.6",
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
+ )