Skip to content

Commit

Permalink
v2.1.1
Browse files Browse the repository at this point in the history
## [Version 2.1.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.1.1) (2022-10-14)

## What's Changed

- Fixed issue were `CustomOff` would send incorrect commands. Also Resolves [#409](#409).
- Fixed issue were IR Commands were not sent from IR Devices, Thanks [@jonzhan](https://github.com/jonzhan). [#520](#520)
- Fixed issue with Curtain not refreshing moving status. [#517](#517)
- Housekeeping and updated dependencies.

**Full Changelog**: v2.1.0...v2.1.1
  • Loading branch information
donavanbecker committed Oct 14, 2022
1 parent 2c09930 commit 3e34ab7
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 38 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. This projec

- Fixed issue were `CustomOff` would send incorrect commands. Also Resolves [#409](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/409).
- Fixed issue were IR Commands were not sent from IR Devices, Thanks [@jonzhan](https://github.com/jonzhan). [#520](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/520)
- Fixed issue with Curtain not refreshing moving status. [#517](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/517)
- Housekeeping and updated dependencies.

**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.1.0...v2.1.1
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": "2.1.0",
"version": "2.1.1",
"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 <support@wondertechlabs.com> (https://github.com/SwitchBot)",
"license": "ISC",
Expand Down
75 changes: 41 additions & 34 deletions src/irdevice/waterheater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import superStringify from 'super-stringify';
import { SwitchBotPlatform } from '../platform';
import { irDevicesConfig, irdevice, HostDomain, DevicePath } from '../settings';
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
const version = process.env.npm_package_version;

/**
* Platform Accessory
Expand All @@ -23,8 +24,8 @@ export class WaterHeater {

constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
// default placeholders
this.logs(device);
this.config(device);
this.logs({ device });
this.config({ device });
this.context();

// set accessory information
Expand All @@ -33,9 +34,9 @@ export class WaterHeater {
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
.setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision({ accessory, device }))
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
.updateValue(this.FirmwareRevision(accessory, device));
.updateValue(this.FirmwareRevision({ accessory, device }));

// get the Television service if it exists, otherwise create a new Television service
// you can create multiple services for each accessory
Expand Down Expand Up @@ -89,7 +90,7 @@ export class WaterHeater {
'parameter': 'default',
'commandType': commandType,
});
await this.pushChanges(body);
await this.pushChanges({ body });
}
}

Expand All @@ -102,11 +103,11 @@ export class WaterHeater {
'parameter': 'default',
'commandType': commandType,
});
await this.pushChanges(body);
await this.pushChanges({ body });
}
}

async pushChanges(body): Promise<void> {
async pushChanges({ body }: { body: any; }): Promise<void> {
if (this.device.connectionType === 'OpenAPI') {
try {
// Make Push On request to the API
Expand All @@ -118,7 +119,7 @@ export class WaterHeater {
.digest();
const sign = signTerm.toString('base64');
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} sign: ${sign}`);
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
this.infoLog({ log: [`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`] });
const options = {
hostname: HostDomain,
port: 443,
Expand All @@ -141,20 +142,24 @@ export class WaterHeater {
});
});
req.on('error', (e: any) => {
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} error message: ${e.message}`);
this.errorLog({ log: [`${this.device.remoteType}: ${this.accessory.displayName} error message: ${e.message}`] });
});
req.write(body);
req.end();
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
this.updateHomeKitCharacteristics();
} catch (e: any) {
this.apiError(e);
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
+ ` Error Message: ${superStringify(e.message)}`);
this.apiError({ e });
this.errorLog({
log: [`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
+ ` Error Message: ${superStringify(e.message)}`],
});
}
} else {
this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
+ ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
this.warnLog({
log: [`${this.device.remoteType}: ${this.accessory.displayName}`
+ ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`],
});
}
}

Expand Down Expand Up @@ -201,24 +206,26 @@ export class WaterHeater {
async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
switch (res.statusCode) {
case 151:
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this device type.`);
this.errorLog({ log: [`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this device type.`] });
break;
case 152:
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found.`);
this.errorLog({ log: [`${this.device.remoteType}: ${this.accessory.displayName} Device not found.`] });
break;
case 160:
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported.`);
this.errorLog({ log: [`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported.`] });
break;
case 161:
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline.`);
this.errorLog({ log: [`${this.device.remoteType}: ${this.accessory.displayName} Device is offline.`] });
break;
case 171:
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
this.errorLog({ log: [`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`] });
break;
case 190:
this.errorLog(
`${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
` with server, Or command: ${superStringify(res)} format is invalid`,
{
log: [`${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
` with server, Or command: ${superStringify(res)} format is invalid`],
},
);
break;
case 100:
Expand All @@ -229,35 +236,35 @@ export class WaterHeater {
}
}

async apiError(e: any): Promise<void> {
async apiError({ e }: { e: any; }): Promise<void> {
this.valveService.updateCharacteristic(this.platform.Characteristic.Active, e);
}

FirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): string {
FirmwareRevision({ accessory, device }: { accessory: PlatformAccessory; device: irdevice & irDevicesConfig; }): string {
let FirmwareRevision: string;
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} version: ${version}`);
if (accessory.context.FirmwareRevision) {
FirmwareRevision = accessory.context.FirmwareRevision;
} else if (device.firmware) {
FirmwareRevision = device.firmware;
} else {
FirmwareRevision = this.platform.version;
FirmwareRevision = version!;
}
return FirmwareRevision;
}

async context() {
async context(): Promise<void> {
if (this.Active === undefined) {
this.Active = this.platform.Characteristic.Active.INACTIVE;
} else {
this.Active = this.accessory.context.Active;
}
}

async config(device: irdevice & irDevicesConfig): Promise<void> {
async config({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
let config = {};
if (device.irwh) {
config = device.irwh;
Expand All @@ -272,11 +279,11 @@ export class WaterHeater {
config['external'] = device.external;
}
if (Object.entries(config).length !== 0) {
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
this.infoLog({ log: [`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`] });
}
}

async logs(device: irdevice & irDevicesConfig): Promise<void> {
async logs({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
if (this.platform.debugMode) {
this.deviceLogging = this.accessory.context.logging = 'debugMode';
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
Expand All @@ -295,33 +302,33 @@ export class WaterHeater {
/**
* Logging for Device
*/
infoLog(...log: any[]): void {
infoLog({ log = [] }: { log?: any[]; } = {}): void {
if (this.enablingDeviceLogging()) {
this.platform.log.info(String(...log));
}
}

warnLog(...log: any[]): void {
warnLog({ log = [] }: { log?: any[]; } = {}): void {
if (this.enablingDeviceLogging()) {
this.platform.log.warn(String(...log));
}
}

debugWarnLog(...log: any[]): void {
debugWarnLog({ log = [] }: { log?: any[]; } = {}): void {
if (this.enablingDeviceLogging()) {
if (this.deviceLogging?.includes('debug')) {
this.platform.log.warn('[DEBUG]', String(...log));
}
}
}

errorLog(...log: any[]): void {
errorLog({ log = [] }: { log?: any[]; } = {}): void {
if (this.enablingDeviceLogging()) {
this.platform.log.error(String(...log));
}
}

debugErrorLog(...log: any[]): void {
debugErrorLog({ log = [] }: { log?: any[]; } = {}): void {
if (this.enablingDeviceLogging()) {
if (this.deviceLogging?.includes('debug')) {
this.platform.log.error('[DEBUG]', String(...log));
Expand Down
2 changes: 1 addition & 1 deletion src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
// this is used to track restored cached accessories
public readonly accessories: PlatformAccessory[] = [];

version = require('../package.json').version || '1.12.8'; // eslint-disable-line @typescript-eslint/no-var-requires
version = process.env.npm_package_version!;
debugMode!: boolean;
platformLogging?: string;

Expand Down

0 comments on commit 3e34ab7

Please sign in to comment.