From 8d5e899e57a61bb44a98877e808a4cd4a89b4822 Mon Sep 17 00:00:00 2001
From: Tristan Herbrink <ttherbrink@gmail.com>
Date: Thu, 23 Nov 2023 16:43:54 +0100
Subject: [PATCH 1/3] Add default options to reset commandclass meter v6

---
 lib/ZwaveDevice.js | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/lib/ZwaveDevice.js b/lib/ZwaveDevice.js
index d4e893a..06c9fc4 100644
--- a/lib/ZwaveDevice.js
+++ b/lib/ZwaveDevice.js
@@ -1049,7 +1049,7 @@ class ZwaveDevice extends Homey.Device {
    * COMMAND_CLASS_METER is on a multi channel node.
    * @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') {
@@ -1059,7 +1059,26 @@ class ZwaveDevice extends Homey.Device {
     }
 
     if (commandClassMeter && commandClassMeter.hasOwnProperty('METER_RESET')) {
-      const result = await commandClassMeter.METER_RESET({});
+      if (commandClassMeter.version < 6 && options.length > 0) {
+        throw new Error('invalid_meter_reset_options');
+      } else {
+        options = {
+          Properties1: {
+            'Scale bit 2': false,
+            'Rate Type': 2,
+            'Meter Type': 'Electric meter',
+          },
+          Properties2: {
+            Size: 1,
+            'Scale bits 10': 0,
+            Precision: 0,
+          },
+          'Meter Value': Buffer.from([0]),
+          'Scale 2': 0,
+          ...options,
+        };
+      }
+      const result = await commandClassMeter.METER_RESET(options);
       if (result !== 'TRANSMIT_COMPLETE_OK') throw result;
 
       // Return if reset was successful

From b8fecedafdd5346222b8444311d0795a6fe9410a Mon Sep 17 00:00:00 2001
From: Tristan Herbrink <ttherbrink@gmail.com>
Date: Mon, 27 Nov 2023 17:02:26 +0100
Subject: [PATCH 2/3] Change rate type to include all types

---
 lib/ZwaveDevice.js | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/ZwaveDevice.js b/lib/ZwaveDevice.js
index 06c9fc4..e28427a 100644
--- a/lib/ZwaveDevice.js
+++ b/lib/ZwaveDevice.js
@@ -1059,13 +1059,15 @@ class ZwaveDevice extends Homey.Device {
     }
 
     if (commandClassMeter && commandClassMeter.hasOwnProperty('METER_RESET')) {
-      if (commandClassMeter.version < 6 && options.length > 0) {
-        throw new Error('invalid_meter_reset_options');
+      if (commandClassMeter.version < 6) {
+        if (options.length > 0) {
+          throw new Error('invalid_meter_reset_options');
+        }
       } else {
         options = {
           Properties1: {
             'Scale bit 2': false,
-            'Rate Type': 2,
+            'Rate Type': 0,
             'Meter Type': 'Electric meter',
           },
           Properties2: {

From b7d498b8bd2c774e13dc04c3ec2d43950ef68c61 Mon Sep 17 00:00:00 2001
From: Tristan Herbrink <ttherbrink@gmail.com>
Date: Tue, 28 Nov 2023 12:09:14 +0100
Subject: [PATCH 3/3] Change options property

---
 lib/ZwaveDevice.js | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/lib/ZwaveDevice.js b/lib/ZwaveDevice.js
index e28427a..1c3407d 100644
--- a/lib/ZwaveDevice.js
+++ b/lib/ZwaveDevice.js
@@ -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 } = {}, { options } = {}) {
+  async meterReset({ multiChannelNodeId } = {}, options = {}) {
     // Get command class object (on mc node if needed)
     let commandClassMeter = null;
     if (typeof multiChannelNodeId === 'number') {
@@ -1059,11 +1063,7 @@ class ZwaveDevice extends Homey.Device {
     }
 
     if (commandClassMeter && commandClassMeter.hasOwnProperty('METER_RESET')) {
-      if (commandClassMeter.version < 6) {
-        if (options.length > 0) {
-          throw new Error('invalid_meter_reset_options');
-        }
-      } else {
+      if (commandClassMeter.version >= 6 && Object.keys(options).length === 0) {
         options = {
           Properties1: {
             'Scale bit 2': false,
@@ -1077,7 +1077,6 @@ class ZwaveDevice extends Homey.Device {
           },
           'Meter Value': Buffer.from([0]),
           'Scale 2': 0,
-          ...options,
         };
       }
       const result = await commandClassMeter.METER_RESET(options);