From 409ea46436163271cc837893c8a197337ff5b689 Mon Sep 17 00:00:00 2001 From: ygelfand Date: Tue, 20 Feb 2024 21:58:50 -0500 Subject: [PATCH] oops, as a map of ints Signed-off-by: ygelfand --- internal/api/alerts.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/internal/api/alerts.go b/internal/api/alerts.go index 8976a3c..ed15475 100644 --- a/internal/api/alerts.go +++ b/internal/api/alerts.go @@ -1,8 +1,6 @@ package api import ( - "slices" - "github.com/gin-gonic/gin" ) @@ -10,11 +8,12 @@ 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...) @@ -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 }