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
|
|
@ -70,7 +70,7 @@ type config struct {
|
|||
Vehicles []qualifiedConfig
|
||||
Tariffs tariffConfig
|
||||
Site map[string]interface{}
|
||||
LoadPoints []map[string]interface{}
|
||||
Loadpoints []map[string]interface{}
|
||||
}
|
||||
|
||||
type mqttConfig struct {
|
||||
|
|
|
|||
|
|
@ -126,11 +126,11 @@ func (d *DeviceTest) testMeter(deviceCategory DeviceCategory, v interface{}) (De
|
|||
return DeviceTestResultInvalid, errors.New("selected device is not a battery meter")
|
||||
}
|
||||
|
||||
_, err := b.SoC()
|
||||
_, err := b.Soc()
|
||||
|
||||
for err != nil && errors.Is(err, api.ErrMustRetry) {
|
||||
time.Sleep(3 * time.Second)
|
||||
_, err = b.SoC()
|
||||
_, err = b.Soc()
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
|
@ -148,7 +148,7 @@ func (d *DeviceTest) testVehicle(v interface{}) (DeviceTestResult, error) {
|
|||
return DeviceTestResultInvalid, errors.New("selected device is not a vehicle")
|
||||
}
|
||||
|
||||
if _, err := vv.SoC(); err != nil {
|
||||
if _, err := vv.Soc(); err != nil {
|
||||
return DeviceTestResultInvalid, err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@ javascript:
|
|||
residualpower: 500,
|
||||
pvpower: 5000,
|
||||
batterypower: -750,
|
||||
batterySoC: 55,
|
||||
batterySoc: 55,
|
||||
gridpower: -1000,
|
||||
loadpoints: [
|
||||
{ enabled: true, vehicleSoC: 62, maxcurrent: 6, phases: 1, chargepower: 0 },
|
||||
{ enabled: false, vehicleSoC: 22, maxcurrent: 0, phases: 3, chargepower: 0 }
|
||||
{ enabled: true, vehicleSoc: 62, maxcurrent: 6, phases: 1, chargepower: 0 },
|
||||
{ enabled: false, vehicleSoc: 22, maxcurrent: 0, phases: 3, chargepower: 0 }
|
||||
]
|
||||
};
|
||||
function get() {
|
||||
|
|
@ -56,10 +56,10 @@ meters:
|
|||
source: js
|
||||
vm: shared
|
||||
script: |
|
||||
if (state.batterypower < 0) state.batterySoC++; else state.batterySoC--;
|
||||
if (state.batterySoC < 10) state.batterySoC = 90;
|
||||
if (state.batterySoC > 90) state.batterySoC = 10;
|
||||
state.batterySoC;
|
||||
if (state.batterypower < 0) state.batterySoc++; else state.batterySoc--;
|
||||
if (state.batterySoc < 10) state.batterySoc = 90;
|
||||
if (state.batterySoc > 90) state.batterySoc = 10;
|
||||
state.batterySoc;
|
||||
|
||||
- name: meter_charger_1
|
||||
type: custom
|
||||
|
|
@ -150,16 +150,16 @@ vehicles:
|
|||
vm: shared
|
||||
script: |
|
||||
var lp = state.loadpoints[0];
|
||||
if (lp.chargepower > 0) lp.vehicleSoC++; else lp.vehicleSoC--;
|
||||
if (lp.vehicleSoC < 15) lp.vehicleSoC = 80;
|
||||
if (lp.vehicleSoC > 80) lp.vehicleSoC = 15;
|
||||
lp.vehicleSoC;
|
||||
if (lp.chargepower > 0) lp.vehicleSoc++; else lp.vehicleSoc--;
|
||||
if (lp.vehicleSoc < 15) lp.vehicleSoc = 80;
|
||||
if (lp.vehicleSoc > 80) lp.vehicleSoc = 15;
|
||||
lp.vehicleSoc;
|
||||
range:
|
||||
source: js
|
||||
vm: shared
|
||||
script: |
|
||||
var lp = state.loadpoints[0]
|
||||
var range = (44 * lp.vehicleSoC) / 15;
|
||||
var range = (44 * lp.vehicleSoc) / 15;
|
||||
range
|
||||
capacity: 44
|
||||
onidentify:
|
||||
|
|
@ -172,16 +172,16 @@ vehicles:
|
|||
vm: shared
|
||||
script: |
|
||||
var lp = state.loadpoints[1];
|
||||
if (lp.chargepower > 0) lp.vehicleSoC++; else lp.vehicleSoC--;
|
||||
if (lp.vehicleSoC < 15) lp.vehicleSoC = 75;
|
||||
if (lp.vehicleSoC > 75) lp.vehicleSoC = 15;
|
||||
lp.vehicleSoC;
|
||||
if (lp.chargepower > 0) lp.vehicleSoc++; else lp.vehicleSoc--;
|
||||
if (lp.vehicleSoc < 15) lp.vehicleSoc = 75;
|
||||
if (lp.vehicleSoc > 75) lp.vehicleSoc = 15;
|
||||
lp.vehicleSoc;
|
||||
range:
|
||||
source: js
|
||||
vm: shared
|
||||
script: |
|
||||
var lp = state.loadpoints[1]
|
||||
var range = (80 * lp.vehicleSoC) / 17;
|
||||
var range = (80 * lp.vehicleSoc) / 17;
|
||||
range
|
||||
status:
|
||||
source: js
|
||||
|
|
|
|||
|
|
@ -125,8 +125,8 @@ func runDump(cmd *cobra.Command, args []string) {
|
|||
d.DumpWithHeader(fmt.Sprintf("vehicle: %s", v.Title()), v)
|
||||
}
|
||||
|
||||
for id, lpI := range site.LoadPoints() {
|
||||
lp := lpI.(*core.LoadPoint)
|
||||
for id, lpI := range site.Loadpoints() {
|
||||
lp := lpI.(*core.Loadpoint)
|
||||
|
||||
d.Header(fmt.Sprintf("loadpoint %d", id+1), "=")
|
||||
fmt.Println("")
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ func (d *dumper) Dump(name string, v interface{}) {
|
|||
// wait up to 1m for the vehicle to wakeup
|
||||
start := time.Now()
|
||||
for err = api.ErrMustRetry; err != nil && errors.Is(err, api.ErrMustRetry); {
|
||||
if soc, err = v.SoC(); err != nil {
|
||||
if soc, err = v.Soc(); err != nil {
|
||||
if time.Since(start) > time.Minute {
|
||||
err = os.ErrDeadlineExceeded
|
||||
} else {
|
||||
|
|
@ -81,9 +81,9 @@ func (d *dumper) Dump(name string, v interface{}) {
|
|||
}
|
||||
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, "SoC:\t%v\n", err)
|
||||
fmt.Fprintf(w, "Soc:\t%v\n", err)
|
||||
} else {
|
||||
fmt.Fprintf(w, "SoC:\t%.0f%%\n", soc)
|
||||
fmt.Fprintf(w, "Soc:\t%.0f%%\n", soc)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -170,10 +170,10 @@ func (d *dumper) Dump(name string, v interface{}) {
|
|||
}
|
||||
|
||||
if v, ok := v.(api.SocLimiter); ok {
|
||||
if targetSoC, err := v.TargetSoC(); err != nil {
|
||||
fmt.Fprintf(w, "Target SoC:\t%v\n", err)
|
||||
if targetSoc, err := v.TargetSoc(); err != nil {
|
||||
fmt.Fprintf(w, "Target Soc:\t%v\n", err)
|
||||
} else {
|
||||
fmt.Fprintf(w, "Target SoC:\t%.0f%%\n", targetSoC)
|
||||
fmt.Fprintf(w, "Target Soc:\t%.0f%%\n", targetSoc)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ func runRoot(cmd *cobra.Command, args []string) {
|
|||
|
||||
// setup database
|
||||
if err == nil && conf.Influx.URL != "" {
|
||||
configureInflux(conf.Influx, site.LoadPoints(), tee.Attach())
|
||||
configureInflux(conf.Influx, site.Loadpoints(), tee.Attach())
|
||||
}
|
||||
|
||||
// setup mqtt publisher
|
||||
|
|
|
|||
12
cmd/setup.go
12
cmd/setup.go
|
|
@ -133,7 +133,7 @@ func configureInflux(conf server.InfluxConfig, loadPoints []loadpoint.API, in <-
|
|||
)
|
||||
|
||||
// eliminate duplicate values
|
||||
dedupe := pipe.NewDeduplicator(30*time.Minute, "vehicleCapacity", "vehicleSoC", "vehicleRange", "vehicleOdometer", "chargedEnergy", "chargeRemainingEnergy")
|
||||
dedupe := pipe.NewDeduplicator(30*time.Minute, "vehicleCapacity", "vehicleSoc", "vehicleRange", "vehicleOdometer", "chargedEnergy", "chargeRemainingEnergy")
|
||||
in = dedupe.Pipe(in)
|
||||
|
||||
go influx.Run(loadPoints, in)
|
||||
|
|
@ -254,8 +254,8 @@ func configureTariffs(conf tariffConfig) (tariff.Tariffs, error) {
|
|||
|
||||
func configureSiteAndLoadpoints(conf config) (site *core.Site, err error) {
|
||||
if err = cp.configure(conf); err == nil {
|
||||
var loadPoints []*core.LoadPoint
|
||||
loadPoints, err = configureLoadPoints(conf, cp)
|
||||
var loadPoints []*core.Loadpoint
|
||||
loadPoints, err = configureLoadpoints(conf, cp)
|
||||
|
||||
var tariffs tariff.Tariffs
|
||||
if err == nil {
|
||||
|
|
@ -275,7 +275,7 @@ func configureSiteAndLoadpoints(conf config) (site *core.Site, err error) {
|
|||
return site, err
|
||||
}
|
||||
|
||||
func configureSite(conf map[string]interface{}, cp *ConfigProvider, loadPoints []*core.LoadPoint, vehicles []api.Vehicle, tariffs tariff.Tariffs) (*core.Site, error) {
|
||||
func configureSite(conf map[string]interface{}, cp *ConfigProvider, loadPoints []*core.Loadpoint, vehicles []api.Vehicle, tariffs tariff.Tariffs) (*core.Site, error) {
|
||||
site, err := core.NewSiteFromConfig(log, cp, conf, loadPoints, vehicles, tariffs)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed configuring site: %w", err)
|
||||
|
|
@ -284,7 +284,7 @@ func configureSite(conf map[string]interface{}, cp *ConfigProvider, loadPoints [
|
|||
return site, nil
|
||||
}
|
||||
|
||||
func configureLoadPoints(conf config, cp *ConfigProvider) (loadPoints []*core.LoadPoint, err error) {
|
||||
func configureLoadpoints(conf config, cp *ConfigProvider) (loadPoints []*core.Loadpoint, err error) {
|
||||
lpInterfaces, ok := viper.AllSettings()["loadpoints"].([]interface{})
|
||||
if !ok || len(lpInterfaces) == 0 {
|
||||
return nil, errors.New("missing loadpoints")
|
||||
|
|
@ -297,7 +297,7 @@ func configureLoadPoints(conf config, cp *ConfigProvider) (loadPoints []*core.Lo
|
|||
}
|
||||
|
||||
log := util.NewLogger("lp-" + strconv.Itoa(id+1))
|
||||
lp, err := core.NewLoadPointFromConfig(log, cp, lpc)
|
||||
lp, err := core.NewLoadpointFromConfig(log, cp, lpc)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed configuring loadpoint: %w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ func TestYamlOff(t *testing.T) {
|
|||
t.Error(err)
|
||||
}
|
||||
|
||||
var lp core.LoadPoint
|
||||
if err := util.DecodeOther(conf.LoadPoints[0], &lp); err != nil {
|
||||
var lp core.Loadpoint
|
||||
if err := util.DecodeOther(conf.Loadpoints[0], &lp); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ func main() {
|
|||
|
||||
start := time.Now()
|
||||
for err = api.ErrMustRetry; err != nil && matchesError(err, api.ErrMustRetry); {
|
||||
if soc, err = v.SoC(); err != nil {
|
||||
if soc, err = v.Soc(); err != nil {
|
||||
if time.Since(start) > time.Minute {
|
||||
err = os.ErrDeadlineExceeded
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue