Skip to content

Commit

Permalink
wip temps
Browse files Browse the repository at this point in the history
Signed-off-by: ygelfand <[email protected]>
  • Loading branch information
ygelfand committed Nov 23, 2024
1 parent 47bb81d commit ce059b4
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 413 deletions.
4 changes: 2 additions & 2 deletions cmd/debug/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"fmt"
"log"

"github.com/spf13/cobra"
"github.com/ygelfand/go-powerwall/cmd/options"
Expand All @@ -29,7 +28,8 @@ func NewDebugQueryCmd(opts *options.PowerwallOptions) *cobra.Command {
if err != nil {
fmt.Println("JSON parse error: ", err)
}
log.Println(string(prettyJSON.Bytes()))

fmt.Println(string(prettyJSON.Bytes()))
},
}
originalUsageFunc := queryCmd.UsageFunc()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
golang.org/x/sync v0.6.0
google.golang.org/protobuf v1.32.0
google.golang.org/protobuf v1.35.2
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
Expand Down
21 changes: 17 additions & 4 deletions internal/api/temps.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
package api

import "github.com/gin-gonic/gin"
import (
"fmt"

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

func (app *Api) temps(c *gin.Context) {
// TODO: one day
// no way to get temps..at this time
c.JSON(200, map[string]interface{}{})
temps := map[string]*float32{}
index := 0
for _, msa := range app.powerwall.Controller.Components.Msa {
for _, signal := range msa.Signals {
if signal.Name == "THC_AmbientTemp" && signal.Value != nil {
index++
temps[fmt.Sprintf("PW%v_temp", index)] = signal.Value
}

}
}
c.JSON(200, temps)
}
16 changes: 16 additions & 0 deletions internal/powerwall/device_controller_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ package powerwall
import "time"

type DeviceControllerResponse struct {
Components struct {
Msa []struct {
ActiveAlerts []struct {
Name string `json:"name,omitempty"`
} `json:"activeAlerts,omitempty"`
PartNumber string `json:"partNumber,omitempty"`
SerialNumber string `json:"serialNumber,omitempty"`
Signals []struct {
BoolValue any `json:"boolValue"`
Name string `json:"name"`
TextValue any `json:"textValue"`
Timestamp string `json:"timestamp"`
Value *float32 `json:"value"`
} `json:"signals"`
} `json:"msa,omitempty"`
} `json:"components,omitempty"`
Control struct {
Alerts struct {
Active []string `json:"active,omitempty"`
Expand Down
Loading

0 comments on commit ce059b4

Please sign in to comment.