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")
def run(self): logger.debug(f"Issuing {self.command} to {self.partitions} ") call_soon_in_main_loop(self._control())
def sendNotification(notification: Notification): call_soon_in_main_loop( pub.sendMessage(PREFIX + "notifications", notification=notification))
def sendChange(change: Change): call_soon_in_main_loop(pub.sendMessage(PREFIX + "changes", change=change))
def sendEvent(event: Event): call_soon_in_main_loop(pub.sendMessage(PREFIX + "events", event=event))
def sendMessage(topicName: str, **msgData): call_soon_in_main_loop(pub.sendMessage(PREFIX + topicName, **msgData))