Skip to content

Commit

Permalink
Use outputOutsidePeriod from end time when period spans midnight (bug…
Browse files Browse the repository at this point in the history
… 184) (#185)
  • Loading branch information
ottopaulsen authored Nov 11, 2023
1 parent 453bcc3 commit c8c2e9d
Show file tree
Hide file tree
Showing 7 changed files with 609 additions and 5 deletions.
4 changes: 4 additions & 0 deletions docs/changelog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ sidebarDepth: 1

List the most significant changes.

## 4.1.5

- Fixed bug based on [this issue](https://github.com/ottopaulsen/node-red-contrib-power-saver/issues/184). Now correctly uses the value for `outputOutsidePeriod` when the planning period spans midnight, and there is no data available before midnight. In this case, the period from midnight to end time cannot be planned, so `outputIfNoSchedule` will be used until end time, and `outputOutsidePeriod` will be used from then. See the issue for more details.

## 4.1.4

- Update dependencies.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-power-saver",
"version": "4.1.4",
"version": "4.1.5",
"description": "A module for Node-RED that you can use to turn on and off a switch based on power prices",
"main": "index.js",
"scripts": {
Expand Down
6 changes: 4 additions & 2 deletions src/strategy-lowest-price.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ function doPlanning(node, priceData) {
if (hour === to && to === from && currentStatus === "Inside") {
endIndexes.push(i - 1);
}
if (hour === to && to !== from && i > 0 && currentStatus !== "StartMissing") {
if (hour === to && to !== from && i > 0 ) {
if(currentStatus !== "StartMissing") {
endIndexes.push(i - 1);
}
currentStatus = "Outside";
endIndexes.push(i - 1);
}
if (hour === from) {
currentStatus = "Inside";
Expand Down
197 changes: 197 additions & 0 deletions test/data/lowest-price-bug184-input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
{
"priceData": [
{
"value": 0.485,
"start": "2023-11-09T00:00:00+01:00"
},
{
"value": 0.429,
"start": "2023-11-09T01:00:00+01:00"
},
{
"value": 0.397,
"start": "2023-11-09T02:00:00+01:00"
},
{
"value": 0.373,
"start": "2023-11-09T03:00:00+01:00"
},
{
"value": 0.374,
"start": "2023-11-09T04:00:00+01:00"
},
{
"value": 0.389,
"start": "2023-11-09T05:00:00+01:00"
},
{
"value": 0.461,
"start": "2023-11-09T06:00:00+01:00"
},
{
"value": 0.528,
"start": "2023-11-09T07:00:00+01:00"
},
{
"value": 0.538,
"start": "2023-11-09T08:00:00+01:00"
},
{
"value": 0.558,
"start": "2023-11-09T09:00:00+01:00"
},
{
"value": 0.558,
"start": "2023-11-09T10:00:00+01:00"
},
{
"value": 0.598,
"start": "2023-11-09T11:00:00+01:00"
},
{
"value": 0.61,
"start": "2023-11-09T12:00:00+01:00"
},
{
"value": 0.688,
"start": "2023-11-09T13:00:00+01:00"
},
{
"value": 0.743,
"start": "2023-11-09T14:00:00+01:00"
},
{
"value": 0.763,
"start": "2023-11-09T15:00:00+01:00"
},
{
"value": 1.342,
"start": "2023-11-09T16:00:00+01:00"
},
{
"value": 1.377,
"start": "2023-11-09T17:00:00+01:00"
},
{
"value": 1.363,
"start": "2023-11-09T18:00:00+01:00"
},
{
"value": 1.237,
"start": "2023-11-09T19:00:00+01:00"
},
{
"value": 0.568,
"start": "2023-11-09T20:00:00+01:00"
},
{
"value": 0.542,
"start": "2023-11-09T21:00:00+01:00"
},
{
"value": 0.484,
"start": "2023-11-09T22:00:00+01:00"
},
{
"value": 0.415,
"start": "2023-11-09T23:00:00+01:00"
},
{
"value": 0.404,
"start": "2023-11-10T00:00:00+01:00"
},
{
"value": 0.363,
"start": "2023-11-10T01:00:00+01:00"
},
{
"value": 0.344,
"start": "2023-11-10T02:00:00+01:00"
},
{
"value": 0.331,
"start": "2023-11-10T03:00:00+01:00"
},
{
"value": 0.327,
"start": "2023-11-10T04:00:00+01:00"
},
{
"value": 0.363,
"start": "2023-11-10T05:00:00+01:00"
},
{
"value": 0.436,
"start": "2023-11-10T06:00:00+01:00"
},
{
"value": 0.912,
"start": "2023-11-10T07:00:00+01:00"
},
{
"value": 1.186,
"start": "2023-11-10T08:00:00+01:00"
},
{
"value": 1.165,
"start": "2023-11-10T09:00:00+01:00"
},
{
"value": 1.149,
"start": "2023-11-10T10:00:00+01:00"
},
{
"value": 1.133,
"start": "2023-11-10T11:00:00+01:00"
},
{
"value": 1.017,
"start": "2023-11-10T12:00:00+01:00"
},
{
"value": 0.757,
"start": "2023-11-10T13:00:00+01:00"
},
{
"value": 0.654,
"start": "2023-11-10T14:00:00+01:00"
},
{
"value": 1.279,
"start": "2023-11-10T15:00:00+01:00"
},
{
"value": 0.688,
"start": "2023-11-10T16:00:00+01:00"
},
{
"value": 1.597,
"start": "2023-11-10T17:00:00+01:00"
},
{
"value": 0.487,
"start": "2023-11-10T18:00:00+01:00"
},
{
"value": 0.405,
"start": "2023-11-10T19:00:00+01:00"
},
{
"value": 0.36,
"start": "2023-11-10T20:00:00+01:00"
},
{
"value": 0.33,
"start": "2023-11-10T21:00:00+01:00"
},
{
"value": 0.32,
"start": "2023-11-10T22:00:00+01:00"
},
{
"value": 0.283,
"start": "2023-11-10T23:00:00+01:00"
}
],
"source": "Nordpool"
}
Loading

0 comments on commit c8c2e9d

Please sign in to comment.