Skip to content

Commit 2f05e30

Browse files
authored
Merge pull request #68 from sinricpro/2.7.4
feat: thermostat example added, thermostat modes added.
2 parents 295311d + 76a357c commit 2f05e30

4 files changed

Lines changed: 55 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [2.7.4]
2+
3+
### Features
4+
* **thermostat example added**
5+
* `THERMOSTAT_MODE_COOL`, `THERMOSTAT_MODE_HEAT`, `THERMOSTAT_MODE_AUTO`, `THERMOSTAT_MODE_OFF` constants added to `_sinricpro_constants.py`
6+
17
## [2.7.1]
28

39
### Features

examples/thermostat.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from sinric import SinricPro, SinricProConstants
2+
import asyncio
3+
from asyncio import sleep
4+
5+
APP_KEY = ""
6+
APP_SECRET = ""
7+
THERMOSTAT_ID = ""
8+
9+
def power_state(device_id, state):
10+
print('device_id: {} state: {}'.format(device_id, state))
11+
return True, state
12+
13+
def target_temperature(device_id, temperature):
14+
print('device_id: {} set temperature: {}'.format(device_id, temperature))
15+
return True, temperature
16+
17+
def set_thermostate_mode(device_id, thermostat_mode):
18+
print('device_id: {} set thermostat mode: {}'.format(device_id, thermostat_mode))
19+
return True, thermostat_mode
20+
21+
def mode_value(device_id, mode_value):
22+
print(device_id, mode_value)
23+
return True, mode_value
24+
25+
async def events():
26+
while True:
27+
# client.event_handler.raise_event(THERMOSTAT_ID, SinricProConstants.SET_THERMOSTAT_MODE, data= { SinricProConstants.MODE : SinricProConstants.THERMOSTAT_MODE_COOL})
28+
# client.event_handler.raise_event(THERMOSTAT_ID, SinricProConstants.SET_POWER_STATE, data= {SinricProConstants.STATE: SinricProConstants.POWER_STATE_OFF})
29+
# client.event_handler.raise_event(THERMOSTAT_ID, SinricProConstants.CURRENT_TEMPERATURE, data={'humidity': 75.3, 'temperature': 24})
30+
# Server will trottle / block IPs sending events too often.
31+
await sleep(60)
32+
33+
callbacks = {
34+
SinricProConstants.SET_POWER_STATE: power_state,
35+
SinricProConstants.TARGET_TEMPERATURE: target_temperature,
36+
SinricProConstants.SET_THERMOSTAT_MODE: set_thermostate_mode
37+
}
38+
39+
if __name__ == '__main__':
40+
loop = asyncio.get_event_loop()
41+
client = SinricPro(APP_KEY, [THERMOSTAT_ID], callbacks, event_callbacks=events,
42+
enable_log=True, restore_states=False, secret_key=APP_SECRET)
43+
loop.run_until_complete(client.connect())

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
if sys.version_info < (3,6):
1111
sys.exit('Sorry, Python < 3.6 is not supported')
1212

13-
VERSION = "2.7.3"
13+
VERSION = "2.7.4"
1414

1515
with open('README.rst', 'r') as f:
1616
long_description = f.read()

sinric/_sinricpro_constants.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,18 @@ class SinricProConstants(object):
5959
BANDS = 'bands'
6060
THERMOSTATMODE = 'thermostatMode'
6161
MODE = 'mode'
62-
63-
6462
# values
6563
LOCK_STATE_LOCKED = 'LOCKED'
6664
LOCK_STATE_UNLOCKED = 'UNLOCKED'
6765

6866
POWER_STATE_ON = 'On'
6967
POWER_STATE_OFF = 'Off'
7068

69+
THERMOSTAT_MODE_COOL = 'COOL'
70+
THERMOSTAT_MODE_HEAT = 'HEAT'
71+
THERMOSTAT_MODE_AUTO = 'AUTO'
72+
THERMOSTAT_MODE_OFF = 'OFF'
73+
7174
CLOSE = "Close"
7275
OPEN = "Open"
7376

0 commit comments

Comments
 (0)