mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Fix HEOS discovery error when previously ignored (#140091)
Abort ignored discovery
This commit is contained in:
parent
e2c050ed40
commit
deea19db51
@ -14,7 +14,12 @@ from pyheos import (
|
|||||||
)
|
)
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult, OptionsFlow
|
from homeassistant.config_entries import (
|
||||||
|
SOURCE_IGNORE,
|
||||||
|
ConfigFlow,
|
||||||
|
ConfigFlowResult,
|
||||||
|
OptionsFlow,
|
||||||
|
)
|
||||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers import selector
|
from homeassistant.helpers import selector
|
||||||
@ -141,8 +146,10 @@ class HeosFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
hostname = urlparse(discovery_info.ssdp_location).hostname
|
hostname = urlparse(discovery_info.ssdp_location).hostname
|
||||||
assert hostname is not None
|
assert hostname is not None
|
||||||
|
|
||||||
# Abort early when discovered host is part of the current system
|
# Abort early when discovery is ignored or host is part of the current system
|
||||||
if entry and hostname in _get_current_hosts(entry):
|
if entry and (
|
||||||
|
entry.source == SOURCE_IGNORE or hostname in _get_current_hosts(entry)
|
||||||
|
):
|
||||||
return self.async_abort(reason="single_instance_allowed")
|
return self.async_abort(reason="single_instance_allowed")
|
||||||
|
|
||||||
# Connect to discovered host and get system information
|
# Connect to discovered host and get system information
|
||||||
|
@ -14,7 +14,12 @@ from pyheos import (
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.heos.const import DOMAIN
|
from homeassistant.components.heos.const import DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_SSDP, SOURCE_USER, ConfigEntryState
|
from homeassistant.config_entries import (
|
||||||
|
SOURCE_IGNORE,
|
||||||
|
SOURCE_SSDP,
|
||||||
|
SOURCE_USER,
|
||||||
|
ConfigEntryState,
|
||||||
|
)
|
||||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
@ -160,6 +165,22 @@ async def test_discovery_aborts_same_system(
|
|||||||
assert config_entry.data[CONF_HOST] == "127.0.0.1"
|
assert config_entry.data[CONF_HOST] == "127.0.0.1"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_discovery_ignored_aborts(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
discovery_data: SsdpServiceInfo,
|
||||||
|
) -> None:
|
||||||
|
"""Test discovery aborts when ignored."""
|
||||||
|
MockConfigEntry(domain=DOMAIN, unique_id=DOMAIN, source=SOURCE_IGNORE).add_to_hass(
|
||||||
|
hass
|
||||||
|
)
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": SOURCE_SSDP}, data=discovery_data
|
||||||
|
)
|
||||||
|
assert result["type"] is FlowResultType.ABORT
|
||||||
|
assert result["reason"] == "single_instance_allowed"
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_fails_to_connect_aborts(
|
async def test_discovery_fails_to_connect_aborts(
|
||||||
hass: HomeAssistant, discovery_data: SsdpServiceInfo, controller: MockHeos
|
hass: HomeAssistant, discovery_data: SsdpServiceInfo, controller: MockHeos
|
||||||
) -> None:
|
) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user