Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add meter_power.imported and meter_power.exported accumulated capabilities #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -1208,10 +1208,14 @@
"accumulatedCost",
"measure_current.L1",
"measure_current.L2",
"measure_current.L3"
"measure_current.L3",
"meter_power.imported",
"meter_power.exported"
],
"energy": {
"cumulative": true
"cumulative": true,
"cumulativeImportedCapability": "meter_power.imported",
"cumulativeExportedCapability": "meter_power.exported"
},
"capabilitiesOptions": {
"accumulatedCost": {
Expand Down Expand Up @@ -1451,10 +1455,14 @@
"accumulatedCost",
"measure_current.L1",
"measure_current.L2",
"measure_current.L3"
"measure_current.L3",
"meter_power.imported",
"meter_power.exported"
],
"energy": {
"cumulative": true
"cumulative": true,
"cumulativeImportedCapability": "meter_power.imported",
"cumulativeExportedCapability": "meter_power.exported"
},
"capabilitiesOptions": {
"accumulatedCost": {
Expand Down
26 changes: 26 additions & 0 deletions drivers/pulse/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,32 @@ class PulseDevice extends Device {
.catch(console.error);
});
}

const lastMeterConsumption =
result.data?.liveMeasurement?.lastMeterConsumption;
if (typeof lastMeterConsumption === 'number') {
if (this.hasCapability('meter_power.imported') !== true)
await this.addCapability('meter_power.imported').catch(console.error);

const fixedLastMeterConsumption = Number(lastMeterConsumption.toFixed(2));
this.setCapabilityValue(
'meter_power.imported',
fixedLastMeterConsumption,
).catch(console.error);
}

const lastMeterProduction =
result.data?.liveMeasurement?.lastMeterProduction;
if (typeof lastMeterProduction === 'number') {
if (this.hasCapability('meter_power.exported') !== true)
await this.addCapability('meter_power.exported').catch(console.error);

const fixedLastMeterProduction = Number(lastMeterProduction.toFixed(2));
this.setCapabilityValue(
'meter_power.exported',
fixedLastMeterProduction,
).catch(console.error);
}
}

onDeleted() {
Expand Down
8 changes: 6 additions & 2 deletions drivers/pulse/driver.compose.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
"accumulatedCost",
"measure_current.L1",
"measure_current.L2",
"measure_current.L3"
"measure_current.L3",
"meter_power.imported",
"meter_power.exported"
],
"energy": {
"cumulative": true
"cumulative": true,
"cumulativeImportedCapability": "meter_power.imported",
"cumulativeExportedCapability": "meter_power.exported"
},
"capabilitiesOptions": {
"accumulatedCost": {
Expand Down
26 changes: 26 additions & 0 deletions drivers/watty/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,32 @@ class WattyDevice extends Device {
});
}
}

const lastMeterConsumption =
result.data?.liveMeasurement?.lastMeterConsumption;
if (typeof lastMeterConsumption === 'number') {
if (this.hasCapability('meter_power.imported') !== true)
await this.addCapability('meter_power.imported').catch(console.error);

const fixedLastMeterConsumption = Number(lastMeterConsumption.toFixed(2));
this.setCapabilityValue(
'meter_power.imported',
fixedLastMeterConsumption,
).catch(console.error);
}

const lastMeterProduction =
result.data?.liveMeasurement?.lastMeterProduction;
if (typeof lastMeterProduction === 'number') {
if (this.hasCapability('meter_power.exported') !== true)
await this.addCapability('meter_power.exported').catch(console.error);

const fixedLastMeterProduction = Number(lastMeterProduction.toFixed(2));
this.setCapabilityValue(
'meter_power.exported',
fixedLastMeterProduction,
).catch(console.error);
}
}

onDeleted() {
Expand Down
8 changes: 6 additions & 2 deletions drivers/watty/driver.compose.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
"accumulatedCost",
"measure_current.L1",
"measure_current.L2",
"measure_current.L3"
"measure_current.L3",
"meter_power.imported",
"meter_power.exported"
],
"energy": {
"cumulative": true
"cumulative": true,
"cumulativeImportedCapability": "meter_power.imported",
"cumulativeExportedCapability": "meter_power.exported"
},
"capabilitiesOptions": {
"accumulatedCost": {
Expand Down
2 changes: 2 additions & 0 deletions lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export interface LiveMeasurement {
power: number;
accumulatedConsumption: number;
accumulatedCost: number | null;
lastMeterConsumption: number | null;
lastMeterProduction: number | null;
currency: string | null;
minPower: number;
averagePower: number;
Expand Down
2 changes: 2 additions & 0 deletions lib/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ export const queries = {
power
accumulatedConsumption
accumulatedCost
lastMeterConsumption
lastMeterProduction
currency
minPower
averagePower
Expand Down