gruijter / com.gruijter.powerhour

Homey app to summarize power meters per hour, day and month
GNU General Public License v3.0
10 stars 13 forks source link

Fix sort of prices for `priceIs...` functions #154

Closed stefan-schweiger closed 10 months ago

stefan-schweiger commented 10 months ago

The current way sort is used only works for numbers < 1 and also not for all negative ranges, since I have my prices converted to cents I was wondering why the When-triggers were not correctly firing for "The price becomes one of number lowest in the period hours before time o'clock" etc.

You can simply see this by this example:

let test1 = [1, 3, 2, 15, -13, -12, 4];
let test2 = [0.1, 0.3, 0.2, 0.15, -0.13, -0.12, 4 ];

console.log(test1.sort()); // [-12, -13, 1, 15, 2, 3, 4]
console.log(test2.sort()); // [-0.12, -0.13, 0.1, 0.15, 0.2, 0.3, ...]

console.log(test1.sort((a, b) => a - b)); // [-13, -12, 1, 2, 3, 4, 15]
console.log(test2.sort((a, b) => a - b)); // [-0.13, -0.12, 0.1, 0.15, 0.2, 0.3, ...]

I've changed all occurences in generc_dap_device.js (which seems to be the only file using sort) to use the correct sort function.

stefan-schweiger commented 10 months ago

@gruijter any chance to get this merged soon-ish? Because it's pretty annoying that this is not working correctly now during the winter time when prices fluctuate so much. Just want to know if I should wait or install a new version manually myself in the meantime. Thanks! 🙂

gruijter commented 10 months ago

Will try this weekend. Good find!