Use of reference strings in Heos config flow (#41282)

This commit is contained in:
Pigotka 2020-10-05 19:22:02 +02:00 committed by GitHub
parent ac795ddcd0
commit 7eaa304fc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 8 deletions

View File

@ -32,7 +32,7 @@ class HeosFlowHandler(config_entries.ConfigFlow):
self.hass.data[DATA_DISCOVERED_HOSTS][friendly_name] = hostname self.hass.data[DATA_DISCOVERED_HOSTS][friendly_name] = hostname
# Abort if other flows in progress or an entry already exists # Abort if other flows in progress or an entry already exists
if self._async_in_progress() or self._async_current_entries(): if self._async_in_progress() or self._async_current_entries():
return self.async_abort(reason="already_setup") return self.async_abort(reason="single_instance_allowed")
await self.async_set_unique_id(DOMAIN) await self.async_set_unique_id(DOMAIN)
# Show selection form # Show selection form
return self.async_show_form(step_id="user") return self.async_show_form(step_id="user")
@ -50,7 +50,7 @@ class HeosFlowHandler(config_entries.ConfigFlow):
self.hass.data.setdefault(DATA_DISCOVERED_HOSTS, {}) self.hass.data.setdefault(DATA_DISCOVERED_HOSTS, {})
# Only a single entry is needed for all devices # Only a single entry is needed for all devices
if self._async_current_entries(): if self._async_current_entries():
return self.async_abort(reason="already_setup") return self.async_abort(reason="single_instance_allowed")
# Try connecting to host if provided # Try connecting to host if provided
errors = {} errors = {}
host = None host = None
@ -64,7 +64,7 @@ class HeosFlowHandler(config_entries.ConfigFlow):
self.hass.data.pop(DATA_DISCOVERED_HOSTS) self.hass.data.pop(DATA_DISCOVERED_HOSTS)
return await self.async_step_import({CONF_HOST: host}) return await self.async_step_import({CONF_HOST: host})
except HeosError: except HeosError:
errors[CONF_HOST] = "connection_failure" errors[CONF_HOST] = "cannot_connect"
finally: finally:
await heos.disconnect() await heos.disconnect()

View File

@ -10,10 +10,10 @@
} }
}, },
"error": { "error": {
"connection_failure": "Unable to connect to the specified host." "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]"
}, },
"abort": { "abort": {
"already_setup": "You can only configure a single Heos connection as it will support all devices on the network." "single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]"
} }
} }
} }

View File

@ -20,7 +20,7 @@ async def test_flow_aborts_already_setup(hass, config_entry):
flow.hass = hass flow.hass = hass
result = await flow.async_step_user() result = await flow.async_step_user()
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "already_setup" assert result["reason"] == "single_instance_allowed"
async def test_no_host_shows_form(hass): async def test_no_host_shows_form(hass):
@ -41,7 +41,7 @@ async def test_cannot_connect_shows_error_form(hass, controller):
) )
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "user" assert result["step_id"] == "user"
assert result["errors"][CONF_HOST] == "connection_failure" assert result["errors"][CONF_HOST] == "cannot_connect"
assert controller.connect.call_count == 1 assert controller.connect.call_count == 1
assert controller.disconnect.call_count == 1 assert controller.disconnect.call_count == 1
controller.connect.reset_mock() controller.connect.reset_mock()
@ -118,7 +118,7 @@ async def test_discovery_flow_aborts_already_setup(
flow.hass = hass flow.hass = hass
result = await flow.async_step_ssdp(discovery_data) result = await flow.async_step_ssdp(discovery_data)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "already_setup" assert result["reason"] == "single_instance_allowed"
async def test_discovery_sets_the_unique_id(hass, controller, discovery_data): async def test_discovery_sets_the_unique_id(hass, controller, discovery_data):