8000 Fix derivative migration from 'none' unit_prefix by karwosts · Pull Request #147820 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix derivative migration from 'none' unit_prefix #147820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions homeassistant/components/derivative/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ async def _get_options_dict(handler: SchemaCommonFlowHandler | None) -> dict:


async def _get_options_schema(handler: SchemaCommonFlowHandler) -> vol.Schema:
if handler.options.get("unit_prefix") == "none":
# Before we had support for optional selectors, "none" was used for selecting nothing
del handler.options["unit_prefix"]

return vol.Schema(await _get_options_dict(handler))


Expand Down
14 changes: 11 additions & 3 deletions tests/components/derivative/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ async def test_config_flow(hass: HomeAssistant, platform) -> None:


@pytest.mark.parametrize("platform", ["sensor"])
async def test_options(hass: HomeAssistant, platform) -> None:
@pytest.mark.parametrize(
"initial_unit_prefix",
[{}, {"unit_prefix": "k"}, {"unit_prefix": "none"}],
)
async def test_options(hass: HomeAssistant, platform, initial_unit_prefix) -> None:
"""Test reconfiguring."""
# Setup the config entry
config_entry = MockConfigEntry(
Expand All @@ -79,7 +83,7 @@ async def test_options(hass: HomeAssistant, platform) -> None:
"round": 1.0,
"source": "sensor.input",
"time_window": {"seconds": 0.0},
"unit_prefix": "k",
**initial_unit_prefix,
"unit_time": "min",
"max_sub_interval": {"seconds": 30},
},
Expand All @@ -99,7 +103,11 @@ async def test_options(hass: HomeAssistant, platform) -> None:
schema = result["data_schema"].schema
assert get_schema_suggested_value(schema, "round") == 1.0
assert get_schema_suggested_value(schema, "time_window") == {"seconds": 0.0}
assert get_schema_suggested_value(schema, "unit_prefix") == "k"
assert get_schema_suggested_value(schema, "unit_prefix") == (
None
if initial_unit_prefix.get("unit_prefix") == "none"
else initial_unit_prefix.get("unit_prefix")
)
assert get_schema_suggested_value(schema, "unit_time") == "min"

source = schema["source"]
Expand Down
0