From fb3924ad8b0ea6e55730fddab58be1121d033e50 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Wed, 25 Sep 2024 08:06:18 -0600 Subject: [PATCH] add readme, set env var for android build few tweaks for readability --- .envrc | 1 + FyneApp.toml | 2 +- README.org | 6 ++++++ main.go | 31 +++++++++++++++++++------------ 4 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 README.org diff --git a/.envrc b/.envrc index 3550a30..27af0e3 100644 --- a/.envrc +++ b/.envrc @@ -1 +1,2 @@ use flake +export ANDROID_NDK_HOME=~/Android/Sdk/ndk/27.1.12297006 diff --git a/FyneApp.toml b/FyneApp.toml index 8017944..aa40024 100644 --- a/FyneApp.toml +++ b/FyneApp.toml @@ -5,4 +5,4 @@ Website = "https://github.com/qbit/fass" Name = "fass" ID = "dev.suah.fass" Version = "1.0.0" - Build = 5 + Build = 11 diff --git a/README.org b/README.org new file mode 100644 index 0000000..c10d400 --- /dev/null +++ b/README.org @@ -0,0 +1,6 @@ +#+TITLE: fass + +A simple [[https://fyne.io/][Fyne]] app for controlling lights and switches in your [[https://www.home-assistant.io/][Home Assistant]] +install. + +[[file:toggleswitch.png]] diff --git a/main.go b/main.go index 6f3b95e..06e0e29 100644 --- a/main.go +++ b/main.go @@ -33,13 +33,17 @@ func loadData(h *hass.Access, lightCards *[]fyne.CanvasObject, switchCards *[]fy for entity := range lights { e := lights[entity] card := makeEntity(e, h) - *lightCards = append(*lightCards, card) + if card != nil { + *lightCards = append(*lightCards, card) + } } for entity := range switches { e := switches[entity] card := makeEntity(e, h) - *switchCards = append(*switchCards, card) + if card != nil { + *switchCards = append(*switchCards, card) + } } } @@ -52,6 +56,9 @@ func getDevice(id string, h *hass.Access) (hass.Device, error) { } func makeEntity(e hass.State, h *hass.Access) *widget.Card { + if e.State != "on" && e.State != "off" { + return nil + } fmt.Printf("%s: (%s) %s\n", e.EntityID, e.Attributes["friendly_name"], e.State) @@ -70,21 +77,23 @@ func makeEntity(e hass.State, h *hass.Access) *widget.Card { dev.Toggle() }) - return widget.NewCard("", entityName, container.NewVBox( + card := widget.NewCard("", entityName, container.NewVBox( container.NewHBox(entityButton), )) + + card.Refresh() + + return card } func loadSavedData(a fyne.App, w fyne.Window, input *widget.Entry, file string) { uri, err := storage.Child(a.Storage().RootURI(), file) if err != nil { - dialog.ShowError(err, w) return } reader, err := storage.Reader(uri) if err != nil { - dialog.ShowError(err, w) return } defer reader.Close() @@ -146,7 +155,7 @@ func main() { h := hass.NewAccess(urlEntry.Text, "") if haExists && tkExists { - if certExists { + if certExists && certEntry.Text != "" { rootCAs, _ := x509.SystemCertPool() if rootCAs == nil { rootCAs = x509.NewCertPool() @@ -197,17 +206,15 @@ func main() { w.Hide() }) + cols := 5 tabs := container.NewAppTabs( container.NewTabItemWithIcon("Lights", theme.VisibilityIcon(), - container.NewVBox( - container.NewAdaptiveGrid(3, lightCards...), - )), + container.NewAdaptiveGrid(cols, lightCards...), + ), container.NewTabItemWithIcon("Switches", theme.RadioButtonIcon(), - container.NewVBox( - container.NewAdaptiveGrid(3, switchCards...), - ), + container.NewAdaptiveGrid(cols, switchCards...), ), ) tabs.SetTabLocation(container.TabLocationLeading)