Skip to content

Commit

Permalink
Fix Contact Sensor not working (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x5e committed Nov 13, 2022
1 parent 7405b10 commit 2d7346e
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/accessory/ContactSensorAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,25 @@ export default class ContaceSensor extends BaseAccessory {
constructor(platform: TuyaPlatform, accessory: PlatformAccessory) {
super(platform, accessory);

const service = this.accessory.getService(this.Service.ContactSensor)
const schema = this.getContactSensorSchema();
if (schema) {
const service = this.accessory.getService(this.Service.ContactSensor)
|| this.accessory.addService(this.Service.ContactSensor);

service.getCharacteristic(this.Characteristic.ContactSensorState)
.onGet(() => {
const status = this.getStatus('doorcontact_state');
return status!.value ?
this.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED:
this.Characteristic.ContactSensorState.CONTACT_DETECTED;
});
const { CONTACT_NOT_DETECTED, CONTACT_DETECTED } = this.Characteristic.ContactSensorState;
service.getCharacteristic(this.Characteristic.ContactSensorState)
.onGet(() => {
const status = this.getStatus(schema.code)!;
return status.value ? CONTACT_NOT_DETECTED : CONTACT_DETECTED;
});
}


}

getContactSensorSchema() {
return this.getSchema('doorcontact_state')
|| this.getSchema('switch');
}

}

0 comments on commit 2d7346e

Please sign in to comment.