Skip to content

Commit

Permalink
Pass deviceId Array instead of deviceId String
Browse files Browse the repository at this point in the history
  • Loading branch information
thegoliathgeek committed Nov 3, 2019
1 parent 5ade4a3 commit 466fff9
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 13 deletions.
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.0"
VERSION = "2.1.1"

with open('README.rst', 'r') as f:
long_description = f.read()
Expand Down
1 change: 0 additions & 1 deletion sinric/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@

from ._sinricpro import SinricPro
from ._sinricproudp import SinricProUdp
from ._mainqueue import queue
from ._events import Events, eventNames
29 changes: 24 additions & 5 deletions sinric/_cbhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
from ._tvcontorller import TvController
from ._speakerController import SpeakerController
from json import dumps, load, dump
from time import time
from time import time, sleep
from uuid import uuid4
from base64 import b64encode, b64decode
import hmac as sinricHmac
from hashlib import sha256
from ._dataTracker import DataTracker
from ._lockController import LockStateController
from ._signature import Signature
Expand Down Expand Up @@ -289,7 +286,10 @@ def jsnHandle(action, resp, dataDict) -> dict:
assert (self.verifySignature(jsn.get('payload'), jsn.get("signature").get("HMAC")))
resp, value = await self.targetTemperature(jsn, self.callbacks.get('targetTemperature'))
response = jsnHandle(action="targetTemperature", resp=resp, dataDict={
"duration": ""
"schedule": {
"duration": "PT4H"
},
"temperature": value
})
if self.enable_track:
self.data_tracker.writeData('temperature', value)
Expand Down Expand Up @@ -551,74 +551,93 @@ def jsnHandle(action, resp, dataDict) -> dict:
self.logger.info('Sending Doorbell Event Response')
await connection.send(dumps(jsn))


elif Trace == 'temp_hum_event_response':
self.logger.info('Sending temperature humidity response')
await connection.send(dumps(jsn))


elif Trace == 'setpowerstate_event_response':
self.logger.info('Sending setpowerstate_event_response')
await connection.send(dumps(jsn))


elif Trace == 'setPowerLevel_event_response':
self.logger.info('Sending setPowerLevel_event_response')
await connection.send(dumps(jsn))


elif Trace == 'setBrightness_event_response':
self.logger.info('Sending setBrightness_event_response')
await connection.send(dumps(jsn))


elif Trace == 'setColor_event_response':
self.logger.info('Sending setColor_event_response')
await connection.send(dumps(jsn))


elif Trace == 'setColorTemperature_event_response':
self.logger.info('Sending setColorTemperature_event_response')
await connection.send(dumps(jsn))


elif Trace == 'setThermostatMode_event_response':
self.logger.info('Sending setThermostatMode_event_response')
await connection.send(dumps(jsn))


elif Trace == 'setRangeValue_event_response':
self.logger.info('Sending setRangeValue_event_response')
await connection.send(dumps(jsn))


elif Trace == 'motion_event_response':
self.logger.info('Sending motion_event_response')
await connection.send(dumps(jsn))


elif Trace == 'contact_event_response':
self.logger.info('Sending contact_event_response')
await connection.send(dumps(jsn))


elif Trace == 'set_volume_event_response':
self.logger.info('Sending set_volume_event_response')
await connection.send(dumps(jsn))


elif Trace == 'select_input_event_response':
self.logger.info('Sending select_input_event_response')
await connection.send(dumps(jsn))


elif Trace == 'media_control_event_response':
self.logger.info('Sending media_control_event_response')
await connection.send(dumps(jsn))


elif Trace == 'change_channel_event_response':
self.logger.info('Sending change_channel_event_response')
await connection.send(dumps(jsn))


elif Trace == 'set_bands_event_response':
self.logger.info('Sending set_bands_event_response')
await connection.send(dumps(jsn))



elif Trace == 'set_mode_event_response':
self.logger.info('Sending set_mode_event_response')
await connection.send(dumps(jsn))


elif Trace == 'set_lock_event_response':
self.logger.info('Sending set_lock_event_response')
await connection.send(dumps(jsn))


elif Trace == 'reset_bands_event_response':
self.logger.info('Sending reset_bands_event_response')
await connection.send(dumps(jsn))
26 changes: 24 additions & 2 deletions sinric/_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* This file is part of the Sinric Pro (https://github.com/sinricpro/)
"""

from time import time
from time import time, sleep
from ._mainqueue import queue
from ._jsoncommands import JSON_COMMANDS
import uuid
Expand All @@ -21,6 +21,7 @@
class Events(Signature):
def __init__(self, connection, logger=None, secretKey=""):
self.connection = connection
self.eventSleepTime = 2
self.logger = logger
self.secretKey = secretKey
Signature.__init__(self, self.secretKey)
Expand All @@ -43,7 +44,7 @@ def jsnHandle(action, deviceId, value) -> dict:
},
"createdAt": int(time()),
"deviceId": deviceId,
"replyToken": str(uuid),
"replyToken": str(uuid.uuid4()),
"type": "event",
"value": value
}
Expand All @@ -55,20 +56,24 @@ def jsnHandle(action, deviceId, value) -> dict:

queue.put([jsnHandle("setPowerState", deviceId, {"state": data.get("state", "Off")}),
'setpowerstate_event_response'])
sleep(self.eventSleepTime)


elif event_name == JSON_COMMANDS.get('SETPOWERLEVEL'):
self.logger.info('setPowerLevel event raised')

queue.put([jsnHandle("setPowerLevel", deviceId, {
"powerLevel": data.get('powerLevel')
}), 'setPowerLevel_event_response'])
sleep(self.eventSleepTime)

elif event_name == JSON_COMMANDS.get('SETBRIGHTNESS'):
self.logger.info('setBrightness event raised')

queue.put([jsnHandle("setBrightness", deviceId, {
"powerLevel": data.get('brightness')
}), 'setBrightness_event_response'])
sleep(self.eventSleepTime)

elif event_name == JSON_COMMANDS.get('SETCOLOR'):
self.logger.info('setColor event raised')
Expand All @@ -80,6 +85,7 @@ def jsnHandle(action, deviceId, value) -> dict:
"b": data.get('b')
}
}), 'setColor_event_response'])
sleep(self.eventSleepTime)


elif event_name == JSON_COMMANDS.get('SETCOLORTEMPERATURE'):
Expand All @@ -88,6 +94,7 @@ def jsnHandle(action, deviceId, value) -> dict:
queue.put([jsnHandle("setColorTemperature", deviceId, {
"colorTemperature": 2400
}), 'setColorTemperature_event_response'])
sleep(self.eventSleepTime)

##########################DOOR BELL EVENT####################################

Expand All @@ -96,33 +103,38 @@ def jsnHandle(action, deviceId, value) -> dict:
queue.put([jsnHandle("DoorbellPress", deviceId, {
"state": "pressed"
}), 'doorbell_event_response'])
sleep(self.eventSleepTime)

elif event_name == 'temperatureHumidityEvent':
self.logger.info('Raised TH event')
queue.put([jsnHandle("setTemperature", deviceId, {
"temperature": data.get('temperature'),
"humidity": data.get('humidity')
}), 'temp_hum_event_response'])
sleep(self.eventSleepTime)

elif event_name == 'setThermostatMode':
self.logger.info("Raised Thermostat event")
queue.put([jsnHandle("setThermostatMode", deviceId, {
"thermostatMode": data.get('Mode')
}), 'setThermostatMode_event_response'])
sleep(self.eventSleepTime)

elif event_name == 'setRangeValue':
self.logger.info('Raised Range value event')

queue.put([jsnHandle("setRangeValue", deviceId, {
"rangeValue": data.get('rangeValue')
}), 'setRangeValue_event_response'])
sleep(self.eventSleepTime)

elif event_name == 'motion':
self.logger.info('Raised motion event')

queue.put([jsnHandle("motion", deviceId, {
"state": data.get('state')
}), 'motion_event_response'])
sleep(self.eventSleepTime)


elif event_name == 'setContactState':
Expand All @@ -131,6 +143,7 @@ def jsnHandle(action, deviceId, value) -> dict:
queue.put([jsnHandle("setContactState", deviceId, {
"state": data.get('state')
}), 'contact_event_response'])
sleep(self.eventSleepTime)


elif event_name == 'setVolume':
Expand All @@ -139,13 +152,15 @@ def jsnHandle(action, deviceId, value) -> dict:
queue.put([jsnHandle("setVolume", deviceId, {
"volume": data.get('volume')
}), 'set_volume_event_response'])
sleep(self.eventSleepTime)

elif event_name == 'selectInput':
self.logger.info('Raised select input event')

queue.put([jsnHandle("selectInput", deviceId, {
"input": data.get('input')
}), 'select_input_event_response'])
sleep(self.eventSleepTime)


elif event_name == 'mediaControl':
Expand All @@ -154,6 +169,7 @@ def jsnHandle(action, deviceId, value) -> dict:
queue.put([jsnHandle("mediaControl", deviceId, {
"control": data.get('control')
}), 'media_control_event_response'])
sleep(self.eventSleepTime)


elif event_name == 'changeChannel':
Expand All @@ -164,6 +180,7 @@ def jsnHandle(action, deviceId, value) -> dict:
"name": data.get('name')
}
}), 'change_channel_event_response'])
sleep(self.eventSleepTime)

elif event_name == 'setBands':
self.logger.info('Set Bands event raised')
Expand All @@ -175,19 +192,22 @@ def jsnHandle(action, deviceId, value) -> dict:
}
]
}), 'set_bands_event_response'])
sleep(self.eventSleepTime)

elif event_name == 'setMode':
self.logger.info('Set Mode event raised')
queue.put([jsnHandle("setMode", deviceId, {
"mode": data.get('mode')
}), 'set_mode_event_response'])
sleep(self.eventSleepTime)

elif event_name == 'setLockState':
self.logger.info('setLockState event raised')

queue.put([jsnHandle("setLockState", deviceId, {
"state": data.get('state')
}), 'set_lock_event_response'])
sleep(self.eventSleepTime)

elif event_name == 'resetBands':
self.logger.info('resetBands event raised')
Expand All @@ -207,13 +227,15 @@ def jsnHandle(action, deviceId, value) -> dict:
"level": 0
}]
}), 'reset_bands_event_response'])
sleep(self.eventSleepTime)

elif event_name == 'setMute':
self.logger.info('setMute event raised')

queue.put([jsnHandle("setMute", deviceId, {
"mute": data.get('mute', False)
}), 'reset_bands_event_response'])
sleep(self.eventSleepTime)

except Exception:
self.logger.exception('Error Occurred')
2 changes: 1 addition & 1 deletion sinric/_sinricpro.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, api, deviceid, request_callbacks, event_callbacks=None, enabl
sys.exit(0)

def verifyDeviceIdArr(self,deviceIdArr):
Arr = deviceIdArr.split(';')
Arr = deviceIdArr
for i in Arr:
res = re.findall(r'^[a-fA-F0-9]{24}$',i)
if len(res) == 0:
Expand Down
2 changes: 1 addition & 1 deletion sinric/_sinricprosocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, appKey, deviceId, callbacks, enable_trace=False, logger=None,
async def connect(self): # Producer
self.connection = await websockets.client.connect('ws://ws.sinric.pro',
extra_headers={'appkey': self.appKey,
'deviceids': self.deviceIds,
'deviceids': ';'.join(self.deviceIds),
'platform': 'python'},
ping_interval=30000, ping_timeout=10000)
if self.connection.open:
Expand Down
4 changes: 2 additions & 2 deletions sinric/_sinricproudp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@


class SinricProUdp:
def __init__(self, callbacks1, deviceIdArr,enable_trace=False):
self.callbacks = callbacks1
def __init__(self, callbacks_udp, deviceIdArr,enable_trace=False):
self.callbacks = callbacks_udp
self.deviceIdArr = deviceIdArr
self.enablePrint = enable_trace
self.udp_ip = '224.9.9.9'
Expand Down

0 comments on commit 466fff9

Please sign in to comment.