Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/met/.translations/en.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"config": {
"error": {
"name_exists": "Name already exists"
"name_exists": "Location already exists"
},
"step": {
"user": {
Expand Down
18 changes: 13 additions & 5 deletions homeassistant/components/met/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@
@callback
def configured_instances(hass):
"""Return a set of configured SimpliSafe instances."""
return set(
entry.data[CONF_NAME] for entry in hass.config_entries.async_entries(DOMAIN)
)
entites = []
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):
Expand All @@ -32,11 +38,13 @@ async def async_step_user(self, user_input=None):
self._errors = {}

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(
title=user_input[CONF_NAME], data=user_input
)

self._errors[CONF_NAME] = "name_exists"

return await self._show_config_form(
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/met/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
},
"error": {
"name_exists": "Name already exists"
"name_exists": "Location already exists"
}
}
}
4 changes: 3 additions & 1 deletion tests/components/met/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ async def test_flow_entry_created_from_user_input():
async def test_flow_entry_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
"""
hass = Mock()
Expand All @@ -112,6 +112,8 @@ async def test_flow_entry_config_entry_already_exists():

first_entry = MockConfigEntry(domain="met")
first_entry.data["name"] = "home"
first_entry.data[CONF_LONGITUDE] = "0"
first_entry.data[CONF_LATITUDE] = "0"
first_entry.add_to_hass(hass)

test_data = {
Expand Down