node-red-contrib-octopus-intelligent 1.4.0 → 1.6.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 +487 -408
- package/README.md +1004 -980
- package/examples/basic-monitoring.json +1 -1
- package/examples/ha-dashboard.yaml +602 -486
- package/examples/mqtt-integration.json +1 -1
- package/examples/node-red-dashboard-flow.json +1287 -0
- package/examples/set-preferences.json +1 -1
- package/lib/api-metrics.js +31 -31
- package/lib/auth.js +20 -20
- package/lib/categories/account.js +32 -32
- package/lib/categories/applicable-rates.js +127 -91
- package/lib/categories/completed-dispatches.js +35 -35
- package/lib/categories/electricity.js +146 -133
- package/lib/categories/flex-planned-dispatches.js +36 -36
- package/lib/categories/free-electricity.js +61 -61
- package/lib/categories/gas.js +95 -95
- package/lib/categories/home-mini.js +37 -37
- package/lib/categories/intelligent.js +155 -124
- package/lib/categories/octoplus.js +32 -32
- package/lib/categories/saving-sessions.js +64 -64
- package/lib/categories/wheel-of-fortune.js +49 -49
- package/lib/commands.js +47 -0
- package/lib/discovery-retry.js +13 -0
- package/lib/discovery.js +92 -85
- package/lib/graphql-errors.js +18 -0
- package/lib/graphql.js +44 -44
- package/lib/http-get-json.js +22 -0
- package/lib/payload.js +89 -77
- package/lib/poll-tick.js +44 -44
- package/lib/preferences.js +32 -0
- package/lib/scheduler.js +47 -47
- package/lib/sensor-definitions.js +219 -0
- package/lib/timezone.js +49 -49
- package/lib/update-check.js +38 -0
- package/octopus-intelligent.html +218 -205
- package/octopus-intelligent.js +1687 -1685
- package/package.json +54 -54
package/lib/categories/gas.js
CHANGED
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
// lib/categories/gas.js
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
// GasTariffType is a single object type (not a union) — direct field access, no fragments.
|
|
5
|
-
const RATES_QUERY = `
|
|
6
|
-
query getGasRates($account: String!) {
|
|
7
|
-
account(accountNumber: $account) {
|
|
8
|
-
gasAgreements {
|
|
9
|
-
validFrom validTo
|
|
10
|
-
tariff {
|
|
11
|
-
productCode
|
|
12
|
-
standingCharge
|
|
13
|
-
unitRate
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}`;
|
|
18
|
-
|
|
19
|
-
const CONSUMPTION_QUERY = `
|
|
20
|
-
query getGasConsumption($account: String!, $startAt: DateTime!, $timezone: String!) {
|
|
21
|
-
account(accountNumber: $account) {
|
|
22
|
-
properties {
|
|
23
|
-
gasMeterPoints {
|
|
24
|
-
meters {
|
|
25
|
-
consumption(startAt: $startAt, last: 1, grouping: DAY, timezone: $timezone) {
|
|
26
|
-
edges { node { startAt endAt value } }
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}`;
|
|
33
|
-
|
|
34
|
-
function buildRatesQuery(account) {
|
|
35
|
-
return { query: RATES_QUERY, variables: { account } };
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function buildConsumptionQuery(account, timezone) {
|
|
39
|
-
const tz = timezone || 'UTC';
|
|
40
|
-
const startAt = new Date(Date.now() - 2 * 24 * 60 * 60 * 1000).toISOString();
|
|
41
|
-
return { query: CONSUMPTION_QUERY, variables: { account, startAt, timezone: tz } };
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function parseRatesResponse(data) {
|
|
45
|
-
const all = (data.account || {}).gasAgreements || [];
|
|
46
|
-
const agreements = all.filter(a => !((a.tariff || {}).productCode || '').includes('OUTGOING'));
|
|
47
|
-
if (agreements.length === 0) {
|
|
48
|
-
return {
|
|
49
|
-
gas_unit_rate: null, gas_standing_charge: null, gas_tariff_code: null,
|
|
50
|
-
gas_valid_from: null, gas_valid_to: null, gas_rates_error: null
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
const latest = agreements[0];
|
|
54
|
-
const tariff = latest.tariff || {};
|
|
55
|
-
// Kraken Float scalars can serialise as strings — coerce defensively
|
|
56
|
-
return {
|
|
57
|
-
gas_unit_rate: tariff.unitRate != null ? parseFloat(tariff.unitRate) : null,
|
|
58
|
-
gas_standing_charge: tariff.standingCharge != null ? parseFloat(tariff.standingCharge) : null,
|
|
59
|
-
gas_tariff_code: tariff.productCode || null,
|
|
60
|
-
gas_valid_from: latest.validFrom || null,
|
|
61
|
-
gas_valid_to: latest.validTo || null,
|
|
62
|
-
gas_rates_error: null
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function parseConsumptionResponse(data) {
|
|
67
|
-
const points = ((data.account || {}).properties || [])[0];
|
|
68
|
-
const meterPoint = points ? (points.gasMeterPoints || [])[0] : null;
|
|
69
|
-
const meter = meterPoint ? (meterPoint.meters || [])[0] : null;
|
|
70
|
-
const connection = meter ? meter.consumption : null;
|
|
71
|
-
const edges = connection ? (connection.edges || []) : [];
|
|
72
|
-
const entry = edges.length > 0 ? edges[edges.length - 1].node : null;
|
|
73
|
-
if (!entry) {
|
|
74
|
-
return {
|
|
75
|
-
gas_consumption_kwh: null, gas_consumption_cost: null,
|
|
76
|
-
gas_consumption_from: null, gas_consumption_to: null, gas_consumption_error: null
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
return {
|
|
80
|
-
gas_consumption_kwh: parseFloat(entry.value),
|
|
81
|
-
gas_consumption_cost: null,
|
|
82
|
-
gas_consumption_from: entry.startAt,
|
|
83
|
-
gas_consumption_to: entry.endAt,
|
|
84
|
-
gas_consumption_error: null
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const defaultData = {
|
|
89
|
-
gas_unit_rate: null, gas_standing_charge: null, gas_tariff_code: null,
|
|
90
|
-
gas_valid_from: null, gas_valid_to: null, gas_rates_error: null,
|
|
91
|
-
gas_consumption_kwh: null, gas_consumption_cost: null,
|
|
92
|
-
gas_consumption_from: null, gas_consumption_to: null, gas_consumption_error: null
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
module.exports = { buildRatesQuery, buildConsumptionQuery, parseRatesResponse, parseConsumptionResponse, defaultData };
|
|
1
|
+
// lib/categories/gas.js
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
// GasTariffType is a single object type (not a union) — direct field access, no fragments.
|
|
5
|
+
const RATES_QUERY = `
|
|
6
|
+
query getGasRates($account: String!) {
|
|
7
|
+
account(accountNumber: $account) {
|
|
8
|
+
gasAgreements {
|
|
9
|
+
validFrom validTo
|
|
10
|
+
tariff {
|
|
11
|
+
productCode
|
|
12
|
+
standingCharge
|
|
13
|
+
unitRate
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}`;
|
|
18
|
+
|
|
19
|
+
const CONSUMPTION_QUERY = `
|
|
20
|
+
query getGasConsumption($account: String!, $startAt: DateTime!, $timezone: String!) {
|
|
21
|
+
account(accountNumber: $account) {
|
|
22
|
+
properties {
|
|
23
|
+
gasMeterPoints {
|
|
24
|
+
meters {
|
|
25
|
+
consumption(startAt: $startAt, last: 1, grouping: DAY, timezone: $timezone) {
|
|
26
|
+
edges { node { startAt endAt value } }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}`;
|
|
33
|
+
|
|
34
|
+
function buildRatesQuery(account) {
|
|
35
|
+
return { query: RATES_QUERY, variables: { account } };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function buildConsumptionQuery(account, timezone) {
|
|
39
|
+
const tz = timezone || 'UTC';
|
|
40
|
+
const startAt = new Date(Date.now() - 2 * 24 * 60 * 60 * 1000).toISOString();
|
|
41
|
+
return { query: CONSUMPTION_QUERY, variables: { account, startAt, timezone: tz } };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function parseRatesResponse(data) {
|
|
45
|
+
const all = (data.account || {}).gasAgreements || [];
|
|
46
|
+
const agreements = all.filter(a => !((a.tariff || {}).productCode || '').includes('OUTGOING'));
|
|
47
|
+
if (agreements.length === 0) {
|
|
48
|
+
return {
|
|
49
|
+
gas_unit_rate: null, gas_standing_charge: null, gas_tariff_code: null,
|
|
50
|
+
gas_valid_from: null, gas_valid_to: null, gas_rates_error: null
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
const latest = agreements[0];
|
|
54
|
+
const tariff = latest.tariff || {};
|
|
55
|
+
// Kraken Float scalars can serialise as strings — coerce defensively
|
|
56
|
+
return {
|
|
57
|
+
gas_unit_rate: tariff.unitRate != null ? parseFloat(tariff.unitRate) : null,
|
|
58
|
+
gas_standing_charge: tariff.standingCharge != null ? parseFloat(tariff.standingCharge) : null,
|
|
59
|
+
gas_tariff_code: tariff.productCode || null,
|
|
60
|
+
gas_valid_from: latest.validFrom || null,
|
|
61
|
+
gas_valid_to: latest.validTo || null,
|
|
62
|
+
gas_rates_error: null
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function parseConsumptionResponse(data) {
|
|
67
|
+
const points = ((data.account || {}).properties || [])[0];
|
|
68
|
+
const meterPoint = points ? (points.gasMeterPoints || [])[0] : null;
|
|
69
|
+
const meter = meterPoint ? (meterPoint.meters || [])[0] : null;
|
|
70
|
+
const connection = meter ? meter.consumption : null;
|
|
71
|
+
const edges = connection ? (connection.edges || []) : [];
|
|
72
|
+
const entry = edges.length > 0 ? edges[edges.length - 1].node : null;
|
|
73
|
+
if (!entry) {
|
|
74
|
+
return {
|
|
75
|
+
gas_consumption_kwh: null, gas_consumption_cost: null,
|
|
76
|
+
gas_consumption_from: null, gas_consumption_to: null, gas_consumption_error: null
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
gas_consumption_kwh: parseFloat(entry.value),
|
|
81
|
+
gas_consumption_cost: null,
|
|
82
|
+
gas_consumption_from: entry.startAt,
|
|
83
|
+
gas_consumption_to: entry.endAt,
|
|
84
|
+
gas_consumption_error: null
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const defaultData = {
|
|
89
|
+
gas_unit_rate: null, gas_standing_charge: null, gas_tariff_code: null,
|
|
90
|
+
gas_valid_from: null, gas_valid_to: null, gas_rates_error: null,
|
|
91
|
+
gas_consumption_kwh: null, gas_consumption_cost: null,
|
|
92
|
+
gas_consumption_from: null, gas_consumption_to: null, gas_consumption_error: null
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
module.exports = { buildRatesQuery, buildConsumptionQuery, parseRatesResponse, parseConsumptionResponse, defaultData };
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const QUERY = `
|
|
4
|
-
query getSmartMeterTelemetry($deviceId: String!, $start: DateTime!, $end: DateTime!) {
|
|
5
|
-
smartMeterTelemetry(deviceId: $deviceId, grouping: HALF_HOURLY, start: $start, end: $end) {
|
|
6
|
-
readAt demand consumptionDelta
|
|
7
|
-
}
|
|
8
|
-
}`;
|
|
9
|
-
|
|
10
|
-
function buildQuery(smartMeterDeviceId) {
|
|
11
|
-
const end = new Date().toISOString();
|
|
12
|
-
const start = new Date(Date.now() - 30 * 60 * 1000).toISOString();
|
|
13
|
-
return { query: QUERY, variables: { deviceId: smartMeterDeviceId, start, end } };
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function parseResponse(data) {
|
|
17
|
-
const readings = data.smartMeterTelemetry || [];
|
|
18
|
-
const latest = readings.length > 0 ? readings[readings.length - 1] : null;
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
// demand is in Watts from API — negative means exporting
|
|
22
|
-
mini_demand_kw: latest && latest.demand != null ? parseFloat(latest.demand) / 1000 : null,
|
|
23
|
-
// consumptionDelta is in Wh per half-hour period
|
|
24
|
-
mini_consumption_delta_kwh: latest && latest.consumptionDelta != null ? parseFloat(latest.consumptionDelta) / 1000 : null,
|
|
25
|
-
mini_read_at: latest ? latest.readAt ?? null : null,
|
|
26
|
-
home_mini_error: null
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const defaultData = {
|
|
31
|
-
mini_demand_kw: null,
|
|
32
|
-
mini_consumption_delta_kwh: null,
|
|
33
|
-
mini_read_at: null,
|
|
34
|
-
home_mini_error: null
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
module.exports = { buildQuery, parseResponse, defaultData };
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const QUERY = `
|
|
4
|
+
query getSmartMeterTelemetry($deviceId: String!, $start: DateTime!, $end: DateTime!) {
|
|
5
|
+
smartMeterTelemetry(deviceId: $deviceId, grouping: HALF_HOURLY, start: $start, end: $end) {
|
|
6
|
+
readAt demand consumptionDelta
|
|
7
|
+
}
|
|
8
|
+
}`;
|
|
9
|
+
|
|
10
|
+
function buildQuery(smartMeterDeviceId) {
|
|
11
|
+
const end = new Date().toISOString();
|
|
12
|
+
const start = new Date(Date.now() - 30 * 60 * 1000).toISOString();
|
|
13
|
+
return { query: QUERY, variables: { deviceId: smartMeterDeviceId, start, end } };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function parseResponse(data) {
|
|
17
|
+
const readings = data.smartMeterTelemetry || [];
|
|
18
|
+
const latest = readings.length > 0 ? readings[readings.length - 1] : null;
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
// demand is in Watts from API — negative means exporting
|
|
22
|
+
mini_demand_kw: latest && latest.demand != null ? parseFloat(latest.demand) / 1000 : null,
|
|
23
|
+
// consumptionDelta is in Wh per half-hour period
|
|
24
|
+
mini_consumption_delta_kwh: latest && latest.consumptionDelta != null ? parseFloat(latest.consumptionDelta) / 1000 : null,
|
|
25
|
+
mini_read_at: latest ? latest.readAt ?? null : null,
|
|
26
|
+
home_mini_error: null
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const defaultData = {
|
|
31
|
+
mini_demand_kw: null,
|
|
32
|
+
mini_consumption_delta_kwh: null,
|
|
33
|
+
mini_read_at: null,
|
|
34
|
+
home_mini_error: null
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
module.exports = { buildQuery, parseResponse, defaultData };
|
|
@@ -1,124 +1,155 @@
|
|
|
1
|
-
// lib/categories/intelligent.js
|
|
2
|
-
'use strict';
|
|
3
|
-
const { convertToTimezone } = require('../timezone');
|
|
4
|
-
|
|
5
|
-
const WEEKDAYS = ['MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY'];
|
|
6
|
-
|
|
7
|
-
const DEVICES_QUERY = `
|
|
8
|
-
query getDevices($account: String!) {
|
|
9
|
-
devices(accountNumber: $account) {
|
|
10
|
-
id
|
|
11
|
-
deviceType
|
|
12
|
-
preferences {
|
|
13
|
-
... on SmartFlexDevicePreferences {
|
|
14
|
-
schedules {
|
|
15
|
-
dayOfWeek
|
|
16
|
-
time
|
|
17
|
-
max
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
}`;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
function
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
//
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
1
|
+
// lib/categories/intelligent.js
|
|
2
|
+
'use strict';
|
|
3
|
+
const { convertToTimezone } = require('../timezone');
|
|
4
|
+
|
|
5
|
+
const WEEKDAYS = ['MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY'];
|
|
6
|
+
|
|
7
|
+
const DEVICES_QUERY = `
|
|
8
|
+
query getDevices($account: String!) {
|
|
9
|
+
devices(accountNumber: $account) {
|
|
10
|
+
id
|
|
11
|
+
deviceType
|
|
12
|
+
preferences {
|
|
13
|
+
... on SmartFlexDevicePreferences {
|
|
14
|
+
schedules {
|
|
15
|
+
dayOfWeek
|
|
16
|
+
time
|
|
17
|
+
max
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
# Separate alias: the Charge Cap field is non-null, so an error on it nulls its parent
|
|
22
|
+
# selection. Keeping it apart stops such an error from blanking the schedules above.
|
|
23
|
+
chargeCap: preferences {
|
|
24
|
+
... on SmartFlexDevicePreferences {
|
|
25
|
+
isChargingDurationCapped
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}`;
|
|
30
|
+
|
|
31
|
+
const DISPATCH_QUERY = `
|
|
32
|
+
query getDispatches($deviceId: String!) {
|
|
33
|
+
flexPlannedDispatches(deviceId: $deviceId) {
|
|
34
|
+
start end type energyAddedKwh
|
|
35
|
+
}
|
|
36
|
+
}`;
|
|
37
|
+
|
|
38
|
+
function buildDevicesQuery(account) {
|
|
39
|
+
return { query: DEVICES_QUERY, variables: { account } };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function buildDispatchQuery(deviceId) {
|
|
43
|
+
return { query: DISPATCH_QUERY, variables: { deviceId } };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function extractEvDevice(devices) {
|
|
47
|
+
return (devices || []).find(d => d.deviceType === 'ELECTRIC_VEHICLES') || null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// isChargingDurationCapped: ENABLED | DISABLED | NOT_APPLICABLE (live-verified 2026-09-29).
|
|
51
|
+
// Anything other than ENABLED/DISABLED (incl. missing) -> null.
|
|
52
|
+
function extractChargeCap(devices) {
|
|
53
|
+
const ev = extractEvDevice(devices);
|
|
54
|
+
const raw = ev && ev.chargeCap ? ev.chargeCap.isChargingDurationCapped : undefined;
|
|
55
|
+
if (raw === 'ENABLED') return true;
|
|
56
|
+
if (raw === 'DISABLED') return false;
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function extractPreferences(devices) {
|
|
61
|
+
const ev = extractEvDevice(devices);
|
|
62
|
+
if (!ev || !ev.preferences) return { confirmed_limit: 80, confirmed_time: '07:30' };
|
|
63
|
+
|
|
64
|
+
const schedules = ev.preferences.schedules || [];
|
|
65
|
+
const weekday = schedules.find(s => WEEKDAYS.includes(s.dayOfWeek));
|
|
66
|
+
if (!weekday) return { confirmed_limit: 80, confirmed_time: '07:30' };
|
|
67
|
+
|
|
68
|
+
// time may arrive as 'HH:MM:SS' or 'HH:MM' — normalise to 'HH:MM'
|
|
69
|
+
const time = weekday.time ? weekday.time.substring(0, 5) : '07:30';
|
|
70
|
+
// parseFloat: '' / ' ' / 'abc' give NaN (Number('') would give 0); a 0% target is never real
|
|
71
|
+
const maxValue = weekday.max == null ? NaN : parseFloat(weekday.max);
|
|
72
|
+
return {
|
|
73
|
+
// Float scalars can arrive as JSON strings; this value is sent back in setDevicePreferences
|
|
74
|
+
confirmed_limit: Number.isFinite(maxValue) && maxValue > 0 ? maxValue : 80,
|
|
75
|
+
confirmed_time: time,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// data must be merged result: { devices: [...], flexPlannedDispatches: [...] }
|
|
80
|
+
function parseResponse(data, { tz, serverTz }) {
|
|
81
|
+
const devices = data.devices || [];
|
|
82
|
+
const dispatches = data.flexPlannedDispatches || [];
|
|
83
|
+
const prefs = extractPreferences(devices);
|
|
84
|
+
|
|
85
|
+
const now = new Date();
|
|
86
|
+
const active = dispatches.filter(s => new Date(s.end) > now);
|
|
87
|
+
const nextSlot = active[0] || null;
|
|
88
|
+
// energyAddedKwh arrives from live API as a string — coerce before arithmetic
|
|
89
|
+
const totalEnergy = active.reduce((sum, s) => sum + (parseFloat(s.energyAddedKwh) || 0), 0);
|
|
90
|
+
|
|
91
|
+
function conv(dt) { return dt ? convertToTimezone(dt, tz) : null; }
|
|
92
|
+
function locale(dt) { return dt ? convertToTimezone(dt, serverTz) : null; }
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
confirmed_limit: prefs.confirmed_limit,
|
|
96
|
+
confirmed_time: prefs.confirmed_time,
|
|
97
|
+
charge_cap: extractChargeCap(devices),
|
|
98
|
+
next_start: nextSlot ? conv(nextSlot.start) : null,
|
|
99
|
+
next_start_raw: nextSlot ? nextSlot.start : null,
|
|
100
|
+
next_start_locale: nextSlot ? locale(nextSlot.start) : null,
|
|
101
|
+
total_energy: parseFloat(totalEnergy.toFixed(2)),
|
|
102
|
+
next_kwh: nextSlot && nextSlot.energyAddedKwh != null ? parseFloat(nextSlot.energyAddedKwh).toFixed(2) : '0',
|
|
103
|
+
next_source: nextSlot ? (nextSlot.type || 'unknown').toLowerCase() : 'unknown',
|
|
104
|
+
slot1_start: active[0] ? conv(active[0].start) : null,
|
|
105
|
+
slot1_end: active[0] ? conv(active[0].end) : null,
|
|
106
|
+
slot2_start: active[1] ? conv(active[1].start) : null,
|
|
107
|
+
slot2_end: active[1] ? conv(active[1].end) : null,
|
|
108
|
+
slot3_start: active[2] ? conv(active[2].start) : null,
|
|
109
|
+
slot3_end: active[2] ? conv(active[2].end) : null,
|
|
110
|
+
window_start: active.length > 0 ? conv(active[0].start) : null,
|
|
111
|
+
window_end: active.length > 0 ? conv(active[active.length - 1].end) : null,
|
|
112
|
+
slot1_start_raw: active[0] ? active[0].start : null,
|
|
113
|
+
slot1_end_raw: active[0] ? active[0].end : null,
|
|
114
|
+
slot2_start_raw: active[1] ? active[1].start : null,
|
|
115
|
+
slot2_end_raw: active[1] ? active[1].end : null,
|
|
116
|
+
slot3_start_raw: active[2] ? active[2].start : null,
|
|
117
|
+
slot3_end_raw: active[2] ? active[2].end : null,
|
|
118
|
+
window_start_raw: active.length > 0 ? active[0].start : null,
|
|
119
|
+
window_end_raw: active.length > 0 ? active[active.length - 1].end : null,
|
|
120
|
+
slot1_start_locale: active[0] ? locale(active[0].start) : null,
|
|
121
|
+
slot1_end_locale: active[0] ? locale(active[0].end) : null,
|
|
122
|
+
slot2_start_locale: active[1] ? locale(active[1].start) : null,
|
|
123
|
+
slot2_end_locale: active[1] ? locale(active[1].end) : null,
|
|
124
|
+
slot3_start_locale: active[2] ? locale(active[2].start) : null,
|
|
125
|
+
slot3_end_locale: active[2] ? locale(active[2].end) : null,
|
|
126
|
+
window_start_locale: active.length > 0 ? locale(active[0].start) : null,
|
|
127
|
+
window_end_locale: active.length > 0 ? locale(active[active.length - 1].end) : null,
|
|
128
|
+
_activeSlots: active
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// True when the not-yet-ended slots differ in start/end time. Energy and timestamp
|
|
133
|
+
// formatting are ignored — only a moved, added or cancelled slot counts.
|
|
134
|
+
function slotsChanged(previous, fresh, nowMs = Date.now()) {
|
|
135
|
+
const key = (slots) => (slots || [])
|
|
136
|
+
.filter(s => new Date(s.end).getTime() > nowMs)
|
|
137
|
+
.map(s => `${new Date(s.start).getTime()}-${new Date(s.end).getTime()}`)
|
|
138
|
+
.join(',');
|
|
139
|
+
return key(previous) !== key(fresh);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const defaultData = {
|
|
143
|
+
confirmed_limit: 80, confirmed_time: '07:30', charge_cap: null,
|
|
144
|
+
next_start: null, next_start_raw: null, next_start_locale: null,
|
|
145
|
+
total_energy: 0, next_kwh: '0', next_source: 'unknown',
|
|
146
|
+
slot1_start: null, slot1_end: null, slot2_start: null, slot2_end: null,
|
|
147
|
+
slot3_start: null, slot3_end: null, window_start: null, window_end: null,
|
|
148
|
+
slot1_start_raw: null, slot1_end_raw: null, slot2_start_raw: null, slot2_end_raw: null,
|
|
149
|
+
slot3_start_raw: null, slot3_end_raw: null, window_start_raw: null, window_end_raw: null,
|
|
150
|
+
slot1_start_locale: null, slot1_end_locale: null, slot2_start_locale: null, slot2_end_locale: null,
|
|
151
|
+
slot3_start_locale: null, slot3_end_locale: null, window_start_locale: null, window_end_locale: null,
|
|
152
|
+
_activeSlots: []
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
module.exports = { buildDevicesQuery, buildDispatchQuery, extractEvDevice, parseResponse, slotsChanged, defaultData };
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
// lib/categories/octoplus.js
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
const QUERY = `
|
|
5
|
-
query getOctoplusInfo($account: String!) {
|
|
6
|
-
octoplusAccountInfo(accountNumber: $account) {
|
|
7
|
-
isOctoplusEnrolled enrollmentStatus isLoyaltyPointsUser
|
|
8
|
-
}
|
|
9
|
-
}`;
|
|
10
|
-
|
|
11
|
-
function buildQuery(account) {
|
|
12
|
-
return { query: QUERY, variables: { account } };
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function parseResponse(data) {
|
|
16
|
-
const info = data.octoplusAccountInfo || {};
|
|
17
|
-
return {
|
|
18
|
-
octoplus_enrolled: info.isOctoplusEnrolled ?? null,
|
|
19
|
-
octoplus_enrollment_status: info.enrollmentStatus || null,
|
|
20
|
-
octoplus_loyalty_points_user: info.isLoyaltyPointsUser ?? null,
|
|
21
|
-
octoplus_error: null
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const defaultData = {
|
|
26
|
-
octoplus_enrolled: null,
|
|
27
|
-
octoplus_enrollment_status: null,
|
|
28
|
-
octoplus_loyalty_points_user: null,
|
|
29
|
-
octoplus_error: null
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
module.exports = { buildQuery, parseResponse, defaultData };
|
|
1
|
+
// lib/categories/octoplus.js
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const QUERY = `
|
|
5
|
+
query getOctoplusInfo($account: String!) {
|
|
6
|
+
octoplusAccountInfo(accountNumber: $account) {
|
|
7
|
+
isOctoplusEnrolled enrollmentStatus isLoyaltyPointsUser
|
|
8
|
+
}
|
|
9
|
+
}`;
|
|
10
|
+
|
|
11
|
+
function buildQuery(account) {
|
|
12
|
+
return { query: QUERY, variables: { account } };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function parseResponse(data) {
|
|
16
|
+
const info = data.octoplusAccountInfo || {};
|
|
17
|
+
return {
|
|
18
|
+
octoplus_enrolled: info.isOctoplusEnrolled ?? null,
|
|
19
|
+
octoplus_enrollment_status: info.enrollmentStatus || null,
|
|
20
|
+
octoplus_loyalty_points_user: info.isLoyaltyPointsUser ?? null,
|
|
21
|
+
octoplus_error: null
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const defaultData = {
|
|
26
|
+
octoplus_enrolled: null,
|
|
27
|
+
octoplus_enrollment_status: null,
|
|
28
|
+
octoplus_loyalty_points_user: null,
|
|
29
|
+
octoplus_error: null
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
module.exports = { buildQuery, parseResponse, defaultData };
|