evcc-io/assets/js/components/VehicleStatus.vue

139 lines
3.5 KiB
Vue

<template>
<div class="d-block evcc-gray" data-testid="vehicle-status">{{ message }}&nbsp;</div>
</template>
<script>
import { DEFAULT_LOCALE } from "../i18n";
import formatter from "../mixins/formatter";
import { CO2_TYPE } from "../units";
export default {
name: "VehicleStatus",
mixins: [formatter],
props: {
vehicleSoc: Number,
vehicleLimitSoc: Number,
minSoc: Number,
enabled: Boolean,
connected: Boolean,
charging: Boolean,
heating: Boolean,
effectivePlanTime: String,
planProjectedStart: String,
chargingPlanDisabled: Boolean,
planActive: Boolean,
phaseAction: String,
phaseRemainingInterpolated: Number,
pvAction: String,
pvRemainingInterpolated: Number,
targetChargeDisabled: Boolean,
vehicleClimaterActive: Boolean,
smartCostLimit: Number,
smartCostType: String,
smartCostActive: Boolean,
tariffGrid: Number,
tariffCo2: Number,
currency: String,
},
computed: {
phaseTimerActive() {
return (
this.phaseRemainingInterpolated > 0 &&
["scale1p", "scale3p"].includes(this.phaseAction)
);
},
pvTimerActive() {
return (
this.pvRemainingInterpolated > 0 && ["enable", "disable"].includes(this.pvAction)
);
},
message: function () {
const t = (key, data) => {
if (this.heating) {
// check for special heating status translation
const name = `main.heatingStatus.${key}`;
if (this.$te(name, DEFAULT_LOCALE)) {
return this.$t(name, data);
}
}
return this.$t(`main.vehicleStatus.${key}`, data);
};
if (!this.connected) {
return t("disconnected");
}
// min charge active
if (this.minSoc > 0 && this.vehicleSoc < this.minSoc) {
return t("minCharge", { soc: this.minSoc });
}
// plan
if (
!this.chargingPlanDisabled &&
this.effectivePlanTime &&
!this.targetChargeDisabled
) {
if (this.planActive && this.charging) {
return t("targetChargeActive");
}
if (this.planActive && this.enabled) {
return t("targetChargeWaitForVehicle");
}
if (this.planProjectedStart) {
return t("targetChargePlanned", {
time: this.fmtAbsoluteDate(new Date(this.planProjectedStart)),
});
}
}
// clean or cheap energy
if (this.charging && this.smartCostActive) {
return this.smartCostType === CO2_TYPE
? t("cleanEnergyCharging", {
co2: this.fmtCo2Short(this.tariffCo2),
limit: this.fmtCo2Short(this.smartCostLimit),
})
: t("cheapEnergyCharging", {
price: this.fmtPricePerKWh(this.tariffGrid, this.currency, true),
limit: this.fmtPricePerKWh(this.smartCostLimit, this.currency, true),
});
}
if (this.pvTimerActive && !this.enabled && this.pvAction === "enable") {
return t("pvEnable", {
remaining: this.fmtDuration(this.pvRemainingInterpolated),
});
}
if (this.enabled && this.vehicleClimaterActive) {
return t("climating");
}
if (this.enabled && !this.charging) {
if (this.vehicleLimitSoc > 0 && this.vehicleSoc >= this.vehicleLimitSoc - 1) {
return t("vehicleLimitReached", { soc: this.vehicleLimitSoc });
}
return t("waitForVehicle");
}
if (this.pvTimerActive && this.charging && this.pvAction === "disable") {
return t("pvDisable", {
remaining: this.fmtDuration(this.pvRemainingInterpolated),
});
}
if (this.phaseTimerActive) {
return t(this.phaseAction, {
remaining: this.fmtDuration(this.phaseRemainingInterpolated),
});
}
if (this.charging) {
return t("charging");
}
return t("connected");
},
},
};
</script>