Skip to content

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

Open
@mbronk

Description

@mbronk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementAn enhancement or new feature of the Core

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions