mirror of
https://github.com/home-assistant/core.git
synced 2026-09-28 02:18:10 -04:00
Add options flow for force_poll setting in upnp (#120843)
This commit is contained in:
@@ -248,7 +248,7 @@ async def mock_config_entry(
|
||||
ssdp_instant_discovery,
|
||||
mock_igd_device: IgdDevice,
|
||||
mock_mac_address_from_host,
|
||||
):
|
||||
) -> MockConfigEntry:
|
||||
"""Create an initialized integration."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
|
||||
@@ -9,6 +9,7 @@ import pytest
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import ssdp
|
||||
from homeassistant.components.upnp.const import (
|
||||
CONFIG_ENTRY_FORCE_POLL,
|
||||
CONFIG_ENTRY_HOST,
|
||||
CONFIG_ENTRY_LOCATION,
|
||||
CONFIG_ENTRY_MAC_ADDRESS,
|
||||
@@ -473,3 +474,28 @@ async def test_flow_ssdp_with_mismatched_udn(hass: HomeAssistant) -> None:
|
||||
CONFIG_ENTRY_MAC_ADDRESS: TEST_MAC_ADDRESS,
|
||||
CONFIG_ENTRY_HOST: TEST_HOST,
|
||||
}
|
||||
|
||||
|
||||
async def test_options_flow(
|
||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test that the options flow works."""
|
||||
result = await hass.config_entries.options.async_init(mock_config_entry.entry_id)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "init"
|
||||
|
||||
user_input = {
|
||||
CONFIG_ENTRY_FORCE_POLL: True,
|
||||
}
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"],
|
||||
user_input,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["data"] == {
|
||||
CONFIG_ENTRY_FORCE_POLL: True,
|
||||
}
|
||||
assert mock_config_entry.options == {
|
||||
CONFIG_ENTRY_FORCE_POLL: True,
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import pytest
|
||||
|
||||
from homeassistant.components import ssdp
|
||||
from homeassistant.components.upnp.const import (
|
||||
CONFIG_ENTRY_FORCE_POLL,
|
||||
CONFIG_ENTRY_LOCATION,
|
||||
CONFIG_ENTRY_MAC_ADDRESS,
|
||||
CONFIG_ENTRY_ORIGINAL_UDN,
|
||||
@@ -46,6 +47,9 @@ async def test_async_setup_entry_default(
|
||||
CONFIG_ENTRY_LOCATION: TEST_LOCATION,
|
||||
CONFIG_ENTRY_MAC_ADDRESS: TEST_MAC_ADDRESS,
|
||||
},
|
||||
options={
|
||||
CONFIG_ENTRY_FORCE_POLL: False,
|
||||
},
|
||||
)
|
||||
|
||||
# Load config_entry.
|
||||
@@ -68,6 +72,9 @@ async def test_async_setup_entry_default_no_mac_address(hass: HomeAssistant) ->
|
||||
CONFIG_ENTRY_LOCATION: TEST_LOCATION,
|
||||
CONFIG_ENTRY_MAC_ADDRESS: None,
|
||||
},
|
||||
options={
|
||||
CONFIG_ENTRY_FORCE_POLL: False,
|
||||
},
|
||||
)
|
||||
|
||||
# Load config_entry.
|
||||
@@ -96,6 +103,9 @@ async def test_async_setup_entry_multi_location(
|
||||
CONFIG_ENTRY_LOCATION: TEST_LOCATION,
|
||||
CONFIG_ENTRY_MAC_ADDRESS: TEST_MAC_ADDRESS,
|
||||
},
|
||||
options={
|
||||
CONFIG_ENTRY_FORCE_POLL: False,
|
||||
},
|
||||
)
|
||||
|
||||
# Load config_entry.
|
||||
@@ -124,6 +134,9 @@ async def test_async_setup_udn_mismatch(
|
||||
CONFIG_ENTRY_LOCATION: TEST_LOCATION,
|
||||
CONFIG_ENTRY_MAC_ADDRESS: TEST_MAC_ADDRESS,
|
||||
},
|
||||
options={
|
||||
CONFIG_ENTRY_FORCE_POLL: False,
|
||||
},
|
||||
)
|
||||
|
||||
# Set up device discovery callback.
|
||||
@@ -148,3 +161,34 @@ async def test_async_setup_udn_mismatch(
|
||||
|
||||
# Ensure that the IPv4 location is used.
|
||||
mock_async_create_device.assert_called_once_with(TEST_LOCATION)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"ssdp_instant_discovery",
|
||||
"mock_get_source_ip",
|
||||
"mock_mac_address_from_host",
|
||||
)
|
||||
async def test_async_setup_entry_force_poll(
|
||||
hass: HomeAssistant, mock_igd_device: IgdDevice
|
||||
) -> None:
|
||||
"""Test async_setup_entry."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id=TEST_USN,
|
||||
data={
|
||||
CONFIG_ENTRY_ST: TEST_ST,
|
||||
CONFIG_ENTRY_UDN: TEST_UDN,
|
||||
CONFIG_ENTRY_ORIGINAL_UDN: TEST_UDN,
|
||||
CONFIG_ENTRY_LOCATION: TEST_LOCATION,
|
||||
CONFIG_ENTRY_MAC_ADDRESS: TEST_MAC_ADDRESS,
|
||||
},
|
||||
options={
|
||||
CONFIG_ENTRY_FORCE_POLL: True,
|
||||
},
|
||||
)
|
||||
|
||||
# Load config_entry.
|
||||
entry.add_to_hass(hass)
|
||||
assert await hass.config_entries.async_setup(entry.entry_id) is True
|
||||
|
||||
mock_igd_device.async_subscribe_services.assert_not_called()
|
||||
|
||||
Reference in New Issue
Block a user