Class MqttPlugin new

The class MqttPlugin implements the base class of all smart-plugins that use MQTT. The implemented methods are described below.

In addition the methods implemented in lib.utils.Utils are inherited.

class lib.model.mqttplugin.MqttPlugin[source]

Bases: lib.model.smartplugin.SmartPlugin

start_subscriptions()[source]

Start subscription to all topics

Should be called from the run method of a plugin

stop_subscriptions()[source]

Stop subscription to all topics

Should be called from the stop method of a plugin

add_subscription(topic, payload_type, bool_values=None, item=None, callback=None)[source]

Add mqtt subscription to subscribed_topics list

subscribing is done directly, if subscriptions have been started by self.start_subscriptions()

Parameters
  • topic – topic to subscribe to

  • payload_type – payload type of the topic (for this subscription to the topic)

  • bool_values – bool values (for this subscription to the topic)

  • item – item that should receive the payload as value. Used by the standard handler (if no callback function is specified)

  • callback – a plugin can provide an own callback function, if special handling of the payload is needed

Returns

publish_topic(topic, payload, item=None, qos=None, retain=False, bool_values=None)[source]

Publish a topic to mqtt

Parameters
  • topic – topic to publish

  • payload – payload to publish

  • item – item (if relevant)

  • qos – qos for this message (optional)

  • retain – retain flag for this message (optional)

  • bool_values – bool values (for publishing this topic, optional)

Returns

broker_config = {}
broker_monitoring = False
get_broker_info()[source]
broker_uptime()[source]

Return formatted uptime of broker

mqtt_init()[source]

Dummy method - should not be called any more :return: Bool value True :rtype: bool