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 incorrect handling of openState in Contact Sensor #1061

Merged
Merged
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
16 changes: 9 additions & 7 deletions src/device/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ export class Contact extends deviceBase {
async BLEparseStatus(): Promise<void> {
await this.debugLog('BLEparseStatus')
// ContactSensorState
this.ContactSensor.ContactSensorState = this.serviceData.doorState === 'open'
? this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
: this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED
this.ContactSensor.ContactSensorState = this.getContactSensorState(this.serviceData.doorState)
donavanbecker marked this conversation as resolved.
Show resolved Hide resolved
await this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`)

// MotionDetected
Expand Down Expand Up @@ -222,9 +220,7 @@ export class Contact extends deviceBase {
async openAPIparseStatus(): Promise<void> {
await this.debugLog('openAPIparseStatus')
// Contact State
this.ContactSensor.ContactSensorState = this.deviceStatus.openState === 'open'
? this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
: this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED
this.ContactSensor.ContactSensorState = this.getContactSensorState(this.deviceStatus.openState)
await this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`)

// MotionDetected
Expand Down Expand Up @@ -268,7 +264,7 @@ export class Contact extends deviceBase {
await this.debugLog('parseStatusWebhook')
await this.debugLog(`(detectionState, brightness, openState) = Webhook:(${this.webhookContext.detectionState}, ${this.webhookContext.brightness}, ${this.webhookContext.openState}), current:(${this.MotionSensor?.MotionDetected}, ${this.LightSensor?.CurrentAmbientLightLevel}, ${this.ContactSensor.ContactSensorState})`)
// ContactSensorState
this.ContactSensor.ContactSensorState = this.webhookContext.openState === 'open' ? 1 : 0
this.ContactSensor.ContactSensorState = this.getContactSensorState(this.webhookContext.openState)
await this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`)
if (!this.device.contact?.hide_motionsensor && this.MotionSensor?.Service) {
// MotionDetected
Expand Down Expand Up @@ -442,4 +438,10 @@ export class Contact extends deviceBase {
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e)
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e)
}

private getContactSensorState(openState: string): CharacteristicValue {
return openState === 'open' || openState === 'timeOutNotClose'
? this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
: this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED
}
}
Loading