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

switch_2_gang Update device.js #819

Open
wants to merge 1 commit into
base: SDK3
Choose a base branch
from
Open
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
40 changes: 29 additions & 11 deletions drivers/switch_2_gang/device.js
Original file line number Diff line number Diff line change
@@ -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;
module.exports = switch_2_gang;