Skip to content

Commit

Permalink
Fix parsing Issue that caused plugin to restart
Browse files Browse the repository at this point in the history
  • Loading branch information
donavanbecker committed Jun 23, 2024
1 parent 70ae5da commit 0d17e79
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 40 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/)

## [2.2.4](https://github.com/donavanbecker/homebridge-august/releases/tag/v2.2.4) (2024-06-23)

### What's Changes
- Fix parsing Issue that caused plugin to restart

**Full Changelog**: https://github.com/donavanbecker/homebridge-august/compare/v2.2.3...v2.2.4

## [2.2.3](https://github.com/donavanbecker/homebridge-august/releases/tag/v2.2.3) (2024-06-22)

### What's Changes
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"displayName": "August",
"name": "homebridge-august",
"version": "2.2.3",
"version": "2.2.4",
"description": "The August plugin allows you to access your August & Yale device(s) from HomeKit.",
"author": {
"name": "donavanbecker",
"url": "https://github.com/donavanbecker"
},
"maintainers": ["donavanbecker"],
"type": "module",
"license": "ISC",
"icon": "https://raw.githubusercontent.com/donavanbecker/homebridge-august/beta-1.3.2/branding/icon.png",
Expand All @@ -18,7 +19,7 @@
"url": "https://github.com/donavanbecker/homebridge-august/issues"
},
"engines": {
"homebridge": "^1.8.2",
"homebridge": "^1.8.3",
"node": "^18 || ^20 || ^22"
},
"main": "dist/index.js",
Expand Down Expand Up @@ -68,6 +69,6 @@
"rimraf": "^5.0.7",
"ts-node": "^10.9.2",
"typescript": "^5.5.2",
"typescript-eslint": "^8.0.0-alpha.14"
"typescript-eslint": "^8.0.0-alpha.30"
}
}
70 changes: 37 additions & 33 deletions src/devices/lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,41 +178,45 @@ export class LockMechanism extends deviceBase {
async parseStatus(): Promise<void> {
await this.debugLog('parseStatus');
const retryCount = 1;
this.platform.augustConfig.addSimpleProps(this.lockStatus);
// BatteryLevel
this.Battery.BatteryLevel = Number((this.lockDetails.battery * 100).toFixed());
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
// StatusLowBattery
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 15
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
// Lock Mechanism
if (!this.device.lock?.hide_lock && this.LockMechanism?.Service) {
this.LockMechanism.LockCurrentState = this.lockStatus.state.locked ? this.hap.Characteristic.LockCurrentState.SECURED
: this.lockStatus.state.unlocked ? this.hap.Characteristic.LockCurrentState.UNSECURED
: retryCount > 1 ? this.hap.Characteristic.LockCurrentState.JAMMED : this.hap.Characteristic.LockCurrentState.UNKNOWN;
await this.debugLog(`LockCurrentState: ${this.LockMechanism.LockCurrentState}`);
}
// Contact Sensor
if (!this.device.lock?.hide_contactsensor && this.ContactSensor?.Service) {
if (this.lockStatus) {
// Lock Mechanism
this.platform.augustConfig.addSimpleProps(this.lockStatus);
if (!this.device.lock?.hide_lock && this.LockMechanism?.Service) {
this.LockMechanism.LockCurrentState = this.lockStatus.state.locked ? this.hap.Characteristic.LockCurrentState.SECURED
: this.lockStatus.state.unlocked ? this.hap.Characteristic.LockCurrentState.UNSECURED
: retryCount > 1 ? this.hap.Characteristic.LockCurrentState.JAMMED : this.hap.Characteristic.LockCurrentState.UNKNOWN;
await this.debugLog(`LockCurrentState: ${this.LockMechanism.LockCurrentState}`);
}
// Contact Sensor
if (!this.device.lock?.hide_contactsensor && this.ContactSensor?.Service) {
// ContactSensorState
this.ContactSensor.ContactSensorState = this.lockStatus.state.open ? this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
: this.lockStatus.state.closed ? this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED
: this.lockStatus.doorState.includes('open') ? this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
: this.lockStatus.doorState.includes('closed') ? this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED
: this.ContactSensor.ContactSensorState;
await this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`);
this.ContactSensor.ContactSensorState = this.lockStatus.state.open ? this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
: this.lockStatus.state.closed ? this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED
: this.lockStatus.doorState.includes('open') ? this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
: this.lockStatus.doorState.includes('closed') ? this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED
: this.ContactSensor.ContactSensorState;
await this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`);
}
}
// Firmware Version
if (this.accessory.context.currentFirmwareVersion !== this.lockDetails.currentFirmwareVersion) {
await this.warnLog(`Firmware Version changed to Current Firmware Version: ${this.lockDetails.currentFirmwareVersion}`);
this.accessory
.getService(this.hap.Service.AccessoryInformation)!
.setCharacteristic(this.hap.Characteristic.HardwareRevision, this.lockDetails.currentFirmwareVersion)
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, this.lockDetails.currentFirmwareVersion)
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
.updateValue(this.lockDetails.currentFirmwareVersion);
this.accessory.context.currentFirmwareVersion = this.lockDetails.currentFirmwareVersion;
if (this.lockDetails) {
// BatteryLevel
this.Battery.BatteryLevel = Number((this.lockDetails.battery * 100).toFixed());
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
// StatusLowBattery
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 15
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
// Firmware Version
if (this.accessory.context.currentFirmwareVersion !== this.lockDetails.currentFirmwareVersion) {
await this.warnLog(`Firmware Version changed to Current Firmware Version: ${this.lockDetails.currentFirmwareVersion}`);
this.accessory
.getService(this.hap.Service.AccessoryInformation)!
.setCharacteristic(this.hap.Characteristic.HardwareRevision, this.lockDetails.currentFirmwareVersion)
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, this.lockDetails.currentFirmwareVersion)
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
.updateValue(this.lockDetails.currentFirmwareVersion);
this.accessory.context.currentFirmwareVersion = this.lockDetails.currentFirmwareVersion;
}
}
}

Expand Down

0 comments on commit 0d17e79

Please sign in to comment.