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;