Rename SoC to Soc and LoadPoint to Loadpoint (#5549)
This commit is contained in:
parent
54f204c0f8
commit
03d6d1418a
165 changed files with 1054 additions and 1032 deletions
|
|
@ -97,8 +97,8 @@ func (s *HTTPd) RegisterSiteHandlers(site site.API, cache *util.Cache) {
|
|||
routes := map[string]route{
|
||||
"health": {[]string{"GET"}, "/health", healthHandler(site)},
|
||||
"state": {[]string{"GET"}, "/state", stateHandler(cache)},
|
||||
"buffersoc": {[]string{"POST", "OPTIONS"}, "/buffersoc/{value:[0-9.]+}", floatHandler(site.SetBufferSoC, site.GetBufferSoC)},
|
||||
"prioritysoc": {[]string{"POST", "OPTIONS"}, "/prioritysoc/{value:[0-9.]+}", floatHandler(site.SetPrioritySoC, site.GetPrioritySoC)},
|
||||
"buffersoc": {[]string{"POST", "OPTIONS"}, "/buffersoc/{value:[0-9.]+}", floatHandler(site.SetBufferSoc, site.GetBufferSoc)},
|
||||
"prioritysoc": {[]string{"POST", "OPTIONS"}, "/prioritysoc/{value:[0-9.]+}", floatHandler(site.SetPrioritySoc, site.GetPrioritySoc)},
|
||||
"residualpower": {[]string{"POST", "OPTIONS"}, "/residualpower/{value:[-0-9.]+}", floatHandler(site.SetResidualPower, site.GetResidualPower)},
|
||||
"sessions": {[]string{"GET"}, "/sessions", sessionHandler},
|
||||
"telemetry": {[]string{"GET"}, "/settings/telemetry", boolGetHandler(telemetry.Enabled)},
|
||||
|
|
@ -110,14 +110,14 @@ func (s *HTTPd) RegisterSiteHandlers(site site.API, cache *util.Cache) {
|
|||
}
|
||||
|
||||
// loadpoint api
|
||||
for id, lp := range site.LoadPoints() {
|
||||
for id, lp := range site.Loadpoints() {
|
||||
loadpoint := api.PathPrefix(fmt.Sprintf("/loadpoints/%d", id+1)).Subrouter()
|
||||
|
||||
routes := map[string]route{
|
||||
"mode": {[]string{"POST", "OPTIONS"}, "/mode/{value:[a-z]+}", chargeModeHandler(lp)},
|
||||
"targetenergy": {[]string{"POST", "OPTIONS"}, "/targetenergy/{value:[0-9.]+}", floatHandler(pass(lp.SetTargetEnergy), lp.GetTargetEnergy)},
|
||||
"targetsoc": {[]string{"POST", "OPTIONS"}, "/targetsoc/{value:[0-9]+}", intHandler(pass(lp.SetTargetSoC), lp.GetTargetSoC)},
|
||||
"minsoc": {[]string{"POST", "OPTIONS"}, "/minsoc/{value:[0-9]+}", intHandler(pass(lp.SetMinSoC), lp.GetMinSoC)},
|
||||
"targetsoc": {[]string{"POST", "OPTIONS"}, "/targetsoc/{value:[0-9]+}", intHandler(pass(lp.SetTargetSoc), lp.GetTargetSoc)},
|
||||
"minsoc": {[]string{"POST", "OPTIONS"}, "/minsoc/{value:[0-9]+}", intHandler(pass(lp.SetMinSoc), lp.GetMinSoc)},
|
||||
"mincurrent": {[]string{"POST", "OPTIONS"}, "/mincurrent/{value:[0-9.]+}", floatHandler(pass(lp.SetMinCurrent), lp.GetMinCurrent)},
|
||||
"maxcurrent": {[]string{"POST", "OPTIONS"}, "/maxcurrent/{value:[0-9.]+}", floatHandler(pass(lp.SetMaxCurrent), lp.GetMaxCurrent)},
|
||||
"phases": {[]string{"POST", "OPTIONS"}, "/phases/{value:[0-9]+}", phasesHandler(lp)},
|
||||
|
|
|
|||
|
|
@ -303,10 +303,10 @@ func targetChargeHandler(loadpoint targetCharger) http.HandlerFunc {
|
|||
}
|
||||
|
||||
res := struct {
|
||||
SoC int `json:"soc"`
|
||||
Soc int `json:"soc"`
|
||||
Time time.Time `json:"time"`
|
||||
}{
|
||||
SoC: socV,
|
||||
Soc: socV,
|
||||
Time: timeV,
|
||||
}
|
||||
|
||||
|
|
@ -380,6 +380,6 @@ func socketHandler(hub *SocketHub) http.HandlerFunc {
|
|||
|
||||
// TargetCharger defines target charge related loadpoint operations
|
||||
type targetCharger interface {
|
||||
// SetTargetCharge sets the charge targetSoC
|
||||
// SetTargetCharge sets the charge targetSoc
|
||||
SetTargetCharge(time.Time, int) error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,22 +11,22 @@ import (
|
|||
)
|
||||
|
||||
type mockLoadpoint struct {
|
||||
SoC int
|
||||
Soc int
|
||||
TargetTime time.Time
|
||||
}
|
||||
|
||||
func (lp *mockLoadpoint) SetTargetCharge(time time.Time, soc int) error {
|
||||
lp.SoC = soc
|
||||
lp.Soc = soc
|
||||
lp.TargetTime = time
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestTargetChargeHandler(t *testing.T) {
|
||||
tc := []struct {
|
||||
inSoC string
|
||||
inSoc string
|
||||
inTime string
|
||||
statusCode int
|
||||
outSoC int
|
||||
outSoc int
|
||||
outTime time.Time
|
||||
}{
|
||||
{
|
||||
|
|
@ -42,13 +42,13 @@ func TestTargetChargeHandler(t *testing.T) {
|
|||
|
||||
handler := http.HandlerFunc(targetChargeHandler(mockLp))
|
||||
|
||||
req, err := http.NewRequest("GET", fmt.Sprintf("/targetcharge/%s/%s", tc.inSoC, tc.inTime), nil)
|
||||
req, err := http.NewRequest("GET", fmt.Sprintf("/targetcharge/%s/%s", tc.inSoc, tc.inTime), nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
vars := map[string]string{
|
||||
"soc": tc.inSoC,
|
||||
"soc": tc.inSoc,
|
||||
"time": tc.inTime,
|
||||
}
|
||||
|
||||
|
|
@ -62,8 +62,8 @@ func TestTargetChargeHandler(t *testing.T) {
|
|||
status, tc.statusCode)
|
||||
}
|
||||
|
||||
if mockLp.SoC != tc.outSoC {
|
||||
t.Errorf("wrong target soc: got %v want %v", mockLp.SoC, tc.outSoC)
|
||||
if mockLp.Soc != tc.outSoc {
|
||||
t.Errorf("wrong target soc: got %v want %v", mockLp.Soc, tc.outSoc)
|
||||
}
|
||||
|
||||
isoFormat := "2006-01-02T15:04:05.999Z07:00"
|
||||
|
|
|
|||
|
|
@ -90,9 +90,9 @@ func (m *Influx) Run(loadPoints []loadpoint.API, in <-chan util.Param) {
|
|||
// add points to batch for async writing
|
||||
for param := range in {
|
||||
// vehicle name
|
||||
if param.LoadPoint != nil {
|
||||
if param.Loadpoint != nil {
|
||||
if name, ok := param.Val.(string); ok && param.Key == "vehicleTitle" {
|
||||
vehicles[*param.LoadPoint] = name
|
||||
vehicles[*param.Loadpoint] = name
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
@ -102,9 +102,9 @@ func (m *Influx) Run(loadPoints []loadpoint.API, in <-chan util.Param) {
|
|||
}
|
||||
|
||||
tags := map[string]string{}
|
||||
if param.LoadPoint != nil {
|
||||
tags["loadpoint"] = loadPoints[*param.LoadPoint].Name()
|
||||
tags["vehicle"] = vehicles[*param.LoadPoint]
|
||||
if param.Loadpoint != nil {
|
||||
tags["loadpoint"] = loadPoints[*param.Loadpoint].Name()
|
||||
tags["vehicle"] = vehicles[*param.Loadpoint]
|
||||
}
|
||||
|
||||
fields := map[string]interface{}{}
|
||||
|
|
|
|||
|
|
@ -109,14 +109,14 @@ func (m *MQTT) listenSetters(topic string, site site.API, lp loadpoint.API) {
|
|||
m.Handler.ListenSetter(topic+"/mode/set", func(payload string) {
|
||||
lp.SetMode(api.ChargeMode(payload))
|
||||
})
|
||||
m.Handler.ListenSetter(topic+"/minSoC/set", func(payload string) {
|
||||
m.Handler.ListenSetter(topic+"/minSoc/set", func(payload string) {
|
||||
if soc, err := strconv.Atoi(payload); err == nil {
|
||||
lp.SetMinSoC(soc)
|
||||
lp.SetMinSoc(soc)
|
||||
}
|
||||
})
|
||||
m.Handler.ListenSetter(topic+"/targetSoC/set", func(payload string) {
|
||||
m.Handler.ListenSetter(topic+"/targetSoc/set", func(payload string) {
|
||||
if soc, err := strconv.Atoi(payload); err == nil {
|
||||
lp.SetTargetSoC(soc)
|
||||
lp.SetTargetSoc(soc)
|
||||
}
|
||||
})
|
||||
m.Handler.ListenSetter(topic+"/minCurrent/set", func(payload string) {
|
||||
|
|
@ -154,15 +154,15 @@ func (m *MQTT) Run(site site.API, in <-chan util.Param) {
|
|||
m.publish(topic, true, "online")
|
||||
|
||||
// site setters
|
||||
m.Handler.ListenSetter(fmt.Sprintf("%s/site/prioritySoC/set", m.root), func(payload string) {
|
||||
m.Handler.ListenSetter(fmt.Sprintf("%s/site/prioritySoc/set", m.root), func(payload string) {
|
||||
if soc, err := strconv.Atoi(payload); err == nil {
|
||||
_ = site.SetPrioritySoC(float64(soc))
|
||||
_ = site.SetPrioritySoc(float64(soc))
|
||||
}
|
||||
})
|
||||
|
||||
m.Handler.ListenSetter(fmt.Sprintf("%s/site/bufferSoC/set", m.root), func(payload string) {
|
||||
m.Handler.ListenSetter(fmt.Sprintf("%s/site/bufferSoc/set", m.root), func(payload string) {
|
||||
if soc, err := strconv.Atoi(payload); err == nil {
|
||||
_ = site.SetBufferSoC(float64(soc))
|
||||
_ = site.SetBufferSoc(float64(soc))
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -174,16 +174,16 @@ func (m *MQTT) Run(site site.API, in <-chan util.Param) {
|
|||
|
||||
// number of loadpoints
|
||||
topic = fmt.Sprintf("%s/loadpoints", m.root)
|
||||
m.publish(topic, true, len(site.LoadPoints()))
|
||||
m.publish(topic, true, len(site.Loadpoints()))
|
||||
|
||||
// loadpoint setters
|
||||
for id, lp := range site.LoadPoints() {
|
||||
for id, lp := range site.Loadpoints() {
|
||||
topic := fmt.Sprintf("%s/loadpoints/%d", m.root, id+1)
|
||||
m.listenSetters(topic, site, lp)
|
||||
}
|
||||
|
||||
// TODO remove deprecated topics
|
||||
for id := range site.LoadPoints() {
|
||||
for id := range site.Loadpoints() {
|
||||
topic := fmt.Sprintf("%s/loadpoints/%d", m.root, id+1)
|
||||
for _, dep := range []string{"activePhases", "range", "socCharge", "vehicleSoc"} {
|
||||
m.publish(fmt.Sprintf("%s/%s", topic, dep), true, nil)
|
||||
|
|
@ -202,8 +202,8 @@ func (m *MQTT) Run(site site.API, in <-chan util.Param) {
|
|||
// publish
|
||||
for p := range in {
|
||||
topic := fmt.Sprintf("%s/site", m.root)
|
||||
if p.LoadPoint != nil {
|
||||
id := *p.LoadPoint + 1
|
||||
if p.Loadpoint != nil {
|
||||
id := *p.Loadpoint + 1
|
||||
topic = fmt.Sprintf("%s/loadpoints/%d", m.root, id)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -122,8 +122,8 @@ func kv(p util.Param) string {
|
|||
|
||||
var msg strings.Builder
|
||||
msg.WriteString("\"")
|
||||
if p.LoadPoint != nil {
|
||||
msg.WriteString(fmt.Sprintf("loadpoints.%d.", *p.LoadPoint))
|
||||
if p.Loadpoint != nil {
|
||||
msg.WriteString(fmt.Sprintf("loadpoints.%d.", *p.Loadpoint))
|
||||
}
|
||||
msg.WriteString(p.Key)
|
||||
msg.WriteString("\":")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue