예제 #1
0
 def start(self):
     ''' Start clients and setup connection '''
     # Request callbacks
     callbs = {}
     if len(self.events) > 0:
         for key, receivers in self.events.items():
             callbs[key] = lambda dev_id, *arg, recv=receivers: self.run_match_dev_id(dev_id,recv,locals()['arg'])
     
     self.client = SinricPro(self.appKey, self.deviceIdArr, callbs, event_callbacks=self.eventsCallbacks, enable_log=False,restore_states=True,secretKey=self.secretKey)
     
     # Instantiate client (setup connections)
     udp_client = SinricProUdp(callbs, self.deviceIdArr,enable_trace=False)  # Set it to True to start logging request Offline Request/Response
     self.client.handle_all(udp_client)
     self.logger = client.logger
     self.logger.success("SinricProOO started!")
예제 #2
0
        "User-Agent": "PostmanRuntime/7.18.0",
        "Accept": "*/*",
        "Cache-Control": "no-cache",
        "Postman-Token":
        "d001f97e-0181-4e40-8518-56d8890142ec,256ed8fa-93bb-4a16-ad34-96929283b2b0",
        "Host": "blynk-cloud.com",
        "Accept-Encoding": "gzip, deflate",
        "Connection": "keep-alive",
        "cache-control": "no-cache",
    }

    response = requests.request("GET",
                                url,
                                headers=headers,
                                params=querystring)


if __name__ == "__main__":
    client = SinricPro(
        appKey,
        deviceIdArr,
        callbacks,
        event_callbacks=event_callback,
        enable_log=False,
        restore_states=False,
        secretKey=secretKey,
    )
    # Set it to True to start logging request Offline Request/Response
    udp_client = SinricProUdp(callbacks, deviceIdArr, enable_trace=False)
    client.handle_all(udp_client)
예제 #3
0
    return True, state


def events():
    while True:
        client.event_handler.raiseEvent(TEMPERATURE_SENSOR_ID,
                                        'temperatureHumidityEvent',
                                        data={
                                            'humidity': 75.3,
                                            'temperature': 24
                                        })
        sleep(60)  # Server will trottle / block IPs sending events too often.
        pass


events_callbacks = {"Events": events}

callbacks = {'powerState': power_state}

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    client = SinricPro(APP_KEY, [TEMPERATURE_SENSOR_ID],
                       callbacks,
                       event_callbacks=events_callbacks,
                       enable_log=True,
                       restore_states=False,
                       secretKey=APP_SECRET)
    loop.run_until_complete(client.connect())

# To update the temperature on server.
#client.event_handler.raiseEvent(temperatureSensorDeviceId, 'temperatureHumidityEvent', data={'humidity': 75.3, 'temperature': 24})
예제 #4
0
def onIncreaseColorTemperature(deviceId, value):
    return True, value


def onDecreaseColorTemperature(deviceId, value):
    return True, value


callbacks = {
    'powerState': onPowerState,
    'setBrightness': onSetBrightness,
    'adjustBrightness': onAdjustBrightness,
    'setColor': onSetColor,
    'setColorTemperature': onSetColorTemperature,
    'increaseColorTemperature': onIncreaseColorTemperature,
    'decreaseColorTemperature': onDecreaseColorTemperature
}

if __name__ == '__main__':
    client = SinricPro(appKey,
                       deviceId,
                       callbacks,
                       event_callbacks=eventsCallbacks,
                       enable_trace=False,
                       secretKey=secretKey)
    udp_client = SinricProUdp(callbacks)
    udp_client.enableUdpPrint(
        False
    )  # Set it to True to start logging request Offline Request/Response
    client.handle_all(udp_client)
예제 #5
0
from sinric import SinricPro
import asyncio

APP_KEY = ''
APP_SECRET = ''
LOCK_ID = ''


def lock_state(device_id, state):
    print(device_id, state)
    return True, state


callbacks = {'setLockState': lock_state}

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    client = SinricPro(APP_KEY, [LOCK_ID],
                       callbacks,
                       enable_log=True,
                       restore_states=False,
                       secretKey=APP_SECRET)
    loop.run_until_complete(client.connect())

# To update the lock state on server.
# client.event_handler.raiseEvent(lockId, 'setLockState',data={'state': 'LOCKED'})
# client.event_handler.raiseEvent(lockId, 'setLockState',data={'state': 'UNLOCKED'})
예제 #6
0
from sinric import SinricProUdp
from sinric import eventNames
from time import sleep
'''
DON'T FORGET TO TURN ON 'Doorbell Press' IN ALEXA APP
'''


def Events():
    while True:
        client.event_handler.raiseEvent(doorBellId,
                                        eventNames['door_bell_event'])
        sleep(2)


request_callbacks = {}

event_callbacks = {'Events': Events}

if __name__ == '__main__':
    client = SinricPro(appKey,
                       deviceId,
                       request_callbacks,
                       event_callbacks,
                       enable_trace=True,
                       enable_track=True)
    udp_client = SinricProUdp(request_callbacks)
    udp_client.enableUdpPrint(
        False)  # Set it to True to start printing request UDP JSON
    client.handle_all(udp_client)
예제 #7
0
from sinric import SinricPro
from sinric import SinricProUdp
from credentials import apiKey, deviceId


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


callbacks = {
    'powerState': onPowerState
}

if __name__ == '__main__':
    client = SinricPro(apiKey, deviceId, callbacks, enable_trace=False, enable_track=False)
    udp_client = SinricProUdp(callbacks)
    udp_client.enableUdpPrint(False)  # Set it to True to start printing request UDP JSON
    client.handle_all(udp_client)
예제 #8
0
def Events():
    while True:
        # Select as per your requirements
        # REMOVE THE COMMENTS TO USE

        # client.event_handler.raiseEvent(lockId, 'setLockState',data={'state': 'LOCKED'})
        # client.event_handler.raiseEvent(lockId, 'setLockState',data={'state': 'UNLOCKED'})
        sleep(2)


event_callback = {'Events': Events}


def onSetLockState(deviceId, state):
    return True, state


callbacks = {'setLockState': onSetLockState}

if __name__ == '__main__':
    client = SinricPro(apiKey,
                       deviceId,
                       callbacks,
                       event_callback,
                       enable_trace=True)
    udp_client = SinricProUdp(callbacks)
    udp_client.enableUdpPrint(
        False)  # Set it to True to start printing request UDP JSON
    client.handle_all(udp_client)
예제 #9
0
class ClientWrapper:
    """ ClientWrapper for comunicate classes and things.\n
    things -> [DimmerSwitch, Switch...] \n
    appKey -> d89f1***-****-****-****-************ \n
    secretKey -> 44d1d31-1c19-****-****-9bc96c34b5bb-d19f42dd-****-****-****-************"""
    
    logger = None
    events = {}
    deviceIdArr = []
    appKey = ""
    secretKey = ""

    def __init__(self, things : list, appKey : str, secretKey : str):
        for thing in things:
            thing.subscribe(self)
            self.deviceIdArr.append(thing.get_dev_id())
        self.appKey = appKey
        self.secretKey = secretKey
        
        
    
    def start(self):
        ''' Start clients and setup connection '''
        # Request callbacks
        callbs = {}
        if len(self.events) > 0:
            for key, receivers in self.events.items():
                callbs[key] = lambda dev_id, *arg, recv=receivers: self.run_match_dev_id(dev_id,recv,locals()['arg'])
        
        self.client = SinricPro(self.appKey, self.deviceIdArr, callbs, event_callbacks=self.eventsCallbacks, enable_log=False,restore_states=True,secretKey=self.secretKey)
        
        # Instantiate client (setup connections)
        udp_client = SinricProUdp(callbs, self.deviceIdArr,enable_trace=False)  # Set it to True to start logging request Offline Request/Response
        self.client.handle_all(udp_client)
        self.logger = client.logger
        self.logger.success("SinricProOO started!")

    def run_match_dev_id(self,dev_id,lista_thing_func,arg):
        #print("dev:",dev_id," | arg:",arg," | lista: ",lista_thing_func)
        for item in lista_thing_func:
            if item['thing'].get_dev_id() == dev_id:
                return item['func'](arg)
        return False
    
    def inscribe(self, thing, event_name, func):
        if not (event_name in self.events):
            self.events[event_name] = list()
        self.events[event_name].append({'thing':thing,'func':func})

    def raiseEvent(self, thing : Thing, event : str, dados):
        ''' Event listed on https://help.sinric.pro/pages/supported_devices.html '''
        self.client.event_handler.raiseEvent(thing.get_dev_id(), event,data=dados)
        



    def Events():
        pass
        # print("Evento.")
        # while True:
            # client.event_handler.raiseEvent(device1, 'setPowerState',data={'state': 'On'})
            # client.event_handler.raiseEvent(device1, 'setPowerLevel',data={'powerLevel': '95%'})
            #sleep(2)
            # pass

    eventsCallbacks={
        "Events": Events
    }
        
예제 #10
0
from sinric import SinricPro
import asyncio
from asyncio import sleep
from loguru import logger

APP_KEY = ''
APP_SECRET = ''
DEVICE_ID = ''


async def events():
    while True:
        client.event_handler.raiseEvent(DEVICE_ID,
                                        'pushNotification',
                                        data={'alert': "Hello there"})
        await sleep(
            60)  # Server will trottle / block IPs sending events too often.


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    client = SinricPro(APP_KEY, [DEVICE_ID], {},
                       event_callbacks=events,
                       enable_log=True,
                       restore_states=False,
                       secretKey=APP_SECRET)
    loop.run_until_complete(client.connect())