Allow empty string for filters for waze_travel_time (#80953)
* Allow empty string for filters Signed-off-by: Kevin Stillhammer <kevin.stillhammer@gmail.com> * Apply PR feedback Signed-off-by: Kevin Stillhammer <kevin.stillhammer@gmail.com> Signed-off-by: Kevin Stillhammer <kevin.stillhammer@gmail.com>pull/81175/head
parent
e47f06fde8
commit
77585686e0
|
@ -52,7 +52,7 @@ class WazeOptionsFlow(config_entries.OptionsFlow):
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title="",
|
title="",
|
||||||
data={k: v for k, v in user_input.items() if v not in (None, "")},
|
data=user_input,
|
||||||
)
|
)
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
|
|
|
@ -185,14 +185,14 @@ class WazeTravelTimeData:
|
||||||
)
|
)
|
||||||
routes = params.calc_all_routes_info(real_time=realtime)
|
routes = params.calc_all_routes_info(real_time=realtime)
|
||||||
|
|
||||||
if incl_filter is not None:
|
if incl_filter not in {None, ""}:
|
||||||
routes = {
|
routes = {
|
||||||
k: v
|
k: v
|
||||||
for k, v in routes.items()
|
for k, v in routes.items()
|
||||||
if incl_filter.lower() in k.lower()
|
if incl_filter.lower() in k.lower()
|
||||||
}
|
}
|
||||||
|
|
||||||
if excl_filter is not None:
|
if excl_filter not in {None, ""}:
|
||||||
routes = {
|
routes = {
|
||||||
k: v
|
k: v
|
||||||
for k, v in routes.items()
|
for k, v in routes.items()
|
||||||
|
|
|
@ -19,6 +19,7 @@ from homeassistant.components.waze_travel_time.const import (
|
||||||
IMPERIAL_UNITS,
|
IMPERIAL_UNITS,
|
||||||
)
|
)
|
||||||
from homeassistant.const import CONF_NAME, CONF_REGION
|
from homeassistant.const import CONF_NAME, CONF_REGION
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .const import MOCK_CONFIG
|
from .const import MOCK_CONFIG
|
||||||
|
|
||||||
|
@ -26,7 +27,7 @@ from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("validate_config_entry")
|
@pytest.mark.usefixtures("validate_config_entry")
|
||||||
async def test_minimum_fields(hass):
|
async def test_minimum_fields(hass: HomeAssistant) -> None:
|
||||||
"""Test we get the form."""
|
"""Test we get the form."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
@ -50,7 +51,7 @@ async def test_minimum_fields(hass):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_options(hass):
|
async def test_options(hass: HomeAssistant) -> None:
|
||||||
"""Test options flow."""
|
"""Test options flow."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -105,7 +106,7 @@ async def test_options(hass):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("validate_config_entry")
|
@pytest.mark.usefixtures("validate_config_entry")
|
||||||
async def test_dupe(hass):
|
async def test_dupe(hass: HomeAssistant) -> None:
|
||||||
"""Test setting up the same entry data twice is OK."""
|
"""Test setting up the same entry data twice is OK."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
@ -138,7 +139,9 @@ async def test_dupe(hass):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("invalidate_config_entry")
|
@pytest.mark.usefixtures("invalidate_config_entry")
|
||||||
async def test_invalid_config_entry(hass, caplog):
|
async def test_invalid_config_entry(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
"""Test we get the form."""
|
"""Test we get the form."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
@ -154,3 +157,46 @@ async def test_invalid_config_entry(hass, caplog):
|
||||||
assert result2["errors"] == {"base": "cannot_connect"}
|
assert result2["errors"] == {"base": "cannot_connect"}
|
||||||
|
|
||||||
assert "Error trying to validate entry" in caplog.text
|
assert "Error trying to validate entry" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_update")
|
||||||
|
async def test_reset_filters(hass: HomeAssistant) -> None:
|
||||||
|
"""Test resetting inclusive and exclusive filters to empty string."""
|
||||||
|
options = {**DEFAULT_OPTIONS}
|
||||||
|
options[CONF_INCL_FILTER] = "test"
|
||||||
|
options[CONF_EXCL_FILTER] = "test"
|
||||||
|
config_entry = MockConfigEntry(
|
||||||
|
domain=DOMAIN, data=MOCK_CONFIG, options=options, entry_id="test"
|
||||||
|
)
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
|
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
result = await hass.config_entries.options.async_init(
|
||||||
|
config_entry.entry_id, data=None
|
||||||
|
)
|
||||||
|
|
||||||
|
result = await hass.config_entries.options.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
user_input={
|
||||||
|
CONF_AVOID_FERRIES: True,
|
||||||
|
CONF_AVOID_SUBSCRIPTION_ROADS: True,
|
||||||
|
CONF_AVOID_TOLL_ROADS: True,
|
||||||
|
CONF_EXCL_FILTER: "",
|
||||||
|
CONF_INCL_FILTER: "",
|
||||||
|
CONF_REALTIME: False,
|
||||||
|
CONF_UNITS: IMPERIAL_UNITS,
|
||||||
|
CONF_VEHICLE_TYPE: "taxi",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert config_entry.options == {
|
||||||
|
CONF_AVOID_FERRIES: True,
|
||||||
|
CONF_AVOID_SUBSCRIPTION_ROADS: True,
|
||||||
|
CONF_AVOID_TOLL_ROADS: True,
|
||||||
|
CONF_EXCL_FILTER: "",
|
||||||
|
CONF_INCL_FILTER: "",
|
||||||
|
CONF_REALTIME: False,
|
||||||
|
CONF_UNITS: IMPERIAL_UNITS,
|
||||||
|
CONF_VEHICLE_TYPE: "taxi",
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue