ux: group device filter by home (structural redesign + wording clarification) - #2920
ux: group device filter by home (structural redesign + wording clarification)#2920jingyulong wants to merge 4 commits into
Conversation
The cloud device filter step mixed devices from every home into one flat multi-select, with a confusing two-step "home_ids" filter that required submitting the form twice. Users routinely imported devices from shared homes by accident. - Render one multi-select per home, keyed home__<home name>, with devices that have no home grouped under "Default Home" - Remove the home_ids two-step filter from the form - Merge all home__* groups back into did_list on submit (both the config and options flows) - Add tests for the grouped schema and the submit merge Wording fixes for the filter step are in PR al-one#2920.
- Devices without a home assignment (nearby/offline devices) are no longer shown in a synthetic 'Default Home' group - Keep the exclude/include labels and filter_did description in sync with PR al-one#2920
- Replace the flat cv.multi_select (inline checkbox list) with selector.SelectSelector(multiple, mode=dropdown) so each home group renders as a standard dropdown with removable chips - Drop the redundant filter_did field description; fold the "checking none includes all" warning into the step description - Label home-less devices as "Unassigned devices (nearby/offline)" via a static translation key, placed after the real homes
The HA frontend renders multi_select fields automatically: groups with fewer than 6 options as checkboxes and larger groups as dropdowns (SHOW_ALL_ENTRIES_LIMIT in ha-form-multi_select), so the explicit SelectSelector(dropdown) is redundant.
9bb9824 to
42771cc
Compare
|
Thanks for the PR! I reviewed the changes. Here is my bilingual feedback (English / 中文). Overall the per-home grouping is a clear improvement. One critical bug and a couple of minor nits below. 谢谢这个 PR!我复查了变更,以下是双语反馈(英文 / 中文)。总体而言,按家庭分组是一处清晰的改进。下面是一个严重缺陷和几个小问题。 🔴 Critical bug: users cannot clear the device filter via the UI / 严重缺陷:用户无法通过 UI 清空设备过滤Location 位置: The merge logic only writes 合并逻辑只有在 did_list = []
for k in list(user_input.keys()):
if k.startswith('home__'):
did_list += user_input.pop(k) or []
if did_list:
user_input['did_list'] = did_list # skipped when did_list == [] / 当 did_list 为空时被跳过Repro 复现: a user with 假设用户有 Suggested fix 修复建议 — always write the key / 始终写入该键: if did_list:
user_input['did_list'] = did_list
else:
user_input['did_list'] = []or simply / 或更简单: 🟡 Minor: duplicated
|
Background: how the problem was discovered
While setting up the integration in a real environment, a Mi account with two homes (the user's own home with 23 devices + a shared home with 15 devices) ended up importing the shared home's devices into HA and none of the user's own — only discovered when comparing device MACs/IPs against the local network.
Reviewing the filter flow surfaced several UX problems:
筛选家庭 (留空保存)/Filter Home (Leave blank to save)label was misleading — blank actually means no home filtering at all (import every home), not "safe";排除 Exclude/包含 Include) carried no semantics — unclear what checking a box does;home_idswas a two-step filter and was not persisted.Changes
Per-home grouped device filtering (structural redesign)
did_listmulti-select and the two-stephome_idsfilter; each home now gets its own multi-select (home__<home name>), and home-less devices get their ownhome__unassignedgroup, always rendered last;home__*groups are merged back intodid_listfor persistence (handled in both the initial config flow and the options flow);Rendering notes
Home-group selectors use
cv.multi_select; the HA frontend picks the rendering automatically: < 6 options → inline checkboxes, ≥ 6 options → dropdown (SHOW_ALL_ENTRIES_LIMIT = 6inha-form-multi_select.ts). No explicit selector is needed, and small groups (like unassigned devices) naturally render as checkboxes at the end.Wording clarifications
排除 Exclude(勾选 = 不接入这些设备)/包含 Include(只接入勾选的设备);未分配家庭的设备(附近的/离线的)/Unassigned devices (nearby/offline).Tests
New
tests/test_cloud_filter_grouped.py(3 cases):did_list/home_idsno longer appear in the schema;home__*defaults from the saveddid_list;home__*values are merged back intodid_listand persisted.Local pytest passes: 21 passed (including options flow and translation cases).
Verification
Tested against a real environment (Home Assistant 2026.8.1, Mi account with two homes / 38 devices) via options → update device list: home groups rendered as dropdown multi-selects, the unassigned group rendered as checkboxes and stayed last; after saving, 26 devices were imported, all from the intended home with no cross-home leakage.
Screenshots
(Sensitive data such as account IDs and IPs is masked in the screenshots.)
Related discussion: #2921