Skip to content

Conversation

@abmantis
Copy link
Member

@abmantis abmantis commented Oct 2, 2025

Proposed change

The desk sends a lot of updates when moving. This adds a debounce to reduce the number of state updates.

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

  • I understand the code I am submitting and can explain how it works.
  • 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.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

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
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements debouncing for the Idasen Desk integration to reduce the frequency of state updates when the desk is moving. The desk sends frequent updates during movement, which can overwhelm Home Assistant with unnecessary state changes.

Key changes:

  • Added a debouncer with 0.2-second delay to coordinator updates
  • Updated test files to accommodate the new debouncing behavior
  • Introduced proper time-based testing using freezegun

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
homeassistant/components/idasen_desk/coordinator.py Added debouncing logic with 0.2s cooldown to handle desk updates more efficiently
tests/components/idasen_desk/__init__.py Added UPDATE_DEBOUNCE_TIME constant for consistent test timing
tests/components/idasen_desk/test_sensor.py Updated tests to handle debounced updates with proper time manipulation
tests/components/idasen_desk/test_cover.py Updated tests to handle debounced updates with proper time manipulation

@abmantis abmantis added this to the 2025.10.1 milestone Oct 2, 2025
@erwindouna
Copy link
Contributor

The Data Update Coordinator also implements a debouncer. That's set to 10 seconds.
How does this work with the Debouncer of the generic DUC?

logger=_LOGGER,
cooldown=UPDATE_DEBOUNCE_TIME,
immediate=True,
function=async_update_data,
Copy link
Member

Choose a reason for hiding this comment

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

I am only wondering if a lambda would be more readable here

Copy link
Member

Choose a reason for hiding this comment

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

Agree in a way, but let's move forward to get this into the patch 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

It needs to have the @callback decorator so it runs in the event loop. Otherwise:

Detected that integration 'idasen_desk' calls async_write_ha_state from a thread other than the event loop, which may cause Home Assistant to crash or data to

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

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

Thanks, @abmantis 👍

../Frenck

@frenck frenck merged commit 3f9421a into dev Oct 3, 2025
34 checks passed
@frenck frenck deleted the idasen_debounce branch October 3, 2025 16:39
frenck pushed a commit that referenced this pull request Oct 3, 2025
@frenck frenck mentioned this pull request Oct 3, 2025
@abmantis
Copy link
Member Author

abmantis commented Oct 3, 2025

The Data Update Coordinator also implements a debouncer. That's set to 10 seconds. How does this work with the Debouncer of the generic DUC?

The Coordinator's Debouncer works only for polling use cases, not when using async_set_updated_data() for push-based integrations.
I considered implementing _async_update_data() and using async_request_refresh() to use the coordinator's debouncer, but I don't really need all the complexity that the coordinator has for poll-based data, so async_set_updated_data() seemed better here.

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

Ikea Idasen Desk intermittently pauses during raising / lowering due to frequent height updates

5 participants