Add discovery to NUT integration (#36827)
* Add discovery to NUT integration * implement async_step_zeroconf * Update test to make sure unique id not set * Remove host/port import when coming from discovery, add title placeholders * fix mis-paste Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
d445c16697
commit
683d960fa5
5 changed files with 98 additions and 12 deletions
|
@ -1,4 +1,5 @@
|
|||
"""Test the Network UPS Tools (NUT) config flow."""
|
||||
|
||||
from homeassistant import config_entries, data_entry_flow, setup
|
||||
from homeassistant.components.nut.const import DOMAIN
|
||||
from homeassistant.const import CONF_RESOURCES, CONF_SCAN_INTERVAL
|
||||
|
@ -16,6 +17,59 @@ VALID_CONFIG = {
|
|||
}
|
||||
|
||||
|
||||
async def test_form_zeroconf(hass):
|
||||
"""Test we can setup from zeroconf."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_ZEROCONF},
|
||||
data={"host": "192.168.1.5", "port": 1234},
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {}
|
||||
|
||||
mock_pynut = _get_mock_pynutclient(
|
||||
list_vars={"battery.voltage": "voltage", "ups.status": "OL"}, list_ups=["ups1"]
|
||||
)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.nut.PyNUTClient", return_value=mock_pynut,
|
||||
):
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{"username": "test-username", "password": "test-password"},
|
||||
)
|
||||
|
||||
assert result2["step_id"] == "resources"
|
||||
assert result2["type"] == "form"
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.nut.PyNUTClient", return_value=mock_pynut,
|
||||
), patch(
|
||||
"homeassistant.components.nut.async_setup", return_value=True
|
||||
) as mock_setup, patch(
|
||||
"homeassistant.components.nut.async_setup_entry", return_value=True,
|
||||
) as mock_setup_entry:
|
||||
result3 = await hass.config_entries.flow.async_configure(
|
||||
result2["flow_id"],
|
||||
{"resources": ["battery.voltage", "ups.status", "ups.status.display"]},
|
||||
)
|
||||
|
||||
assert result3["type"] == "create_entry"
|
||||
assert result3["title"] == "192.168.1.5:1234"
|
||||
assert result3["data"] == {
|
||||
"host": "192.168.1.5",
|
||||
"password": "test-password",
|
||||
"port": 1234,
|
||||
"resources": ["battery.voltage", "ups.status", "ups.status.display"],
|
||||
"username": "test-username",
|
||||
}
|
||||
assert result3["result"].unique_id is None
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_form_user_one_ups(hass):
|
||||
"""Test we get the form."""
|
||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue