Asset Connector Documentation
Loading...
Searching...
No Matches
python_connector.mqtt.mqtt_client.MqttClient Class Reference

Connector for managing connections to MQTT topics. More...

Public Member Functions

 __init__ (self, str base_url, list[str] topics, IAuthenticationDetails auth)
 Initialize the MQTTConnector with broker host and port.
 
 connect (self)
 Connect to the MQTT broker and subscribe to all topics.
 
 start_async (self)
 Start the MQTT client loop in a separate thread for non-blocking operation.
 
 stop (self)
 Stop the MQTT client loop and disconnect from the broker.
 
 disconnect (self)
 Disconnect from the MQTT broker gracefully.
 
 dispose (self)
 Clean up resources and disconnect from the MQTT broker.
 
 __enter__ (self)
 Context manager entry point.
 
 __exit__ (self, exc_type, exc_val, exc_tb)
 Context manager exit point - ensures proper cleanup.
 
 add_topics (self, topics)
 Add topics to the MQTTConnector.
 
 get_cached_value (self, topic)
 Retrieve the cached value for a specific topic.
 
 publish (self, str topic, str payload)
 Publish a message to a specific topic.
 

Public Attributes

 cache
 
 base_url
 
 host
 
 port
 
 path
 
 client
 
 topics
 

Static Public Attributes

str base_url
 
str host
 
int port
 
str path
 

Protected Member Functions

 _parse_url (self)
 Extract host, port, and path from broker_url.
 
 _detect_transport (self)
 Determine if plain MQTT or MQTT over WebSocket is needed.
 
 _on_connect (self, client, userdata, flags, rc)
 Handle response from the server.
 
 _on_message (self, client, userdata, message)
 Handle incoming messages from subscribed topics.
 

Protected Attributes

 _is_connected
 

Properties

 is_connected = property
 

Detailed Description

Connector for managing connections to MQTT topics.

Definition at line 18 of file mqtt_client.py.

Constructor & Destructor Documentation

◆ __init__()

python_connector.mqtt.mqtt_client.MqttClient.__init__ (   self,
str  base_url,
list[str]  topics,
IAuthenticationDetails  auth 
)

Initialize the MQTTConnector with broker host and port.

Definition at line 26 of file mqtt_client.py.

Member Function Documentation

◆ __enter__()

python_connector.mqtt.mqtt_client.MqttClient.__enter__ (   self)

Context manager entry point.

Returns
The MQTTConnector instance.

Definition at line 171 of file mqtt_client.py.

◆ __exit__()

python_connector.mqtt.mqtt_client.MqttClient.__exit__ (   self,
  exc_type,
  exc_val,
  exc_tb 
)

Context manager exit point - ensures proper cleanup.

Parameters
exc_typeException type if an exception was raised.
exc_valException value if an exception was raised.
exc_tbException traceback if an exception was raised.

Definition at line 180 of file mqtt_client.py.

Here is the call graph for this function:

◆ _detect_transport()

python_connector.mqtt.mqtt_client.MqttClient._detect_transport (   self)
protected

Determine if plain MQTT or MQTT over WebSocket is needed.

Definition at line 78 of file mqtt_client.py.

◆ _on_connect()

python_connector.mqtt.mqtt_client.MqttClient._on_connect (   self,
  client,
  userdata,
  flags,
  rc 
)
protected

Handle response from the server.

Parameters
clientThe client instance for this callback.
userdataThe private user data as set in Client() or userdata_set().
flagsResponse flags sent by the broker.
rcThe connection result.

Definition at line 103 of file mqtt_client.py.

◆ _on_message()

python_connector.mqtt.mqtt_client.MqttClient._on_message (   self,
  client,
  userdata,
  message 
)
protected

Handle incoming messages from subscribed topics.

Parameters
clientThe client instance for this callback.
userdataThe private user data as set in Client() or userdata_set().
messageThe message instance containing topic and payload.

Definition at line 121 of file mqtt_client.py.

◆ _parse_url()

python_connector.mqtt.mqtt_client.MqttClient._parse_url (   self)
protected

Extract host, port, and path from broker_url.

Definition at line 54 of file mqtt_client.py.

◆ add_topics()

python_connector.mqtt.mqtt_client.MqttClient.add_topics (   self,
  topics 
)

Add topics to the MQTTConnector.

Definition at line 184 of file mqtt_client.py.

◆ connect()

python_connector.mqtt.mqtt_client.MqttClient.connect (   self)

Connect to the MQTT broker and subscribe to all topics.

   This method should be called after initializing the MQTTConnector.

Definition at line 87 of file mqtt_client.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ disconnect()

python_connector.mqtt.mqtt_client.MqttClient.disconnect (   self)

Disconnect from the MQTT broker gracefully.

Definition at line 142 of file mqtt_client.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dispose()

python_connector.mqtt.mqtt_client.MqttClient.dispose (   self)

Clean up resources and disconnect from the MQTT broker.

   This method should be called when the connector is no longer needed
   to ensure proper cleanup of resources.

Definition at line 150 of file mqtt_client.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_cached_value()

python_connector.mqtt.mqtt_client.MqttClient.get_cached_value (   self,
  topic 
)

Retrieve the cached value for a specific topic.

Parameters
topicThe topic to retrieve the cached value for.
Returns
The cached value if it exists, otherwise None.

Definition at line 192 of file mqtt_client.py.

◆ publish()

python_connector.mqtt.mqtt_client.MqttClient.publish (   self,
str  topic,
str  payload 
)

Publish a message to a specific topic.

Parameters
topicThe topic to publish the message to.
payloadThe message payload to be published.

Definition at line 206 of file mqtt_client.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_async()

python_connector.mqtt.mqtt_client.MqttClient.start_async (   self)

Start the MQTT client loop in a separate thread for non-blocking operation.

Returns
True if the loop started successfully, False otherwise.

Definition at line 133 of file mqtt_client.py.

◆ stop()

python_connector.mqtt.mqtt_client.MqttClient.stop (   self)

Stop the MQTT client loop and disconnect from the broker.

Definition at line 137 of file mqtt_client.py.

Here is the call graph for this function:

Member Data Documentation

◆ _is_connected

python_connector.mqtt.mqtt_client.MqttClient._is_connected
protected

Definition at line 46 of file mqtt_client.py.

◆ base_url [1/2]

str python_connector.mqtt.mqtt_client.MqttClient.base_url
static

Definition at line 20 of file mqtt_client.py.

◆ base_url [2/2]

python_connector.mqtt.mqtt_client.MqttClient.base_url

Definition at line 31 of file mqtt_client.py.

◆ cache

python_connector.mqtt.mqtt_client.MqttClient.cache

Definition at line 27 of file mqtt_client.py.

◆ client

python_connector.mqtt.mqtt_client.MqttClient.client

Definition at line 34 of file mqtt_client.py.

◆ host [1/2]

str python_connector.mqtt.mqtt_client.MqttClient.host
static

Definition at line 21 of file mqtt_client.py.

◆ host [2/2]

python_connector.mqtt.mqtt_client.MqttClient.host

Definition at line 32 of file mqtt_client.py.

◆ path [1/2]

str python_connector.mqtt.mqtt_client.MqttClient.path
static

Definition at line 23 of file mqtt_client.py.

◆ path [2/2]

python_connector.mqtt.mqtt_client.MqttClient.path

Definition at line 32 of file mqtt_client.py.

◆ port [1/2]

int python_connector.mqtt.mqtt_client.MqttClient.port
static

Definition at line 22 of file mqtt_client.py.

◆ port [2/2]

python_connector.mqtt.mqtt_client.MqttClient.port

Definition at line 32 of file mqtt_client.py.

◆ topics

python_connector.mqtt.mqtt_client.MqttClient.topics

Definition at line 185 of file mqtt_client.py.

Property Documentation

◆ is_connected

python_connector.mqtt.mqtt_client.MqttClient.is_connected = property
static

Definition at line 196 of file mqtt_client.py.


The documentation for this class was generated from the following file: