Skip to content

Commit

Permalink
Allow ignored airthings_ble devices to be set up from the user flow
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bdraco committed Feb 1, 2025
1 parent 1157a08 commit 3334ba4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/airthings_ble/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ async def async_step_user(

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:
Expand Down
53 changes: 52 additions & 1 deletion tests/components/airthings_ble/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 3334ba4

Please sign in to comment.