From af7dfbd7c600b75e859142a300fed36795ffe2b3 Mon Sep 17 00:00:00 2001 From: TzK069 <159542871+TzK069@users.noreply.github.com> Date: Mon, 1 Apr 2024 01:07:18 +0300 Subject: [PATCH] Update device.js can you check? --- drivers/switch_2_gang/device.js | 40 ++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/drivers/switch_2_gang/device.js b/drivers/switch_2_gang/device.js index 5e786509..bb7bcf16 100644 --- a/drivers/switch_2_gang/device.js +++ b/drivers/switch_2_gang/device.js @@ -1,41 +1,59 @@ 'use strict'; -const Homey = require('homey'); const { ZigBeeDevice } = require('homey-zigbeedriver'); -const { debug, CLUSTER } = require('zigbee-clusters'); +const { CLUSTER, Cluster, ZCLDataTypes } = require('zigbee-clusters'); -class switch_2_gang extends ZigBeeDevice { +Cluster.addCluster(TuyaOnOffCluster); // Assuming TuyaOnOffCluster is used - async onNodeInit({zclNode}) { +class switch_2_gang extends ZigBeeDevice { + async onNodeInit({ zclNode }) { this.printNode(); debug(true); if (!this.isSubDevice()) { await zclNode.endpoints[1].clusters.basic.readAttributes('manufacturerName', 'zclVersion', 'appVersion', 'modelId', 'powerSource', 'attributeReportingStatus') - .catch(err => { - this.error('Error when reading device attributes ', err); - }); + .catch(err => { + this.error('Error when reading device attributes ', err); + }); } const { subDeviceId } = this.getData(); this.log("Device data: ", subDeviceId); try { + // Register 'onoff' capability for both endpoints this.registerCapability('onoff', CLUSTER.ON_OFF, { - endpoint: subDeviceId === 'secondSwitch' ? 2 : 1, + endpoint: 1, }); + this.registerCapability('onoff', CLUSTER.ON_OFF, { + endpoint: 2, + }); + + // Register 'indicator_mode' capability and handle accordingly + // You can reuse the logic from wall_switch_1_gang for indicator mode handling + // Read indicator mode attribute and set it in settings, handle settings changes } catch (err) { this.error('Error registering capability: ', err); } - } - onDeleted(){ + onDeleted() { const { subDeviceId } = this.getData(); this.log("2 Gang Switch, channel ", subDeviceId, " removed"); } + async onSettings({ oldSettings, newSettings, changedKeys }) { + let parsedValue = 0; + + // Handle indicator mode setting changes + if (changedKeys.includes('indicator_mode')) { + parsedValue = parseInt(newSettings.indicator_mode); + // Write indicator mode attribute to the respective endpoint based on the setting + // You can reuse the logic from wall_switch_1_gang + } + } + } -module.exports = switch_2_gang; \ No newline at end of file +module.exports = switch_2_gang;