Axis - Allow manual configuration to update existing configuration (#30467)

* Allow manual configuration to update existing configuration

* Harmonize tests

* Understand what Elupus means...
This commit is contained in:
Robert Svensson authored and GitHub committed 2020-01-05 10:11:17 +01:00
1 parent 063193e6e5
commit 35e19eec18
2 files changed
+183 -79

No files matched your search

+14 -11
View File
@@ -64,9 +64,13 @@ class AxisFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
device = await get_device(self.hass, self.device_config)
self.serial_number = device.vapix.params.system_serialnumber
await self.async_set_unique_id(self.serial_number)
self._abort_if_unique_id_configured()
config_entry = await self.async_set_unique_id(self.serial_number)
if config_entry:
return self._update_entry(
config_entry,
host=user_input[CONF_HOST],
port=user_input[CONF_PORT],
)
self.model = device.vapix.params.prodnbr
@@ -143,15 +147,14 @@ class AxisFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
if discovery_info[CONF_HOST].startswith("169.254"):
return self.async_abort(reason="link_local_address")
for entry in self.hass.config_entries.async_entries(DOMAIN):
if serial_number == entry.unique_id:
return self._update_entry(
entry,
host=discovery_info[CONF_HOST],
port=discovery_info[CONF_PORT],
)
config_entry = await self.async_set_unique_id(serial_number)
if config_entry:
return self._update_entry(
config_entry,
host=discovery_info[CONF_HOST],
port=discovery_info[CONF_PORT],
)
await self.async_set_unique_id(serial_number)
# pylint: disable=no-member # https://github.com/PyCQA/pylint/issues/3167
self.context["title_placeholders"] = {
"name": discovery_info["hostname"][:-7],