1
mirror of https://github.com/home-assistant/core synced 2024-09-06 10:29:55 +02:00

Only allow a single duotecno config entry (#102478)

This commit is contained in:
Maikel Punie 2023-10-23 10:58:11 +02:00 committed by GitHub
parent 0c5b963847
commit 109819e9cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 1 deletions

View File

@ -34,6 +34,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle the initial step."""
if self._async_current_entries():
return self.async_abort(reason="single_instance_allowed")
errors: dict[str, str] = {}
if user_input is not None:
try:

View File

@ -12,7 +12,8 @@
"error": {
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"unknown": "[%key:common::config_flow::error::unknown%]"
"unknown": "[%key:common::config_flow::error::unknown%]",
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]"
}
},
"entity": {

View File

@ -9,6 +9,8 @@ from homeassistant.components.duotecno.const import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from tests.common import MockConfigEntry
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
@ -87,3 +89,20 @@ async def test_invalid(hass: HomeAssistant, test_side_effect, test_error):
"port": 1234,
"password": "test-password2",
}
async def test_already_setup(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
"""Test duoteco flow - already setup."""
entry = MockConfigEntry(
domain=DOMAIN,
unique_id="duotecno_1234",
data={},
)
entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "single_instance_allowed"