@switchbot/homebridge-switchbot 3.5.0-beta.57 → 3.5.0-beta.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +4 -1
- package/dist/device/blindtilt.d.ts +5 -5
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +103 -69
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +4 -4
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +201 -154
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +3 -3
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +41 -36
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +3 -3
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +36 -37
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +4 -4
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +76 -55
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +4 -4
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +99 -55
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +4 -4
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +11 -9
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +3 -3
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +54 -24
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +4 -4
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +40 -57
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +3 -3
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +39 -39
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +3 -3
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +41 -50
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +4 -4
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +36 -33
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +3 -3
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +68 -59
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +3 -3
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +42 -51
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +3 -3
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +42 -51
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +3 -3
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +52 -40
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +3 -3
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +13 -13
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +4 -4
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +81 -98
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +3 -3
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +39 -31
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +20 -14
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +3 -3
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +9 -9
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +3 -3
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +1 -1
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +3 -3
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +2 -2
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +6 -6
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +37 -29
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +3 -3
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +9 -14
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +67 -88
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +3 -3
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +1 -1
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +3 -3
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +3 -3
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +3 -3
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +2 -2
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +3 -3
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +2 -2
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +7 -7
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +20 -23
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +24 -10
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +16 -0
- package/dist/settings.js.map +1 -1
- package/eslint.config.js +89 -78
- package/package.json +3 -3
- package/src/device/blindtilt.ts +120 -87
- package/src/device/bot.ts +238 -175
- package/src/device/ceilinglight.ts +49 -46
- package/src/device/colorbulb.ts +40 -43
- package/src/device/contact.ts +91 -65
- package/src/device/curtain.ts +113 -66
- package/src/device/device.ts +12 -13
- package/src/device/fan.ts +66 -29
- package/src/device/hub.ts +53 -60
- package/src/device/humidifier.ts +54 -56
- package/src/device/iosensor.ts +57 -56
- package/src/device/lightstrip.ts +43 -39
- package/src/device/lock.ts +79 -68
- package/src/device/meter.ts +54 -54
- package/src/device/meterplus.ts +54 -54
- package/src/device/motion.ts +62 -46
- package/src/device/plug.ts +19 -18
- package/src/device/robotvacuumcleaner.ts +89 -104
- package/src/device/waterdetector.ts +46 -34
- package/src/homebridge-ui/public/index.html +20 -14
- package/src/index.ts +3 -2
- package/src/irdevice/airconditioner.ts +13 -11
- package/src/irdevice/airpurifier.ts +5 -3
- package/src/irdevice/camera.ts +6 -4
- package/src/irdevice/fan.ts +42 -29
- package/src/irdevice/irdevice.ts +4 -5
- package/src/irdevice/light.ts +83 -103
- package/src/irdevice/other.ts +5 -3
- package/src/irdevice/tv.ts +7 -5
- package/src/irdevice/vacuumcleaner.ts +6 -4
- package/src/irdevice/waterheater.ts +6 -4
- package/src/platform.ts +59 -66
- package/src/settings.ts +73 -58
package/dist/platform.js
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
/* Copyright(C) 2017-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* platform.ts: @switchbot/homebridge-switchbot platform class.
|
|
4
|
+
*/
|
|
5
|
+
import { Hub } from './device/hub.js';
|
|
2
6
|
import { Bot } from './device/bot.js';
|
|
3
7
|
import { Plug } from './device/plug.js';
|
|
4
8
|
import { Lock } from './device/lock.js';
|
|
5
9
|
import { Meter } from './device/meter.js';
|
|
6
10
|
import { Motion } from './device/motion.js';
|
|
7
|
-
import { Hub } from './device/hub.js';
|
|
8
11
|
import { Contact } from './device/contact.js';
|
|
9
12
|
import { Curtain } from './device/curtain.js';
|
|
10
13
|
import { IOSensor } from './device/iosensor.js';
|
|
11
|
-
import { WaterDetector } from './device/waterdetector.js';
|
|
12
14
|
import { MeterPlus } from './device/meterplus.js';
|
|
13
15
|
import { ColorBulb } from './device/colorbulb.js';
|
|
14
|
-
import { CeilingLight } from './device/ceilinglight.js';
|
|
15
16
|
import { StripLight } from './device/lightstrip.js';
|
|
16
17
|
import { Humidifier } from './device/humidifier.js';
|
|
18
|
+
import { CeilingLight } from './device/ceilinglight.js';
|
|
19
|
+
import { WaterDetector } from './device/waterdetector.js';
|
|
17
20
|
import { RobotVacuumCleaner } from './device/robotvacuumcleaner.js';
|
|
18
21
|
import { Fan } from './device/fan.js';
|
|
19
22
|
import { TV } from './irdevice/tv.js';
|
|
@@ -26,16 +29,17 @@ import { AirPurifier } from './irdevice/airpurifier.js';
|
|
|
26
29
|
import { WaterHeater } from './irdevice/waterheater.js';
|
|
27
30
|
import { VacuumCleaner } from './irdevice/vacuumcleaner.js';
|
|
28
31
|
import { AirConditioner } from './irdevice/airconditioner.js';
|
|
29
|
-
import * as http from 'http';
|
|
30
32
|
import { Buffer } from 'buffer';
|
|
31
33
|
import { request } from 'undici';
|
|
34
|
+
import asyncmqtt from 'async-mqtt';
|
|
35
|
+
import { sleep } from './utils.js';
|
|
36
|
+
import { createServer } from 'http';
|
|
32
37
|
import { queueScheduler } from 'rxjs';
|
|
33
38
|
import fakegato from 'fakegato-history';
|
|
34
|
-
import asyncmqtt from 'async-mqtt';
|
|
35
39
|
import crypto, { randomUUID } from 'crypto';
|
|
36
40
|
import { readFileSync, writeFileSync } from 'fs';
|
|
37
41
|
import { EveHomeKitTypes } from 'homebridge-lib/EveHomeKitTypes';
|
|
38
|
-
import {
|
|
42
|
+
import { PLATFORM_NAME, PLUGIN_NAME, Devices, setupWebhook, updateWebhook, deleteWebhook, queryWebhook } from './settings.js';
|
|
39
43
|
/**
|
|
40
44
|
* HomebridgePlatform
|
|
41
45
|
* This class is the main constructor for your plugin, this is where you should
|
|
@@ -103,7 +107,6 @@ export class SwitchBotPlatform {
|
|
|
103
107
|
await this.updateToken();
|
|
104
108
|
}
|
|
105
109
|
else if (this.config.credentials?.token && !this.config.credentials?.secret) {
|
|
106
|
-
// eslint-disable-next-line no-useless-escape
|
|
107
110
|
this.errorLog('"secret" config is not populated, you must populate then please restart Homebridge.');
|
|
108
111
|
}
|
|
109
112
|
else {
|
|
@@ -157,7 +160,7 @@ export class SwitchBotPlatform {
|
|
|
157
160
|
const xurl = new URL(url);
|
|
158
161
|
const port = Number(xurl.port);
|
|
159
162
|
const path = xurl.pathname;
|
|
160
|
-
this.webhookEventListener =
|
|
163
|
+
this.webhookEventListener = createServer((request, response) => {
|
|
161
164
|
try {
|
|
162
165
|
if (request.url === path && request.method === 'POST') {
|
|
163
166
|
request.on('data', async (data) => {
|
|
@@ -196,7 +199,7 @@ export class SwitchBotPlatform {
|
|
|
196
199
|
return;
|
|
197
200
|
}
|
|
198
201
|
try {
|
|
199
|
-
const { body, statusCode } = await request(
|
|
202
|
+
const { body, statusCode } = await request(setupWebhook, {
|
|
200
203
|
method: 'POST',
|
|
201
204
|
headers: this.generateHeaders(),
|
|
202
205
|
body: JSON.stringify({
|
|
@@ -218,10 +221,8 @@ export class SwitchBotPlatform {
|
|
|
218
221
|
this.errorLog(`Failed to configure webhook. Error: ${e.message}`);
|
|
219
222
|
}
|
|
220
223
|
try {
|
|
221
|
-
const { body, statusCode } = await request(
|
|
222
|
-
method: 'POST',
|
|
223
|
-
headers: this.generateHeaders(),
|
|
224
|
-
body: JSON.stringify({
|
|
224
|
+
const { body, statusCode } = await request(updateWebhook, {
|
|
225
|
+
method: 'POST', headers: this.generateHeaders(), body: JSON.stringify({
|
|
225
226
|
'action': 'updateWebhook',
|
|
226
227
|
'config': {
|
|
227
228
|
'url': url,
|
|
@@ -241,7 +242,7 @@ export class SwitchBotPlatform {
|
|
|
241
242
|
this.errorLog(`Failed to update webhook. Error:${e.message}`);
|
|
242
243
|
}
|
|
243
244
|
try {
|
|
244
|
-
const { body, statusCode } = await request(
|
|
245
|
+
const { body, statusCode } = await request(queryWebhook, {
|
|
245
246
|
method: 'POST',
|
|
246
247
|
headers: this.generateHeaders(),
|
|
247
248
|
body: JSON.stringify({
|
|
@@ -263,7 +264,7 @@ export class SwitchBotPlatform {
|
|
|
263
264
|
}
|
|
264
265
|
this.api.on('shutdown', async () => {
|
|
265
266
|
try {
|
|
266
|
-
const { body, statusCode } = await request(
|
|
267
|
+
const { body, statusCode } = await request(deleteWebhook, {
|
|
267
268
|
method: 'POST',
|
|
268
269
|
headers: this.generateHeaders(),
|
|
269
270
|
body: JSON.stringify({
|
|
@@ -417,13 +418,11 @@ export class SwitchBotPlatform {
|
|
|
417
418
|
}
|
|
418
419
|
// Move openToken to token
|
|
419
420
|
if (!this.config.credentials.secret) {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
// eslint-disable-next-line no-useless-escape
|
|
421
|
+
this.warnLog('This plugin has been updated to use OpenAPI v1.1, config is set with openToken,'
|
|
422
|
+
+ ' "openToken" cconfig has been moved to the "token" config');
|
|
423
423
|
this.errorLog('"secret" config is not populated, you must populate then please restart Homebridge.');
|
|
424
424
|
}
|
|
425
425
|
else {
|
|
426
|
-
// eslint-disable-next-line no-useless-escape, max-len
|
|
427
426
|
this.warnLog('This plugin has been updated to use OpenAPI v1.1, config is set with openToken, '
|
|
428
427
|
+ '"openToken" config has been moved to the "token" config, please restart Homebridge.');
|
|
429
428
|
}
|
|
@@ -709,9 +708,7 @@ export class SwitchBotPlatform {
|
|
|
709
708
|
this.createFan(device);
|
|
710
709
|
break;
|
|
711
710
|
default:
|
|
712
|
-
this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported
|
|
713
|
-
// eslint-disable-next-line max-len
|
|
714
|
-
this.warnLog('Submit Feature Requests Here: ' + 'https://tinyurl.com/SwitchBotFeatureRequest');
|
|
711
|
+
this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`, +'Submit Feature Requests Here: https://tinyurl.com/SwitchBotFeatureRequest');
|
|
715
712
|
}
|
|
716
713
|
}
|
|
717
714
|
createIRDevice(device) {
|