Options flow for Monoprice sources (#33156)
* Options flow for monoprice sources * Fix lint errors
This commit is contained in:
1 parent
2d002f3ef6
commit
b50281a917
6 files changed
+169
-28
No files matched your search
@@ -2,7 +2,7 @@
|
||||
from asynctest import patch
|
||||
from serial import SerialException
|
||||
|
||||
from homeassistant import config_entries, setup
|
||||
from homeassistant import config_entries, data_entry_flow, setup
|
||||
from homeassistant.components.monoprice.const import (
|
||||
CONF_SOURCE_1,
|
||||
CONF_SOURCE_4,
|
||||
@@ -12,6 +12,8 @@ from homeassistant.components.monoprice.const import (
|
||||
)
|
||||
from homeassistant.const import CONF_PORT
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
CONFIG = {
|
||||
CONF_PORT: "/test/port",
|
||||
CONF_SOURCE_1: "one",
|
||||
@@ -45,7 +47,7 @@ async def test_form(hass):
|
||||
assert result2["title"] == CONFIG[CONF_PORT]
|
||||
assert result2["data"] == {
|
||||
CONF_PORT: CONFIG[CONF_PORT],
|
||||
CONF_SOURCES: {1: CONFIG[CONF_SOURCE_1], 4: CONFIG[CONF_SOURCE_4]},
|
||||
CONF_SOURCES: {"1": CONFIG[CONF_SOURCE_1], "4": CONFIG[CONF_SOURCE_4]},
|
||||
}
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
@@ -86,3 +88,32 @@ async def test_generic_exception(hass):
|
||||
|
||||
assert result2["type"] == "form"
|
||||
assert result2["errors"] == {"base": "unknown"}
|
||||
|
||||
|
||||
async def test_options_flow(hass):
|
||||
"""Test config flow options."""
|
||||
conf = {CONF_PORT: "/test/port", CONF_SOURCES: {"4": "four"}}
|
||||
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
# unique_id="abcde12345",
|
||||
data=conf,
|
||||
# options={CONF_SHOW_ON_MAP: True},
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.monoprice.async_setup_entry", return_value=True
|
||||
):
|
||||
result = await hass.config_entries.options.async_init(config_entry.entry_id)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "init"
|
||||
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={CONF_SOURCE_1: "one", CONF_SOURCE_4: "", CONF_SOURCE_5: "five"},
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert config_entry.options[CONF_SOURCES] == {"1": "one", "5": "five"}
|
||||
@@ -37,6 +37,7 @@ from homeassistant.helpers.entity_component import async_update_entity
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
MOCK_CONFIG = {CONF_PORT: "fake port", CONF_SOURCES: {"1": "one", "3": "three"}}
|
||||
MOCK_OPTIONS = {CONF_SOURCES: {"2": "two", "4": "four"}}
|
||||
|
||||
ZONE_1_ID = "media_player.zone_11"
|
||||
ZONE_2_ID = "media_player.zone_12"
|
||||
@@ -117,6 +118,20 @@ async def _setup_monoprice(hass, monoprice):
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
async def _setup_monoprice_with_options(hass, monoprice):
|
||||
with patch(
|
||||
"homeassistant.components.monoprice.get_monoprice", new=lambda *a: monoprice,
|
||||
):
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN, data=MOCK_CONFIG, options=MOCK_OPTIONS
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
# setup_component(self.hass, DOMAIN, MOCK_CONFIG)
|
||||
# self.hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
async def _call_media_player_service(hass, name, data):
|
||||
await hass.services.async_call(
|
||||
MEDIA_PLAYER_DOMAIN, name, service_data=data, blocking=True
|
||||
@@ -256,7 +271,6 @@ async def test_restore_without_snapshort(hass):
|
||||
|
||||
async def test_update(hass):
|
||||
"""Test updating values from monoprice."""
|
||||
"""Test snapshot save/restore service calls."""
|
||||
monoprice = MockMonoprice()
|
||||
await _setup_monoprice(hass, monoprice)
|
||||
|
||||
@@ -305,6 +319,15 @@ async def test_source_list(hass):
|
||||
assert ["one", "three"] == state.attributes[ATTR_INPUT_SOURCE_LIST]
|
||||
|
||||
|
||||
async def test_source_list_with_options(hass):
|
||||
"""Test source list property."""
|
||||
await _setup_monoprice_with_options(hass, MockMonoprice())
|
||||
|
||||
state = hass.states.get(ZONE_1_ID)
|
||||
# Note, the list is sorted!
|
||||
assert ["two", "four"] == state.attributes[ATTR_INPUT_SOURCE_LIST]
|
||||
|
||||
|
||||
async def test_select_source(hass):
|
||||
"""Test source selection methods."""
|
||||
monoprice = MockMonoprice()
|
||||
|
||||
Reference in new issue
Block a user