mirror of
https://github.com/home-assistant/core.git
synced 2026-09-26 09:23:17 -04:00
Fix duplicate devices in Airthings BLE on incomplete read (#182417)
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
145ff1cadf
commit
0622758c09
@@ -102,4 +102,14 @@ class AirthingsBLEDataUpdateCoordinator(DataUpdateCoordinator[AirthingsDevice]):
|
||||
data = await self.airthings.update_device(self.ble_device)
|
||||
except Exception as err:
|
||||
raise UpdateFailed(f"Unable to fetch data: {err}") from err
|
||||
|
||||
if not data.address:
|
||||
# The device did not report its address, which means the read did not
|
||||
# complete. Building entities from this would create a duplicate device
|
||||
# and entities with an empty unique id prefix.
|
||||
raise UpdateFailed(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="incomplete_read",
|
||||
)
|
||||
|
||||
return data
|
||||
|
||||
@@ -67,6 +67,9 @@
|
||||
"exceptions": {
|
||||
"device_not_found": {
|
||||
"message": "Could not find Airthings device with address {address}: {reason}"
|
||||
},
|
||||
"incomplete_read": {
|
||||
"message": "The Airthings device did not return complete data, retrying"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,6 +98,33 @@ async def test_setup_retries_when_device_not_found(
|
||||
)
|
||||
|
||||
|
||||
async def test_setup_retries_on_incomplete_read(
|
||||
hass: HomeAssistant,
|
||||
) -> None:
|
||||
"""Test setup is retried when the device returns data without an address."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id=WAVE_SERVICE_INFO.address,
|
||||
data={DEVICE_MODEL: WAVE_DEVICE_INFO.model.value},
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
inject_bluetooth_service_info(hass, WAVE_SERVICE_INFO)
|
||||
|
||||
incomplete_device_info = deepcopy(WAVE_DEVICE_INFO)
|
||||
incomplete_device_info.address = ""
|
||||
|
||||
with (
|
||||
patch_async_ble_device_from_address(WAVE_SERVICE_INFO.device),
|
||||
patch_airthings_ble(incomplete_device_info),
|
||||
):
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert entry.state is ConfigEntryState.SETUP_RETRY
|
||||
assert len(hass.states.async_all()) == 0
|
||||
|
||||
|
||||
async def test_no_migration_when_device_model_exists(
|
||||
hass: HomeAssistant,
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user