@energiok/node-red-contrib-pricecontrol-thermal 1.2.1 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,90 +0,0 @@
1
- /**
2
- * Test: Does the algorithm work correctly when machine runs in UTC?
3
- *
4
- * Scenario: It's 16:30 Oslo time (15:30 UTC) on Jan 15.
5
- * The expensive peak is at 17:00 Oslo (16:00 UTC).
6
- * Should we be in "coast" mode? Will setTimeout fire at the right time?
7
- */
8
-
9
- const { DateTime } = require("luxon");
10
- const { createSchedule, getCurrentMode } = require('./src/strategy-smart-thermal-functions.js');
11
-
12
- console.log("=== TESTING UTC MACHINE BEHAVIOR ===\n");
13
-
14
- // Simple test data - one cheap hour, one expensive hour
15
- const prices = [
16
- { timestamp: "2026-01-15T15:00:00Z", price: 80 }, // 16:00 Oslo - normal
17
- { timestamp: "2026-01-15T16:00:00Z", price: 150 }, // 17:00 Oslo - EXPENSIVE (coast)
18
- { timestamp: "2026-01-15T17:00:00Z", price: 80 }, // 18:00 Oslo - normal
19
- { timestamp: "2026-01-15T18:00:00Z", price: 70 }, // 19:00 Oslo - cheap (boost)
20
- ];
21
-
22
- const config = {
23
- heatLossCoefficient: 0.05,
24
- minModeDuration: 60,
25
- outputTimezone: "Europe/Oslo",
26
- };
27
-
28
- const schedule = createSchedule(prices, 5, config);
29
-
30
- console.log("Schedule created:");
31
- schedule.forEach(entry => {
32
- console.log(` Oslo: ${entry.time.substring(11,16)} | UTC: ${entry.timeUtc.substring(11,16)} | ${entry.mode.padEnd(6)} | ${entry.price}`);
33
- });
34
-
35
- console.log("\n--- Simulating getCurrentMode at different times ---\n");
36
-
37
- // Test 1: Machine running in UTC, current time is 15:30 UTC = 16:30 Oslo
38
- // We're BEFORE the 16:00 UTC coast period
39
- const utcTime1 = DateTime.fromISO("2026-01-15T15:30:00Z");
40
- const mode1 = getCurrentMode(schedule, utcTime1);
41
- console.log(`Test 1: UTC 15:30 (Oslo 16:30)`);
42
- console.log(` Current mode: ${mode1}`);
43
- console.log(` Expected: normal (we're in the 15:00 UTC / 16:00 Oslo slot)`);
44
- console.log(` Correct: ${mode1 === "normal" ? "✓ YES" : "✗ NO"}`);
45
-
46
- // Test 2: Machine running in UTC, current time is 16:30 UTC = 17:30 Oslo
47
- // We're IN the 16:00 UTC coast period
48
- const utcTime2 = DateTime.fromISO("2026-01-15T16:30:00Z");
49
- const mode2 = getCurrentMode(schedule, utcTime2);
50
- console.log(`\nTest 2: UTC 16:30 (Oslo 17:30)`);
51
- console.log(` Current mode: ${mode2}`);
52
- console.log(` Expected: coast (we're in the 16:00 UTC / 17:00 Oslo slot)`);
53
- console.log(` Correct: ${mode2 === "coast" ? "✓ YES" : "✗ NO"}`);
54
-
55
- // Test 3: User passes Oslo time string with offset
56
- const osloTime = DateTime.fromISO("2026-01-15T17:30:00+01:00");
57
- const mode3 = getCurrentMode(schedule, osloTime);
58
- console.log(`\nTest 3: Oslo 17:30+01:00 (same as UTC 16:30)`);
59
- console.log(` Current mode: ${mode3}`);
60
- console.log(` Expected: coast (same moment as Test 2)`);
61
- console.log(` Correct: ${mode3 === "coast" ? "✓ YES" : "✗ NO"}`);
62
-
63
- // Test 4: Verify timeout calculation would work
64
- console.log("\n--- setTimeout timing verification ---\n");
65
-
66
- const currentUtc = DateTime.fromISO("2026-01-15T15:30:00Z");
67
- console.log(`Current time: UTC 15:30 (Oslo 16:30)`);
68
-
69
- // Find next mode change
70
- for (let i = 0; i < schedule.length; i++) {
71
- const entryUtc = DateTime.fromISO(schedule[i].timeUtc).toUTC();
72
- if (entryUtc > currentUtc) {
73
- const waitMs = entryUtc.diff(currentUtc).as('milliseconds');
74
- const waitMin = waitMs / 60000;
75
- console.log(`Next mode change: ${schedule[i].mode} at UTC ${schedule[i].timeUtc.substring(11,16)} (Oslo ${schedule[i].time.substring(11,16)})`);
76
- console.log(`Wait time: ${waitMin.toFixed(0)} minutes (${waitMs} ms)`);
77
- console.log(`\nThis means setTimeout(fn, ${waitMs}) will fire at the correct moment`);
78
- console.log(`regardless of whether machine TZ is UTC or Europe/Oslo`);
79
- break;
80
- }
81
- }
82
-
83
- console.log("\n=== CONCLUSION ===\n");
84
- console.log("The algorithm uses UTC internally for all time comparisons.");
85
- console.log("Schedule output shows Oslo time for DISPLAY purposes only.");
86
- console.log("setTimeout delays are calculated from UTC differences.");
87
- console.log("");
88
- console.log("✓ Machine timezone does NOT affect when events fire");
89
- console.log("✓ Coast mode will activate at the correct physical moment");
90
- console.log("✓ Display times show Oslo for user convenience");