Fix setting up multiple UPSes with NUT in 0.108.x (#34427)
parent
334fecdf6f
commit
5635cdb77c
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue