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

Decrease timeout and update_interval in Xiaomi Miio integration #57339

Merged
merged 3 commits into from
Oct 17, 2021
Merged

Decrease timeout and update_interval in Xiaomi Miio integration #57339

merged 3 commits into from
Oct 17, 2021

Conversation

bieniu
Copy link
Member

@bieniu bieniu commented Oct 8, 2021

Breaking change

Proposed change

This PR:
- decreases data update timeout from 10 to 5 seconds (this is a local communication so 5 seconds is sufficient)

  • decreases data update interval from 60 to 15 seconds

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)
  • 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
  • The code has been formatted using Black (black --fast 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.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@probot-home-assistant
Copy link

This pull request needs to be manually signed off by @home-assistant/core before it can get merged.
(message by ReviewEnforcer)

@probot-home-assistant
Copy link

Hey there @rytilahti, @syssi, @starkillerOG, mind taking a look at this pull request as it has been labeled with an integration (xiaomi_miio) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

Copy link
Contributor

@jbouwh jbouwh left a comment

Choose a reason for hiding this comment

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

Looks good to me, since we have all data synced central place

@rytilahti
Copy link
Member

This might be problematic with my vacuum at least, as it relies on a re-try every update cycle (the internal python-miio timeout being 5s, so the updates take a bit longer). I'll give this a test later today, but maybe we should also adjust the the timeout for miio.Device() to be shorter?

@bieniu bieniu marked this pull request as draft October 8, 2021 15:46
@bieniu
Copy link
Member Author

bieniu commented Oct 8, 2021

I'm afraid to change timeout in pythin-miio. We could break something. Many custom components or other systems use this library and we don't know how this decreasing timeout will affect them.
So my proposition is to leave 10 seconds as timeout and use 20 seconds as update_interval.

@rytilahti
Copy link
Member

rytilahti commented Oct 12, 2021

Tested to work with non-cloud gen1 with timeout=10, update_interval=15. The timeout of 5s is too fast in some failure cases as python-miio itself has that as a default timeout, making it fail intermittently on cases where the device is not responsive for a reason or another. I created rytilahti/python-miio#1158 as a todo to reduce the timeouts in python-miio.

My previous recommendation for reducing the timeout in homeassistant using the construct parameter does not work as the method signatures are not consistent (rytilahti/python-miio#1156).

@bieniu bieniu marked this pull request as ready for review October 13, 2021 07:17
@jbouwh
Copy link
Contributor

jbouwh commented Oct 13, 2021

Looks good to me.

@@ -70,6 +70,9 @@

_LOGGER = logging.getLogger(__name__)

POLLING_TIMEOUT_SEC = 10
UPDATE_INTERVAL = timedelta(seconds=15)
Copy link
Member

Choose a reason for hiding this comment

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

Is this the most safe update interval in most cases?

Users that want a different update interval can turn off automatic polling and automate the update at their own update interval. This is built in when using config entries and the update coordinator or builtin basic polling entities.

So we should not decrease the default update interval at the risk of other problems due to some users needing a shorter interval.

Copy link
Member Author

Choose a reason for hiding this comment

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

We have been testing this change from @rytilahti for several days. The devices have no problems with the current values. But of course, we are not able to test all device models.

Before DataUpdateCoordinator implementing, the integration updated device state every 30 seconds. Maybe we should return to this value if you think the current value is too low.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, this seems to be working fine except on special cases (like watchdog rebooting the device because it has no cloud access) but I would be fine with 30s update interval, too.

Copy link
Member

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

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

Let's merge this now, and adjust/revert if necessary. Thanks a lot @bieniu for making me to take a look at the (not so great) backend lib behavior that should be fixed for the future release!

@rytilahti rytilahti merged commit 276345e into home-assistant:dev Oct 17, 2021
@bieniu bieniu deleted the xiaomi_miio/update_interval branch October 17, 2021 06:31
@bieniu
Copy link
Member Author

bieniu commented Oct 17, 2021

@rytilahti No problem, we accidentally found a place for improvement 😉

@github-actions github-actions bot locked and limited conversation to collaborators Oct 18, 2021
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.

Xiaomi Air Purifier/Humidifier update interval was made too high and not configurable
6 participants