Skip to content

Commit

Permalink
Cost limit: show negative price options, add 0.5ct steps (#14021)
Browse files Browse the repository at this point in the history
* Cost limit: show negative price options, add 0.5ct steps

* adjust test

* fix test
  • Loading branch information
naltatis authored May 24, 2024
1 parent 73ece1b commit ae6cfbe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
19 changes: 12 additions & 7 deletions assets/js/components/SmartCostLimit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ export default {
for (let i = 1; i <= 100; i++) {
const value = this.optionStartValue + stepSize * i;
if (value != 0) {
values.push(value.toFixed(2));
values.push(this.roundLimit(value));
}
}
// add special entry if currently selected value is not in the scale
const selected = this.selectedSmartCostLimit;
if (selected !== undefined && !values.includes(selected)) {
if (selected && !values.includes(selected)) {
values.push(selected);
}
values.sort((a, b) => a - b);
Expand All @@ -134,16 +134,18 @@ export default {
return 0;
}
const { min } = this.costRange(this.totalSlots);
const minValue = Math.min(0, min);
const stepSize = this.optionStepSize;
return Math.ceil(minValue / stepSize) * stepSize;
// always show some negative values for price
const start = this.isCo2 ? 0 : stepSize * -11;
const minValue = Math.min(start, min);
return Math.floor(minValue / stepSize) * stepSize;
},
optionStepSize() {
if (!this.tariff) {
return 1;
}
const { min, max } = this.costRange(this.totalSlots);
for (const scale of [0.1, 1, 10, 50, 100, 200, 500, 1000, 2000, 5000, 10000]) {
for (const scale of [0.1, 0.5, 1, 10, 50, 100, 200, 500, 1000, 2000, 5000, 10000]) {
if (max - Math.min(0, min) < scale) {
return scale / 100;
}
Expand Down Expand Up @@ -225,14 +227,17 @@ export default {
this.updateTariff();
},
smartCostLimit(limit) {
this.selectedSmartCostLimit = limit?.toFixed(2);
this.selectedSmartCostLimit = this.roundLimit(limit);
},
},
mounted() {
this.updateTariff();
this.selectedSmartCostLimit = this.smartCostLimit?.toFixed(2);
this.selectedSmartCostLimit = this.roundLimit(this.smartCostLimit);
},
methods: {
roundLimit(limit) {
return limit ? Math.round(limit * 1000) / 1000 : 0;
},
updateTariff: async function () {
try {
this.tariff = (await api.get(`tariff/planner`)).data.result;
Expand Down
4 changes: 2 additions & 2 deletions tests/smart-cost.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ test.describe("smart cost limit", async () => {
await page
.getByTestId("loadpoint-settings-modal")
.getByLabel("Price limit")
.selectOption("≤ 50.0 ct/kWh");
.selectOption("≤ 40.0 ct/kWh");
await page.getByTestId("loadpoint-settings-modal").getByLabel("Close").click();
await expect(page.getByTestId("loadpoint-settings-modal")).not.toBeVisible();
await expect(page.getByTestId("vehicle-status")).toContainText("Charging cheap energy");
await expect(page.getByTestId("vehicle-status")).toContainText("(limit 50.0 ct)");
await expect(page.getByTestId("vehicle-status")).toContainText("(limit 40.0 ct)");
});
test("price above limit", async ({ page }) => {
await page.goto("/");
Expand Down

0 comments on commit ae6cfbe

Please sign in to comment.