Skip to content

Conversation

@LaStrada
Copy link
Contributor

@LaStrada LaStrada commented Nov 2, 2025

Breaking change

Proposed change

Adjusting the scan interval for the Airthings Corentium Home 2 to avoid a known firmware issue where the device may stop advertising over BLE when too many BLE connections occur. This appears to be triggered over time when scanning frequently. For me personally, the device has stopped advertising after 20–90 days when using a 5-minute scan interval. By increasing the scan interval to 30 minutes, the device continues advertising reliably for much longer.

Longer scan interval will also improve the battery life, which makes sense for this product since most users will place it in the basement or similar and rarely interact with it.

We can revisit this change later once more information about the firmware bug is available, or if user feedback indicates that they prefer more frequent updates at the expense of battery life.

Would be nice to get this in 2025.11.0

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

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

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:

@home-assistant
Copy link

home-assistant bot commented Nov 2, 2025

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

Code owner commands

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

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 adds dynamic scan interval adjustment for the Airthings BLE integration based on device type. Specifically, it increases the polling interval to 30 minutes (1800 seconds) for Corentium Home 2 devices, which are radon-only monitors that don't need frequent polling, while keeping the default 5-minute interval for other device types.

  • Adds logic to adjust the coordinator's update interval to 30 minutes when a Corentium Home 2 device is detected
  • Introduces a new constant RADON_SCAN_INTERVAL (1800 seconds) for radon-only devices
  • Adds comprehensive test coverage for the scan interval adjustment behavior

Reviewed Changes

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

File Description
homeassistant/components/airthings_ble/const.py Adds RADON_SCAN_INTERVAL constant for radon-specific devices
homeassistant/components/airthings_ble/coordinator.py Implements dynamic scan interval adjustment based on device model type
tests/components/airthings_ble/init.py Adds test fixture for Corentium Home 2 device
tests/components/airthings_ble/test_coordinator.py Adds parametrized tests to verify scan interval adjustment for different device types


from . import CORENTIUM_HOME_2_DEVICE_INFO, WAVE_DEVICE_INFO, WAVE_ENHANCE_DEVICE_INFO

from tests.components.bluetooth import MockConfigEntry, generate_ble_device
Copy link

Copilot AI Nov 2, 2025

Choose a reason for hiding this comment

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

Incorrect import path for MockConfigEntry. The tests.components.bluetooth module does not export MockConfigEntry in its all list. Import MockConfigEntry from tests.common instead, matching the pattern used in other test files in this integration.

Suggested change
from tests.components.bluetooth import MockConfigEntry, generate_ble_device
from tests.common import MockConfigEntry
from tests.components.bluetooth import generate_ble_device

Copilot uses AI. Check for mistakes.
Comment on lines 72 to 76
if (
self.update_interval == timedelta(seconds=DEFAULT_SCAN_INTERVAL)
and data.model == AirthingsDeviceType.CORENTIUM_HOME_2
):
self.update_interval = timedelta(seconds=RADON_SCAN_INTERVAL)
Copy link

Copilot AI Nov 2, 2025

Choose a reason for hiding this comment

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

The scan interval adjustment logic runs on every update but only changes the interval once. This check will execute unnecessarily on all subsequent updates after the initial adjustment. Consider using a flag or moving this logic to a one-time initialization location (e.g., after first successful data fetch) to avoid repeated checks.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When we first fetch data, we don't know the type of device. As copilot says, we could add a flag, but isn't that a bit too much?

Copy link
Member

Choose a reason for hiding this comment

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

I think ideally we store this in the entry data so we don't have to recalculate this. I think we can add it behind a boolean for now, but we should avoid checking this on every update

Comment on lines 72 to 76
if (
self.update_interval == timedelta(seconds=DEFAULT_SCAN_INTERVAL)
and data.model == AirthingsDeviceType.CORENTIUM_HOME_2
):
self.update_interval = timedelta(seconds=RADON_SCAN_INTERVAL)
Copy link
Member

Choose a reason for hiding this comment

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

I think ideally we store this in the entry data so we don't have to recalculate this. I think we can add it behind a boolean for now, but we should avoid checking this on every update

Copy link
Member

Choose a reason for hiding this comment

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

I would argue that we should still test this via test_sensor.py, and just use the freezer to make sure we only update when we expect it to

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored it now, and it's now storing the model name in the config flow. If not set, it will be set when setting up the device (e.g. already configured the device before this PR).

Also added more tests

Copy link
Member

Choose a reason for hiding this comment

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

Right, we should still not create coordinators directly. instead, let's test the migration in test_init.py and the update interval via test_sensor.py

@home-assistant home-assistant bot marked this pull request as draft November 3, 2025 00:32
@home-assistant
Copy link

home-assistant bot commented Nov 3, 2025

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.

@joostlek joostlek added this to the 2025.11.0 milestone Nov 3, 2025
@LaStrada LaStrada marked this pull request as ready for review November 4, 2025 00:42
@home-assistant home-assistant bot marked this pull request as draft November 5, 2025 13:22
@LaStrada LaStrada marked this pull request as ready for review November 5, 2025 13:55
@home-assistant home-assistant bot requested a review from edenhaus November 5, 2025 13:56
Copy link
Member

@edenhaus edenhaus left a comment

Choose a reason for hiding this comment

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

We require 100% test coverage in the config flow

======================================================================== tests coverage =========================================================================
________________________________________________________ coverage: platform linux, python 3.13.7-final-0 ________________________________________________________

Name                                                    Stmts   Miss  Cover   Missing
-------------------------------------------------------------------------------------
homeassistant/components/airthings_ble/__init__.py         15      0   100%
homeassistant/components/airthings_ble/config_flow.py     120      1    99%   139
homeassistant/components/airthings_ble/const.py             9      0   100%
homeassistant/components/airthings_ble/coordinator.py      45      5    89%   67, 76-77, 95-96
homeassistant/components/airthings_ble/sensor.py           73      4    95%   185-188
-------------------------------------------------------------------------------------
TOTAL                                                     262     10    96%

assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "Airthings Wave Plus (2930123456)"
assert result["result"].unique_id == "cc:cc:cc:cc:cc:cc"
assert result["data"] == {"device_model": "2930"}
Copy link
Member

Choose a reason for hiding this comment

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

Please also use the constant in the tests


inject_bluetooth_service_info(hass, service_info)

assert "device_model" not in entry.data
Copy link
Member

Choose a reason for hiding this comment

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

Also in these tests


# Migration should have added device_model to entry data
assert "device_model" in entry.data
assert entry.data["device_model"] == CORENTIUM_HOME_2_DEVICE_INFO.model.value
Copy link
Member

Choose a reason for hiding this comment

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

Same here

@home-assistant home-assistant bot marked this pull request as draft November 5, 2025 14:06
@frenck frenck removed this from the 2025.11.0 milestone Nov 5, 2025
@LaStrada LaStrada marked this pull request as ready for review November 5, 2025 21:06
@home-assistant home-assistant bot requested a review from edenhaus November 5, 2025 21:06
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Confirm discovery."""
assert self._discovered_device is not None
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it okey to do this? This should really not be None in this step. Not sure how to rewrite it without this.

I previously had a if self._discovered_device is None, but wasn't sure how to actually test it.

@joostlek
Copy link
Member

joostlek commented Nov 7, 2025

I now refactored the tests to not touch runtime data

@joostlek joostlek dismissed edenhaus’s stale review November 7, 2025 11:17

test coverage on par now

@joostlek joostlek merged commit c9e76ae into home-assistant:dev Nov 7, 2025
36 checks passed
@joostlek joostlek added this to the 2025.11.1 milestone Nov 7, 2025
@LaStrada LaStrada deleted the airthings-ble-improve-scan-interval branch November 7, 2025 11:19
frenck pushed a commit that referenced this pull request Nov 7, 2025
@frenck frenck mentioned this pull request Nov 7, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Nov 8, 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.

4 participants