8000 Fix ESPHome entities unavailable if deep sleep enabled after entry setup by oddstr13 · Pull Request #144970 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix ESPHome entities unavailable if deep sleep enabled after entry setup #144970

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

Merged
merged 5 commits into from
May 15, 2025

Conversation

oddstr13
Copy link
Contributor
@oddstr13 oddstr13 commented May 15, 2025

Proposed change

This change removes the entity-local caching of the device_info object.
This object is never updated with new metadata, but is replaced when the device connects, causing the cached object to become stale.

This is likely most often noticed as the device entities going unavailable when the device enters deep sleep, even if it disconnected properly.

To reproduce the issue;

  • Create a new ESPHome device with a few sensors (wifi RSSI for example)
  • Add it to Home Assistant
  • Configure the deep sleep component and update the device
  • Observe that the device's entities go unavailable when the device enters deep sleep

The reason for why this happens is that, even if the has_deep_sleep flag is properly picked up by HA, the entity objects are still holding on to an old copy of the device_info object, which still has the has_deep_sleep flag set to False.

The following actions will seemingly fix the issue (but only until the conditions are triggered again);

  • Deleting and re-adding the device
  • Restarting Home Assistant
  • Updating Home Assistant (restart)
  • Reloading the device configuration
    This can make it seem like updates have fixed the issue, but then reappear at a later time.

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

The debugging conversation can be found in this Discord thread on the ESPHome server.

Issue introduced with #94930

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:

Copy link
@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

Hi @oddstr13

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@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 May 15, 2025 12:18
@home-assistant
Copy link

Hey there @OttoWinter, @jesserockz, @kbx81, @bdraco, mind taking a look at this pull request as it has been labeled with an integration (esphome) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of esphome 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 esphome 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.

@oddstr13
Copy link
Contributor Author

apologies, accidentally submitted while filling in and formatting the PR message, give me a bit to complete it.

@oddstr13 oddstr13 changed the title Remove caching of device_info in ESPHome Fix ESPHome entities being Unavailable after enabling deep sleep May 15, 2025
@oddstr13 oddstr13 marked this pull request as ready for review May 15, 2025 13:18
@home-assistant home-assistant bot dismissed their stale review May 15, 2025 13:18

Stale

@bdraco
Copy link
Member
bdraco commented May 15, 2025

We should update the cached version when it changes instead so the entity isn't re-reading it every time.

@bdraco
Copy link
Member
bdraco commented May 15, 2025

This change will also need test coverage

@oddstr13
Copy link
Contributor Author

This change will also need test coverage

How would you suggest the testing be implemented?

@bdraco bdraco added this to the 2025.5.2 milestone May 15, 2025
@bdraco
Copy link
Member
bdraco commented May 15, 2025

We should update the cached version when it changes instead so the entity isn't re-reading it every time.

I made a tweak to only update it when it changes. Please check that it still solves the issue.

For a test we already have some that mock_disconnect, change device_info, and reconnect. We can copy one of those and adjust it for this case

@oddstr13
Copy link
Contributor Author

I was looking at the callback stuff right now, it's a bit complex to track down what it does, but if it indeed does what I think it might, that change looks good – I'll do some testing.

@oddstr13
Copy link
Contributor Author

Are PRs squash-merged, or should I clean up the git history? (when that time comes)

@bdraco bdraco changed the title Fix ESPHome entities being Unavailable after enabling deep sleep Fix ESPHome entities unavailable if deep sleep enabled after entry setup May 15, 2025
@bdraco
Copy link
Member
bdraco commented May 15, 2025

Are PRs squash-merged, or should I clean up the git history? (when that time comes)

everything is squashed at the end. ok to be a bit messy if you want

@bdraco bdraco marked this pull request as draft May 15, 2025 16:27
@bdraco bdraco marked this pull request as ready for review May 15, 2025 17:04
@oddstr13
Copy link
Contributor Author

The updated changes also fix the issue 👍

The new tests are also working, undoing the fix and it catches the problem.

@bdraco bdraco merged commit cc62943 into home-assistant:dev May 15, 2025
34 checks passed
@frenck frenck mentioned this pull request May 16, 2025
frenck added a commit that referenced this pull request May 16, 2025
Co-authored-by: Shay Levy <levyshay1@gmail.com>
Co-authored-by: Allen Porter <allen.porter@gmail.com>
Co-authored-by: Franck Nijhof <git@frenck.dev>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: TimL <tl@smlight.tech>
Co-authored-by: Seweryn Zeman <seweryn.zeman@jazzy.pro>
Co-authored-by: hahn-th <15319212+hahn-th@users.noreply.github.com>
Co-authored-by: Luke Lashley <conway220@gmail.com>
Co-authored-by: starkillerOG <starkiller.og@gmail.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
Co-authored-by: Arie Catsman <120491684+catsmanac@users.noreply.github.com>
Co-authored-by: Josef Zweck <josef@zweck.dev>
Co-authored-by: Simon Lamon <32477463+silamon@users.noreply.github.com>
Co-authored-by: Ruben van Dijk <15885455+RubenNL@users.noreply.github.com>
Co-authored-by: G Johansson <goran.johansson@shiftit.se>
Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
Co-authored-by: Thomas55555 <59625598+Thomas55555@users.noreply.github.com>
Co-authored-by: Øyvind Matheson Wergeland <oyvind@wergeland.org>
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>
Co-authored-by: Brett Adams <Bre77@users.noreply.github.com>
Co-authored-by: rjblake <richard.blake@gmail.com>
Co-authored-by: Daniel Hjelseth Høyer <github@dahoiv.net>
Co-authored-by: Matthias Alphart <farmio@alphart.net>
Co-authored-by: Erik Montnemery <erik@montnemery.com>
Co-authored-by: Robert Resch <robert@resch.dev>
Co-authored-by: Odd Stråbø <oddstr13@openshell.no>
Co-authored-by: puddly <32534428+puddly@users.noreply.github.com>
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
fix privacy mode availability for NVR IPC cams (#144569)
fix enphase_envoy diagnostics home endpoint name (#144634)
Close Octoprint aiohttp session on unload (#144670)
Fix strings typo for Comelit (#144672)
Fix wrong state in Husqvarna Automower (#144684)
Fix Netgear handeling of missing MAC in device registry (#144722)
Fix blocking call in azure storage (#144803)
Fix Z-Wave unique id after controller reset (#144813)
Fix blocking call in azure_storage config flow (#144818)
Fix wall connector states in Teslemetry (#144855)
Fix Reolink setup when ONVIF push is unsupported (#144869)
Fix some Home Connect translation strings (#144905)
Fix unknown Pure AQI in Sensibo (#144924)
Fix Home Assistant Yellow config entry data (#144948)
Fix ESPHome entities unavailable if deep sleep enabled after entry setup (#144970)
fix from ZHA event `unique_id` (#145006)
Fix climate idle state for Comelit (#145059)
Fix fan AC mode in SmartThings AC (#145064)
Fix Ecovacs mower area sensors (#145071)
@github-actions github-actions bot locked and limited conversation to collaborators May 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
6 participants
0