diff --git a/CHANGELOG.md b/CHANGELOG.md index 5df7b9e6..e435cf7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/) +## [Version 1.8.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.8.2) (2022-01-15) + +## What's Changed +* Fixed Bug: Only log config if it is set. + +**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.8.1...v1.8.2 + ## [Version 1.8.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.8.1) (2022-01-15) ## What's Changed diff --git a/package-lock.json b/package-lock.json index 575a7630..e1100d50 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@switchbot/homebridge-switchbot", - "version": "1.8.1", + "version": "1.8.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@switchbot/homebridge-switchbot", - "version": "1.8.1", + "version": "1.8.2", "funding": [ { "type": "Paypal", diff --git a/package.json b/package.json index 12e004e8..532e7e1d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "displayName": "Homebridge SwitchBot", "name": "@switchbot/homebridge-switchbot", - "version": "1.8.1", + "version": "1.8.2", "description": "The [Homebridge](https://homebridge.io) SwitchBot plugin allows you to access your [SwitchBot](https://www.switch-bot.com) device(s) from HomeKit.", "author": "SwitchBot (https://github.com/SwitchBot)", "license": "ISC", diff --git a/src/devices/bots.ts b/src/devices/bots.ts index a5a830d6..43a37bfa 100644 --- a/src/devices/bots.ts +++ b/src/devices/bots.ts @@ -1030,7 +1030,7 @@ export class Bot { if (device.scanDuration !== undefined) { config['scanDuration'] = device.scanDuration; } - if (config !== undefined) { + if (Object.entries(config).length !== 0) { this.warnLog(`Bot: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`); } } diff --git a/src/devices/colorbulb.ts b/src/devices/colorbulb.ts index 1cbc72ec..e9db414f 100644 --- a/src/devices/colorbulb.ts +++ b/src/devices/colorbulb.ts @@ -634,7 +634,7 @@ export class ColorBulb { if (device.scanDuration !== undefined) { config['scanDuration'] = device.scanDuration; } - if (config !== undefined) { + if (Object.entries(config).length !== 0) { this.warnLog(`Color Bulb: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`); } } diff --git a/src/devices/contact.ts b/src/devices/contact.ts index fa658c3a..f68deb0d 100644 --- a/src/devices/contact.ts +++ b/src/devices/contact.ts @@ -441,7 +441,7 @@ export class Contact { if (device.scanDuration !== undefined) { config['scanDuration'] = device.scanDuration; } - if (config !== undefined) { + if (Object.entries(config).length !== 0) { this.warnLog(`Contact Sensor: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`); } } diff --git a/src/devices/curtains.ts b/src/devices/curtains.ts index 6a1e821e..3d4f2381 100644 --- a/src/devices/curtains.ts +++ b/src/devices/curtains.ts @@ -734,7 +734,7 @@ export class Curtain { if (device.scanDuration !== undefined) { config['scanDuration'] = device.scanDuration; } - if (config !== undefined) { + if (Object.entries(config).length !== 0) { this.warnLog(`Curtain: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`); } } diff --git a/src/devices/humidifiers.ts b/src/devices/humidifiers.ts index 4e2738e5..f9b02b27 100644 --- a/src/devices/humidifiers.ts +++ b/src/devices/humidifiers.ts @@ -728,7 +728,7 @@ export class Humidifier { if (device.scanDuration !== undefined) { config['scanDuration'] = device.scanDuration; } - if (config !== undefined) { + if (Object.entries(config).length !== 0) { this.warnLog(`Humidifier: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`); } } diff --git a/src/devices/meters.ts b/src/devices/meters.ts index 5c401a65..0f9894da 100644 --- a/src/devices/meters.ts +++ b/src/devices/meters.ts @@ -407,7 +407,7 @@ export class Meter { if (device.scanDuration !== undefined) { config['scanDuration'] = device.scanDuration; } - if (config !== undefined) { + if (Object.entries(config).length !== 0) { this.warnLog(`Meter: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`); } } diff --git a/src/devices/motion.ts b/src/devices/motion.ts index 45277304..a8764396 100644 --- a/src/devices/motion.ts +++ b/src/devices/motion.ts @@ -381,7 +381,7 @@ export class Motion { if (device.scanDuration !== undefined) { config['scanDuration'] = device.scanDuration; } - if (config !== undefined) { + if (Object.entries(config).length !== 0) { this.warnLog(`Motion Sensor: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`); } } diff --git a/src/devices/plugs.ts b/src/devices/plugs.ts index bdbff84d..78356c8d 100644 --- a/src/devices/plugs.ts +++ b/src/devices/plugs.ts @@ -266,7 +266,7 @@ export class Plug { if (device.scanDuration !== undefined) { config['scanDuration'] = device.scanDuration; } - if (config !== undefined) { + if (Object.entries(config).length !== 0) { this.warnLog(`Plug: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`); } } diff --git a/src/irdevices/airconditioners.ts b/src/irdevices/airconditioners.ts index cbefebae..0d506f04 100644 --- a/src/irdevices/airconditioners.ts +++ b/src/irdevices/airconditioners.ts @@ -566,7 +566,7 @@ export class AirConditioner { if (device.logging !== undefined) { config['logging'] = device.logging; } - if (config !== undefined) { + if (Object.entries(config).length !== 0) { this.warnLog(`Air Conditioner: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`); } } diff --git a/src/irdevices/airpurifiers.ts b/src/irdevices/airpurifiers.ts index 47576e28..f4c33ea9 100644 --- a/src/irdevices/airpurifiers.ts +++ b/src/irdevices/airpurifiers.ts @@ -288,7 +288,7 @@ export class AirPurifier { if (device.logging !== undefined) { config['logging'] = device.logging; } - if (config !== undefined) { + if (Object.entries(config).length !== 0) { this.warnLog(`Air Purifier: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`); } } diff --git a/src/irdevices/cameras.ts b/src/irdevices/cameras.ts index c6fd6600..f04cba1c 100644 --- a/src/irdevices/cameras.ts +++ b/src/irdevices/cameras.ts @@ -177,7 +177,7 @@ export class Camera { if (device.logging !== undefined) { config['logging'] = device.logging; } - if (config !== undefined) { + if (Object.entries(config).length !== 0) { this.warnLog(`Camera: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`); } } diff --git a/src/irdevices/fans.ts b/src/irdevices/fans.ts index 12f35f97..9161e54e 100644 --- a/src/irdevices/fans.ts +++ b/src/irdevices/fans.ts @@ -301,7 +301,7 @@ export class Fan { if (device.logging !== undefined) { config['logging'] = device.logging; } - if (config !== undefined) { + if (Object.entries(config).length !== 0) { this.warnLog(`Fan: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`); } } diff --git a/src/irdevices/lights.ts b/src/irdevices/lights.ts index b04b5547..ecc79693 100644 --- a/src/irdevices/lights.ts +++ b/src/irdevices/lights.ts @@ -211,7 +211,7 @@ export class Light { if (device.logging !== undefined) { config['logging'] = device.logging; } - if (config !== undefined) { + if (Object.entries(config).length !== 0) { this.warnLog(`Light: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`); } } diff --git a/src/irdevices/others.ts b/src/irdevices/others.ts index 9fe4a819..b44f5476 100644 --- a/src/irdevices/others.ts +++ b/src/irdevices/others.ts @@ -220,7 +220,7 @@ export class Others { if (device.logging !== undefined) { config['logging'] = device.logging; } - if (config !== undefined) { + if (Object.entries(config).length !== 0) { this.warnLog(`Other: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`); } } diff --git a/src/irdevices/tvs.ts b/src/irdevices/tvs.ts index f36f7c5c..b7430b70 100644 --- a/src/irdevices/tvs.ts +++ b/src/irdevices/tvs.ts @@ -417,7 +417,7 @@ export class TV { if (device.logging !== undefined) { config['logging'] = device.logging; } - if (config !== undefined) { + if (Object.entries(config).length !== 0) { this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`); } } diff --git a/src/irdevices/vacuumcleaners.ts b/src/irdevices/vacuumcleaners.ts index 3352a26a..a3ebf02f 100644 --- a/src/irdevices/vacuumcleaners.ts +++ b/src/irdevices/vacuumcleaners.ts @@ -177,7 +177,7 @@ export class VacuumCleaner { if (device.logging !== undefined) { config['logging'] = device.logging; } - if (config !== undefined) { + if (Object.entries(config).length !== 0) { this.warnLog(`Vacuum Cleaner: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`); } } diff --git a/src/irdevices/waterheaters.ts b/src/irdevices/waterheaters.ts index 582ff3ae..963000c2 100644 --- a/src/irdevices/waterheaters.ts +++ b/src/irdevices/waterheaters.ts @@ -191,7 +191,7 @@ export class WaterHeater { if (device.logging !== undefined) { config['logging'] = device.logging; } - if (config !== undefined) { + if (Object.entries(config).length !== 0) { this.warnLog(`Water Heater: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`); } } diff --git a/src/platform.ts b/src/platform.ts index 65c818e3..c248e308 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -1,4 +1,3 @@ - import { Bot } from './devices/bots'; import { Plug } from './devices/plugs'; import { Meter } from './devices/meters'; @@ -97,17 +96,19 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug'); if (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none') { this.platformLogging = this.config.options!.logging; - if (this.debugMode) { + if (this.platformLogging.includes('debug')) { this.log.warn(`Using Config Logging: ${this.platformLogging}`); } } else if (this.debugMode) { - if (this.debugMode) { - this.log.warn('Using debugMode Logging'); - } this.platformLogging = 'debugMode'; + if (this.platformLogging?.includes('debug')) { + this.log.warn(`Using ${this.platformLogging} Logging`); + } } else { - this.log.warn('Using Standard Logging'); this.platformLogging = 'standard'; + if (this.platformLogging?.includes('debug')) { + this.log.warn(`Using ${this.platformLogging} Logging`); + } } } @@ -126,14 +127,23 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { * Verify the config passed to the plugin is valid */ verifyConfig() { - /** - * Hidden Device Discovery Option - * This will disable adding any device and will just output info. - */ this.config.options = this.config.options || {}; - if (this.config.options) { + const platformConfig = {}; + if (this.config.options.logging) { + platformConfig['logging'] = this.config.options.logging; + } + if (this.config.options.logging) { + platformConfig['refreshRate'] = this.config.options.refreshRate; + } + if (this.config.options.logging) { + platformConfig['pushRate'] = this.config.options.pushRate; + } + if (Object.entries(platformConfig).length !== 0) { + this.warnLog(`Platform Config: ${JSON.stringify(platformConfig)}`); + } + if (this.config.options) { // Device Config if (this.config.options.devices) { for (const deviceConfig of this.config.options.devices) { @@ -170,41 +180,32 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { if (!this.config.options.refreshRate) { // default 120 seconds (2 minutes) this.config.options!.refreshRate! = 120; - if (this.debugMode) { - this.warnLog('Using Default Refresh Rate (2 minutes).'); + if (this.platformLogging?.includes('debug')) { + this.debugLog('Using Default Refresh Rate (2 minutes).'); } if (!this.config.options.pushRate) { // default 100 milliseconds this.config.options!.pushRate! = 0.1; - if (this.debugMode) { + if (this.platformLogging?.includes('debug')) { this.warnLog('Using Default Push Rate.'); } } if (!this.config.credentials) { - this.debugLog('Missing Credentials'); + if (this.platformLogging?.includes('debug')) { + this.debugLog('Missing Credentials'); + } } if (!this.config.credentials?.openToken) { - this.errorLog('Missing openToken'); - this.warnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work'); + if (this.platformLogging?.includes('debug')) { + this.errorLog('Missing openToken'); + this.warnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work'); + } } } } - connectBLE() { - let Switchbot: new () => any; - let switchbot: any; - try { - Switchbot = require('node-switchbot'); - switchbot = new Switchbot(); - } catch (e) { - switchbot = false; - this.errorLog(`Was 'node-switchbot' found: ${switchbot}`); - } - return switchbot; - } - /** * this method discovers devices */ @@ -1499,6 +1500,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { } } + // BLE Connection + connectBLE() { + let Switchbot: new () => any; + let switchbot: any; + try { + Switchbot = require('node-switchbot'); + switchbot = new Switchbot(); + } catch (e) { + switchbot = false; + this.errorLog(`Was 'node-switchbot' found: ${switchbot}`); + } + return switchbot; + } + /** * If device level logging is turned on, log to log.warn * Otherwise send debug logs to log.debug diff --git a/src/settings.ts b/src/settings.ts index b58a9dfd..e2956373 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -51,7 +51,7 @@ export interface devicesConfig extends device { motion?: motion; colorbulb?: colorbulb; plug?: Record; - ble?: string; + ble?: boolean; scanDuration?: number; hide_device?: boolean; offline?: boolean;