From b09e7891683a85d05b820b9d561fc04b939b7be1 Mon Sep 17 00:00:00 2001 From: Donavan Becker Date: Mon, 17 Apr 2023 07:42:42 -0500 Subject: [PATCH] v2.6.2 (#723) ## [Version 2.6.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.6.2) (2023-04-17) ## What's Changed - Fix for Commands not being sent, [#721](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/721) - Housekeeping. **Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.6.1....v2.6.2 --- CHANGELOG.md | 9 ++++++ nodemon.json | 2 +- package-lock.json | 4 +-- package.json | 2 +- src/device/blindtilt.ts | 13 +++++---- src/device/bot.ts | 7 +++-- src/device/ceilinglight.ts | 22 ++++++++------ src/device/colorbulb.ts | 20 +++++++------ src/device/curtain.ts | 7 +++-- src/device/humidifier.ts | 15 ++++++---- src/device/lightstrip.ts | 15 ++++++---- src/device/lock.ts | 5 ++-- src/device/plug.ts | 5 ++-- src/device/robotvacuumcleaner.ts | 5 ++-- src/irdevice/airconditioner.ts | 17 +++++------ src/irdevice/airpurifier.ts | 17 +++++------ src/irdevice/camera.ts | 13 +++++---- src/irdevice/fan.ts | 25 ++++++++-------- src/irdevice/light.ts | 21 +++++++------- src/irdevice/other.ts | 13 +++++---- src/irdevice/tv.ts | 49 ++++++++++++++++---------------- src/irdevice/vacuumcleaner.ts | 13 +++++---- src/irdevice/waterheater.ts | 13 +++++---- src/settings.ts | 10 ------- 24 files changed, 175 insertions(+), 147 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e14385d..ceba7a47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/) +## [Version 2.6.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.6.2) (2023-04-17) + +## What's Changed + +- Fix for Commands not being sent, [#721](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/721) +- Housekeeping. + +**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.6.1....v2.6.2 + ## [Version 2.6.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.6.1) (2023-04-15) ## What's Changed diff --git a/nodemon.json b/nodemon.json index efd2979c..94937da0 100644 --- a/nodemon.json +++ b/nodemon.json @@ -2,7 +2,7 @@ "watch": ["src"], "ext": "ts", "ignore": [], - "exec": "DEBUG= tsc && homebridge -T -D -P ..", + "exec": "DEBUG= tsc && homebridge -T -D -P -I ..", "signal": "SIGTERM", "env": { "NODE_OPTIONS": "--trace-warnings" diff --git a/package-lock.json b/package-lock.json index 93a34a0e..576bc853 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@switchbot/homebridge-switchbot", - "version": "2.6.1", + "version": "2.6.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@switchbot/homebridge-switchbot", - "version": "2.6.1", + "version": "2.6.2", "funding": [ { "type": "Paypal", diff --git a/package.json b/package.json index 31e1ec83..fc52de8f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "displayName": "Homebridge SwitchBot", "name": "@switchbot/homebridge-switchbot", - "version": "2.6.1", + "version": "2.6.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/device/blindtilt.ts b/src/device/blindtilt.ts index cdbc5ba6..9ec8a487 100644 --- a/src/device/blindtilt.ts +++ b/src/device/blindtilt.ts @@ -629,7 +629,7 @@ export class BlindTilt { } async openAPIpushChanges(): Promise { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI pushChanges`); + this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`); const hasDifferentAndRelevantHorizontalTiltAngle = ( this.mappingMode === BlindTiltMappingMode.UseTiltForDirection && this.TargetHorizontalTiltAngle !== this.CurrentHorizontalTiltAngle); @@ -637,27 +637,28 @@ export class BlindTilt { const [direction, position] = this.mapHomekitValuesToDeviceValues(Number(this.TargetPosition), Number(this.TargetHorizontalTiltAngle)); this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing ${this.TargetPosition} (device = ${direction};${position})`); this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Mode: ${this.Mode}`); - let body = ''; + let bodyChange = ''; if (position === 100) { - body = JSON.stringify({ + bodyChange = JSON.stringify({ 'command': 'fullyOpen', 'commandType': 'command', }); } else if (position === 0) { - body = JSON.stringify({ + bodyChange = JSON.stringify({ 'command': direction === 'up' ? 'closeUp' : 'closeDown', 'commandType': 'command', }); } else { - body = JSON.stringify({ + bodyChange = JSON.stringify({ 'command': 'setPosition', 'parameter': `${direction};${position}`, 'commandType': 'command', }); } - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); diff --git a/src/device/bot.ts b/src/device/bot.ts index d3951dd9..757b7fa3 100644 --- a/src/device/bot.ts +++ b/src/device/bot.ts @@ -659,7 +659,7 @@ export class Bot { } async openAPIpushChanges(): Promise { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI pushChanges`); + this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`); if (this.multiPressCount > 0) { this.debugLog(`${this.device.deviceType}: ${this.multiPressCount} request(s) queued.`); this.On = true; @@ -681,14 +681,15 @@ export class Bot { } else { throw new Error(`${this.device.deviceType}: ${this.accessory.displayName} Device Paramters not set for this Bot.`); } - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': `${command}`, 'parameter': 'default', 'commandType': 'command', }); - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); diff --git a/src/device/ceilinglight.ts b/src/device/ceilinglight.ts index 3aafb151..ef4e132a 100644 --- a/src/device/ceilinglight.ts +++ b/src/device/ceilinglight.ts @@ -489,7 +489,7 @@ export class CeilingLight { } async openAPIpushChanges(): Promise { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI pushChanges`); + this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`); if (this.On !== this.accessory.context.On) { let command = ''; if (this.On) { @@ -497,14 +497,15 @@ export class CeilingLight { } else { command = 'turnOff'; } - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': `${command}`, 'parameter': 'default', 'commandType': 'command', }); - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); @@ -543,14 +544,15 @@ export class CeilingLight { this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`); const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation)); this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`); - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'setColor', 'parameter': `${red}:${green}:${blue}`, 'commandType': 'command', }); - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); @@ -575,14 +577,15 @@ export class CeilingLight { if (this.ColorTemperature !== this.accessory.context.ColorTemperature) { const kelvin = Math.round(1000000 / Number(this.ColorTemperature)); this.cacheKelvin = kelvin; - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'setColorTemperature', 'parameter': `${kelvin}`, 'commandType': 'command', }); - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); @@ -605,14 +608,15 @@ export class CeilingLight { async pushBrightnessChanges(): Promise { this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges`); if (this.Brightness !== this.accessory.context.Brightness) { - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'setBrightness', 'parameter': `${this.Brightness}`, 'commandType': 'command', }); - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); diff --git a/src/device/colorbulb.ts b/src/device/colorbulb.ts index 3f4e2839..e621637d 100644 --- a/src/device/colorbulb.ts +++ b/src/device/colorbulb.ts @@ -651,14 +651,15 @@ export class ColorBulb { } else { command = 'turnOff'; } - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': `${command}`, 'parameter': 'default', 'commandType': 'command', }); - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); @@ -697,14 +698,15 @@ export class ColorBulb { this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`); const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation)); this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`); - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'setColor', 'parameter': `${red}:${green}:${blue}`, 'commandType': 'command', }); - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); @@ -729,14 +731,15 @@ export class ColorBulb { if (this.ColorTemperature !== this.accessory.context.ColorTemperature) { const kelvin = Math.round(1000000 / Number(this.ColorTemperature)); this.cacheKelvin = kelvin; - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'setColorTemperature', 'parameter': `${kelvin}`, 'commandType': 'command', }); - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); @@ -759,14 +762,15 @@ export class ColorBulb { async pushBrightnessChanges(): Promise { this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges`); if (this.Brightness !== this.accessory.context.Brightness) { - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'setBrightness', 'parameter': `${this.Brightness}`, 'commandType': 'command', }); - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); diff --git a/src/device/curtain.ts b/src/device/curtain.ts index f2119580..06060bb6 100644 --- a/src/device/curtain.ts +++ b/src/device/curtain.ts @@ -588,7 +588,7 @@ export class Curtain { } async openAPIpushChanges(): Promise { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI pushChanges`); + this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`); if ((this.TargetPosition !== this.CurrentPosition) || this.device.disableCaching) { this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing ${this.TargetPosition}`); const adjustedTargetPosition = 100 - Number(this.TargetPosition); @@ -606,14 +606,15 @@ export class Curtain { } this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Mode: ${this.Mode}`); const adjustedMode = this.setPositionMode || 'ff'; - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'setPosition', 'parameter': `0,${adjustedMode},${adjustedTargetPosition}`, 'commandType': 'command', }); - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); diff --git a/src/device/humidifier.ts b/src/device/humidifier.ts index d15b6700..c2c971cd 100644 --- a/src/device/humidifier.ts +++ b/src/device/humidifier.ts @@ -444,14 +444,15 @@ export class Humidifier { if (this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER && this.Active === this.platform.Characteristic.Active.ACTIVE) { this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`); - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'setMode', 'parameter': `${this.RelativeHumidityHumidifierThreshold}`, 'commandType': 'command', }); - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); @@ -483,14 +484,15 @@ export class Humidifier { if (this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER && this.Active === this.platform.Characteristic.Active.ACTIVE) { this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Auto`); - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'setMode', 'parameter': 'auto', 'commandType': 'command', }); - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); @@ -517,14 +519,15 @@ export class Humidifier { this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushActiveChanges`); if (this.Active === this.platform.Characteristic.Active.INACTIVE) { this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Off`); - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'turnOff', 'parameter': 'default', 'commandType': 'command', }); - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); diff --git a/src/device/lightstrip.ts b/src/device/lightstrip.ts index 3455acc0..b677caca 100644 --- a/src/device/lightstrip.ts +++ b/src/device/lightstrip.ts @@ -554,14 +554,15 @@ export class StripLight { } else { command = 'turnOff'; }*/ - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': `${command}`, 'parameter': 'default', 'commandType': 'command', }); - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); @@ -597,14 +598,15 @@ export class StripLight { const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation)); this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`); // Make Push On request to the API - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'setColor', 'parameter': `${red}:${green}:${blue}`, 'commandType': 'command', }); - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); @@ -627,14 +629,15 @@ export class StripLight { async pushBrightnessChanges(): Promise { this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges`); if (this.Brightness !== this.accessory.context.Brightness) { - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'setBrightness', 'parameter': `${this.Brightness}`, 'commandType': 'command', }); - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); diff --git a/src/device/lock.ts b/src/device/lock.ts index d227a767..121c5460 100644 --- a/src/device/lock.ts +++ b/src/device/lock.ts @@ -385,14 +385,15 @@ export class Lock { } else { command = 'unlock'; } - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': `${command}`, 'parameter': 'default', 'commandType': 'command', }); - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); diff --git a/src/device/plug.ts b/src/device/plug.ts index 7fcc69e5..52bace1b 100644 --- a/src/device/plug.ts +++ b/src/device/plug.ts @@ -356,14 +356,15 @@ export class Plug { } else { command = 'turnOff'; } - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': `${command}`, 'parameter': 'default', 'commandType': 'command', }); - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); diff --git a/src/device/robotvacuumcleaner.ts b/src/device/robotvacuumcleaner.ts index 43b1e953..fc602579 100644 --- a/src/device/robotvacuumcleaner.ts +++ b/src/device/robotvacuumcleaner.ts @@ -367,14 +367,15 @@ export class RobotVacuumCleaner { } else { command = 'turnOff'; } - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': `${command}`, 'parameter': 'default', 'commandType': 'command', }); - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); diff --git a/src/irdevice/airconditioner.ts b/src/irdevice/airconditioner.ts index 238df693..0f3ebd26 100644 --- a/src/irdevice/airconditioner.ts +++ b/src/irdevice/airconditioner.ts @@ -172,12 +172,12 @@ export class AirConditioner { if (this.Active === this.platform.Characteristic.Active.ACTIVE && !this.disablePushOn) { const commandType: string = await this.commandType(); const command: string = await this.commandOn(); - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': command, 'parameter': 'default', 'commandType': commandType, }); - await this.pushChanges(body); + await this.pushChanges(bodyChange); } } @@ -187,12 +187,12 @@ export class AirConditioner { if (this.Active === this.platform.Characteristic.Active.INACTIVE && !this.disablePushOff) { const commandType: string = await this.commandType(); const command: string = await this.commandOff(); - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': command, 'parameter': 'default', 'commandType': commandType, }); - await this.pushChanges(body); + await this.pushChanges(bodyChange); } } @@ -243,21 +243,22 @@ export class AirConditioner { } else { this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE; } - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'setAll', 'parameter': `${parameter}`, 'commandType': 'command', }); - await this.pushChanges(body); + await this.pushChanges(bodyChange); } - async pushChanges(body: any): Promise { + async pushChanges(bodyChange: any): Promise { this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`); if (this.device.connectionType === 'OpenAPI' && !this.disablePushDetail) { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); diff --git a/src/irdevice/airpurifier.ts b/src/irdevice/airpurifier.ts index 3f7c68a5..7ba4cdec 100644 --- a/src/irdevice/airpurifier.ts +++ b/src/irdevice/airpurifier.ts @@ -134,12 +134,12 @@ export class AirPurifier { if (this.Active === this.platform.Characteristic.Active.ACTIVE && !this.disablePushOn) { const commandType: string = await this.commandType(); const command: string = await this.commandOn(); - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': command, 'parameter': 'default', 'commandType': commandType, }); - await this.pushChanges(body); + await this.pushChanges(bodyChange); } } @@ -149,12 +149,12 @@ export class AirPurifier { if (this.Active === this.platform.Characteristic.Active.INACTIVE && !this.disablePushOn) { const commandType: string = await this.commandType(); const command: string = await this.commandOff(); - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': command, 'parameter': 'default', 'commandType': commandType, }); - await this.pushChanges(body); + await this.pushChanges(bodyChange); } } @@ -179,7 +179,7 @@ export class AirPurifier { this.CurrentAPFanSpeed = this.CurrentFanSpeed || 1; this.APActive = this.Active === 1 ? 'on' : 'off'; const parameter = `${this.CurrentAPTemp},${this.CurrentAPMode},${this.CurrentAPFanSpeed},${this.APActive}`; - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'setAll', 'parameter': `${parameter}`, 'commandType': 'command', @@ -193,15 +193,16 @@ export class AirPurifier { } else { this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE; } - await this.pushChanges(body); + await this.pushChanges(bodyChange); } - async pushChanges(body: any): Promise { + async pushChanges(bodyChange: any): Promise { this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`); if (this.device.connectionType === 'OpenAPI') { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); diff --git a/src/irdevice/camera.ts b/src/irdevice/camera.ts index 75e69b98..f2fe4dea 100644 --- a/src/irdevice/camera.ts +++ b/src/irdevice/camera.ts @@ -85,12 +85,12 @@ export class Camera { if (this.On && !this.disablePushOn) { const commandType: string = await this.commandType(); const command: string = await this.commandOn(); - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': command, 'parameter': 'default', 'commandType': commandType, }); - await this.pushChanges(body); + await this.pushChanges(bodyChange); } } @@ -100,21 +100,22 @@ export class Camera { if (!this.On && !this.disablePushOff) { const commandType: string = await this.commandType(); const command: string = await this.commandOff(); - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': command, 'parameter': 'default', 'commandType': commandType, }); - await this.pushChanges(body); + await this.pushChanges(bodyChange); } } - async pushChanges(body: any): Promise { + async pushChanges(bodyChange: any): Promise { this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`); if (this.device.connectionType === 'OpenAPI') { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); diff --git a/src/irdevice/fan.ts b/src/irdevice/fan.ts index 78023465..d00aba09 100644 --- a/src/irdevice/fan.ts +++ b/src/irdevice/fan.ts @@ -175,12 +175,12 @@ export class Fan { if (this.Active === this.platform.Characteristic.Active.ACTIVE && !this.disablePushOn) { const commandType: string = await this.commandType(); const command: string = await this.commandOn(); - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': command, 'parameter': 'default', 'commandType': commandType, }); - await this.pushChanges(body); + await this.pushChanges(bodyChange); } } @@ -190,48 +190,49 @@ export class Fan { if (this.Active === this.platform.Characteristic.Active.INACTIVE && !this.disablePushOff) { const commandType: string = await this.commandType(); const command: string = await this.commandOff(); - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': command, 'parameter': 'default', 'commandType': commandType, }); - await this.pushChanges(body); + await this.pushChanges(bodyChange); } } async pushFanSpeedUpChanges(): Promise { - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'highSpeed', 'parameter': 'default', 'commandType': 'command', }); - await this.pushChanges(body); + await this.pushChanges(bodyChange); } async pushFanSpeedDownChanges(): Promise { - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'lowSpeed', 'parameter': 'default', 'commandType': 'command', }); - await this.pushChanges(body); + await this.pushChanges(bodyChange); } async pushFanSwingChanges(): Promise { - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'swing', 'parameter': 'default', 'commandType': 'command', }); - await this.pushChanges(body); + await this.pushChanges(bodyChange); } - async pushChanges(body: any): Promise { + async pushChanges(bodyChange: any): Promise { this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`); if (this.device.connectionType === 'OpenAPI') { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); diff --git a/src/irdevice/light.ts b/src/irdevice/light.ts index 60cf00bf..b95286aa 100644 --- a/src/irdevice/light.ts +++ b/src/irdevice/light.ts @@ -89,12 +89,12 @@ export class Light { if (this.On && !this.disablePushOn) { const commandType: string = await this.commandType(); const command: string = await this.commandOn(); - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': command, 'parameter': 'default', 'commandType': commandType, }); - await this.pushChanges(body); + await this.pushChanges(bodyChange); } } @@ -104,39 +104,40 @@ export class Light { if (!this.On && !this.disablePushOff) { const commandType: string = await this.commandType(); const command: string = await this.commandOff(); - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': command, 'parameter': 'default', 'commandType': commandType, }); - await this.pushChanges(body); + await this.pushChanges(bodyChange); } } async pushLightBrightnessUpChanges(): Promise { - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'brightnessUp', 'parameter': 'default', 'commandType': 'command', }); - await this.pushChanges(body); + await this.pushChanges(bodyChange); } async pushLightBrightnessDownChanges(): Promise { - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'brightnessDown', 'parameter': 'default', 'commandType': 'command', }); - await this.pushChanges(body); + await this.pushChanges(bodyChange); } - async pushChanges(body: any): Promise { + async pushChanges(bodyChange: any): Promise { this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`); if (this.device.connectionType === 'OpenAPI') { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); diff --git a/src/irdevice/other.ts b/src/irdevice/other.ts index 5bb4a12b..67c6e694 100644 --- a/src/irdevice/other.ts +++ b/src/irdevice/other.ts @@ -93,12 +93,12 @@ export class Others { if (this.Active === this.platform.Characteristic.Active.ACTIVE && !this.disablePushOn) { const commandType: string = await this.commandType(); const command: string = await this.commandOn(); - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': command, 'parameter': 'default', 'commandType': commandType, }); - await this.pushChanges(body); + await this.pushChanges(bodyChange); } } else { this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} On Command not set`); @@ -112,24 +112,25 @@ export class Others { if (this.Active === this.platform.Characteristic.Active.INACTIVE && !this.disablePushOff) { const commandType: string = await this.commandType(); const command: string = await this.commandOff(); - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': command, 'parameter': 'default', 'commandType': commandType, }); - await this.pushChanges(body); + await this.pushChanges(bodyChange); } } else { this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Off Command not set.`); } } - async pushChanges(body: any): Promise { + async pushChanges(bodyChange: any): Promise { this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`); if (this.device.connectionType === 'OpenAPI') { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); diff --git a/src/irdevice/tv.ts b/src/irdevice/tv.ts index 397e6eff..e0b77c0f 100644 --- a/src/irdevice/tv.ts +++ b/src/irdevice/tv.ts @@ -227,12 +227,12 @@ export class TV { if (this.Active === this.platform.Characteristic.Active.ACTIVE && !this.disablePushOn) { const commandType: string = await this.commandType(); const command: string = await this.commandOn(); - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': command, 'parameter': 'default', 'commandType': commandType, }); - await this.pushTVChanges(body); + await this.pushTVChanges(bodyChange); } } @@ -242,129 +242,130 @@ export class TV { if (this.Active === this.platform.Characteristic.Active.INACTIVE && !this.disablePushOff) { const commandType: string = await this.commandType(); const command: string = await this.commandOff(); - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': command, 'parameter': 'default', 'commandType': commandType, }); - await this.pushTVChanges(body); + await this.pushTVChanges(bodyChange); } } async pushOkChanges(): Promise { this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOkChanges disablePushDetail: ${this.disablePushDetail}`); if (!this.disablePushDetail) { - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'Ok', 'parameter': 'default', 'commandType': 'command', }); - await this.pushTVChanges(body); + await this.pushTVChanges(bodyChange); } } async pushBackChanges(): Promise { this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushBackChanges disablePushDetail: ${this.disablePushDetail}`); if (!this.disablePushDetail) { - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'Back', 'parameter': 'default', 'commandType': 'command', }); - await this.pushTVChanges(body); + await this.pushTVChanges(bodyChange); } } async pushMenuChanges(): Promise { this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushMenuChanges disablePushDetail: ${this.disablePushDetail}`); if (!this.disablePushDetail) { - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'Menu', 'parameter': 'default', 'commandType': 'command', }); - await this.pushTVChanges(body); + await this.pushTVChanges(bodyChange); } } async pushUpChanges(): Promise { this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushUpChanges disablePushDetail: ${this.disablePushDetail}`); if (!this.disablePushDetail) { - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'Up', 'parameter': 'default', 'commandType': 'command', }); - await this.pushTVChanges(body); + await this.pushTVChanges(bodyChange); } } async pushDownChanges(): Promise { this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushDownChanges disablePushDetail: ${this.disablePushDetail}`); if (!this.disablePushDetail) { - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'Down', 'parameter': 'default', 'commandType': 'command', }); - await this.pushTVChanges(body); + await this.pushTVChanges(bodyChange); } } async pushRightChanges(): Promise { this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushRightChanges disablePushDetail: ${this.disablePushDetail}`); if (!this.disablePushDetail) { - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'Right', 'parameter': 'default', 'commandType': 'command', }); - await this.pushTVChanges(body); + await this.pushTVChanges(bodyChange); } } async pushLeftChanges(): Promise { this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushLeftChanges disablePushDetail: ${this.disablePushDetail}`); if (!this.disablePushDetail) { - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'Left', 'parameter': 'default', 'commandType': 'command', }); - await this.pushTVChanges(body); + await this.pushTVChanges(bodyChange); } } async pushVolumeUpChanges(): Promise { this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushVolumeUpChanges disablePushDetail: ${this.disablePushDetail}`); if (!this.disablePushDetail) { - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'volumeAdd', 'parameter': 'default', 'commandType': 'command', }); - await this.pushTVChanges(body); + await this.pushTVChanges(bodyChange); } } async pushVolumeDownChanges(): Promise { this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushVolumeDownChanges disablePushDetail: ${this.disablePushDetail}`); if (!this.disablePushDetail) { - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': 'volumeSub', 'parameter': 'default', 'commandType': 'command', }); - await this.pushTVChanges(body); + await this.pushTVChanges(bodyChange); } } - async pushTVChanges(body: any): Promise { + async pushTVChanges(bodyChange: any): Promise { this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushTVChanges`); if (this.device.connectionType === 'OpenAPI') { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); diff --git a/src/irdevice/vacuumcleaner.ts b/src/irdevice/vacuumcleaner.ts index 602715fb..dc2c6940 100644 --- a/src/irdevice/vacuumcleaner.ts +++ b/src/irdevice/vacuumcleaner.ts @@ -81,12 +81,12 @@ export class VacuumCleaner { if (this.On && !this.disablePushOn) { const commandType: string = await this.commandType(); const command: string = await this.commandOn(); - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': command, 'parameter': 'default', 'commandType': commandType, }); - await this.pushChanges(body); + await this.pushChanges(bodyChange); } } @@ -96,21 +96,22 @@ export class VacuumCleaner { if (!this.On && !this.disablePushOff) { const commandType: string = await this.commandType(); const command: string = await this.commandOff(); - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': command, 'parameter': 'default', 'commandType': commandType, }); - await this.pushChanges(body); + await this.pushChanges(bodyChange); } } - async pushChanges(body: any): Promise { + async pushChanges(bodyChange: any): Promise { this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`); if (this.device.connectionType === 'OpenAPI') { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); diff --git a/src/irdevice/waterheater.ts b/src/irdevice/waterheater.ts index d7e5fb7a..99d8bee1 100644 --- a/src/irdevice/waterheater.ts +++ b/src/irdevice/waterheater.ts @@ -86,12 +86,12 @@ export class WaterHeater { if (this.Active === this.platform.Characteristic.Active.ACTIVE && !this.disablePushOn) { const commandType: string = await this.commandType(); const command: string = await this.commandOn(); - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': command, 'parameter': 'default', 'commandType': commandType, }); - await this.pushChanges(body); + await this.pushChanges(bodyChange); } } @@ -101,21 +101,22 @@ export class WaterHeater { if (this.Active === this.platform.Characteristic.Active.INACTIVE && !this.disablePushOff) { const commandType: string = await this.commandType(); const command: string = await this.commandOff(); - const body = JSON.stringify({ + const bodyChange = JSON.stringify({ 'command': command, 'parameter': 'default', 'commandType': commandType, }); - await this.pushChanges(body); + await this.pushChanges(bodyChange); } } - async pushChanges(body: any): Promise { + async pushChanges(bodyChange: any): Promise { this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`); if (this.device.connectionType === 'OpenAPI') { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); + this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`); try { const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, { + body: bodyChange, method: 'POST', headers: this.platform.generateHeaders(), }); diff --git a/src/settings.ts b/src/settings.ts index ef854bd8..e44db748 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -16,16 +16,6 @@ export const PLUGIN_NAME = '@switchbot/homebridge-switchbot'; */ export const Devices = 'https://api.switch-bot.com/v1.1/devices'; -/** - * This is the main url used to access SwitchBot API - */ -export const HostDomain = 'api.switch-bot.com'; - -/** - * This is the main url used to access SwitchBot API - */ -export const DevicePath = '/v1.1/devices'; - //Config export interface SwitchBotPlatformConfig extends PlatformConfig { credentials?: credentials;