Skip to content

Commit

Permalink
v2.2.1 (#118)
Browse files Browse the repository at this point in the history
## [2.2.1](https://github.com/donavanbecker/homebridge-august/releases/tag/v2.2.1) (2024-06-22)

### What's Changes
- Housekeeping and updated dependencies.

**Full Changelog**: v2.2.0...v2.2.1
  • Loading branch information
donavanbecker authored Jun 23, 2024
1 parent 1b8f920 commit 391539c
Show file tree
Hide file tree
Showing 7 changed files with 2,869 additions and 1,556 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.1](https://github.com/donavanbecker/homebridge-august/releases/tag/v2.2.1) (2024-06-22)

### What's Changes
- Housekeeping and updated dependencies.

**Full Changelog**: https://github.com/donavanbecker/homebridge-august/compare/v2.2.0...v2.2.1

## [2.2.0](https://github.com/donavanbecker/homebridge-august/releases/tag/v2.2.0) (2024-05-25)

### What's Changes
Expand Down
1 change: 0 additions & 1 deletion config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@
"refreshRate": {
"title": "Refresh Rate",
"type": "number",
"minimum": 30,
"placeholder": 360,
"description": "Indicates the number of seconds between polls of August API."
},
Expand Down
3,800 changes: 2,608 additions & 1,192 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"displayName": "August",
"name": "homebridge-august",
"version": "2.2.0",
"version": "2.2.1",
"description": "The August plugin allows you to access your August & Yale device(s) from HomeKit.",
"author": {
"name": "donavanbecker",
Expand Down Expand Up @@ -55,19 +55,19 @@
"rxjs": "^7.8.1"
},
"devDependencies": {
"@eslint/js": "^9.3.0",
"@stylistic/eslint-plugin": "^2.1.0",
"@eslint/js": "^9.5.0",
"@stylistic/eslint-plugin": "^2.2.2",
"@types/eslint__js": "^8.42.3",
"@types/node": "^20.12.12",
"eslint": "^9.3.0",
"globals": "^15.3.0",
"homebridge": "^1.8.2",
"homebridge-config-ui-x": "4.56.2",
"nodemon": "^3.1.0",
"@types/node": "^20.14.8",
"eslint": "^9.5.0",
"globals": "^15.6.0",
"homebridge": "^1.8.3",
"homebridge-config-ui-x": "4.56.3",
"nodemon": "^3.1.4",
"npm-check-updates": "^16.14.20",
"rimraf": "^5.0.7",
"ts-node": "^10.9.2",
"typescript": "^5.4.5",
"typescript": "^5.5.2",
"typescript-eslint": "^8.0.0-alpha.14"
}
}
194 changes: 77 additions & 117 deletions src/devices/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* device.ts: homebridge-august.
*/
import type { AugustPlatform } from '../platform.js';
import type { API, HAP, Logging, PlatformAccessory } from 'homebridge';
import type { API, HAP, Logging, PlatformAccessory, Service, CharacteristicValue } from 'homebridge';
import type { device, devicesConfig, AugustPlatformConfig } from '../settings.js';

export abstract class deviceBase {
Expand Down Expand Up @@ -44,74 +44,30 @@ export abstract class deviceBase {
}

async getDeviceLogSettings(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
if (this.platform.debugMode) {
this.deviceLogging = this.accessory.context.logging = 'debugMode';
this.debugWarnLog(`Lock: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
} else if (device.logging) {
this.deviceLogging = this.accessory.context.logging = device.logging;
this.debugWarnLog(`Lock: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
} else if (this.config.logging) {
this.deviceLogging = this.accessory.context.logging = this.config.logging;
this.debugWarnLog(`Lock: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
} else {
this.deviceLogging = this.accessory.context.logging = 'standard';
this.debugWarnLog(`Lock: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
}
this.deviceLogging = this.platform.debugMode ? 'debugMode' : device.logging ?? this.config.options?.logging ?? 'standard';
const logging = this.platform.debugMode ? 'debugMode' : device.logging ? 'Device Config' : this.config.options?.logging
? 'Platform Confg' : 'Default';
accessory.context.logging = this.deviceLogging;
await this.debugLog(`Using ${logging} Logging: ${this.deviceLogging}`);
}

async getDeviceRateSettings(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
if (device.refreshRate) {
if (device.refreshRate === 0) {
this.deviceRefreshRate = 0;
this.warnLog('Refresh Rate set to 0, this will disable the refresh rate for this device');
} else if (device.refreshRate < 1800) {
this.deviceRefreshRate = 1800;
this.warnLog('Refresh Rate cannot be set to lower the 5 mins, as Lock detail (battery level, etc) are unlikely to change within that period');
} else {
this.deviceRefreshRate = device.refreshRate;
}
this.accessory.context.deviceRefreshRate = this.deviceRefreshRate;
this.debugLog(`Lock: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
} else if (this.config.refreshRate) {
this.deviceRefreshRate = this.accessory.context.refreshRate = this.config.refreshRate;
this.debugLog(`Lock: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
}
// refreshRate
if (device.refreshRate) {
this.deviceRefreshRate = device.refreshRate;
this.debugLog(`${device.Type}: ${accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
} else if (this.config.options?.refreshRate) {
this.deviceRefreshRate = this.config.options.refreshRate;
this.debugLog(`${device.Type}: ${accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
} else {
this.deviceRefreshRate = 5;
this.debugLog(`${device.Type}: ${accessory.displayName} Using Default refreshRate: ${this.deviceRefreshRate}`);
}
this.deviceRefreshRate = device.refreshRate === 0 ? 0 : device.refreshRate ?? this.config.options?.refreshRate ?? 30;
const refreshRate = device.refreshRate === 0 ? 'Disabled' : device.refreshRate ? 'Device Config' : this.config.options?.refreshRate
? 'Platform Config' : 'Default';
accessory.context.deviceRefreshRate = this.deviceRefreshRate;
await this.debugLog(`Using ${refreshRate} refreshRate`);
// updateRate
if (device.updateRate) {
this.deviceUpdateRate = device.updateRate;
this.debugLog(`${device.Type}: ${accessory.displayName} Using Device Config updateRate: ${this.deviceUpdateRate}`);
} else if (this.config.options?.updateRate) {
this.deviceUpdateRate = this.config.options.updateRate;
this.debugLog(`${device.Type}: ${accessory.displayName} Using Platform Config updateRate: ${this.deviceUpdateRate}`);
} else {
this.deviceUpdateRate = 5;
this.debugLog(`${device.Type}: ${accessory.displayName} Using Default updateRate: ${this.deviceUpdateRate}`);
}
this.deviceUpdateRate = device.updateRate ?? this.config.options?.updateRate ?? 5;
const updateRate = device.updateRate ? 'Device Config' : this.config.options?.updateRate ? 'Platform Config' : 'Default';
accessory.context.deviceUpdateRate = this.deviceUpdateRate;
await this.debugLog(`Using ${updateRate} updateRate`);
// pushRate
if (device.pushRate) {
this.devicePushRate = device.pushRate;
this.debugLog(`${device.Type}: ${accessory.displayName} Using Device Config pushRate: ${this.deviceUpdateRate}`);
} else if (this.config.options?.pushRate) {
this.devicePushRate = this.config.options.pushRate;
this.debugLog(`${device.Type}: ${accessory.displayName} Using Platform Config pushRate: ${this.deviceUpdateRate}`);
} else {
this.devicePushRate = 1;
this.debugLog(`${device.Type}: ${accessory.displayName} Using Default pushRate: ${this.deviceUpdateRate}`);
}
this.devicePushRate = device.pushRate ?? this.config.options?.pushRate ?? 1;
const pushRate = device.pushRate ? 'Device Config' : this.config.options?.pushRate ? 'Platform Config' : 'Default';
accessory.context.devicePushRate = this.devicePushRate;
await this.debugLog(`Using ${pushRate} pushRate`);
}

async getDeviceConfigSettings(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
Expand Down Expand Up @@ -141,32 +97,15 @@ export abstract class deviceBase {
}
const config = Object.assign({}, deviceConfig);
if (Object.entries(config).length !== 0) {
this.infoLog(`Lock: ${accessory.displayName} Config: ${JSON.stringify(config)}`);
await this.infoLog(`Config: ${JSON.stringify(config)}`);
}
}

async getDeviceContext(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
// Firmware Version
let deviceFirmwareVersion: string;
if (device.firmware) {
deviceFirmwareVersion = device.firmware;
this.debugSuccessLog(`${device.Type}: ${accessory.displayName} 1 FirmwareRevision: ${device.firmware}`);
} else if (device.currentFirmwareVersion) {
deviceFirmwareVersion = device.currentFirmwareVersion;
this.debugSuccessLog(`${device.Type}: ${accessory.displayName} 2 FirmwareRevision: ${device.currentFirmwareVersion}`);
} else if (accessory.context.deviceVersion) {
deviceFirmwareVersion = accessory.context.deviceVersion;
this.debugSuccessLog(`${device.Type}: ${accessory.displayName} 3 FirmwareRevision: ${accessory.context.deviceVersion}`);
} else {
deviceFirmwareVersion = this.platform.version ?? '0.0.0';
if (this.platform.version) {
this.debugSuccessLog(`${device.Type}: ${accessory.displayName} 4 FirmwareRevision: ${this.platform.version}`);
} else {
this.debugSuccessLog(`${device.Type}: ${accessory.displayName} 5 FirmwareRevision: ${deviceFirmwareVersion}`);
}
}
const deviceFirmwareVersion = device.firmware ?? device.currentFirmwareVersion ?? this.platform.version ?? '0.0.0';
const version = deviceFirmwareVersion.toString();
this.debugLog(`${this.device.Type}: ${accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
await this.debugLog(`${this.device.Type}: ${accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
let deviceVersion: string;
if (version?.includes('.') === false) {
const replace = version?.replace(/^V|-.*$/g, '');
Expand All @@ -184,91 +123,112 @@ export abstract class deviceBase {
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
.updateValue(deviceVersion);
accessory.context.deviceVersion = deviceVersion;
this.debugSuccessLog(`${device.Type}: ${accessory.displayName} deviceVersion: ${accessory.context.deviceVersion}`);
await this.debugSuccessLog(`deviceVersion: ${accessory.context.deviceVersion}`);
}

/**
* Update the characteristic value and log the change.
*
* @param Service: Service
* @param Characteristic: Characteristic
* @param CharacteristicValue: CharacteristicValue | undefined
* @param CharacteristicName: string
* @return: void
*
*/
async updateCharacteristic(Service: Service, Characteristic: any,
CharacteristicValue: CharacteristicValue | undefined, CharacteristicName: string): Promise<void> {
if (CharacteristicValue === undefined) {
this.debugLog(`${CharacteristicName}: ${CharacteristicValue}`);
} else {
Service.updateCharacteristic(Characteristic, CharacteristicValue);
this.debugLog(`updateCharacteristic ${CharacteristicName}: ${CharacteristicValue}`);
this.debugWarnLog(`context before: ${this.accessory.context[CharacteristicName]}`);
this.accessory.context[CharacteristicName] = CharacteristicValue;
this.debugWarnLog(`context after: ${this.accessory.context[CharacteristicName]}`);
}
}

async statusCode(accessory: PlatformAccessory, device: device & devicesConfig, error: { message: string; }): Promise<void> {
async statusCode(device: device & devicesConfig, action, error: { message: string; }): Promise<void> {
if (!device.hide_device) {
const statusCodeString = JSON.stringify(error); // Convert statusCode to a string
const statusCodeString = error.message; // Convert statusCode to a string
if (statusCodeString.includes('100')) {
this.debugLog(`Lock: ${accessory.displayName} Command successfully sent, statusCode: ${statusCodeString}`);
await this.debugLog(`Command successfully sent, statusCode: ${statusCodeString}`);
} else if (statusCodeString.includes('200')) {
this.debugLog(`Lock: ${accessory.displayName} Request successful, statusCode: ${statusCodeString}`);
await this.debugLog(`Request successful, statusCode: ${statusCodeString}`);
} else if (statusCodeString.includes('400')) {
this.errorLog(`Lock: ${accessory.displayName} Bad Request, statusCode: ${statusCodeString}`);
await this.errorLog(`Bad Request, statusCode: ${statusCodeString}`);
} else if (statusCodeString.includes('429')) {
this.errorLog(`Lock: ${accessory.displayName} Too Many Requests, exceeded the number of `
+ `requests allowed for a given time window, statusCode: ${statusCodeString}`);
await this.errorLog(`Too Many Requests, exceeded the number of requests allowed for a given time window, statusCode: ${statusCodeString}`);
} else {
this.debugLog(`Lock: ${accessory.displayName} Unknown statusCode: ${statusCodeString}, Submit Bugs Here: '
+ 'https://tinyurl.com/AugustYaleBug`);
this.debugErrorLog(`Lock: ${accessory.displayName} failed lockStatus (refreshStatus), Error: ${JSON.stringify(error)}`);
await this.debugLog(`Unknown statusCode: ${statusCodeString}, Submit Bugs Here: https://tinyurl.com/AugustYaleBug`);
await this.debugErrorLog(`failed ${action}, Error: ${JSON.stringify(error)}`);
}
}
}

/**
* Logging for Device
*/
infoLog(...log: any[]): void {
if (this.enablingDeviceLogging()) {
this.log.info(String(...log));
async infoLog(...log: any[]): Promise<void> {
if (await this.enablingDeviceLogging()) {
this.log.info(`Lock: ${this.accessory.displayName}`, String(...log));
}
}

successLog(...log: any[]): void {
if (this.enablingDeviceLogging()) {
this.log.success(String(...log));
async successLog(...log: any[]): Promise<void> {
if (await this.enablingDeviceLogging()) {
this.log.success(`Lock: ${this.accessory.displayName}`, String(...log));
}
}

debugSuccessLog(...log: any[]): void {
if (this.enablingDeviceLogging()) {
async debugSuccessLog(...log: any[]): Promise<void> {
if (await this.enablingDeviceLogging()) {
if (this.deviceLogging?.includes('debug')) {
this.log.success('[DEBUG]', String(...log));
this.log.success(`[DEBUG] Lock: ${this.accessory.displayName}`, String(...log));
}
}
}

warnLog(...log: any[]): void {
if (this.enablingDeviceLogging()) {
this.log.warn(String(...log));
async warnLog(...log: any[]): Promise<void> {
if (await this.enablingDeviceLogging()) {
this.log.warn(`Lock: ${this.accessory.displayName}`, String(...log));
}
}

debugWarnLog(...log: any[]): void {
if (this.enablingDeviceLogging()) {
async debugWarnLog(...log: any[]): Promise<void> {
if (await this.enablingDeviceLogging()) {
if (this.deviceLogging?.includes('debug')) {
this.log.warn('[DEBUG]', String(...log));
this.log.warn(`[DEBUG] Lock: ${this.accessory.displayName}`, String(...log));
}
}
}

errorLog(...log: any[]): void {
if (this.enablingDeviceLogging()) {
this.log.error(String(...log));
async errorLog(...log: any[]): Promise<void> {
if (await this.enablingDeviceLogging()) {
this.log.error(`Lock: ${this.accessory.displayName}`, String(...log));
}
}

debugErrorLog(...log: any[]): void {
if (this.enablingDeviceLogging()) {
async debugErrorLog(...log: any[]): Promise<void> {
if (await this.enablingDeviceLogging()) {
if (this.deviceLogging?.includes('debug')) {
this.log.error('[DEBUG]', String(...log));
this.log.error(`[DEBUG] Lock: ${this.accessory.displayName}`, String(...log));
}
}
}

debugLog(...log: any[]): void {
if (this.enablingDeviceLogging()) {
async debugLog(...log: any[]): Promise<void> {
if (await this.enablingDeviceLogging()) {
if (this.deviceLogging === 'debug') {
this.log.info('[DEBUG]', String(...log));
this.log.info(`[DEBUG] Lock: ${this.accessory.displayName}`, String(...log));
} else {
this.log.debug(String(...log));
this.log.debug(`Lock: ${this.accessory.displayName}`, String(...log));
}
}
}

enablingDeviceLogging(): boolean {
async enablingDeviceLogging(): Promise<boolean> {
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
}
}
Loading

0 comments on commit 391539c

Please sign in to comment.