node-red-contrib-octopus-intelligent 1.3.0 → 1.3.2
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,26 @@ 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.2] — 2026-05-14
|
|
9
|
+
|
|
10
|
+
Defensive hardening pass following the v1.3.1 hotfix audit. No user-facing behaviour change against the current live Kraken API — every affected field already arrives as a JSON number today. The fix forecloses the same latent crash class (`TypeError: ...toFixed is not a function`) if Kraken ever serialises these scalars as strings, matching how `energyAddedKwh` is already returned.
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
- `lib/categories/electricity.js` — `tariff.unitRate` and `tariff.standingCharge` (both import and export branches) now coerce via `parseFloat()` before emitting. Prevents string passthrough that would (a) break `device_class: monetary` sensors in HA and (b) crash any downstream arithmetic.
|
|
14
|
+
- `lib/categories/gas.js` — same treatment for `tariff.unitRate` and `tariff.standingCharge`.
|
|
15
|
+
- `lib/categories/account.js` — `balance` (pence) now coerces via `parseFloat()` before emitting `account_balance_pence`. JavaScript's `/` operator was already coercing for `account_balance_pounds`, so this only tightens type consistency on the integer pence field.
|
|
16
|
+
|
|
17
|
+
### Tests
|
|
18
|
+
- Added string-input regression tests for each coerced field, asserting `typeof === 'number'`. 4 new tests, 237 total (was 233).
|
|
19
|
+
|
|
20
|
+
## [1.3.1] — 2026-05-14
|
|
21
|
+
|
|
22
|
+
Critical hotfix for v1.3.0. Users on 1.3.0 should upgrade immediately.
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
- **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.
|
|
26
|
+
- `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.
|
|
27
|
+
|
|
8
28
|
## [1.3.0] — 2026-05-12
|
|
9
29
|
|
|
10
30
|
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.
|
|
@@ -13,7 +13,9 @@ function buildQuery(account) {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
function parseResponse(data) {
|
|
16
|
-
|
|
16
|
+
// Kraken numeric scalars can serialise as strings — coerce defensively
|
|
17
|
+
const raw = ((data.account || {}).balance) ?? null;
|
|
18
|
+
const balancePence = raw !== null ? parseFloat(raw) : null;
|
|
17
19
|
return {
|
|
18
20
|
account_balance_pence: balancePence,
|
|
19
21
|
account_balance_pounds: balancePence !== null ? parseFloat((balancePence / 100).toFixed(2)) : null,
|
|
@@ -55,9 +55,10 @@ function parseRatesResponse(data) {
|
|
|
55
55
|
const fieldsFor = (prefix, agreements) => {
|
|
56
56
|
const latest = agreements[0];
|
|
57
57
|
const tariff = (latest && latest.tariff) || {};
|
|
58
|
+
// Kraken Float scalars can serialise as strings — coerce defensively
|
|
58
59
|
return {
|
|
59
|
-
[`${prefix}_unit_rate`]: tariff.unitRate
|
|
60
|
-
[`${prefix}_standing_charge`]: tariff.standingCharge
|
|
60
|
+
[`${prefix}_unit_rate`]: tariff.unitRate != null ? parseFloat(tariff.unitRate) : null,
|
|
61
|
+
[`${prefix}_standing_charge`]: tariff.standingCharge != null ? parseFloat(tariff.standingCharge) : null,
|
|
61
62
|
[`${prefix}_tariff_code`]: tariff.productCode || null,
|
|
62
63
|
[`${prefix}_valid_from`]: (latest && latest.validFrom) || null,
|
|
63
64
|
[`${prefix}_valid_to`]: (latest && latest.validTo) || null,
|
package/lib/categories/gas.js
CHANGED
|
@@ -52,9 +52,10 @@ function parseRatesResponse(data) {
|
|
|
52
52
|
}
|
|
53
53
|
const latest = agreements[0];
|
|
54
54
|
const tariff = latest.tariff || {};
|
|
55
|
+
// Kraken Float scalars can serialise as strings — coerce defensively
|
|
55
56
|
return {
|
|
56
|
-
gas_unit_rate: tariff.unitRate
|
|
57
|
-
gas_standing_charge: tariff.standingCharge
|
|
57
|
+
gas_unit_rate: tariff.unitRate != null ? parseFloat(tariff.unitRate) : null,
|
|
58
|
+
gas_standing_charge: tariff.standingCharge != null ? parseFloat(tariff.standingCharge) : null,
|
|
58
59
|
gas_tariff_code: tariff.productCode || null,
|
|
59
60
|
gas_valid_from: latest.validFrom || null,
|
|
60
61
|
gas_valid_to: latest.validTo || null,
|
|
@@ -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
|
-
|
|
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
|
|
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