Skip to content
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

Allow to sort options in select selector #97680

Merged
merged 2 commits into from
Aug 3, 2023
Merged
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
2 changes: 2 additions & 0 deletions homeassistant/helpers/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,7 @@ class SelectSelectorConfig(TypedDict, total=False):
custom_value: bool
mode: SelectSelectorMode
translation_key: str
sort: bool


@SELECTORS.register("select")
Expand All @@ -1005,6 +1006,7 @@ class SelectSelector(Selector[SelectSelectorConfig]):
vol.Coerce(SelectSelectorMode), lambda val: val.value
),
vol.Optional("translation_key"): cv.string,
vol.Optional("sort", default=False): cv.boolean,
}
)

Expand Down
1 change: 1 addition & 0 deletions tests/components/knx/test_device_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ async def test_get_trigger_capabilities_node_status(
"mode": "dropdown",
"multiple": True,
"options": [],
"sort": False,
},
},
}
Expand Down
5 changes: 5 additions & 0 deletions tests/helpers/test_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,11 @@ def test_text_selector_schema(schema, valid_selections, invalid_selections) -> N
(["red"], ["green", "blue"], []),
(0, None, "red"),
),
(
{"options": ["red", "green", "blue"], "sort": True},
("red", "blue"),
(0, None, ["red"]),
),
),
)
def test_select_selector_schema(schema, valid_selections, invalid_selections) -> None:
Expand Down