|
9 | 9 | ## Dependencies |
10 | 10 | * Python 3.9.7 or newer |
11 | 11 | * websockets 8.1 |
12 | | - |
13 | | -### Check the examples [here](https://github.com/sinricpro/Python-Examples) |
14 | | - |
15 | | -### How to set it up? click [here](https://dev.to/imdhanush/automation-with-alexa-jo) |
16 | | - |
17 | 12 | ### Install |
18 | 13 |
|
19 | 14 | pip install sinricpro --user |
|
22 | 17 |
|
23 | 18 | pip install sinricpro --upgrade --user |
24 | 19 |
|
25 | | -### Simple example |
26 | | - |
27 | | -```python |
28 | | -from sinric import SinricPro |
29 | | -from sinric import SinricProUdp |
30 | | -import asyncio |
31 | | - |
32 | | -appKey = '' # d89f1***-****-****-****-************ |
33 | | -secretKey = '' # f44d1d31-1c19-****-****-9bc96c34b5bb-d19f42dd-****-****-****-************ |
34 | | -device1 = '' # 5d7e7d96069e275ea9****** |
35 | | -device2 = '' # 5d80ac5713fa175e99****** |
36 | | -deviceIdArr = [device1,device2] |
37 | | - |
38 | | -def Events(): |
39 | | - while True: |
40 | | - # Select as per your requirements |
41 | | - # REMOVE THE COMMENTS TO USE |
42 | | - # client.event_handler.raiseEvent(device1, 'setPowerState',data={'state': 'On'}) |
43 | | - pass |
44 | | -def onPowerState(did, state): |
45 | | - # Alexa, turn ON/OFF Device |
46 | | - print(did, state) |
47 | | - return True, state |
48 | | - |
49 | | - |
50 | | -eventsCallbacks={ |
51 | | - "Events": Events |
52 | | -} |
53 | | - |
54 | | -callbacks = { |
55 | | -'powerState': onPowerState |
56 | | -} |
57 | | - |
58 | | -if __name__ == '__main__': |
59 | | - loop = asyncio.get_event_loop() |
60 | | - |
61 | | - client = SinricPro(appKey, deviceIdArr, callbacks,event_callbacks=eventsCallbacks, |
62 | | - enable_log=False,restore_states=True,secretKey=secretKey) |
63 | | - |
64 | | - udp_client = SinricProUdp(callbacks,deviceIdArr, |
65 | | - enable_trace=False, loopInstance=loop) # Set enable_trace to True to start logging request Offline Request/Response |
66 | | - |
67 | | - loop.run_until_complete(client.connect(udp_client=udp_client)) |
68 | | - |
69 | | -``` |
70 | | - |
71 | | -### Credentials file (credential.py) |
72 | | - |
73 | | -```python |
74 | | -appKey = 'd89f1***-****-****-****-************' |
75 | | -secretKey = 'f44d1d31-1c19-****-****-9bc96c34b5bb-d19f42dd-****-****-****-************' |
76 | | -deviceId1 = '5d7e7d96069e275ea9******' |
77 | | -deviceId2 = ' 5j7e7d96069e275ea9******' |
78 | | -deviceId3 = ' 5d7e7d96069e275ea9******' |
79 | | -lock = ' 5d7e7d96069e275ea9******' |
80 | | -deviceIdArr = [deviceId1, deviceId2, deviceId3, lock] |
81 | | -``` |
82 | | - |
83 | | -### Pro Switch [Demo](https://github.com/sinricpro/Python-Examples/tree/master/pro_switch_example): |
84 | | - |
85 | | -```python |
86 | | -from sinric import SinricPro |
87 | | -from sinric import SinricProUdp |
88 | | -from credentials import appKey, deviceIdArr, secretKey |
89 | | -from time import sleep |
90 | | - |
91 | | -def Events(): |
92 | | - while True: |
93 | | - # Select as per your requirements |
94 | | - # REMOVE THE COMMENTS TO USE |
95 | | - # client.event_handler.raiseEvent(device1, 'setPowerState',data={'state': 'On'}) |
96 | | - pass |
97 | | -def onPowerState(did, state): |
98 | | - # Alexa, turn ON/OFF Device |
99 | | - print(did, state) |
100 | | - return True, state |
101 | | - |
102 | | - |
103 | | -eventsCallbacks={ |
104 | | - "Events": Events |
105 | | -} |
106 | | - |
107 | | -callbacks = { |
108 | | -'powerState': onPowerState |
109 | | -} |
110 | | - |
111 | | -if __name__ == '__main__': |
112 | | - loop = asyncio.get_event_loop() |
113 | | - |
114 | | - client = SinricPro(appKey, deviceIdArr, callbacks,event_callbacks=eventsCallbacks, |
115 | | - enable_log=False,restore_states=True,secretKey=secretKey) |
116 | | - |
117 | | - udp_client = SinricProUdp(callbacks,deviceIdArr, |
118 | | - enable_trace=False, loopInstance=loop) # Set enable_trace to True to start logging request Offline Request/Response |
119 | | - |
120 | | - loop.run_until_complete(client.connect(udp_client=udp_client)) |
121 | | -``` |
| 20 | +### Check the examples [here](https://github.com/sinricpro/Python-Examples) |
0 commit comments