-
-
Notifications
You must be signed in to change notification settings - Fork 35.8k
Improve scan interval for Airthings Corentium Home 2 #155694
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
base: dev
Are you sure you want to change the base?
Improve scan interval for Airthings Corentium Home 2 #155694
Conversation
|
Hey there @vincegio, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this 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 |
Copilot
AI
Nov 2, 2025
There was a problem hiding this comment.
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.
| from tests.components.bluetooth import MockConfigEntry, generate_ble_device | |
| from tests.common import MockConfigEntry | |
| from tests.components.bluetooth import generate_ble_device |
| if ( | ||
| self.update_interval == timedelta(seconds=DEFAULT_SCAN_INTERVAL) | ||
| and data.model == AirthingsDeviceType.CORENTIUM_HOME_2 | ||
| ): | ||
| self.update_interval = timedelta(seconds=RADON_SCAN_INTERVAL) |
Copilot
AI
Nov 2, 2025
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
| if ( | ||
| self.update_interval == timedelta(seconds=DEFAULT_SCAN_INTERVAL) | ||
| and data.model == AirthingsDeviceType.CORENTIUM_HOME_2 | ||
| ): | ||
| self.update_interval = timedelta(seconds=RADON_SCAN_INTERVAL) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
| try: | ||
| _LOGGER.debug("Fetching device info for migration") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: