Connector for managing connections to MQTT topics.
More...
|
| | __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.
|
| |
|
| | _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.
|
| |
Connector for managing connections to MQTT topics.
Definition at line 18 of file mqtt_client.py.
◆ __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.
◆ __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_type | Exception type if an exception was raised. |
| exc_val | Exception value if an exception was raised. |
| exc_tb | Exception traceback if an exception was raised. |
Definition at line 180 of file mqtt_client.py.
◆ _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
-
| client | The client instance for this callback. |
| userdata | The private user data as set in Client() or userdata_set(). |
| flags | Response flags sent by the broker. |
| rc | The 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
-
| client | The client instance for this callback. |
| userdata | The private user data as set in Client() or userdata_set(). |
| message | The 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 |
|
) |
| |
◆ 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.
◆ disconnect()
| python_connector.mqtt.mqtt_client.MqttClient.disconnect |
( |
|
self | ) |
|
Disconnect from the MQTT broker gracefully.
Definition at line 142 of file mqtt_client.py.
◆ 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.
◆ get_cached_value()
| python_connector.mqtt.mqtt_client.MqttClient.get_cached_value |
( |
|
self, |
|
|
|
topic |
|
) |
| |
Retrieve the cached value for a specific topic.
- Parameters
-
| topic | The 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
-
| topic | The topic to publish the message to. |
| payload | The message payload to be published. |
Definition at line 206 of file mqtt_client.py.
◆ 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.
◆ _is_connected
| python_connector.mqtt.mqtt_client.MqttClient._is_connected |
|
protected |
◆ base_url [1/2]
| str python_connector.mqtt.mqtt_client.MqttClient.base_url |
|
static |
◆ base_url [2/2]
| python_connector.mqtt.mqtt_client.MqttClient.base_url |
◆ cache
| python_connector.mqtt.mqtt_client.MqttClient.cache |
◆ client
| python_connector.mqtt.mqtt_client.MqttClient.client |
◆ host [1/2]
| str python_connector.mqtt.mqtt_client.MqttClient.host |
|
static |
◆ host [2/2]
| python_connector.mqtt.mqtt_client.MqttClient.host |
◆ path [1/2]
| str python_connector.mqtt.mqtt_client.MqttClient.path |
|
static |
◆ path [2/2]
| python_connector.mqtt.mqtt_client.MqttClient.path |
◆ port [1/2]
| int python_connector.mqtt.mqtt_client.MqttClient.port |
|
static |
◆ port [2/2]
| python_connector.mqtt.mqtt_client.MqttClient.port |
◆ topics
| python_connector.mqtt.mqtt_client.MqttClient.topics |
◆ is_connected
| python_connector.mqtt.mqtt_client.MqttClient.is_connected = property |
|
static |
The documentation for this class was generated from the following file: