Skip to content

Commit

Permalink
fix(agent): handle no sensors data display
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuar committed Jun 3, 2023
1 parent 7281cbb commit 4d22c2f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions internal/agent/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fyne.io/fyne/v2/widget"
xlayout "fyne.io/x/fyne/layout"
"github.com/joshuar/go-hass-agent/assets/trayicon"
"github.com/rs/zerolog/log"
)

func newUI(appID string) fyne.App {
Expand Down Expand Up @@ -88,7 +89,12 @@ func (agent *Agent) setupSystemTray() {
}

func (agent *Agent) makeSensorTable() {
s, _ := hassConfig.Get("entities")
s, err := hassConfig.Get("entities")
if err != nil {
log.Debug().Caller().Err(err).
Msg("Could not get entities from config.")
return
}
sensors := s.(map[string]map[string]interface{})
var sensorsTable []fyne.CanvasObject
for rowKey, rowValue := range sensors {
Expand All @@ -97,7 +103,7 @@ func (agent *Agent) makeSensorTable() {
sensorState := tracker.Get(rowKey)
if sensorState != nil {
sensorRow = append(sensorRow, widget.NewLabel(fmt.Sprintf("%v %s",
sensorState.State(), sensorState.UnitOfMeasurement())))
sensorState.State(), sensorState.Units())))
} else {
sensorRow = append(sensorRow, widget.NewLabel(""))
}
Expand Down

0 comments on commit 4d22c2f

Please sign in to comment.