diff --git a/CHANGELOG.md b/CHANGELOG.md index a54448c..df932f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## v1.0.10 + +- Update manifest requirements to use only AWS IoT Device SDK v2 +- Fix parameter of callback to the right convention +- Fix AWS IoT MQTT publish message validation and QoS +- Change clean_session parameter to start a new session on every attempt to connect +- Set the AWS Client ID to the entry ID instead of randomize on every attempt to connect +- Set message being sent while publishing empty message to empty JSON instead of empty string + ## v1.0.9 - Upgrade AWS IoT Device SDK to v2 diff --git a/custom_components/mydolphin_plus/managers/aws_client.py b/custom_components/mydolphin_plus/managers/aws_client.py index e07e931..15eed02 100644 --- a/custom_components/mydolphin_plus/managers/aws_client.py +++ b/custom_components/mydolphin_plus/managers/aws_client.py @@ -7,7 +7,6 @@ import sys from time import sleep from typing import Any -import uuid from awscrt import auth, mqtt from awsiot import mqtt_connection_builder @@ -95,6 +94,7 @@ def __init__(self, hass: HomeAssistant | None, config_manager: ConfigManager): try: self._hass = hass self._config_manager = config_manager + self._awsiot_id = config_manager.entry_id self._api_data = {} self._data = {} @@ -165,7 +165,6 @@ async def initialize(self): self._set_status(ConnectivityStatus.Connecting) - awsiot_id = str(uuid.uuid4()) aws_token = self._api_data.get(API_RESPONSE_DATA_TOKEN) aws_key = self._api_data.get(API_RESPONSE_DATA_ACCESS_KEY_ID) aws_secret = self._api_data.get(API_RESPONSE_DATA_SECRET_ACCESS_KEY) @@ -192,10 +191,9 @@ async def initialize(self): region=AWS_REGION, ca_filepath=ca_file_path, credentials_provider=credentials_provider, - client_id=awsiot_id, - clean_session=False, + client_id=self._awsiot_id, + clean_session=True, keep_alive_secs=30, - http_proxy_options=None, on_connection_success=self._connection_callbacks.get( ConnectionCallbacks.SUCCESS ), @@ -288,7 +286,7 @@ def _on_connection_closed(self, connection, callback_data): self._set_status(ConnectivityStatus.Disconnected) - def _on_connection_interrupted(self, _connection, error, **_kwargs): + def _on_connection_interrupted(self, connection, error, **_kwargs): _LOGGER.error(f"AWS IoT connection interrupted, Error: {error}") self._set_status(ConnectivityStatus.Failed) @@ -411,19 +409,23 @@ def _send_dynamic_command(self, description: str, payload: dict | None): self._publish(self._topic_data.dynamic, payload) def _publish(self, topic: str, data: dict | None): - payload = "" if data is None else json.dumps(data) + if data is None: + data = {} + + payload = json.dumps(data) if self._status == ConnectivityStatus.Connected: try: if self._awsiot_client is not None: - published = self._awsiot_client.publish( - topic, payload, mqtt.QoS.AT_LEAST_ONCE + _LOGGER.debug(f"Trying to publish message {payload} to {topic}") + + publish_future, packet_id = self._awsiot_client.publish( + topic, payload, mqtt.QoS.AT_MOST_ONCE ) - if published: - _LOGGER.debug(f"Published message: {data} to {topic}") - else: - _LOGGER.warning(f"Failed to publish message: {data} to {topic}") + publish_future.result() + + _LOGGER.debug(f"Published message: {data} to {topic}") except Exception as ex: _LOGGER.error( diff --git a/custom_components/mydolphin_plus/manifest.json b/custom_components/mydolphin_plus/manifest.json index 38538b7..d195ed7 100644 --- a/custom_components/mydolphin_plus/manifest.json +++ b/custom_components/mydolphin_plus/manifest.json @@ -8,6 +8,6 @@ "documentation": "https://github.com/sh00t2kill/dolphin-robot", "iot_class": "cloud_push", "issue_tracker": "https://github.com/sh00t2kill/dolphin-robot/issues", - "requirements": ["awscrt~=0.20.2", "awsiotsdk~=1.21.0"], - "version": "1.0.9" + "requirements": ["awsiotsdk"], + "version": "1.0.10" }