sort entries for consistent user interaction

This commit is contained in:
Aaron Bieber 2024-10-16 07:42:34 -06:00
parent 7af3e406f0
commit 4236c591a7
No known key found for this signature in database
2 changed files with 19 additions and 1 deletions

View File

@ -5,4 +5,4 @@ Website = "https://github.com/qbit/fass"
Name = "fass"
ID = "dev.suah.fass"
Version = "1.0.0"
Build = 11
Build = 16

18
main.go
View File

@ -1,12 +1,15 @@
package main
import (
"cmp"
"crypto/tls"
"crypto/x509"
"fmt"
"io"
"log"
"net/http"
"slices"
"strings"
"time"
"fyne.io/fyne/v2"
@ -20,6 +23,18 @@ import (
"github.com/pawal/go-hass"
)
func sortEntries(entries *hass.States) {
slices.SortFunc(*entries, func(a hass.State, b hass.State) int {
an := fmt.Sprintf("%s", a.Attributes["friendly_name"])
bn := fmt.Sprintf("%s", b.Attributes["friendly_name"])
if n := strings.Compare(an, bn); n != 0 {
return n
}
return cmp.Compare(a.EntityID, b.EntityID)
})
}
func loadData(h *hass.Access, lightCards *[]fyne.CanvasObject, switchCards *[]fyne.CanvasObject) {
lights, err := h.FilterStates("light")
if err != nil {
@ -30,6 +45,9 @@ func loadData(h *hass.Access, lightCards *[]fyne.CanvasObject, switchCards *[]fy
log.Fatalln(err)
}
sortEntries(&lights)
sortEntries(&switches)
for entity := range lights {
e := lights[entity]
card := makeEntity(e, h)