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

Fix motion_sensor_2 luminance and zoneStatus report handling #1121

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
36 changes: 17 additions & 19 deletions drivers/motion_sensor_2/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

const { ZigBeeDevice } = require('homey-zigbeedriver');
const { CLUSTER } = require('zigbee-clusters');
const TuyaSpecificCluster = require('../../lib/TuyaSpecificCluster');

Cluster.addCluster(TuyaSpecificCluster);
require('../../lib/TuyaSpecificCluster');

class motion_sensor_2 extends ZigBeeDevice {

Expand Down Expand Up @@ -40,26 +38,26 @@ class motion_sensor_2 extends ZigBeeDevice {
}

// alarm_motion handler
zclNode.endpoints[1].clusters[CLUSTER.IAS_ZONE.NAME]
.on('attr.zoneStatus', this.onZoneStatusAttributeReport.bind(this));
zclNode.endpoints[1].clusters[CLUSTER.IAS_ZONE.NAME]
.onZoneStatusChangeNotification = this.onZoneStatusAttributeReport.bind(this);

// measure_battery and alarm_battery handler
zclNode.endpoints[1].clusters[CLUSTER.POWER_CONFIGURATION.NAME]
.on('attr.batteryPercentageRemaining', this.onBatteryPercentageRemainingAttributeReport.bind(this));
// measure_illuminance handler
zclNode.endpoints[1].clusters[CLUSTER.ILLUMINANCE_MEASUREMENT.NAME]
.on('attr.IlluminanceMeasured', this.onIlluminanceMeasuredAttributeReport.bind(this));
zclNode.endpoints[1].clusters[CLUSTER.POWER_CONFIGURATION.NAME]
.on('attr.batteryPercentageRemaining', this.onBatteryPercentageRemainingAttributeReport.bind(this));

// measure_luminance handler
zclNode.endpoints[1].clusters[CLUSTER.ILLUMINANCE_MEASUREMENT.NAME]
.on('attr.measuredValue', this.onIlluminanceMeasuredAttributeReport.bind(this));

// Tuya specific cluster handler
zclNode.endpoints[1].clusters.tuya.on("reporting", value => this.processResponse(value));

}

// Handle motion status attribute reports
onZoneStatusAttributeReport(status) {
this.log("Motion status: ", status.alarm1);
this.setCapabilityValue('alarm_motion', status.alarm1).catch(this.error);
onZoneStatusAttributeReport({ zoneStatus, extendedStatus, zoneId, delay }) {
this.log('onZoneStatusChanged received:', zoneStatus, extendedStatus, zoneId, delay);
this.setCapabilityValue('alarm_motion', zoneStatus.alarm1).catch(this.error);
}

// Handle battery status attribute reports
Expand All @@ -70,19 +68,19 @@ class motion_sensor_2 extends ZigBeeDevice {
this.setCapabilityValue('measure_battery', batteryLevel).catch(this.error);
this.setCapabilityValue('alarm_battery', batteryLevel < batteryThreshold).catch(this.error);
}

// Handle illuminance attribute reports
onIlluminanceMeasuredAttributeReport(measuredValue) {
const luxValue = Math.round(Math.pow(10, ((measuredValue - 1) / 10000))); // Convert measured value to lux
this.log('measure_illuminance | Illuminance (lux):', luxValue);
this.setCapabilityValue('measure_illuminance', luxValue).catch(this.error);
this.log('measure_luminance | Illuminance (lux):', luxValue);
this.setCapabilityValue('measure_luminance', luxValue).catch(this.error);
}

// Process Tuya-specific data
processResponse(data) {
this.log('Tuya-specific cluster data:', data);
}

// Handle device removal
onDeleted() {
this.log('Motion Sensor removed');
Expand Down Expand Up @@ -359,4 +357,4 @@ module.exports = motion_sensor_2;
"bindings": {}
}
}
} */
} */