node-red-contrib-octopus-intelligent 1.3.0 → 1.3.1

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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.3.1] — 2026-05-14
9
+
10
+ Critical hotfix for v1.3.0. Users on 1.3.0 should upgrade immediately.
11
+
12
+ ### Fixed
13
+ - **Intelligent category crash on numeric string inputs** — `flexPlannedDispatches.energyAddedKwh` is returned by the live Kraken API as a string. The intelligent category's reduce accumulator concatenated strings instead of summing, then called `.toFixed()` on the resulting string, raising `TypeError: totalEnergy.toFixed is not a function`. Whole intelligent payload section fell back to `defaultData` (null slot times, `total_energy: 0`, `next_kwh: "0"`), which surfaced in Home Assistant as "Error updating entity" for every intelligent sensor. Fixed by coercing `energyAddedKwh` via `parseFloat()` before arithmetic and formatting in `lib/categories/intelligent.js`, matching the pattern already used in `lib/categories/flex-planned-dispatches.js`. Added regression tests covering both positive and negative (export dispatch) string inputs.
14
+ - `next_kwh` now consistently formats with two decimal places (e.g. `"5.50"`, `"15.20"`) per the documented contract in README, HTML help, and `test-mocks.js`. The v1.3.0 path stripped trailing zeros via `String(parseFloat(...))` — that branch is unreachable now because it always crashed before reaching it, but the format is corrected for completeness.
15
+
8
16
  ## [1.3.0] — 2026-05-12
9
17
 
10
18
  Major additive release covering the full Octopus Energy consumer read surface. No breaking changes to v1.2.x payload fields, entity IDs, MQTT topics, input commands, or node config fields. All v1.2.x automations and dashboards continue to work unchanged.
@@ -65,7 +65,8 @@ function parseResponse(data, { tz, serverTz }) {
65
65
  const now = new Date();
66
66
  const active = dispatches.filter(s => new Date(s.end) > now);
67
67
  const nextSlot = active[0] || null;
68
- const totalEnergy = active.reduce((sum, s) => sum + (s.energyAddedKwh || 0), 0);
68
+ // energyAddedKwh arrives from live API as a string — coerce before arithmetic
69
+ const totalEnergy = active.reduce((sum, s) => sum + (parseFloat(s.energyAddedKwh) || 0), 0);
69
70
 
70
71
  function conv(dt) { return dt ? convertToTimezone(dt, tz) : null; }
71
72
  function locale(dt) { return dt ? convertToTimezone(dt, serverTz) : null; }
@@ -77,7 +78,7 @@ function parseResponse(data, { tz, serverTz }) {
77
78
  next_start_raw: nextSlot ? nextSlot.start : null,
78
79
  next_start_locale: nextSlot ? locale(nextSlot.start) : null,
79
80
  total_energy: parseFloat(totalEnergy.toFixed(2)),
80
- next_kwh: nextSlot ? (nextSlot.energyAddedKwh != null ? String(parseFloat(nextSlot.energyAddedKwh.toFixed(2))) : '0') : '0',
81
+ next_kwh: nextSlot && nextSlot.energyAddedKwh != null ? parseFloat(nextSlot.energyAddedKwh).toFixed(2) : '0',
81
82
  next_source: nextSlot ? (nextSlot.type || 'unknown').toLowerCase() : 'unknown',
82
83
  slot1_start: active[0] ? conv(active[0].start) : null,
83
84
  slot1_end: active[0] ? conv(active[0].end) : null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-octopus-intelligent",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Node-RED integration for Octopus Energy Intelligent Octopus Go with Home Assistant MQTT discovery",
5
5
  "main": "octopus-intelligent.js",
6
6
  "scripts": {