Skip to content

Update climate.py#29

Open
Big-Szu wants to merge 1 commit into
floringhimie:mainfrom
Big-Szu:patch-1
Open

Update climate.py#29
Big-Szu wants to merge 1 commit into
floringhimie:mainfrom
Big-Szu:patch-1

Conversation

@Big-Szu
Copy link
Copy Markdown

@Big-Szu Big-Szu commented Jan 7, 2025

Improved Asynchronous Handling:

Replaced blocking HTTP requests with non-blocking aiohttp requests for better performance and integration with Home Assistant's asynchronous framework.

Session Management:

Introduced a single aiohttp.ClientSession initialized in the __init__ method to avoid repeatedly creating new sessions, which can lead to resource exhaustion.
Added a close method to properly close the session when the component is unloaded.

Token Expiry Handling:

Added logic to detect expired tokens (HTTP 401) and automatically re-authenticate by fetching a new token and retrying the failed request.

Error Handling Enhancements:

Introduced detailed exception handling for network-related issues (aiohttp.ClientError) and JSON decoding errors to prevent the component from crashing and improve error logging.

Concurrency Protection:

Added an asyncio.Lock to ensure that multiple calls to async_update do not lead to race conditions when updating thermostat data.

Content Type Validation:

Enhanced the _get_data method to handle responses with text/html content type that contain valid JSON data, ensuring robust parsing.

Code Refactoring for Logging:

Improved logging by providing more detailed and descriptive messages, including response status and error details, while avoiding logging sensitive data (e.g., tokens).

Improved Asynchronous Handling:

    Replaced blocking HTTP requests with non-blocking aiohttp requests for better performance and integration with Home Assistant's asynchronous framework.

Session Management:

    Introduced a single aiohttp.ClientSession initialized in the __init__ method to avoid repeatedly creating new sessions, which can lead to resource exhaustion.
    Added a close method to properly close the session when the component is unloaded.

Token Expiry Handling:

    Added logic to detect expired tokens (HTTP 401) and automatically re-authenticate by fetching a new token and retrying the failed request.

Error Handling Enhancements:

    Introduced detailed exception handling for network-related issues (aiohttp.ClientError) and JSON decoding errors to prevent the component from crashing and improve error logging.

Concurrency Protection:

    Added an asyncio.Lock to ensure that multiple calls to async_update do not lead to race conditions when updating thermostat data.

Content Type Validation:

    Enhanced the _get_data method to handle responses with text/html content type that contain valid JSON data, ensuring robust parsing.

Code Refactoring for Logging:

    Improved logging by providing more detailed and descriptive messages, including response status and error details, while avoiding logging sensitive data (e.g., tokens).
@kmaid
Copy link
Copy Markdown

kmaid commented Mar 9, 2025

I forked and merged this pr into a new repo https://github.com/kmaid/salusfy which works with hacs and latest HA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants