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 requested a review from joostlek November 4, 2025 00:42
Comment on lines 73 to 74
try:
_LOGGER.debug("Fetching device info for migration")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
try:
_LOGGER.debug("Fetching device info for migration")
_LOGGER.debug("Fetching device info for migration")
try:

try:
_LOGGER.debug("Fetching device info for migration")
data = await self.airthings.update_device(self.ble_device)
except Exception as err:
Copy link
Member

Choose a reason for hiding this comment

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

We should be more specific here, ideally we should also update the one in async_update_data but that is outside of the scope

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted. Will try to handle this (+ the other one) in a separate PR.

_LOGGER.debug("Fetching device info for migration")
data = await self.airthings.update_device(self.ble_device)
except Exception as err:
raise ConfigEntryNotReady(
Copy link
Member

Choose a reason for hiding this comment

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

UpdateFailed

)
self.ble_device = ble_device

if "device_model" not in self.config_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.

Can we use a constant for device_model

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 assume these changes also have an effect to the test_config_flow.py

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 4, 2025 06:18
@LaStrada LaStrada marked this pull request as ready for review November 4, 2025 18:48
@home-assistant home-assistant bot requested a review from joostlek November 4, 2025 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants