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 ())
0 commit comments