Ejemplo n.º 1
0
 def set_value(self, name, status):
     super().set_value(name, status)
     message = ""
     val = look_for_param(self.values, name)
     if (val.type == "binary"):
         if (int(status) == 1):
             message = val.high
         else:
             message = val.low
     elif (val.type == "number"):
         if (int(status) > int(val.high)):
             message = int(val.high)
         elif (int(status) < int(val.low)):
             message = int(val.low)
         else:
             message = int(status)
     else:
         message = status
     if (self.valueType == "json"):
         data = dict()
         data[val.address] = message
         data = json.dumps(data)
         get("Mqtt_MqttConnect").publish(self.coreAddress + "/set", data)
     else:
         alltopic = self.coreAddress + "/" + val.address
         get("Mqtt_MqttConnect").publish(alltopic, message)
Ejemplo n.º 2
0
 def updateTopic(self):
     zigbee = configManager.getConfig('zigbee')
     if not zigbee:
         logger.error("no zigbee config")
         return
     get("Mqtt_MqttConnect").publish(
         self.topic + "/bridge/request/options",
         '{"options": {"mqtt": {"base_topic":"' + zigbee['topic'] + '"}}}')
     self.topic = zigbee['topic']
Ejemplo n.º 3
0
 def connect(self):
     get("Mqtt_MqttValue").addConnect(DEVICE_NAME)
     try:
         logger.debug("mqtt conecting...")
         conf = configManager.getConfig("mqttBroker")
         self.mqttClient = mqtt.Client()
         self.mqttClient.username_pw_set(conf["user"], conf["password"])
         self.mqttClient.connect(conf["host"], int(conf["port"]))
         self.mqttClient.loop_start()
         self.mqttClient.on_message = self.on_message
         self.mqttClient.subscribe("#")
         logger.debug("mqtt conect")
         return self.mqttClient
     except Exception as e:
         logger.error(f'error connecting to mqtt {e}')
Ejemplo n.º 4
0
    def on_message(self, client, userdata, msg):
        try:
            logger.debug(
                f"mqtt message. topic:{msg.topic}, message:{str(msg.payload.decode('utf-8'))}"
            )
            for item in self.callbacks:
                f = self.callbacks[item]
                asyncio.run(f(msg.topic, str(msg.payload.decode('utf-8'))))
            get("Mqtt_MqttValue").setValueAtToken(
                msg.topic, str(msg.payload.decode('utf-8')))
            asyncio.run(
                self.history.add(msg.topic, str(msg.payload.decode('utf-8'))))

            # zigbeeInfoSearch(msg.topic,str(msg.payload.decode('utf-8')))
        except Exception as e:
            logger.error(f'error reception mqtt message {e}')
Ejemplo n.º 5
0
 def permission_join(self, state: bool):
     topic = self.topic + "/bridge/request/permit_join"
     get("Mqtt_MqttConnect").publish(topic, state)
Ejemplo n.º 6
0
 def reboot(self):
     topic = self.topic + "/bridge/request/restart"
     get("Mqtt_MqttConnect").publish(topic, "")
Ejemplo n.º 7
0
 def update_value(self, *args, **kwargs):
     if (self.valueType == "json"):
         data = dict()
         data[self.values[0].address] = ""
         data = json.dumps(data)
         get("Mqtt_MqttConnect").publish(self.coreAddress + "/get", data)
Ejemplo n.º 8
0
async def geter(auth_data: dict = Depends(token_dep)):
    get("Mqtt_MqttConnect").getHistory().clear()
    return "ok"
Ejemplo n.º 9
0
async def rename(data: RenameForm, auth_data: dict = Depends(token_dep)):
    get("Zigbee_ZigbeeCoordinator").zigbeeDeviceRename(data.name, data.newName)
    return "ok"
Ejemplo n.º 10
0
async def device(address: str, auth_data: dict = Depends(token_dep)):
    get("Zigbee_ZigbeeCoordinator").zigbeeDeviceDelete(address)
    return "ok"
Ejemplo n.º 11
0
async def devices(auth_data: dict = Depends(token_dep)):
    return get("Zigbee_ZigbeeInMessage").getDevices()
Ejemplo n.º 12
0
async def permit_join_set(data: PermitJoin,
                          auth_data: dict = Depends(token_dep)):
    get("Zigbee_ZigbeeCoordinator").permission_join(data.state)
    return "ok"
Ejemplo n.º 13
0
async def permit_join_get(auth_data: dict = Depends(token_dep)):
    return PermitJoin(state=get("Zigbee_ZigbeeInMessage").permit_join)
Ejemplo n.º 14
0
async def reboot(auth_data: dict = Depends(token_dep)):
    get("Zigbee_ZigbeeCoordinator").reboot()
    return "ok"
Ejemplo n.º 15
0
 def zigbeeDeviceRename(self, name: str, newName: str):
     topic = self.topic + "/bridge/request/device/rename"
     message = '{"from": "' + name + '", "to": "' + newName + '"}'
     get("Mqtt_MqttConnect").publish(topic, message)
Ejemplo n.º 16
0
 def zigbeeDeviceDelete(self, name):
     topic = self.topic + "/bridge/request/device/remove"
     message = '{"id": "' + name + '"}'
     get("Mqtt_MqttConnect").publish(topic, message)
Ejemplo n.º 17
0
async def gete(auth_data: dict = Depends(token_dep)):
    res = get("Mqtt_MqttConnect").getHistory().getTopicksAndLinc()
    if (res == None):
        return JSONResponse(status_code=400,
                            content={"message": "unknown error"})
    return res