Skip to content

Commit

Permalink
Publish smartCostActive (#10297)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Oct 13, 2023
1 parent 2ebd09e commit 51fa490
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 18 deletions.
1 change: 1 addition & 0 deletions assets/js/components/Loadpoint.vue
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export default {
guardAction: String,
smartCostLimit: Number,
smartCostType: String,
smartCostActive: Boolean,
tariffGrid: Number,
tariffCo2: Number,
currency: String,
Expand Down
2 changes: 2 additions & 0 deletions assets/js/components/Loadpoints.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
:vehicles="vehicles"
:smartCostLimit="smartCostLimit"
:smartCostType="smartCostType"
:smartCostActive="smartCostActive"
:tariffGrid="tariffGrid"
:tariffCo2="tariffCo2"
:currency="currency"
Expand Down Expand Up @@ -51,6 +52,7 @@ export default {
vehicles: Array,
smartCostLimit: Number,
smartCostType: String,
smartCostActive: Boolean,
tariffGrid: Number,
tariffCo2: Number,
currency: String,
Expand Down
2 changes: 2 additions & 0 deletions assets/js/components/Site.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
:vehicles="vehicles"
:smartCostLimit="smartCostLimit"
:smartCostType="smartCostType"
:smartCostActive="smartCostActive"
:tariffGrid="tariffGrid"
:tariffCo2="tariffCo2"
:currency="currency"
Expand Down Expand Up @@ -103,6 +104,7 @@ export default {
sponsorTokenExpires: Number,
smartCostLimit: Number,
smartCostType: String,
smartCostActive: Boolean,
},
computed: {
energyflow: function () {
Expand Down
1 change: 1 addition & 0 deletions assets/js/components/Vehicle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export default {
climaterActive: Boolean,
smartCostLimit: Number,
smartCostType: String,
smartCostActive: Boolean,
tariffGrid: Number,
tariffCo2: Number,
currency: String,
Expand Down
8 changes: 5 additions & 3 deletions assets/js/components/VehicleStatus.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,9 @@ describe("smart grid charging", () => {
tariffCo2: 400,
smartCostLimit: 500,
smartCostType: "co2",
smartCostActive: true,
},
"cleanEnergyCharging"
`cleanEnergyCharging:{"co2":"400 g","limit":"500 g"}`
);
});
test("show cheap energy message", () => {
Expand All @@ -219,9 +220,10 @@ describe("smart grid charging", () => {
charging: true,
tariffGrid: 0.28,
smartCostLimit: 0.29,
currency: "EUR",
currency: "CHF",
smartCostActive: true,
},
"cheapEnergyCharging"
`cheapEnergyCharging:{"price":"28,0 rp","limit":"29,0 rp"}`
);
});
});
24 changes: 13 additions & 11 deletions assets/js/components/VehicleStatus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ export default {
climaterActive: Boolean,
smartCostLimit: Number,
smartCostType: String,
smartCostActive: Boolean,
tariffGrid: Number,
tariffCo2: Number,
currency: String,
},
computed: {
phaseTimerActive() {
Expand All @@ -46,9 +48,6 @@ export default {
guardTimerActive() {
return this.guardRemainingInterpolated > 0 && this.guardAction === "enable";
},
isCo2() {
return this.smartCostType === CO2_TYPE;
},
message: function () {
const t = (key, data) => {
return this.$t(`main.vehicleStatus.${key}`, data);
Expand Down Expand Up @@ -77,14 +76,17 @@ export default {
}
}
// clean energy
if (this.charging && this.isCo2 && this.tariffCo2 < this.smartCostLimit) {
return t("cleanEnergyCharging");
}
// cheap energy
if (this.charging && !this.isCo2 && this.tariffGrid < this.smartCostLimit) {
return t("cheapEnergyCharging");
// 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") {
Expand Down
2 changes: 2 additions & 0 deletions core/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ func (site *Site) update(lp Updater) {
if err == nil {
limit := site.GetSmartCostLimit()
autoCharge = limit != 0 && rate.Price <= limit
site.publish("smartCostActive", autoCharge)
} else {
site.log.ERROR.Println("tariff:", err)
}
Expand Down Expand Up @@ -802,6 +803,7 @@ func (site *Site) prepare() {
site.publish("residualPower", site.ResidualPower)
site.publish("smartCostLimit", site.SmartCostLimit)
site.publish("smartCostType", nil)
site.publish("smartCostActive", false)
if tariff := site.GetTariff(PlannerTariff); tariff != nil {
site.publish("smartCostType", tariff.Type().String())
}
Expand Down
4 changes: 2 additions & 2 deletions i18n/de.toml
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ vehicleTarget = "Fahrzeuglimit: {soc}%"

[main.vehicleStatus]
charging = "Ladevorgang aktiv …"
cheapEnergyCharging = "Günstige Energie verfügbar. Ladevorgang aktiv …"
cleanEnergyCharging = "Saubere Energie verfügbar. Ladevorgang aktiv …"
cheapEnergyCharging = "Lade günstige Energie: {price} (Grenze < {limit})"
cleanEnergyCharging = "Lade saubere Energie: {co2} (Grenze < {limit})"
climating = "Vorklimatisierung erkannt."
connected = "Verbunden."
disconnected = "Nicht verbunden."
Expand Down
4 changes: 2 additions & 2 deletions i18n/en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ vehicleTarget = "Vehicle limit: {soc}%"

[main.vehicleStatus]
charging = "Charging…"
cheapEnergyCharging = "Cheap energy available. Charging…"
cleanEnergyCharging = "Clean energy available. Charging…"
cheapEnergyCharging = "Charging cheap energy: {price} (limit < {limit})"
cleanEnergyCharging = "Charging clean energy: {co2} (limit < {limit})"
climating = "Pre-conditioning detected."
connected = "Connected."
disconnected = "Disconnected."
Expand Down

0 comments on commit 51fa490

Please sign in to comment.