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

Per-group sort settings (& sort by value) #4627

Open
mbronk opened this issue Mar 2, 2025 · 1 comment
Open

Per-group sort settings (& sort by value) #4627

mbronk opened this issue Mar 2, 2025 · 1 comment
Labels
enhancement An enhancement or new feature of the Core

Comments

@mbronk
Copy link

mbronk commented Mar 2, 2025

Since OH 3.1 (#2123), it is possible to specify a system-wide sort order for items in groups (so that, for example, Basic UI always displays them in the exact same way).

Currently supported options (#2417) include:

  • no sorting (NONE)
  • by label, lexicographically ascending (LABEL)
  • by item name, lexicographically ascending (NAME)

This is great 🏅 for deterministic display of the UI, but often times it is the most useful to have items sorted by value (ASC or DESC).
For example, it makes sense to display device battery levels 🔋 as lowest first 📈 or energy consumption 🔌 from highest to lowest 📉 . Accomplishing it today (via rules) is cumbersome and may be brittle - ex. see this community thread.

Enhancement proposed

  • Extend Group:Number definition to allow for specifying per-Group sort order.
    ItemUIRegistry::getChildren() would keep providing sorted outputs for groups, but:
    • If there's a per-group sort order defined (also including by-value sort) - use that as primary sorting criterion,
    • system-wide setting (as-today) becomes a 2ndary sort criterion (ex. first by-value,descending, then by-name).
  • Enhance Group definition to allow expressing the sort order. For example:
    1. [option 1‍⃣ ] - as metadata

      • Example group definition syntax:
        Group:Number:MIN GBatteryLevel "Battery levels [%.0f %unit%]" <battery> (gApartment) ["Battery"] 
        {
            unit = "%",
            item_sort_order = "BY_VALUE_ASC"   //<-- new
        }
        • The sort order direction could be an UI-only parameter (no impact on core). Not sure about it though, given the default sort has been implemented by core already and this could lead to split responsibilities.
    2. [option 2‍⃣] Extend definition syntax itself for the grouping functions, ex. Group:Number:Energy:MAX(SORT_DESC) or Group:Number:Energy:MAX:SORT_DESC.
      Notice also that functions such as MAX or MIN may imply the sort order on their own, so perhaps this could be exploited...

  • Add BY_VALUE_ASC and BY_VALUE_DESC item sort criteria.
@mbronk mbronk added the enhancement An enhancement or new feature of the Core label Mar 2, 2025
@mbronk
Copy link
Author

mbronk commented Mar 2, 2025

Looks like the following PR implements this concept already 🥳:

@cweitkamp - The PR looks a little stale though... Can you confirm if you plan to pursue it or if there's a newer PR with it somewhere❓


(Sorry for duplicate, missed it on initial search.)
BTW. Not closing this issue though, to allow a place for discussing the feature itself (vs. implementation discussion on the PR).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature of the Core
Projects
None yet
Development

No branches or pull requests

1 participant