diff --git a/src/strategy-battery-charging-functions.js b/src/strategy-battery-charging-functions.js index 19c5cb6..12bbd85 100644 --- a/src/strategy-battery-charging-functions.js +++ b/src/strategy-battery-charging-functions.js @@ -198,13 +198,12 @@ const mergeInput = (config) => { priceData, consumptionForecast, productionForecast, - soc, } = config let now = Date.now() now = new Date(now - (now % (60 * 60 * 1000))) return priceData - .filter((v) => new Date(v.start) >= now) + .filter((v) => new Date(v.start).getTime() >= now.getTime()) .map((v) => { return { start: new Date(v.start), @@ -235,7 +234,6 @@ const calculateBatteryChargingStrategy = (config) => { batteryMaxEnergy, batteryMaxInputPower, soc, - priceData, } = config const input = mergeInput(config) @@ -269,12 +267,12 @@ const calculateBatteryChargingStrategy = (config) => { const noBattery = { periods: [], excessPvEnergyUse: 0 } return { best: { - schedule: toSchedule(best.periods, priceData[0].start), + schedule: toSchedule(best.periods, input[0].start), excessPvEnergyUse: best.excessPvEnergyUse, cost: f(best) * -1, }, noBattery: { - schedule: toSchedule(noBattery.periods, priceData[0].start), + schedule: toSchedule(noBattery.periods, input[0].start), excessPvEnergyUse: noBattery.excessPvEnergyUse, cost: f(noBattery) * -1, }, diff --git a/test/strategy-battery-charging.test.js b/test/strategy-battery-charging.test.js index 042d9fd..fd66055 100644 --- a/test/strategy-battery-charging.test.js +++ b/test/strategy-battery-charging.test.js @@ -96,11 +96,13 @@ describe('Battery charging strategy Node', () => { n2.on('input', function inputCallback(msg) { expect(msg).toHaveProperty('payload') expect(msg.payload).toHaveProperty('schedule') + + console.log(JSON.stringify(msg.payload, null, 1)) done() }) let now = Date.now() - now = now - (now % (60 * 60 * 1000)) + now = now - (now % (24 * 60 * 60 * 1000)) const inputPayload = { soc: 75, priceData: [