Fix setting up multiple UPSes with NUT in 0.108.x (#34427)

pull/34517/head
J. Nick Koston 2020-04-21 12:47:31 -05:00 committed by GitHub
parent 334fecdf6f
commit 5635cdb77c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -99,7 +99,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
def _host_port_alias_already_configured(self, host, port, alias):
"""See if we already have a nut entry matching user input configured."""
existing_host_port_aliases = {
_format_host_port_alias(host, port, alias)
_format_host_port_alias(
entry.data[CONF_HOST], entry.data[CONF_PORT], entry.data.get(CONF_ALIAS)
)
for entry in self._async_current_entries()
}
return _format_host_port_alias(host, port, alias) in existing_host_port_aliases

View File

@ -4,6 +4,8 @@ from asynctest import MagicMock, patch
from homeassistant import config_entries, setup
from homeassistant.components.nut.const import DOMAIN
from tests.common import MockConfigEntry
def _get_mock_pynutclient(list_vars=None):
pynutclient = MagicMock()
@ -62,6 +64,12 @@ async def test_form_import(hass):
"""Test we get the form with import source."""
await setup.async_setup_component(hass, "persistent_notification", {})
config_entry = MockConfigEntry(
domain=DOMAIN,
data={"host": "2.2.2.2", "port": 123, "resources": ["battery.charge"]},
)
config_entry.add_to_hass(hass)
mock_pynut = _get_mock_pynutclient(list_vars={"battery.voltage": "serial"})
with patch(
@ -92,7 +100,7 @@ async def test_form_import(hass):
}
await hass.async_block_till_done()
assert len(mock_setup.mock_calls) == 1
assert len(mock_setup_entry.mock_calls) == 1
assert len(mock_setup_entry.mock_calls) == 2
async def test_form_cannot_connect(hass):