Skip to content

Commit

Permalink
Merge pull request #139 from athombv/master
Browse files Browse the repository at this point in the history
Merge master into production
  • Loading branch information
RobinBol authored Nov 29, 2023
2 parents bf2fe27 + 511ffbd commit 1e424f6
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions lib/ZwaveDevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -1045,11 +1045,15 @@ class ZwaveDevice extends Homey.Device {
/**
* Method that resets the accumulated power meter value on the node. It tries to find the root
* node of the device and then looks for the COMMAND_CLASS_METER.
* In case of a CommandClass version >= 6, the options object will be provided to set which meter
* needs to be reset and to what value. By default it resets the kWh meter to 0.
*
* @param multiChannelNodeId - define the multi channel node id in case the
* COMMAND_CLASS_METER is on a multi channel node.
* @param options - options given to the METER_RESET command, Only used when version >= 6
* @returns {Promise<any>}
*/
async meterReset({ multiChannelNodeId } = {}) {
async meterReset({ multiChannelNodeId } = {}, options = {}) {
// Get command class object (on mc node if needed)
let commandClassMeter = null;
if (typeof multiChannelNodeId === 'number') {
Expand All @@ -1059,7 +1063,23 @@ class ZwaveDevice extends Homey.Device {
}

if (commandClassMeter && commandClassMeter.hasOwnProperty('METER_RESET')) {

Check warning on line 1065 in lib/ZwaveDevice.js

View workflow job for this annotation

GitHub Actions / Lint

Do not access Object.prototype method 'hasOwnProperty' from target object
const result = await commandClassMeter.METER_RESET({});
if (commandClassMeter.version >= 6 && Object.keys(options).length === 0) {
options = {
Properties1: {
'Scale bit 2': false,
'Rate Type': 0,
'Meter Type': 'Electric meter',
},
Properties2: {
Size: 1,
'Scale bits 10': 0,
Precision: 0,
},
'Meter Value': Buffer.from([0]),
'Scale 2': 0,
};
}
const result = await commandClassMeter.METER_RESET(options);
if (result !== 'TRANSMIT_COMPLETE_OK') throw result;

// Return if reset was successful
Expand Down

0 comments on commit 1e424f6

Please sign in to comment.