Skip to content

Commit 4b0bfa1

Browse files
authored
Create multi_switch.py
1 parent 30f9d0f commit 4b0bfa1

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

examples/multi_switch.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from sinric import SinricPro
2+
import asyncio
3+
4+
APP_KEY = ''
5+
APP_SECRET = ''
6+
SWITCH_ID_1 = ''
7+
SWITCH_ID_2 = ''
8+
9+
def power_state(device_id, state):
10+
if device_id == SWITCH_ID_1:
11+
print(device_id, state)
12+
elif device_id == SWITCH_ID_2:
13+
print(device_id, state)
14+
else:
15+
print("device_id not found!")
16+
17+
return True, state
18+
19+
callbacks = {
20+
'powerState': power_state
21+
}
22+
23+
if __name__ == '__main__':
24+
loop = asyncio.get_event_loop()
25+
client = SinricPro(APP_KEY, [SWITCH_ID_1, SWITCH_ID_2], callbacks, enable_log=False, restore_states=False, secretKey=APP_SECRET)
26+
loop.run_until_complete(client.connect())
27+
28+
# To update the power state on server.
29+
# client.event_handler.raiseEvent(tvId, 'setPowerState',data={'state': 'On'})

0 commit comments

Comments
 (0)