Skip to content

Commit

Permalink
Vehicles: move more properties to /vehicles (BC) (evcc-io#11181)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Jan 20, 2024
1 parent 02214bc commit bc0343a
Show file tree
Hide file tree
Showing 26 changed files with 182 additions and 162 deletions.
76 changes: 1 addition & 75 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,88 +2,13 @@ package api

import (
"context"
"fmt"
"io"
"net/http"
"strings"
"time"
)

//go:generate mockgen -package api -destination mock.go github.com/evcc-io/evcc/api Charger,ChargeState,CurrentLimiter,PhaseSwitcher,Identifier,Meter,MeterEnergy,Vehicle,ChargeRater,Battery,Tariff,BatteryController

// ChargeMode is the charge operation mode. Valid values are off, now, minpv and pv
type ChargeMode string

// Charge modes
const (
ModeEmpty ChargeMode = ""
ModeOff ChargeMode = "off"
ModeNow ChargeMode = "now"
ModeMinPV ChargeMode = "minpv"
ModePV ChargeMode = "pv"
)

// String implements Stringer
func (c ChargeMode) String() string {
return string(c)
}

// ChargeStatus is the EV's charging status from A to F
type ChargeStatus string

// Charging states
const (
StatusNone ChargeStatus = ""
StatusA ChargeStatus = "A" // Fzg. angeschlossen: nein Laden aktiv: nein Ladestation betriebsbereit, Fahrzeug getrennt
StatusB ChargeStatus = "B" // Fzg. angeschlossen: ja Laden aktiv: nein Fahrzeug verbunden, Netzspannung liegt nicht an
StatusC ChargeStatus = "C" // Fzg. angeschlossen: ja Laden aktiv: ja Fahrzeug lädt, Netzspannung liegt an
StatusD ChargeStatus = "D" // Fzg. angeschlossen: ja Laden aktiv: ja Fahrzeug lädt mit externer Belüfungsanforderung (für Blei-Säure-Batterien)
StatusE ChargeStatus = "E" // Fzg. angeschlossen: ja Laden aktiv: nein Fehler Fahrzeug / Kabel (CP-Kurzschluss, 0V)
StatusF ChargeStatus = "F" // Fzg. angeschlossen: ja Laden aktiv: nein Fehler EVSE oder Abstecken simulieren (CP-Wake-up, -12V)
)

var StatusEasA = map[ChargeStatus]ChargeStatus{StatusE: StatusA}

// ChargeStatusString converts a string to ChargeStatus
func ChargeStatusString(status string) (ChargeStatus, error) {
s := strings.ToUpper(strings.Trim(status, "\x00 "))

if len(s) == 0 {
return StatusNone, fmt.Errorf("invalid status: %s", status)
}

switch s1 := s[:1]; s1 {
case "A", "B":
return ChargeStatus(s1), nil

case "C", "D":
if s == "C1" || s == "D1" {
return StatusB, nil
}
return StatusC, nil

case "E", "F":
return ChargeStatus(s1), fmt.Errorf("invalid status: %s", s)

default:
return StatusNone, fmt.Errorf("invalid status: %s", status)
}
}

// ChargeStatusStringWithMapping converts a string to ChargeStatus. In case of error, mapping is applied.
func ChargeStatusStringWithMapping(s string, m map[ChargeStatus]ChargeStatus) (ChargeStatus, error) {
status, err := ChargeStatusString(s)
if mappedStatus, ok := m[status]; ok && err != nil {
return mappedStatus, nil
}
return status, err
}

// String implements Stringer
func (c ChargeStatus) String() string {
return string(c)
}

// Meter provides total active power in W
type Meter interface {
CurrentPower() (float64, error)
Expand Down Expand Up @@ -187,6 +112,7 @@ type Vehicle interface {
Battery
BatteryCapacity
IconDescriber
FeatureDescriber
Title() string
SetTitle(string)
Phases() int
Expand Down
79 changes: 79 additions & 0 deletions api/chargemodestatus.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package api

import (
"fmt"
"strings"
)

// ChargeMode is the charge operation mode. Valid values are off, now, minpv and pv
type ChargeMode string

// Charge modes
const (
ModeEmpty ChargeMode = ""
ModeOff ChargeMode = "off"
ModeNow ChargeMode = "now"
ModeMinPV ChargeMode = "minpv"
ModePV ChargeMode = "pv"
)

// String implements Stringer
func (c ChargeMode) String() string {
return string(c)
}

// ChargeStatus is the EV's charging status from A to F
type ChargeStatus string

// Charging states
const (
StatusNone ChargeStatus = ""
StatusA ChargeStatus = "A" // Fzg. angeschlossen: nein Laden aktiv: nein Ladestation betriebsbereit, Fahrzeug getrennt
StatusB ChargeStatus = "B" // Fzg. angeschlossen: ja Laden aktiv: nein Fahrzeug verbunden, Netzspannung liegt nicht an
StatusC ChargeStatus = "C" // Fzg. angeschlossen: ja Laden aktiv: ja Fahrzeug lädt, Netzspannung liegt an
StatusD ChargeStatus = "D" // Fzg. angeschlossen: ja Laden aktiv: ja Fahrzeug lädt mit externer Belüfungsanforderung (für Blei-Säure-Batterien)
StatusE ChargeStatus = "E" // Fzg. angeschlossen: ja Laden aktiv: nein Fehler Fahrzeug / Kabel (CP-Kurzschluss, 0V)
StatusF ChargeStatus = "F" // Fzg. angeschlossen: ja Laden aktiv: nein Fehler EVSE oder Abstecken simulieren (CP-Wake-up, -12V)
)

var StatusEasA = map[ChargeStatus]ChargeStatus{StatusE: StatusA}

// ChargeStatusString converts a string to ChargeStatus
func ChargeStatusString(status string) (ChargeStatus, error) {
s := strings.ToUpper(strings.Trim(status, "\x00 "))

if len(s) == 0 {
return StatusNone, fmt.Errorf("invalid status: %s", status)
}

switch s1 := s[:1]; s1 {
case "A", "B":
return ChargeStatus(s1), nil

case "C", "D":
if s == "C1" || s == "D1" {
return StatusB, nil
}
return StatusC, nil

case "E", "F":
return ChargeStatus(s1), fmt.Errorf("invalid status: %s", s)

default:
return StatusNone, fmt.Errorf("invalid status: %s", status)
}
}

// ChargeStatusStringWithMapping converts a string to ChargeStatus. In case of error, mapping is applied.
func ChargeStatusStringWithMapping(s string, m map[ChargeStatus]ChargeStatus) (ChargeStatus, error) {
status, err := ChargeStatusString(s)
if mappedStatus, ok := m[status]; ok && err != nil {
return mappedStatus, nil
}
return status, err
}

// String implements Stringer
func (c ChargeStatus) String() string {
return string(c)
}
14 changes: 14 additions & 0 deletions api/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions assets/js/components/ChargingPlan.vue
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export default {
socBasedCharging: Boolean,
socPerKwh: Number,
vehicle: Object,
vehicleCapacity: Number,
capacity: Number,
vehicleSoc: Number,
vehicleTargetSoc: Number,
},
Expand Down Expand Up @@ -208,7 +208,7 @@ export default {
}
return fmtEnergy(
this.planEnergy,
optionStep(this.vehicleCapacity || 100),
optionStep(this.capacity || 100),
this.fmtKWh,
this.$t("main.targetEnergy.noLimit")
);
Expand Down
6 changes: 3 additions & 3 deletions assets/js/components/ChargingPlanSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:id="`${id}_0`"
class="mb-2"
v-bind="plans[0] || {}"
:vehicle-capacity="vehicleCapacity"
:capacity="capacity"
:range-per-soc="rangePerSoc"
:soc-per-kwh="socPerKwh"
:soc-based-planning="socBasedPlanning"
Expand Down Expand Up @@ -58,7 +58,7 @@ export default {
smartCostType: String,
currency: String,
mode: String,
vehicleCapacity: Number,
capacity: Number,
vehicle: Object,
vehicleTargetSoc: Number,
},
Expand Down Expand Up @@ -161,7 +161,7 @@ export default {
this.$emit("plan-updated", {
time: this.defaultDate(),
soc: 100,
energy: this.vehicleCapacity || 10,
energy: this.capacity || 10,
});
},
removePlan: function (index) {
Expand Down
6 changes: 3 additions & 3 deletions assets/js/components/ChargingPlanSettingsEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default {
time: String,
rangePerSoc: Number,
socPerKwh: Number,
vehicleCapacity: Number,
capacity: Number,
socBasedPlanning: Boolean,
},
emits: ["plan-updated", "plan-removed", "plan-preview"],
Expand All @@ -173,7 +173,7 @@ export default {
energyOptions: function () {
const options = energyOptions(
0,
this.vehicleCapacity || 100,
this.capacity || 100,
this.socPerKwh,
this.fmtKWh,
"-"
Expand Down Expand Up @@ -241,7 +241,7 @@ export default {
}
if (!this.selectedEnergy) {
this.selectedEnergy =
window.localStorage[LAST_ENERGY_GOAL_KEY] || this.vehicleCapacity || 10;
window.localStorage[LAST_ENERGY_GOAL_KEY] || this.capacity || 10;
}
let time = this.time;
Expand Down
1 change: 0 additions & 1 deletion assets/js/components/ChargingSessionModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
:id="session.vehicle"
class="options"
:vehicles="vehicles"
:is-unknown="false"
connected
@change-vehicle="changeVehicle"
@remove-vehicle="removeVehicle"
Expand Down
6 changes: 3 additions & 3 deletions assets/js/components/LimitEnergySelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@ export default {
limitEnergy: Number,
socPerKwh: Number,
chargedEnergy: Number,
vehicleCapacity: Number,
capacity: Number,
},
emits: ["limit-energy-updated"],
computed: {
options: function () {
return energyOptions(
this.chargedEnergy,
this.vehicleCapacity || 100,
this.capacity || 100,
this.socPerKwh,
this.fmtKWh,
this.$t("main.targetEnergy.noLimit")
);
},
step() {
return optionStep(this.vehicleCapacity || 100);
return optionStep(this.capacity || 100);
},
estimated: function () {
return estimatedSoc(this.limitEnergy, this.socPerKwh);
Expand Down
6 changes: 3 additions & 3 deletions assets/js/components/Loadpoint.story.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const state = reactive({
chargePower: 2800,
chargedEnergy: 11e3,
chargeDuration: 95 * 60,
vehiclePresent: true,
vehicleTitle: "Mein Auto",
vehicleName: "meinauto",
enabled: true,
connected: true,
mode: "pv",
Expand All @@ -29,14 +29,14 @@ const state = reactive({
<Loadpoint v-bind="state" />
</Variant>
<Variant title="without soc">
<Loadpoint v-bind="state" vehicleTitle="" :vehiclePresent="false" />
<Loadpoint v-bind="state" vehicleTitle="" vehicleName="" />
</Variant>
<Variant title="idle">
<Loadpoint
v-bind="state"
:enabled="false"
:connected="false"
:vehiclePresent="false"
vehicleName=""
mode="off"
:charging="false"
:chargeCurrent="0"
Expand Down
6 changes: 2 additions & 4 deletions assets/js/components/Loadpoint.vue
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ export default {
vehicleName: String,
vehicleIcon: String,
vehicleTargetSoc: Number,
vehicleCapacity: Number,
vehicleFeatureOffline: Boolean,
vehicles: Array,
planActive: Boolean,
planProjectedStart: String,
Expand Down Expand Up @@ -247,13 +245,13 @@ export default {
return !!this.vehicleName;
},
vehicleHasSoc: function () {
return this.vehicleKnown && !this.vehicleFeatureOffline;
return this.vehicleKnown && !this.vehicle?.features?.includes("Offline");
},
socBasedCharging: function () {
return this.vehicleHasSoc || this.vehicleSoc > 0;
},
socBasedPlanning: function () {
return this.socBasedCharging && this.vehicleCapacity > 0;
return this.socBasedCharging && this.vehicle?.capacity > 0;
},
},
watch: {
Expand Down
2 changes: 1 addition & 1 deletion assets/js/components/Loadpoints.story.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function loadpoint(opts) {
chargePower: 2800,
chargedEnergy: 11e3,
chargeDuration: 95 * 60,
vehiclePresent: true,
vehicleName: "tesla",
vehicleTitle: "Tesla Model 3",
enabled: true,
connected: true,
Expand Down
3 changes: 2 additions & 1 deletion assets/js/components/Site.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ export default {
},
loadpointsCompact: function () {
return this.loadpoints.map((lp) => {
const icon = lp.chargerIcon || lp.vehicleIcon || "car";
const vehicleIcon = this.vehicles?.[lp.vehicleName]?.icon;
const icon = lp.chargerIcon || vehicleIcon || "car";
const charging = lp.charging;
const power = lp.chargePower || 0;
return { icon, charging, power };
Expand Down
Loading

0 comments on commit bc0343a

Please sign in to comment.