Fix HEOS discovery error when previously ignored (#140091)

Abort ignored discovery
This commit is contained in:
Andrew Sayre 2025-03-07 22:31:32 -06:00 committed by GitHub
parent e2c050ed40
commit deea19db51
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 4 deletions

View File

@ -14,7 +14,12 @@ from pyheos import (
)
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.core import callback
from homeassistant.helpers import selector
@ -141,8 +146,10 @@ class HeosFlowHandler(ConfigFlow, domain=DOMAIN):
hostname = urlparse(discovery_info.ssdp_location).hostname
assert hostname is not None
# Abort early when discovered host is part of the current system
if entry and hostname in _get_current_hosts(entry):
# Abort early when discovery is ignored or host is part of the current system
if entry and (
entry.source == SOURCE_IGNORE or hostname in _get_current_hosts(entry)
):
return self.async_abort(reason="single_instance_allowed")
# Connect to discovered host and get system information

View File

@ -14,7 +14,12 @@ from pyheos import (
import pytest
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.core import HomeAssistant
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"
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(
hass: HomeAssistant, discovery_data: SsdpServiceInfo, controller: MockHeos
) -> None: