mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
Met, check for existing location (#26400)
This commit is contained in:
parent
22d3cf4117
commit
b9923ca109
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"config": {
|
"config": {
|
||||||
"error": {
|
"error": {
|
||||||
"name_exists": "Name already exists"
|
"name_exists": "Location already exists"
|
||||||
},
|
},
|
||||||
"step": {
|
"step": {
|
||||||
"user": {
|
"user": {
|
||||||
|
@ -12,9 +12,15 @@ from .const import DOMAIN, HOME_LOCATION_NAME, CONF_TRACK_HOME
|
|||||||
@callback
|
@callback
|
||||||
def configured_instances(hass):
|
def configured_instances(hass):
|
||||||
"""Return a set of configured SimpliSafe instances."""
|
"""Return a set of configured SimpliSafe instances."""
|
||||||
return set(
|
entites = []
|
||||||
entry.data[CONF_NAME] for entry in hass.config_entries.async_entries(DOMAIN)
|
for entry in hass.config_entries.async_entries(DOMAIN):
|
||||||
)
|
if entry.data.get("track_home"):
|
||||||
|
entites.append("home")
|
||||||
|
continue
|
||||||
|
entites.append(
|
||||||
|
f"{entry.data.get(CONF_LATITUDE)}-{entry.data.get(CONF_LONGITUDE)}"
|
||||||
|
)
|
||||||
|
return set(entites)
|
||||||
|
|
||||||
|
|
||||||
class MetFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
class MetFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
@ -32,11 +38,13 @@ class MetFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
self._errors = {}
|
self._errors = {}
|
||||||
|
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
if user_input[CONF_NAME] not in configured_instances(self.hass):
|
if (
|
||||||
|
f"{user_input.get(CONF_LATITUDE)}-{user_input.get(CONF_LONGITUDE)}"
|
||||||
|
not in configured_instances(self.hass)
|
||||||
|
):
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title=user_input[CONF_NAME], data=user_input
|
title=user_input[CONF_NAME], data=user_input
|
||||||
)
|
)
|
||||||
|
|
||||||
self._errors[CONF_NAME] = "name_exists"
|
self._errors[CONF_NAME] = "name_exists"
|
||||||
|
|
||||||
return await self._show_config_form(
|
return await self._show_config_form(
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"error": {
|
"error": {
|
||||||
"name_exists": "Name already exists"
|
"name_exists": "Location already exists"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ async def test_flow_entry_created_from_user_input():
|
|||||||
async def test_flow_entry_config_entry_already_exists():
|
async def test_flow_entry_config_entry_already_exists():
|
||||||
"""Test that create data from user input and config_entry already exists.
|
"""Test that create data from user input and config_entry already exists.
|
||||||
|
|
||||||
Test when the form should show when user puts existing name
|
Test when the form should show when user puts existing location
|
||||||
in the config gui. Then the form should show with error
|
in the config gui. Then the form should show with error
|
||||||
"""
|
"""
|
||||||
hass = Mock()
|
hass = Mock()
|
||||||
@ -112,6 +112,8 @@ async def test_flow_entry_config_entry_already_exists():
|
|||||||
|
|
||||||
first_entry = MockConfigEntry(domain="met")
|
first_entry = MockConfigEntry(domain="met")
|
||||||
first_entry.data["name"] = "home"
|
first_entry.data["name"] = "home"
|
||||||
|
first_entry.data[CONF_LONGITUDE] = "0"
|
||||||
|
first_entry.data[CONF_LATITUDE] = "0"
|
||||||
first_entry.add_to_hass(hass)
|
first_entry.add_to_hass(hass)
|
||||||
|
|
||||||
test_data = {
|
test_data = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user