Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion api/plans.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package api

import "time"

type RepeatingPlan struct {
Weekdays []int `json:"weekdays"` // 0-6 (Sunday-Saturday)
Time string `json:"time"` // HH:MM
Tz string `json:"tz"` // timezone in IANA format
Soc int `json:"soc"` // target soc
Precondition int64 `json:"precondition"` // precondition duration in seconds
Active bool `json:"active"` // active flag
Precondition int64 `json:"-" todo:"..."` // TODO deprecated
}

type PlanStrategy struct {
Continuous bool `json:"continuous"` // force continuous planning
Precondition time.Duration `json:"precondition"` // precondition duration in seconds
}
30 changes: 20 additions & 10 deletions assets/js/components/ChargingPlans/ChargingPlan.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
@static-plan-updated="updateStaticPlan"
@static-plan-removed="removeStaticPlan"
@repeating-plans-updated="updateRepeatingPlans"
@plan-strategy-updated="updatePlanStrategy"
/>
<ChargingPlanArrival
v-if="arrivalTabActive"
Expand All @@ -95,7 +96,13 @@ import api from "@/api";
import { optionStep, fmtEnergy } from "@/utils/energyOptions.ts";
import { defineComponent, type PropType } from "vue";
import type { CURRENCY, Timeout, Vehicle } from "@/types/evcc";
import type { StaticPlan, StaticSocPlan, StaticEnergyPlan, RepeatingPlan } from "./types";
import type {
StaticPlan,
StaticSocPlan,
StaticEnergyPlan,
RepeatingPlan,
PlanStrategy,
} from "./types";
import type { Forecast } from "@/types/evcc.ts";
const ONE_MINUTE = 60 * 1000;

Expand All @@ -114,14 +121,15 @@ export default defineComponent({
effectiveLimitSoc: Number,
effectivePlanSoc: Number,
effectivePlanTime: String,
effectivePlanPrecondition: Number,
effectivePlanContinuous: Boolean,
id: [String, Number],
limitEnergy: Number,
mode: String,
planActive: Boolean,
planEnergy: Number,
planTime: String,
planTimeUnreachable: Boolean,
planPrecondition: { type: Number, default: 0 },
planOverrun: Number,
rangePerSoc: Number,
smartCostType: String,
Expand Down Expand Up @@ -166,7 +174,6 @@ export default defineComponent({
return {
soc: plan.soc,
time: new Date(plan.time),
precondition: plan.precondition,
};
}
return null;
Expand All @@ -175,7 +182,6 @@ export default defineComponent({
return {
energy: this.planEnergy,
time: new Date(this.planTime),
precondition: this.planPrecondition,
};
}
return null;
Expand All @@ -186,7 +192,7 @@ export default defineComponent({
this.vehicle.repeatingPlans &&
this.vehicle.repeatingPlans.length > 0
) {
return [...this.vehicle.repeatingPlans];
return [...(this.vehicle.repeatingPlans || [])];
}
return [];
},
Expand Down Expand Up @@ -286,15 +292,12 @@ export default defineComponent({
},
updateStaticPlan(plan: StaticPlan): void {
const timeISO = plan.time.toISOString();
const params = plan.precondition ? { precondition: plan.precondition } : undefined;
if (this.socBasedPlanning) {
const p = plan as StaticSocPlan;
api.post(`${this.apiVehicle}plan/soc/${p.soc}/${timeISO}`, null, { params });
api.post(`${this.apiVehicle}plan/soc/${p.soc}/${timeISO}`, null);
} else {
const p = plan as StaticEnergyPlan;
api.post(`${this.apiLoadpoint}plan/energy/${p.energy}/${timeISO}`, null, {
params,
});
api.post(`${this.apiLoadpoint}plan/energy/${p.energy}/${timeISO}`, null);
}
},
removeStaticPlan(): void {
Expand All @@ -307,6 +310,13 @@ export default defineComponent({
updateRepeatingPlans(plans: RepeatingPlan[]): void {
api.post(`${this.apiVehicle}plan/repeating`, plans);
},
updatePlanStrategy(strategy: PlanStrategy): void {
if (this.socBasedPlanning) {
api.post(`${this.apiVehicle}plan/strategy`, strategy);
} else {
api.post(`${this.apiLoadpoint}plan/strategy`, strategy);
}
},
setMinSoc(soc: number): void {
api.post(`${this.apiVehicle}minsoc/${soc}`);
},
Expand Down
57 changes: 8 additions & 49 deletions assets/js/components/ChargingPlans/PlanRepeatingSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,12 @@
{{ $t("main.chargingPlan.time") }}
</label>
</div>
<div :class="showPrecondition ? 'col-3' : 'col-4'">
<div class="col-3">
<label :for="formId('goal')">
{{ $t("main.chargingPlan.goal") }}
</label>
</div>
<div v-if="showPrecondition" class="col-1">
<label :for="formId('precondition')">
{{ $t("main.chargingPlan.preconditionShort") }}
</label>
</div>
<div class="col-1">
<div class="col-2">
<label :for="formId('active')"> {{ $t("main.chargingPlan.active") }} </label>
</div>
</div>
Expand Down Expand Up @@ -81,7 +76,7 @@
{{ $t("main.chargingPlan.goal") }}
</label>
</div>
<div :class="['col-7', showPrecondition ? 'col-lg-3' : 'col-lg-4', 'mb-2', 'mb-lg-0']">
<div class="col-7 col-lg-3 mb-2 mb-lg-0">
<select
:id="formId('goal')"
v-model="selectedSoc"
Expand All @@ -94,21 +89,6 @@
</option>
</select>
</div>
<div v-if="showPrecondition" class="col-5 d-lg-none col-form-label">
<label :for="formId('precondition')">
{{ $t("main.chargingPlan.preconditionLong") }}
</label>
</div>
<div
v-if="showPrecondition"
class="col-7 col-lg-1 mb-2 mb-lg-0 d-flex align-items-center"
>
<PreconditionSelect
:id="formId('precondition')"
v-model="selectedPrecondition"
testid="repeating-plan-precondition"
/>
</div>
<div class="col-5 d-lg-none col-form-label">
<label :for="formId('active')">
{{ $t("main.chargingPlan.active") }}
Expand All @@ -130,7 +110,7 @@
</div>
</div>
<div
class="col-4 col-lg-1 d-flex align-items-center justify-content-end justify-content-lg-start"
class="col-4 col-lg-2 d-flex align-items-center justify-content-end justify-content-lg-start"
>
<button
v-if="showApply"
Expand All @@ -140,11 +120,7 @@
tabindex="0"
@click="update(true)"
>
<span class="d-lg-none">{{ $t("main.chargingPlan.update") }}</span>
<shopicon-regular-checkmark
size="s"
class="flex-shrink-0 d-none d-lg-block"
></shopicon-regular-checkmark>
{{ $t("main.chargingPlan.update") }}
</button>
<button
v-else
Expand All @@ -158,44 +134,33 @@
</button>
</div>
</div>
<!-- Large screen precondition description -->
<div class="plan-id-inset">
<PreconditionSelect
:id="formId('precondition')"
v-model="selectedPrecondition"
testid="repeating-plan-precondition"
description-lg-only
/>
</div>
</div>
</template>

<script lang="ts">
import "@h2d2/shopicons/es/regular/trash";
import "@h2d2/shopicons/es/regular/checkmark";
import { distanceUnit } from "@/units";
import MultiSelect from "../Helper/MultiSelect.vue";
import formatter from "@/mixins/formatter";
import deepEqual from "@/utils/deepEqual";
import PreconditionSelect from "./PreconditionSelect.vue";
import type { SelectOption } from "@/types/evcc";
import { defineComponent, type PropType } from "vue";

export default defineComponent({
name: "ChargingPlanRepeatingSettings",
components: { MultiSelect, PreconditionSelect },
components: { MultiSelect },
mixins: [formatter],
props: {
number: Number,
weekdays: { type: Array as PropType<number[]>, default: () => [] },
time: String,
tz: String,
soc: Number,
precondition: Number,
showHeader: Boolean,
active: Boolean,
rangePerSoc: Number,
formIdPrefix: String,
showPrecondition: Boolean,
},
emits: ["updated", "removed"],
data() {
Expand All @@ -204,7 +169,6 @@ export default defineComponent({
selectedTime: this.time,
selectedSoc: this.soc,
selectedActive: this.active,
selectedPrecondition: this.precondition,
};
},
computed: {
Expand All @@ -213,8 +177,7 @@ export default defineComponent({
!deepEqual(this.weekdays, this.selectedWeekdays) ||
this.time !== this.selectedTime ||
this.soc !== this.selectedSoc ||
this.active !== this.selectedActive ||
this.precondition !== this.selectedPrecondition
this.active !== this.selectedActive
);
},
showApply(): boolean {
Expand Down Expand Up @@ -248,9 +211,6 @@ export default defineComponent({
active(newValue: boolean) {
this.selectedActive = newValue;
},
precondition(newValue: number) {
this.selectedPrecondition = newValue;
},
},
methods: {
id(): number {
Expand All @@ -274,7 +234,6 @@ export default defineComponent({
soc: this.selectedSoc,
tz: this.tz,
active: this.selectedActive,
precondition: this.selectedPrecondition,
};

if (forceSave || !this.selectedActive) {
Expand Down
Loading
Loading