Skip to content

Commit

Permalink
Merge pull request #68 from sinricpro/2.7.4
Browse files Browse the repository at this point in the history
feat: thermostat example added, thermostat modes added.
  • Loading branch information
kakopappa authored Aug 22, 2024
2 parents 295311d + 76a357c commit 2f05e30
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [2.7.4]

### Features
* **thermostat example added**
* `THERMOSTAT_MODE_COOL`, `THERMOSTAT_MODE_HEAT`, `THERMOSTAT_MODE_AUTO`, `THERMOSTAT_MODE_OFF` constants added to `_sinricpro_constants.py`

## [2.7.1]

### Features
Expand Down
43 changes: 43 additions & 0 deletions examples/thermostat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from sinric import SinricPro, SinricProConstants
import asyncio
from asyncio import sleep

APP_KEY = ""
APP_SECRET = ""
THERMOSTAT_ID = ""

def power_state(device_id, state):
print('device_id: {} state: {}'.format(device_id, state))
return True, state

def target_temperature(device_id, temperature):
print('device_id: {} set temperature: {}'.format(device_id, temperature))
return True, temperature

def set_thermostate_mode(device_id, thermostat_mode):
print('device_id: {} set thermostat mode: {}'.format(device_id, thermostat_mode))
return True, thermostat_mode

def mode_value(device_id, mode_value):
print(device_id, mode_value)
return True, mode_value

async def events():
while True:
# client.event_handler.raise_event(THERMOSTAT_ID, SinricProConstants.SET_THERMOSTAT_MODE, data= { SinricProConstants.MODE : SinricProConstants.THERMOSTAT_MODE_COOL})
# client.event_handler.raise_event(THERMOSTAT_ID, SinricProConstants.SET_POWER_STATE, data= {SinricProConstants.STATE: SinricProConstants.POWER_STATE_OFF})
# client.event_handler.raise_event(THERMOSTAT_ID, SinricProConstants.CURRENT_TEMPERATURE, data={'humidity': 75.3, 'temperature': 24})
# Server will trottle / block IPs sending events too often.
await sleep(60)

callbacks = {
SinricProConstants.SET_POWER_STATE: power_state,
SinricProConstants.TARGET_TEMPERATURE: target_temperature,
SinricProConstants.SET_THERMOSTAT_MODE: set_thermostate_mode
}

if __name__ == '__main__':
loop = asyncio.get_event_loop()
client = SinricPro(APP_KEY, [THERMOSTAT_ID], callbacks, event_callbacks=events,
enable_log=True, restore_states=False, secret_key=APP_SECRET)
loop.run_until_complete(client.connect())
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
if sys.version_info < (3,6):
sys.exit('Sorry, Python < 3.6 is not supported')

VERSION = "2.7.3"
VERSION = "2.7.4"

with open('README.rst', 'r') as f:
long_description = f.read()
Expand Down
7 changes: 5 additions & 2 deletions sinric/_sinricpro_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,18 @@ class SinricProConstants(object):
BANDS = 'bands'
THERMOSTATMODE = 'thermostatMode'
MODE = 'mode'


# values
LOCK_STATE_LOCKED = 'LOCKED'
LOCK_STATE_UNLOCKED = 'UNLOCKED'

POWER_STATE_ON = 'On'
POWER_STATE_OFF = 'Off'

THERMOSTAT_MODE_COOL = 'COOL'
THERMOSTAT_MODE_HEAT = 'HEAT'
THERMOSTAT_MODE_AUTO = 'AUTO'
THERMOSTAT_MODE_OFF = 'OFF'

CLOSE = "Close"
OPEN = "Open"

Expand Down

0 comments on commit 2f05e30

Please sign in to comment.