Allow ignored airthings_ble devices to be set up from the user flow (#137102)

Every few days we get an issue report about a device a user ignored and forgot about, and than can no longer get set up. Sometimes its a govee device, sometimes its a switchbot device, but the pattern is consistent.

Allow ignored devices to be selected in the user step and replace the ignored entry.

Same as #137056 and #137052 but for airthings
This commit is contained in:
J. Nick Koston 2025-02-01 13:22:13 -06:00 committed by Paulus Schoutsen
parent 2d1d9bbe5a
commit bad966f3ab
2 changed files with 53 additions and 2 deletions

View File

@ -144,7 +144,7 @@ class AirthingsConfigFlow(ConfigFlow, domain=DOMAIN):
return self.async_create_entry(title=discovery.name, data={})
current_addresses = self._async_current_ids()
current_addresses = self._async_current_ids(include_ignore=False)
for discovery_info in async_discovered_service_info(self.hass):
address = discovery_info.address
if address in current_addresses or address in self._discovered_devices:

View File

@ -7,7 +7,7 @@ from bleak import BleakError
import pytest
from homeassistant.components.airthings_ble.const import DOMAIN
from homeassistant.config_entries import SOURCE_BLUETOOTH, SOURCE_USER
from homeassistant.config_entries import SOURCE_BLUETOOTH, SOURCE_IGNORE, SOURCE_USER
from homeassistant.const import CONF_ADDRESS
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
@ -153,6 +153,57 @@ async def test_user_setup(hass: HomeAssistant) -> None:
assert result["result"].unique_id == "cc:cc:cc:cc:cc:cc"
async def test_user_setup_replaces_ignored_device(hass: HomeAssistant) -> None:
"""Test the user initiated form can replace an ignored device."""
entry = MockConfigEntry(
domain=DOMAIN,
unique_id="cc:cc:cc:cc:cc:cc",
source=SOURCE_IGNORE,
data={CONF_ADDRESS: "cc:cc:cc:cc:cc:cc"},
)
entry.add_to_hass(hass)
with (
patch(
"homeassistant.components.airthings_ble.config_flow.async_discovered_service_info",
return_value=[WAVE_SERVICE_INFO],
),
patch_async_ble_device_from_address(WAVE_SERVICE_INFO),
patch_airthings_ble(
AirthingsDevice(
manufacturer="Airthings AS",
model=AirthingsDeviceType.WAVE_PLUS,
name="Airthings Wave Plus",
identifier="123456",
)
),
):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] is None
assert result["data_schema"] is not None
schema = result["data_schema"].schema
assert schema.get(CONF_ADDRESS).container == {
"cc:cc:cc:cc:cc:cc": "Airthings Wave Plus"
}
with patch(
"homeassistant.components.airthings_ble.async_setup_entry",
return_value=True,
):
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={CONF_ADDRESS: "cc:cc:cc:cc:cc:cc"}
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "Airthings Wave Plus (123456)"
assert result["result"].unique_id == "cc:cc:cc:cc:cc:cc"
async def test_user_setup_no_device(hass: HomeAssistant) -> None:
"""Test the user initiated form without any device detected."""
with patch(