Skip to content

Disable Home Connect appliance refresh when frequent disconnects are detected #142615

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

Conversation

Diegorro98
Copy link
Contributor

Proposed change

Some users face an issue where the appliance is reportedly to be connected repeatedly until the API rate limit hits.
This PR tries to avoid that by disabling the appliance refresh and creating an issue that the user can confirm to re-enable the refresh.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link

home-assistant bot commented Apr 9, 2025

Hey there @DavidMStraub, @MartinHjelmare, mind taking a look at this pull request as it has been labeled with an integration (home_connect) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of home_connect can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign home_connect Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@Diegorro98
Copy link
Contributor Author

i don't undertand why test are failing. test seems to be broken.
I was able to make them work at my devcontainer, and I rebuilt the devcontainer and stoped working.
I tried to get back commit by commit testing until a point I know it worked, which is 1cedacc. but they don't work neither...

@Diegorro98
Copy link
Contributor Author

More info:

@Diegorro98
Copy link
Contributor Author

Diegorro98 commented Apr 10, 2025

Seems like an issue related to Python 3.13.3and StrEnum, as the following statement is returning True when it should return False:

if event_key in SettingKey:

If you have _missing_ method defined, and it returns a value

class AEnumClass(StrEnum):

    @classmethod
    def _missing_(cls, value: object) -> "AEnumClass":
        """Return UNKNOWN for missing keys."""
        return cls.UNKNOWN

    UNKNOWN = "unknown"
    VALUE_1 = "value_1"
    VALUE_2 = "value_2"

value in AEnumClass will be always evaluated as True in python 3.13.3, but in python 3.13.2, any value different than the ones from the enumeration will be evaluated as False

But it you don't have it defined

class AEnumClass(StrEnum):

    VALUE_1 = "value_1"
    VALUE_2 = "value_2"

value in AEnumClass will be evaluated as true only if the value is in the Enumeration

@emontnemery
Copy link
Contributor

emontnemery commented Apr 10, 2025

@Diegorro98 OK, that's an interesting theory for the failing tests. But I don't think the tests are always failing, they seem to pass sometimes. Does the StrEnum issue account for that?
Also, is there an issue on CPython?

Edit: CPython 3.13.3 has this enum issue fixed, python/cpython#131045 this is the 3.13 PR: python/cpython#131167

@emontnemery
Copy link
Contributor

I can confirm that reverting the change in https://github.com/python/cpython/pull/131167 makes the home_connect tests pass

@emontnemery
Copy link
Contributor

Changing the enum check like this makes it work again with Python 3.13.3:

diff --git a/homeassistant/components/home_connect/coordinator.py b/homeassistant/components/home_connect/coordinator.py
index fb86bb2edc6..b30f60aea6b 100644
--- a/homeassistant/components/home_connect/coordinator.py
+++ b/homeassistant/components/home_connect/coordinator.py
@@ -208,7 +208,7 @@ class HomeConnectCoordinator(
                             events = self.data[event_message_ha_id].events
                             for event in event_message.data.items:
                                 event_key = event.key
-                                if event_key in SettingKey:
+                                if event_key in SettingKey.__members__:
                                     setting_key = SettingKey(event_key)
                                     if setting_key in settings:
                                         settings[setting_key].value = event.value

@MartinHjelmare
Copy link
Member

Should be fixed now with #142666 merged.

@Diegorro98 Diegorro98 marked this pull request as draft April 10, 2025 15:50
@Diegorro98
Copy link
Contributor Author

Diegorro98 commented Apr 10, 2025

Moving to draft as I'm not able to see the message description at the UI

@Diegorro98 Diegorro98 marked this pull request as ready for review April 10, 2025 16:04
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant home-assistant bot marked this pull request as draft April 11, 2025 09:31
@Diegorro98 Diegorro98 marked this pull request as ready for review April 11, 2025 17:33
@home-assistant home-assistant bot requested a review from MartinHjelmare April 11, 2025 17:33
Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@MartinHjelmare MartinHjelmare changed the title Disable specific updates for a Home Connect appliance when is done repeatedly Disable Home Connect appliance refresh when frequent disconnects are detected Apr 12, 2025
@MartinHjelmare MartinHjelmare merged commit eb19c7a into home-assistant:dev Apr 12, 2025
34 checks passed
@Diegorro98 Diegorro98 deleted the home_connect/disable_appliance_updates branch April 12, 2025 13:38
@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants