def test_reportEvent(self):
     config = {"productKey":"a1ICUKj3Pyf", "deviceName":"Hb9TYuRNqqw445xGYmu3"}
     client = lethingaccesssdk.ThingAccessClient(config)
     demo = Demo_device()
     client.registerAndonline(demo)
     try:
         client.reportEvent("eventName", "abcd")
     except Exception as e:
         logging.error(e)
     client.offline()
 def test_reportProperty1(self):
     config = {"productKey":"a1ICUKj3Pyf", "deviceName":"Hb9TYuRNqqw445xGYmu3"}
     client = lethingaccesssdk.ThingAccessClient(config)
     demo = Demo_device()
     client.registerAndonline(demo)
     property = {"property1":"values"}
     try:
         client.reportProperties(property)
     except Exception as e:
         logging.error(e)    
     client.offline()
        else:
            return -1, {}

    def setProperties(self, input_value):
        if "illuminance" in input_value:
            self.illuminance = input_value["illuminance"]
            return 0, {}


try:
    driver_conf = json.loads(os.environ.get("FC_DRIVER_CONFIG"))
    if "deviceList" in driver_conf and len(driver_conf["deviceList"]) > 0:
        device_list_conf = driver_conf["deviceList"]
        config = device_list_conf[0]
        light_sensor = Light_Sensor()
        client = lethingaccesssdk.ThingAccessClient(config)
        client.registerAndonline(light_sensor)
        while True:
            time.sleep(1)
            propertiesDict = {"illuminance": light_sensor.illuminance}
            client.reportProperties(propertiesDict)
            if light_sensor.illuminance == 600:
                light_sensor.illuminance = 100
            else:
                light_sensor.illuminance = light_sensor.illuminance + 100
except Exception as e:
    logging.error(e)


def handler(event, context):
Пример #4
0
    def __init__(self, opcdaClient, config):
        self.opcdaClient = opcdaClient
        self.cloudClient = lethingaccesssdk.ThingAccessClient(config)

        self.reportType = opcdaConfig.OPC_REPORT_TYPE_TIMER
        if "reportType" in config["custom"]:
            if config["custom"]["reportType"] == 1:
                self.reportType = opcdaConfig.OPC_REPORT_TYPE_CHANGE

        self.deviceConfig = config
        self.deviceName = config["custom"]["devicePath"]
        '''
        {
            "alibaba.aliyun.iot.led.led1.temperature": 
            {
                "identifier": "temperature",
                "itemMode" : "rw",
                "itemType" : "dataType": {
                                "specs": {
                                    "min": "-100",
                                    "max": "1000",
                                    "step": "1"
                                },
                                "type": "int"
                            }
            },
            "alibaba.aliyun.iot.led.led1.power": 
            {
                "identifier": "power",
                "itemMode" : "rw",
                "itemType" : "dataType": {
                                "specs": {
                                    "min": "0",
                                    "max": "1",
                                    "step": "1"
                                },
                                "type": "int"
                            }
            }
        }
        '''
        self.deviceModel = {}
        '''
        {
            "temperature":"alibaba.aliyun.iot.led.led1.temperature"
        }
        '''
        self.identifier2ItemId = {}
        '''
        {
            "alibaba.aliyun.iot.led.led1.temperature":"temperature"
        }
        '''
        self.itemId2Identifier = {}

        self.deviceItemList = []
        '''
        {
            "alibaba.aliyun.iot.led.led1.temperature":
            {
                "itemName" : "temperature",
                "itemValue": 50,
                "itemQuality": "Good",
                "itemTimestamp": 1569554708,
            }
        }
        '''
        self.deviceItemData = {}
 def __init__(self, config, light):
     self.light = light
     self._client = lethingaccesssdk.ThingAccessClient(config)
Пример #6
0
        '''
        return 0, {}


def thing_behavior(client, app_callback):
    while True:
        properties = {
            "temperature": app_callback.temperature,
            "humidity": app_callback.humidity
        }
        client.reportProperties(properties)
        client.reportEvent("high_temperature", {"temperature": 41})
        time.sleep(2)


try:
    infos = lethingaccesssdk.Config().getThingInfos()
    for info in infos:
        app_callback = Temperature_device()
        client = lethingaccesssdk.ThingAccessClient(info)
        client.registerAndOnline(app_callback)
        t = Timer(2, thing_behavior, (client, app_callback))
        t.start()
except Exception as e:
    logging.error(e)


# don't remove this function
def handler(event, context):
    return 'hello world'
 def test_registerAndonline3(self):
     config = {"productKey":"a1ICUKj3Pyf", "deviceName":"Hb9TYuRNqqw445xGYmu3"} # wrong callback
     client = lethingaccesssdk.ThingAccessClient(config)
     demo = None
     client.registerAndonline(demo)
 def test_registerAndonline2(self):
     config = {"productKey":123456, "deviceName":"Hb9TYuRNqqw445xGYmu3"} # wrong pk or dn
     client = lethingaccesssdk.ThingAccessClient(config)
     demo = Demo_device()
     client.registerAndonline(demo)
 def test_registerAndonline1(self):
     config = {"productKey":"a1ICUKj3Pyf"} # miss parameter
     client = lethingaccesssdk.ThingAccessClient(config)
     demo = Demo_device()
     client.registerAndonline(demo)
 def test_registerAndonline(self):
     config = 123 # wrong type
     client = lethingaccesssdk.ThingAccessClient(config)
     demo = Demo_device()
     client.registerAndonline(demo)