Esempio n. 1
0
    def wrapper(self: "BasicMQTTInterface", client: Client, userdata, message: MQTTMessage):
        try:
            if message.retain:
                logger.warning(
                    "Ignoring command: retained message topic={}, payload={}".format(
                        message.topic, str(message.payload.decode("utf-8"))
                    )
                )
                return

            if self.alarm is None:
                logger.warning(
                    "No alarm. Ignoring command: message topic={}, payload={}".format(
                        message.topic, str(message.payload.decode("utf-8"))
                    )
                )
                return

            logger.info(
                "message topic={}, payload={}".format(
                    message.topic,
                    str(message.payload.decode("utf-8"))
                )
            )

            topic = message.topic.split(cfg.MQTT_BASE_TOPIC)[1]

            topics = topic.split("/")

            if len(topics) < 3:
                logger.error(
                    "Invalid topic in mqtt message: {}".format(message.topic))
                return

            content = message.payload.decode("utf-8").strip()

            element = None
            if len(topics) >= 4:
                element = topics[3]

            call_soon_in_main_loop(func(self, ParsedMessage(topics, element, content)))
        except Exception:
            logger.exception("Failed to execute command")
Esempio n. 2
0
 def run(self):
     logger.debug(f"Issuing {self.command} to {self.partitions} ")
     call_soon_in_main_loop(self._control())
Esempio n. 3
0
def sendNotification(notification: Notification):
    call_soon_in_main_loop(
        pub.sendMessage(PREFIX + "notifications", notification=notification))
Esempio n. 4
0
def sendChange(change: Change):
    call_soon_in_main_loop(pub.sendMessage(PREFIX + "changes", change=change))
Esempio n. 5
0
def sendEvent(event: Event):
    call_soon_in_main_loop(pub.sendMessage(PREFIX + "events", event=event))
Esempio n. 6
0
def sendMessage(topicName: str, **msgData):
    call_soon_in_main_loop(pub.sendMessage(PREFIX + topicName, **msgData))