mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Allow configuring ignored devices from improve_ble user flow (#140595)
This commit is contained in:
parent
96a6d88dca
commit
08fc6dcff6
@ -83,12 +83,9 @@ class ImprovBLEConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self._discovery_info = self._discovered_devices[address]
|
self._discovery_info = self._discovered_devices[address]
|
||||||
return await self.async_step_start_improv()
|
return await self.async_step_start_improv()
|
||||||
|
|
||||||
current_addresses = self._async_current_ids()
|
|
||||||
for discovery in bluetooth.async_discovered_service_info(self.hass):
|
for discovery in bluetooth.async_discovered_service_info(self.hass):
|
||||||
if (
|
if discovery.address in self._discovered_devices or not device_filter(
|
||||||
discovery.address in current_addresses
|
discovery.advertisement
|
||||||
or discovery.address in self._discovered_devices
|
|
||||||
or not device_filter(discovery.advertisement)
|
|
||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
self._discovered_devices[discovery.address] = discovery
|
self._discovered_devices[discovery.address] = discovery
|
||||||
@ -364,6 +361,18 @@ class ImprovBLEConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
assert self._provision_result is not None
|
assert self._provision_result is not None
|
||||||
|
|
||||||
result = self._provision_result
|
result = self._provision_result
|
||||||
|
if result["type"] == "abort" and result["reason"] in (
|
||||||
|
"provision_successful",
|
||||||
|
"provision_successful_url",
|
||||||
|
):
|
||||||
|
# Delete ignored config entry, if it exists
|
||||||
|
address = self.context["unique_id"]
|
||||||
|
current_entries = self._async_current_entries(include_ignore=True)
|
||||||
|
for entry in current_entries:
|
||||||
|
if entry.unique_id == address:
|
||||||
|
_LOGGER.debug("Removing ignored entry: %s", entry)
|
||||||
|
await self.hass.config_entries.async_remove(entry.entry_id)
|
||||||
|
break
|
||||||
self._provision_result = None
|
self._provision_result = None
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import pytest
|
|||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components.bluetooth import BluetoothChange
|
from homeassistant.components.bluetooth import BluetoothChange
|
||||||
from homeassistant.components.improv_ble.const import DOMAIN
|
from homeassistant.components.improv_ble.const import DOMAIN
|
||||||
|
from homeassistant.config_entries import SOURCE_IGNORE
|
||||||
from homeassistant.const import CONF_ADDRESS
|
from homeassistant.const import CONF_ADDRESS
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResult, FlowResultType
|
from homeassistant.data_entry_flow import FlowResult, FlowResultType
|
||||||
@ -21,6 +22,8 @@ from . import (
|
|||||||
PROVISIONED_IMPROV_BLE_DISCOVERY_INFO,
|
PROVISIONED_IMPROV_BLE_DISCOVERY_INFO,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
IMPROV_BLE = "homeassistant.components.improv_ble"
|
IMPROV_BLE = "homeassistant.components.improv_ble"
|
||||||
|
|
||||||
|
|
||||||
@ -118,6 +121,32 @@ async def test_async_step_user_takes_precedence_over_discovery(
|
|||||||
assert not hass.config_entries.flow.async_progress(DOMAIN)
|
assert not hass.config_entries.flow.async_progress(DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_user_setup_removes_ignored_entry(hass: HomeAssistant) -> None:
|
||||||
|
"""Test the user initiated form can replace an ignored device."""
|
||||||
|
ignored_entry = MockConfigEntry(
|
||||||
|
domain=DOMAIN,
|
||||||
|
unique_id=IMPROV_BLE_DISCOVERY_INFO.address,
|
||||||
|
source=SOURCE_IGNORE,
|
||||||
|
)
|
||||||
|
ignored_entry.add_to_hass(hass)
|
||||||
|
with patch(
|
||||||
|
f"{IMPROV_BLE}.config_flow.bluetooth.async_discovered_service_info",
|
||||||
|
return_value=[NOT_IMPROV_BLE_DISCOVERY_INFO, IMPROV_BLE_DISCOVERY_INFO],
|
||||||
|
):
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
)
|
||||||
|
assert result["type"] is FlowResultType.FORM
|
||||||
|
assert result["step_id"] == "user"
|
||||||
|
assert result["errors"] == {}
|
||||||
|
|
||||||
|
await _test_common_success_wo_identify(
|
||||||
|
hass, result, IMPROV_BLE_DISCOVERY_INFO.address
|
||||||
|
)
|
||||||
|
# Check the ignored entry is removed
|
||||||
|
assert not hass.config_entries.async_entries(DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
async def test_bluetooth_step_provisioned_device(hass: HomeAssistant) -> None:
|
async def test_bluetooth_step_provisioned_device(hass: HomeAssistant) -> None:
|
||||||
"""Test bluetooth step when device is already provisioned."""
|
"""Test bluetooth step when device is already provisioned."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user