Only allow single Home Connect config entry (#137088)

* Make Home Connect config entry unique

* Use unique ID for Home connect config entry

* Remove unnecessary code

* Revert "Use unique ID for Home connect config entry"

This reverts commit 424131746990dfbbba05b578f61fd49f4f7cb8d7.

* Added tests
This commit is contained in:
J. Diego Rodríguez Royo 2025-02-08 16:29:00 +01:00 committed by GitHub
parent 7f6855045a
commit 91dbe3092f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 2 deletions

View File

@ -7,5 +7,6 @@
"documentation": "https://www.home-assistant.io/integrations/home_connect", "documentation": "https://www.home-assistant.io/integrations/home_connect",
"iot_class": "cloud_push", "iot_class": "cloud_push",
"loggers": ["aiohomeconnect"], "loggers": ["aiohomeconnect"],
"requirements": ["aiohomeconnect==0.12.3"] "requirements": ["aiohomeconnect==0.12.3"],
"single_config_entry": true
} }

View File

@ -2609,7 +2609,8 @@
"name": "Home Connect", "name": "Home Connect",
"integration_type": "hub", "integration_type": "hub",
"config_flow": true, "config_flow": true,
"iot_class": "cloud_push" "iot_class": "cloud_push",
"single_config_entry": true
}, },
"home_plus_control": { "home_plus_control": {
"name": "Legrand Home+ Control", "name": "Legrand Home+ Control",

View File

@ -16,6 +16,7 @@ from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType from homeassistant.data_entry_flow import FlowResultType
from homeassistant.helpers import config_entry_oauth2_flow from homeassistant.helpers import config_entry_oauth2_flow
from tests.common import MockConfigEntry
from tests.test_util.aiohttp import AiohttpClientMocker from tests.test_util.aiohttp import AiohttpClientMocker
from tests.typing import ClientSessionGenerator from tests.typing import ClientSessionGenerator
@ -77,3 +78,18 @@ async def test_full_flow(
assert len(hass.config_entries.async_entries(DOMAIN)) == 1 assert len(hass.config_entries.async_entries(DOMAIN)) == 1
assert len(mock_setup_entry.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1
async def test_prevent_multiple_config_entries(
hass: HomeAssistant,
config_entry: MockConfigEntry,
) -> None:
"""Test we only allow one config entry."""
config_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
"home_connect", context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == "abort"
assert result["reason"] == "single_instance_allowed"