mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Remove extra otbr config entries (#96785)
This commit is contained in:
parent
1e3fdcc4d1
commit
8559af8232
@ -24,6 +24,9 @@ CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN)
|
|||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the Open Thread Border Router component."""
|
"""Set up the Open Thread Border Router component."""
|
||||||
websocket_api.async_setup(hass)
|
websocket_api.async_setup(hass)
|
||||||
|
if len(config_entries := hass.config_entries.async_entries(DOMAIN)):
|
||||||
|
for config_entry in config_entries[1:]:
|
||||||
|
await hass.config_entries.async_remove(config_entry.entry_id)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""Tests for the Open Thread Border Router integration."""
|
"""Tests for the Open Thread Border Router integration."""
|
||||||
BASE_URL = "http://core-silabs-multiprotocol:8081"
|
BASE_URL = "http://core-silabs-multiprotocol:8081"
|
||||||
CONFIG_ENTRY_DATA = {"url": "http://core-silabs-multiprotocol:8081"}
|
CONFIG_ENTRY_DATA = {"url": "http://core-silabs-multiprotocol:8081"}
|
||||||
|
CONFIG_ENTRY_DATA_2 = {"url": "http://core-silabs-multiprotocol_2:8081"}
|
||||||
|
|
||||||
DATASET_CH15 = bytes.fromhex(
|
DATASET_CH15 = bytes.fromhex(
|
||||||
"0E080000000000010000000300000F35060004001FFFE00208F642646DA209B1D00708FDF57B5A"
|
"0E080000000000010000000300000F35060004001FFFE00208F642646DA209B1D00708FDF57B5A"
|
||||||
|
@ -11,10 +11,12 @@ from homeassistant.components import otbr
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import issue_registry as ir
|
from homeassistant.helpers import issue_registry as ir
|
||||||
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from . import (
|
from . import (
|
||||||
BASE_URL,
|
BASE_URL,
|
||||||
CONFIG_ENTRY_DATA,
|
CONFIG_ENTRY_DATA,
|
||||||
|
CONFIG_ENTRY_DATA_2,
|
||||||
DATASET_CH15,
|
DATASET_CH15,
|
||||||
DATASET_CH16,
|
DATASET_CH16,
|
||||||
DATASET_INSECURE_NW_KEY,
|
DATASET_INSECURE_NW_KEY,
|
||||||
@ -280,3 +282,32 @@ async def test_get_active_dataset_tlvs_invalid(
|
|||||||
aioclient_mock.get(f"{BASE_URL}/node/dataset/active", text="unexpected")
|
aioclient_mock.get(f"{BASE_URL}/node/dataset/active", text="unexpected")
|
||||||
with pytest.raises(HomeAssistantError):
|
with pytest.raises(HomeAssistantError):
|
||||||
assert await otbr.async_get_active_dataset_tlvs(hass)
|
assert await otbr.async_get_active_dataset_tlvs(hass)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_remove_extra_entries(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
|
"""Test we remove additional config entries."""
|
||||||
|
|
||||||
|
config_entry1 = MockConfigEntry(
|
||||||
|
data=CONFIG_ENTRY_DATA,
|
||||||
|
domain=otbr.DOMAIN,
|
||||||
|
options={},
|
||||||
|
title="Open Thread Border Router",
|
||||||
|
)
|
||||||
|
config_entry2 = MockConfigEntry(
|
||||||
|
data=CONFIG_ENTRY_DATA_2,
|
||||||
|
domain=otbr.DOMAIN,
|
||||||
|
options={},
|
||||||
|
title="Open Thread Border Router",
|
||||||
|
)
|
||||||
|
config_entry1.add_to_hass(hass)
|
||||||
|
config_entry2.add_to_hass(hass)
|
||||||
|
assert len(hass.config_entries.async_entries(otbr.DOMAIN)) == 2
|
||||||
|
with patch(
|
||||||
|
"python_otbr_api.OTBR.get_active_dataset_tlvs", return_value=DATASET_CH16
|
||||||
|
), patch(
|
||||||
|
"homeassistant.components.otbr.util.compute_pskc"
|
||||||
|
): # Patch to speed up tests
|
||||||
|
assert await async_setup_component(hass, otbr.DOMAIN, {})
|
||||||
|
assert len(hass.config_entries.async_entries(otbr.DOMAIN)) == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user