From 73aa8d15c10663263eb28a83c845307f57de1095 Mon Sep 17 00:00:00 2001 From: imdhanush Date: Tue, 5 Nov 2019 20:29:49 +0530 Subject: [PATCH] Added simple example. --- README.md | 50 +++++++++++++++++++++++++++++++++++++++++++++----- setup.py | 2 +- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index deb04d9..d876204 100644 --- a/README.md +++ b/README.md @@ -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): @@ -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) ``` diff --git a/setup.py b/setup.py index 1586629..396d20e 100644 --- a/setup.py +++ b/setup.py @@ -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()