def on_message(self, msgid, content): logger.info(u"MQ: New pub message {0}".format(msgid)) logger.info(u"MQ: {0}".format(content)) if isinstance(content["stored_value"], list): content["stored_value"] = content["stored_value"][0] logger.error(u"MQ: PATCH for issue #1976") # If sensor stat, we update the sensor last value if msgid == 'device-stats': Sensor.update(content["sensor_id"], content["timestamp"], content["stored_value"]) WSHandler.sendAllMessage([msgid, content])
def on_message(self, msgid, content): #logger.info(u"MQ: New pub message {0}".format(msgid)) #logger.info(u"MQ: {0}".format(content)) if isinstance(content["stored_value"], list): content["stored_value"] = content["stored_value"][0] logger.error(u"MQ: PATCH for issue #1976") # If sensor stat, we update the sensor last value if msgid == 'device-stats': Sensor.update(content["sensor_id"], content["timestamp"], content["stored_value"]) WSHandler.sendAllMessage([msgid, content])
def on_message(self, msgid, content): #logger.info(u"MQ: New pub message {0}".format(msgid)) #logger.info(u"MQ: {0}".format(content)) # If sensor stat, we update the sensor last value if msgid == 'device-stats': if isinstance(content["stored_value"], list): content["stored_value"] = content["stored_value"][0] logger.error(u"MQ: PATCH for issue #1976") Sensor.update(content["sensor_id"], content["timestamp"], content["stored_value"]) WSHandler.sendAllMessage([msgid, content]) elif msgid == 'device.update': logger.info("MQ: message 'device.update' catched! Reloading the devices list") mqDataLoader.loadDevices(options.develop)
def addField(cls, option): types = json.loads(option.types) for t in types: types += DataType.getChilds(id=t) sensors = Sensor.getTypesFilter(types=types) if (option.group): cls.addGroupModelChoiceField(key=option.key, label=option.name, min=option.groupmin, max=option.groupmax, queryset=sensors, group_by_field='device_id', empty_label="--Select Sensor--", help_text=option.description) else: cls.addModelChoiceField(key=option.key, label=option.name, required=option.required, queryset=sensors, group_by_field='device_id', empty_label="--Select Sensor--", help_text=option.description)
def loadDevices(cls, develop): logger.info(u"MQ: Loading Devices info") Device.clean() msg = MQMessage() msg.set_action('client.list.get') res = cli.request('manager', msg.get(), timeout=10) if res is not None: _datac = res.get_data() else: _datac = {} session = Session() for client in _datac.itervalues(): # for each plugin client, we request the list of devices if client["type"] == "plugin": msg = MQMessage() msg.set_action('device.get') msg.add_data('type', 'plugin') msg.add_data('name', client["name"]) msg.add_data('host', client["host"]) logger.info( u"MQ: Get devices list for client {0}-{1}.{2}".format( "plugin", client["name"], client["host"])) res = cli.request('dbmgr', msg.get(), timeout=10) if res is not None: _datad = res.get_data() else: _datad = {} if 'devices' in _datad: for device in _datad["devices"]: logger.info(u"- {0}".format(device["name"])) d = Device(id=device["id"], name=device["name"], type=device["device_type_id"], reference=device["reference"]) session.add(d) if "commands" in device: for ref, command in device["commands"].iteritems(): c = Command(id=command["id"], name=command["name"], device_id=device["id"], reference=ref, return_confirmation=command[ "return_confirmation"]) session.add(c) c.datatypes = "" for param in command["parameters"]: p = CommandParam( command_id=c.id, key=param["key"], datatype_id=param["data_type"]) session.add(p) c.datatypes += param["data_type"] session.add(c) if "sensors" in device: for ref, sensor in device["sensors"].iteritems(): s = Sensor( id=sensor["id"], name=sensor["name"], device_id=device["id"], reference=ref, datatype_id=sensor["data_type"], last_value=sensor["last_value"], last_received=sensor["last_received"], timeout=sensor["timeout"]) session.add(s) session.commit() session.flush()