diff --git a/CHANGELOG.md b/CHANGELOG.md index 5be1afa..5790345 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/examples/thermostat.py b/examples/thermostat.py new file mode 100644 index 0000000..aa54375 --- /dev/null +++ b/examples/thermostat.py @@ -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()) \ No newline at end of file diff --git a/setup.py b/setup.py index 6d652d2..818abba 100644 --- a/setup.py +++ b/setup.py @@ -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() diff --git a/sinric/_sinricpro_constants.py b/sinric/_sinricpro_constants.py index 8a07ee3..8841555 100644 --- a/sinric/_sinricpro_constants.py +++ b/sinric/_sinricpro_constants.py @@ -59,8 +59,6 @@ class SinricProConstants(object): BANDS = 'bands' THERMOSTATMODE = 'thermostatMode' MODE = 'mode' - - # values LOCK_STATE_LOCKED = 'LOCKED' LOCK_STATE_UNLOCKED = 'UNLOCKED' @@ -68,6 +66,11 @@ class SinricProConstants(object): 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"