Skip to content

Commit

Permalink
Version 1.8.2 (#201)
Browse files Browse the repository at this point in the history
## [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**: v1.8.1...v1.8.2
  • Loading branch information
donavanbecker authored Jan 16, 2022
1 parent 375abcd commit 7ee4a27
Show file tree
Hide file tree
Showing 22 changed files with 73 additions and 51 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/)

## [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
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]> (https://github.com/SwitchBot)",
"license": "ISC",
Expand Down
2 changes: 1 addition & 1 deletion src/devices/bots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/devices/colorbulb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/devices/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/devices/curtains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/devices/humidifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/devices/meters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/devices/motion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/devices/plugs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/irdevices/airconditioners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/irdevices/airpurifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/irdevices/cameras.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/irdevices/fans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/irdevices/lights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/irdevices/others.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/irdevices/tvs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/irdevices/vacuumcleaners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/irdevices/waterheaters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
}
}
Expand Down
75 changes: 45 additions & 30 deletions src/platform.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { Bot } from './devices/bots';
import { Plug } from './devices/plugs';
import { Meter } from './devices/meters';
Expand Down Expand Up @@ -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`);
}
}
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface devicesConfig extends device {
motion?: motion;
colorbulb?: colorbulb;
plug?: Record<any, any>;
ble?: string;
ble?: boolean;
scanDuration?: number;
hide_device?: boolean;
offline?: boolean;
Expand Down

0 comments on commit 7ee4a27

Please sign in to comment.