Skip to content

Commit

Permalink
add pod
Browse files Browse the repository at this point in the history
Signed-off-by: ygelfand <[email protected]>
  • Loading branch information
ygelfand committed Feb 25, 2024
1 parent f9ed39a commit 43e24eb
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 34 deletions.
1 change: 1 addition & 0 deletions internal/api/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func (api *Api) Run(listen string) {
v1.GET("/alerts", api.withCache(), api.withForcedRefresh(api.powerwall.UpdateController), api.alerts)
v1.GET("/freq", api.withCache(), api.withForcedRefresh(api.powerwall.UpdateController), api.voltage)
v1.GET("/temps", api.withCache(), api.withForcedRefresh(api.powerwall.UpdateController), api.temps)
v1.GET("/pod", api.withCache(), api.withForcedRefresh(api.powerwall.UpdateController), api.pods)
v1.GET("/aggregates", api.withCache(), api.powerwall.JSONReverseProxy("GET", "meters/aggregates", nil))
v1.GET("/soe", api.withCache(), api.powerwall.JSONReverseProxy("GET", "system_status/soe", nil))
debug := v1.Group("/debug")
Expand Down
45 changes: 45 additions & 0 deletions internal/api/pods.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package api

import (
"fmt"

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

func (app *Api) pods(c *gin.Context) {
c.JSON(200, app.parsedPods())
}

func (app *Api) parsedPods() map[string]podResponse {
pods := map[string]podResponse{}
if app.powerwall.Controller == nil {
return pods
}
for id, pod := range app.powerwall.Controller.EsCan.Bus.Pod {
if !pod.PODEnergyStatus.IsMIA {
pod := podResponse{
PODNomEnergyRemaining: pod.PODEnergyStatus.PODNomEnergyRemaining,
PODNomFullPackEnergy: pod.PODEnergyStatus.PODNomFullPackEnergy,
}
if len(app.powerwall.Controller.EsCan.Bus.Thc) > id {
thc := app.powerwall.Controller.EsCan.Bus.Thc[id]
if !thc.THCInfoMsg.IsMIA {
pod.PackagePartNumber = thc.PackagePartNumber
pod.PackageSerialNumber = thc.PackageSerialNumber
}
}
if len(app.powerwall.Controller.EsCan.Bus.Pinv) > id {
inv := app.powerwall.Controller.EsCan.Bus.Pinv[id]
if !inv.PINVStatus.IsMIA {
pod.PinvGridState = inv.PINVStatus.PINVGridState
pod.PinvState = inv.PINVStatus.PINVState
pod.POut = inv.PINVStatus.PINVPout
pod.VOut = inv.PINVStatus.PINVVout
pod.FOut = inv.PINVStatus.PINVFout
}
}
pods[fmt.Sprintf("PW%v", id+1)] = pod
}
}
return pods
}
33 changes: 33 additions & 0 deletions internal/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,36 @@ type islandPower struct {
VL3NMain float64 `json:"VL3N_Main,omitempty"`
}

type podResponse struct {
Name string `json:"name"`
PODActiveHeating any `json:"POD_ActiveHeating"`
PODChargeComplete any `json:"POD_ChargeComplete"`
PODChargeRequest any `json:"POD_ChargeRequest"`
PODDischargeComplete any `json:"POD_DischargeComplete"`
PODPermanentlyFaulted any `json:"POD_PermanentlyFaulted"`
PODPersistentlyFaulted any `json:"POD_PersistentlyFaulted"`
PODEnableLine any `json:"POD_enable_line"`
PODAvailableChargePower any `json:"POD_available_charge_power"`
PODAvailableDischgPower any `json:"POD_available_dischg_power"`
PODNomEnergyRemaining int `json:"POD_nom_energy_remaining"`
PODNomEnergyToBeCharged any `json:"POD_nom_energy_to_be_charged"`
PODNomFullPackEnergy int `json:"POD_nom_full_pack_energy"`
PackagePartNumber string `json:"PackagePartNumber"`
PackageSerialNumber string `json:"PackageSerialNumber"`
PinvState string `json:"pinv_state"`
PinvGridState string `json:"pinv_grid_state"`
POut float64 `json:"p_out"`
QOut float64 `json:"q_out"`
VOut float64 `json:"v_out"`
FOut float64 `json:"f_out"`
IOut float64 `json:"i_out"`
EnergyCharged int `json:"energy_charged"`
EnergyDischarged int `json:"energy_discharged"`
OffGrid int `json:"off_grid"`
VfMode int `json:"vf_mode"`
WobbleDetected int `json:"wobble_detected"`
ChargePowerClamped int `json:"charge_power_clamped"`
BackupReady int `json:"backup_ready"`
OpSeqState string `json:"OpSeqState"`
Version string `json:"version"`
}
34 changes: 0 additions & 34 deletions internal/powerwall/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,37 +63,3 @@ type loginResponse struct {
Provider string `json:"provider"`
LoginTime string `json:"loginTime"`
}

type podResponse struct {
Name string `json:"name"`
PODActiveHeating any `json:"POD_ActiveHeating"`
PODChargeComplete any `json:"POD_ChargeComplete"`
PODChargeRequest any `json:"POD_ChargeRequest"`
PODDischargeComplete any `json:"POD_DischargeComplete"`
PODPermanentlyFaulted any `json:"POD_PermanentlyFaulted"`
PODPersistentlyFaulted any `json:"POD_PersistentlyFaulted"`
PODEnableLine any `json:"POD_enable_line"`
PODAvailableChargePower any `json:"POD_available_charge_power"`
PODAvailableDischgPower any `json:"POD_available_dischg_power"`
PODNomEnergyRemaining int `json:"POD_nom_energy_remaining"`
PODNomEnergyToBeCharged any `json:"POD_nom_energy_to_be_charged"`
PODNomFullPackEnergy int `json:"POD_nom_full_pack_energy"`
PackagePartNumber string `json:"PackagePartNumber"`
PackageSerialNumber string `json:"PackageSerialNumber"`
PinvState string `json:"pinv_state"`
PinvGridState string `json:"pinv_grid_state"`
POut int `json:"p_out"`
QOut int `json:"q_out"`
VOut float64 `json:"v_out"`
FOut float64 `json:"f_out"`
IOut float64 `json:"i_out"`
EnergyCharged int `json:"energy_charged"`
EnergyDischarged int `json:"energy_discharged"`
OffGrid int `json:"off_grid"`
VfMode int `json:"vf_mode"`
WobbleDetected int `json:"wobble_detected"`
ChargePowerClamped int `json:"charge_power_clamped"`
BackupReady int `json:"backup_ready"`
OpSeqState string `json:"OpSeqState"`
Version string `json:"version"`
}

0 comments on commit 43e24eb

Please sign in to comment.