sort entries for consistent user interaction
This commit is contained in:
parent
7af3e406f0
commit
4236c591a7
@ -5,4 +5,4 @@ Website = "https://github.com/qbit/fass"
|
|||||||
Name = "fass"
|
Name = "fass"
|
||||||
ID = "dev.suah.fass"
|
ID = "dev.suah.fass"
|
||||||
Version = "1.0.0"
|
Version = "1.0.0"
|
||||||
Build = 11
|
Build = 16
|
||||||
|
18
main.go
18
main.go
@ -1,12 +1,15 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"cmp"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
@ -20,6 +23,18 @@ import (
|
|||||||
"github.com/pawal/go-hass"
|
"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) {
|
func loadData(h *hass.Access, lightCards *[]fyne.CanvasObject, switchCards *[]fyne.CanvasObject) {
|
||||||
lights, err := h.FilterStates("light")
|
lights, err := h.FilterStates("light")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -30,6 +45,9 @@ func loadData(h *hass.Access, lightCards *[]fyne.CanvasObject, switchCards *[]fy
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sortEntries(&lights)
|
||||||
|
sortEntries(&switches)
|
||||||
|
|
||||||
for entity := range lights {
|
for entity := range lights {
|
||||||
e := lights[entity]
|
e := lights[entity]
|
||||||
card := makeEntity(e, h)
|
card := makeEntity(e, h)
|
||||||
|
Loading…
Reference in New Issue
Block a user