energomera_hass_mqtt.mqtt_client
The package provides additional functionality over aiomqtt.
Classes
Class providing dummy functionality of asyncio.Lock - that is, no locking is actually done and it reports being always unlocked. |
|
|
The class extends the aiomqtt.Client to provide better convenience working with last wills. |
- class energomera_hass_mqtt.mqtt_client.DummyLock
Bases:
LockClass providing dummy functionality of asyncio.Lock - that is, no locking is actually done and it reports being always unlocked.
- class energomera_hass_mqtt.mqtt_client.MqttClient(*args, dry_run=False, **kwargs)
Bases:
ClientThe class extends the aiomqtt.Client to provide better convenience working with last wills. Namely, the original class only allows setting the last will thru its constructor, while the EnergomeraHassMqtt consuming it only has required property for that around actual publish calls.
- Parameters:
- async connect()
Connects to MQTT broker using __aenter__ method of the base class as recommended in https://github.com/sbtinstruments/aiomqtt/blob/main/docs/migration-guide-v2.md. Multiple calls will result only in single call to __aenter__() method of parent class if the MQTT client needs a connection (not being connected or got disconnected), to allow the method to be called within a process loop with no risk of hitting non-reentrant error from base class.
- Return type:
- async disconnect()
Disconnects from MQTT broker using __aexit__ method of the base class as per migration guide above.
- Return type:
- async publish(*args, **kwargs)
Publishes a message to the MQTT broker.
- will_set(*args, **kwargs)
Allows setting last will to the underlying MQTT client.
Skips updating the last will if one has already been set (either via the method or through the constructor).
- property identifier: str
The client’s identifier.
Note that paho-mqtt stores the client ID as bytes internally. We assume that the client ID is a UTF8-encoded string and decode it first.
- property messages: MessagesIterator
Dynamic view of the client’s message queue.
- async subscribe(topic, qos=0, options=None, properties=None, *args, timeout=None, **kwargs)
Subscribe to a topic or wildcard.
- Args:
topic: The topic or wildcard to subscribe to. qos: The requested QoS level for the subscription. options: (MQTT v5.0 only) Optional paho-mqtt subscription options. properties: (MQTT v5.0 only) Optional paho-mqtt properties. *args: Additional positional arguments to pass to paho-mqtt’s subscribe
method.
- timeout: The maximum time in seconds to wait for the subscription to
complete. Use
math.infto wait indefinitely.- **kwargs: Additional keyword arguments to pass to paho-mqtt’s subscribe
method.
- async unsubscribe(topic, properties=None, *args, timeout=None, **kwargs)
Unsubscribe from a topic or wildcard.
- Return type:
- Args:
topic: The topic or wildcard to unsubscribe from. properties: (MQTT v5.0 only) Optional paho-mqtt properties. *args: Additional positional arguments to pass to paho-mqtt’s unsubscribe
method.
- timeout: The maximum time in seconds to wait for the unsubscription to
complete. Use
math.infto wait indefinitely.- **kwargs: Additional keyword arguments to pass to paho-mqtt’s unsubscribe
method.