Skip to content

Commit

Permalink
oops, as a map of ints
Browse files Browse the repository at this point in the history
Signed-off-by: ygelfand <[email protected]>
  • Loading branch information
ygelfand committed Feb 21, 2024
1 parent 559d4d2 commit 409ea46
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions internal/api/alerts.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package api

import (
"slices"

"github.com/gin-gonic/gin"
)

func (app *Api) alerts(c *gin.Context) {
c.JSON(200, app.parsedAlerts())
}

func (app *Api) parsedAlerts() []string {
alerts := []string{}
func (app *Api) parsedAlerts() map[string]int {
alertMap := map[string]int{}
if app.powerwall.Controller == nil {
return alerts
return alertMap
}
alerts := []string{}
alerts = append(alerts, app.powerwall.Controller.Control.Alerts.Active...)
for _, inv := range app.powerwall.Controller.EsCan.Bus.Pinv {
alerts = append(alerts, inv.Alerts.Active...)
Expand All @@ -25,6 +24,8 @@ func (app *Api) parsedAlerts() []string {
for _, inv := range app.powerwall.Controller.EsCan.Bus.Pvs {
alerts = append(alerts, inv.Alerts.Active...)
}
slices.Sort(alerts)
return slices.Compact(alerts)
for _, v := range alerts {
alertMap[v] = 1
}
return alertMap
}

0 comments on commit 409ea46

Please sign in to comment.