Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor new client initialization process to non-blocking call #212

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## v1.0.16

- Refactor new client initialization process to non-blocking call
- Improved log messages of status changes
- Removed vacuum actions
- Turn on - not supported
Expand Down
63 changes: 35 additions & 28 deletions custom_components/mydolphin_plus/managers/aws_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,36 +199,10 @@ async def initialize(self):

self._topic_data = TopicData(motor_unit_serial)

credentials_provider = auth.AwsCredentialsProvider.new_static(
aws_key, aws_secret, aws_token
)

ca_content = await self._get_certificate()

client = mqtt_connection_builder.websockets_with_default_aws_signing(
endpoint=AWS_IOT_URL,
port=AWS_IOT_PORT,
region=AWS_REGION,
ca_bytes=ca_content,
credentials_provider=credentials_provider,
client_id=self._awsiot_id,
clean_session=False,
keep_alive_secs=30,
on_connection_success=self._connection_callbacks.get(
ConnectionCallbacks.SUCCESS
),
on_connection_failure=self._connection_callbacks.get(
ConnectionCallbacks.FAILURE
),
on_connection_closed=self._connection_callbacks.get(
ConnectionCallbacks.CLOSED
),
on_connection_interrupted=self._connection_callbacks.get(
ConnectionCallbacks.INTERRUPTED
),
on_connection_resumed=self._connection_callbacks.get(
ConnectionCallbacks.RESUMED
),
client = await self._hass.async_add_executor_job(
self._get_client, aws_key, aws_secret, aws_token, ca_content
)

def _on_connect_future_completed(future):
Expand All @@ -248,6 +222,39 @@ def _on_connect_future_completed(future):

self._set_status(ConnectivityStatus.Failed, message)

def _get_client(self, aws_key, aws_secret, aws_token, ca_content):
credentials_provider = auth.AwsCredentialsProvider.new_static(
aws_key, aws_secret, aws_token
)

client = mqtt_connection_builder.websockets_with_default_aws_signing(
endpoint=AWS_IOT_URL,
port=AWS_IOT_PORT,
region=AWS_REGION,
ca_bytes=ca_content,
credentials_provider=credentials_provider,
client_id=self._awsiot_id,
clean_session=False,
keep_alive_secs=30,
on_connection_success=self._connection_callbacks.get(
ConnectionCallbacks.SUCCESS
),
on_connection_failure=self._connection_callbacks.get(
ConnectionCallbacks.FAILURE
),
on_connection_closed=self._connection_callbacks.get(
ConnectionCallbacks.CLOSED
),
on_connection_interrupted=self._connection_callbacks.get(
ConnectionCallbacks.INTERRUPTED
),
on_connection_resumed=self._connection_callbacks.get(
ConnectionCallbacks.RESUMED
),
)

return client

def _subscribe(self):
_LOGGER.debug(f"Subscribing topics: {self._topic_data.subscribe}")

Expand Down
Loading