MQTT client module for the MySkoda server.
Inspired by https://github.com/YoSmart-Inc/yolink-api/tree/main
AbstractMqttClientWrapper
Bases: Protocol
Interface for an aiomqtt.Client wrapper.
We're using an interface so we can pass in a fake wrapper in tests. We're wrapping (technically subclassing) so we can add a clean public update_username_password method.
AioMqttClientWrapper
Bases: Client
set_connect_properties(fcm_token)
Set MQTTv5 CONNECT properties based on an FCM Token.update_username_password.
Similar to update_username_password, this must be set dynamically right before attempting to connect.
| Parameters: |
|
|---|
update_username_password(username, password)
Update the username and password set in an aiomqtt.Client object.
This isn't super clean since _client is a private member but it's just an instance of paho.mqtt.Client so unlikely to change.
We want the ability to update the username/pw so that MySkodaMqttClient can instantiate this in its init but defer setting the username/pw.
MySkodaMqttClient
A custom MQTT Client for MySkoda.
Connects to the MQTT broker and allows MySkoda to receive callbacks on MQTT events.
| Parameters: |
|
|---|
connect(user_id, vehicle_vins, connect_timeout=MQTT_CONNECT_TIMEOUT)
async
Connect to the MQTT broker and listen for messages for the given user_id and VINs.
Blocks until the initial subscription succeeds or connect_timeout seconds elapse.
On timeout the background reconnect loop is cancelled and a TimeoutError is raised
so the caller can decide what to do.
disconnect()
async
Cancel listener task and set self_running to False, causing the listen loop to end.
subscribe(callback)
Listen for events emitted by MySkoda's MQTT broker.
wait_for_operation(operation_name)
Wait until the next operation of the specified type completes.
OperationListener
Used to track callbacks to execute for a given OperationName.