Skip to content

Commit

Permalink
Added simple example.
Browse files Browse the repository at this point in the history
  • Loading branch information
thegoliathgeek committed Nov 5, 2019
1 parent 466fff9 commit 73aa8d1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
50 changes: 45 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,60 @@
source sinricenv/bin/activate

pip install sinricpro



### Simple example
```python
from sinric import SinricPro
from sinric import SinricProUdp
from time import sleep

appKey = '' # d89f1***-****-****-****-************
secretKey = '' # f44d1d31-1c19-****-****-9bc96c34b5bb-d19f42dd-****-****-****-************
device1 = '' #// 5d7e7d96069e275ea9******
device2 = '' # 5d80ac5713fa175e99******
deviceIdArr = [device1,device2]

def Events():
while True:
# Select as per your requirements
# REMOVE THE COMMENTS TO USE
# client.event_handler.raiseEvent(device1, 'setPowerState',data={'state': 'On'})
sleep(2) #Sleep for 2 seconds

def onPowerState(did, state):
# Alexa, turn ON/OFF Device
print(did, state)
return True, state


eventsCallbacks={
"Events": Events
}

callbacks = {
'powerState': onPowerState
}

if __name__ == '__main__':
client = SinricPro(appKey, deviceIdArr, callbacks,event_callbacks=eventsCallbacks, enable_trace=False,secretKey=secretKey)
udp_client = SinricProUdp(callbacks,deviceIdArr,enable_trace=False) # Set it to True to start logging request Offline Request/Response
client.handle_all(udp_client)

```

### Pro Switch [Demo](https://github.com/sinricpro/Python-Examples/tree/master/pro_switch_example):
```python
from sinric import SinricPro
from sinric import SinricProUdp
from credentials import appKey, deviceId, secretKey
from credentials import appKey, deviceIdArr, secretKey
from time import sleep

def Events():
while True:
# Select as per your requirements
# REMOVE THE COMMENTS TO USE
# client.event_handler.raiseEvent(deviceId1, 'setPowerState',data={'state': 'On'})
# client.event_handler.raiseEvent(device1, 'setPowerState',data={'state': 'On'})
sleep(2) #Sleep for 2 seconds

def onPowerState(did, state):
Expand All @@ -53,7 +93,7 @@ callbacks = {
}

if __name__ == '__main__':
client = SinricPro(appKey, deviceId, callbacks,event_callbacks=eventsCallbacks, enable_trace=False,secretKey=secretKey)
udp_client = SinricProUdp(callbacks,deviceId,enable_trace=False) # Set it to True to start logging request Offline Request/Response
client = SinricPro(appKey, deviceIdArr, callbacks,event_callbacks=eventsCallbacks, enable_trace=False,secretKey=secretKey)
udp_client = SinricProUdp(callbacks,deviceIdArr,enable_trace=False) # Set it to True to start logging request Offline Request/Response
client.handle_all(udp_client)
```
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
if sys.version_info < (3,7):
sys.exit('Sorry, Python < 3.7 is not supported')

VERSION = "2.1.1"
VERSION = "2.1.2"

with open('README.rst', 'r') as f:
long_description = f.read()
Expand Down

0 comments on commit 73aa8d1

Please sign in to comment.