Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 626092f

Browse files
committed
Merge branch 'dev' into v2.2.0
2 parents d30a72a + 90e3a37 commit 626092f

31 files changed

+632
-482
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ lib64
2828
pyvenv.cfg
2929
share
3030

31+
# pip
32+
pip-selfcheck.json
33+
3134
# HAP-python-generated files
3235
accessory.pickle
3336
accessory.state

AUTHORS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cdce8p
2+
jslay88
3+
Ivan Kalchev <ikalchev> - Maintainer of the library
4+
Lee Marlow <lmarlow>
5+
Matthew Schinckel <schinckel>
6+
Miroslav Kudrnac <mkudrnac>

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,34 @@ Sections
1010
### Added
1111
### Changed
1212
### Deprecated
13+
### Removed
1314
### Fixed
1415
### Breaking Changes
1516
### Developers
1617
-->
1718

19+
## [2.2.0] - 2018-05-26
20+
21+
### Added
22+
- Option to pass custom loader object to `driver` with parameter `loader`. [#105](https://github.com/ikalchev/HAP-python/pull/105)
23+
- Default port for `accessory_driver.port = 51234`. [#105](https://github.com/ikalchev/HAP-python/pull/105)
24+
25+
### Changed
26+
- The `loader` object is now stored in the `driver` and can be accessed through `driver.loader`. [#105](https://github.com/ikalchev/HAP-python/pull/105)
27+
- Use the `Accessory.run_at_interval` decorator for the `run` method, instead of `while True: sleep(x); do_stuff()`. [#124](https://github.com/ikalchev/HAP-python/pull/124)
28+
29+
### Breaking Changes
30+
- The `driver` doesn't take the top `accessory` anymore. Instead it's added through `driver.add_accessory()` after the initialization. [#105](https://github.com/ikalchev/HAP-python/pull/105)
31+
- All `driver` init parameter are now required to be passed as keywords. [#105](https://github.com/ikalchev/HAP-python/pull/105)
32+
- Any `accessory` needs the `driver` object for its initialization, passed as first argument. [#105](https://github.com/ikalchev/HAP-python/pull/105)
33+
- Removed class `AsyncAccessory`. All of its methods are now fully integrated into the `Accessory` class. `run`, `stop` can be either normal or async methods and `run_at_interval` works with both as well. [#124](https://github.com/ikalchev/HAP-python/pull/124)
34+
35+
### Developers
36+
- Removed `acc.set_driver()` and `acc.set_sentinel()` methods. `acc.run_sentinel`, `acc.aio_stop_event` and `acc.loop` are now accessed through `acc.driver.xxx`. `run_sentinel` is changed to `stop_event`. [#105](https://github.com/ikalchev/HAP-python/pull/105)
37+
- Added scripts for `setup` and `release`. [#125](https://github.com/ikalchev/HAP-python/pull/125)
38+
- Added `async` helper methods and restructured `start` and `stop` methods for `async` conversion. [#124](https://github.com/ikalchev/HAP-python/pull/124)
39+
40+
1841

1942
## [2.1.0] - 2018-05-18
2043

LICENSE

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,75 @@
1+
HAP-python is licensed under the Apache License, version 2.0.
2+
3+
This package/repository contains code from the HAP-python project as well as
4+
some open-source works.
5+
6+
File Copyrights
7+
===============
8+
9+
All fines not explicitly mentioned below
10+
What: HAP-python
11+
Source URL: https://github.com/ikalchev/HAP-python
12+
Copyright: HAP-python Authors (see AUTHORS file)
13+
License: Apache License 2.0
14+
License text: See below
15+
16+
pyhap/accessory_driver.py
17+
What: Async helper methods
18+
Methods:
19+
callback
20+
is_callback
21+
AccessoryDriver.start
22+
AccessoryDriver.stop
23+
AccessoryDriver.async_stop
24+
AccessoryDriver.add_job
25+
AccessoryDriver.async_add_job
26+
AccessoryDriver.async_run_job
27+
Inspired from: Home Assistant [1]
28+
Original file:
29+
https://github.com/home-assistant/home-assistant/blob/master/homeassistant/core.py
30+
31+
setup.py
32+
Inspired from: Home Assistant [1]
33+
Original file:
34+
https://github.com/home-assistant/home-assistant/blob/master/setup.py
35+
36+
scripts/release
37+
Inspired from: Home Assistant [1]
38+
File: script/release
39+
https://github.com/home-assistant/home-assistant/blob/master/script/release
40+
41+
scripts/setup
42+
Inspired from: Home Assistant [1]
43+
File: script/setup
44+
https://github.com/home-assistant/home-assistant/blob/master/script/setup
45+
46+
Credit
47+
======
48+
49+
Some HAP know-how
50+
What: HAP-NodeJS
51+
Source URL: https://github.com/KhaosT/HAP-NodeJS
52+
Copyright: Khaos Tian
53+
License: Apache License 2.0
54+
License URL: https://github.com/KhaosT/HAP-NodeJS/blob/master/LICENSE
55+
56+
Some Async know-how
57+
What: Home Assistant [1]
58+
59+
HomeKit Accessory Protocol Specification
60+
Source URL: https://developer.apple.com/homekit/specification/
61+
62+
Footnotes
63+
=========
64+
65+
[1] Home Assistant
66+
Source URL: https://github.com/home-assistant/home-assistant
67+
Copyright: The Home Assistant Authors
68+
License: Apache License 2.0
69+
License URL: https://github.com/home-assistant/home-assistant/blob/dev/LICENSE.md
70+
71+
===============================================================================
72+
173
Apache License
274
Version 2.0, January 2004
375
http://www.apache.org/licenses/
@@ -173,4 +245,4 @@
173245
incurred by, or claims asserted against, such Contributor by reason
174246
of your accepting any such warranty or additional liability.
175247

176-
END OF TERMS AND CONDITIONS
248+
END OF TERMS AND CONDITIONS

README.md

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,10 @@ will take care of advertising it on the local network, setting a HAP server and
5151
running the Accessory. Take a look at [main.py](main.py) for a quick start on that.
5252

5353
```python
54-
from pyhap.accessory import Accessory, AsyncAccessory, Category
54+
from pyhap.accessory import Accessory, Category
5555
import pyhap.loader as loader
5656

57-
### Async accessory - run method is run asynchronously in the event loop
58-
class TemperatureSensor(AsyncAccessory):
57+
class TemperatureSensor(Accessory):
5958
"""Implementation of a mock temperature sensor accessory."""
6059

6160
category = Category.SENSOR # This is for the icon in the iOS Home app.
@@ -81,8 +80,9 @@ class TemperatureSensor(AsyncAccessory):
8180
"""
8281
print('Temperature changed to: ', value)
8382

84-
@AsyncAcessory.run_at_interval(3) # Run this method every 3 seconds
85-
async def run(self):
83+
@Acessory.run_at_interval(3) # Run this method every 3 seconds
84+
# The `run` method can be `async` as well
85+
def run(self):
8686
"""We override this method to implement what the accessory will do when it is
8787
started.
8888
@@ -91,21 +91,12 @@ class TemperatureSensor(AsyncAccessory):
9191
"""
9292
self.temp_char.set_value(random.randint(18, 26))
9393

94+
# The `stop` method can be `async` as well
9495
def stop(self):
9596
"""We override this method to clean up any resources or perform final actions, as
9697
this is called by the AccessoryDriver when the Accessory is being stopped.
9798
"""
9899
print('Stopping accessory.')
99-
100-
### Synchronouse accessory - run method is in a thread
101-
class SyncTemperatureSensor(Accessory):
102-
"""Everything is same as in the TemperatureSensor, apart from the run method which is
103-
not async.
104-
"""
105-
106-
@Accessory.run_at_interval(3)
107-
def run(self):
108-
self.temp_char.set_value(random.randint(18, 26))
109100
```
110101

111102
## Integrating non-compatible devices <a name="HttpAcc"></a>

accessories/AM2302.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ def __setstate__(self, state):
4040
self.__dict__.update(state)
4141
self.sensor = DHT22.sensor(pigpio.pi(), self.pin)
4242

43+
@Accessory.run_at_interval(10)
4344
def run(self):
44-
while not self.run_sentinel.wait(10):
45-
self.sensor.trigger()
46-
time.sleep(0.2)
47-
t = self.sensor.temperature()
48-
h = self.sensor.humidity()
49-
self.char_temp.set_value(t)
50-
self.char_humidity.set_value(h)
45+
self.sensor.trigger()
46+
time.sleep(0.2)
47+
t = self.sensor.temperature()
48+
h = self.sensor.humidity()
49+
self.char_temp.set_value(t)
50+
self.char_humidity.set_value(h)

accessories/BMP180.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __setstate__(self, state):
2828
self.__dict__.update(state)
2929
self.sensor = sensor()
3030

31+
@Accessory.run_at_interval(30)
3132
def run(self):
32-
while not self.run_sentinel.wait(30):
33-
temp, _pressure = self.sensor.read()
34-
self.char_temp.set_value(temp)
33+
temp, _pressure = self.sensor.read()
34+
self.char_temp.set_value(temp)

accessories/DisplaySwitch.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ def __init__(self, *args, **kwargs):
3232
self.display = serv_switch.configure_char(
3333
'On', setter_callback=self.set_display)
3434

35+
@Accessory.run_at_interval(1)
3536
def run(self):
36-
while not self.run_sentinel.wait(1):
37-
# We can't just use .set_value(state), because that will
38-
# trigger our listener.
39-
state = get_display_state()
40-
if self.display.value != state:
41-
self.display.value = state
42-
self.display.notify()
37+
# We can't just use .set_value(state), because that will
38+
# trigger our listener.
39+
state = get_display_state()
40+
if self.display.value != state:
41+
self.display.value = state
42+
self.display.notify()
4343

4444
def set_display(self, state):
4545
if get_display_state() != state:

accessories/SDS011.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def run(self):
126126
self.pm10_quality.set_value(
127127
self.get_quality_classification(pm10, is_pm25=False))
128128
self.sensor.sleep()
129-
while not self.run_sentinel.wait(self.sleep_duration_s):
129+
while not self.driver.stop_event.wait(self.sleep_duration_s):
130130
logger.debug("Waking up sensor.")
131131
self.sensor.sleep(sleep=False)
132132
time.sleep(self.calib_duration_s)

accessories/TSL2591.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ def __setstate__(self, state):
2727
self.__dict__.update(state)
2828
self.tsl = tsl2591.Tsl2591()
2929

30+
@Accessory.run_at_interval(10)
3031
def run(self):
31-
while not self.run_sentinel.wait(10):
32-
full, ir = self.tsl.get_full_luminosity()
33-
lux = min(max(0.001, self.tsl.calculate_lux(full, ir)), 10000)
34-
self.char_lux.set_value(lux)
35-
32+
full, ir = self.tsl.get_full_luminosity()
33+
lux = min(max(0.001, self.tsl.calculate_lux(full, ir)), 10000)
34+
self.char_lux.set_value(lux)

0 commit comments

Comments
 (0)