@switchbot/homebridge-switchbot 3.7.1-beta.9 → 3.8.0
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/CHANGELOG.md +8 -2
- package/README.md +14 -0
- package/assets/security-privacy-bluetooth.png +0 -0
- package/config.schema.json +76 -1
- package/dist/device/blindtilt.d.ts +18 -8
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +108 -70
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -9
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +133 -160
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +13 -13
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +38 -73
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +12 -12
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +41 -79
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +5 -5
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +20 -42
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +15 -5
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +127 -81
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +18 -18
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +33 -36
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +8 -8
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +43 -75
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +5 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +18 -39
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +5 -5
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +38 -78
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +5 -5
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +21 -40
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +6 -6
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +34 -73
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +9 -9
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +37 -52
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +5 -5
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +21 -39
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +5 -5
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +21 -38
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +5 -5
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +14 -32
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +12 -12
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +16 -25
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +11 -11
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +42 -56
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +5 -5
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +47 -44
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/server.js +2 -2
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -8
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +61 -105
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +10 -10
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +22 -42
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +9 -9
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +15 -25
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +8 -8
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +21 -40
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +11 -11
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +14 -22
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +9 -9
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +24 -47
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +9 -9
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +40 -83
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +9 -9
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +29 -54
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +5 -5
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +11 -21
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +5 -5
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +11 -22
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +20 -19
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +466 -710
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +5 -2
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +9 -9
- package/dist/types/bledevicestatus.d.ts.map +1 -1
- package/dist/types/devicelist.d.ts +6 -6
- package/dist/types/devicelist.d.ts.map +1 -1
- package/dist/types/deviceresponse.d.ts +4 -4
- package/dist/types/deviceresponse.d.ts.map +1 -1
- package/dist/types/devicestatus.d.ts +2 -2
- package/dist/types/devicestatus.d.ts.map +1 -1
- package/dist/types/devicewebhookstatus.d.ts +5 -5
- package/dist/types/devicewebhookstatus.d.ts.map +1 -1
- package/dist/types/irdevicelist.d.ts +4 -4
- package/dist/types/irdevicelist.d.ts.map +1 -1
- package/dist/types/pushbody.d.ts +2 -2
- package/dist/types/pushbody.d.ts.map +1 -1
- package/dist/utils.d.ts +4 -4
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +9 -13
- package/dist/utils.js.map +1 -1
- package/eslint.config.js +48 -93
- package/package.json +61 -54
- package/src/device/blindtilt.ts +509 -460
- package/src/device/bot.ts +696 -718
- package/src/device/ceilinglight.ts +331 -364
- package/src/device/colorbulb.ts +412 -448
- package/src/device/contact.ts +200 -221
- package/src/device/curtain.ts +506 -444
- package/src/device/device.ts +206 -208
- package/src/device/fan.ts +307 -340
- package/src/device/hub.ts +184 -209
- package/src/device/humidifier.ts +297 -342
- package/src/device/iosensor.ts +182 -204
- package/src/device/lightstrip.ts +362 -399
- package/src/device/lock.ts +262 -276
- package/src/device/meter.ts +183 -205
- package/src/device/meterplus.ts +183 -204
- package/src/device/motion.ts +169 -185
- package/src/device/plug.ts +174 -177
- package/src/device/robotvacuumcleaner.ts +256 -269
- package/src/device/waterdetector.ts +185 -185
- package/src/homebridge-ui/server.ts +16 -15
- package/src/index.ts +5 -6
- package/src/irdevice/airconditioner.ts +277 -326
- package/src/irdevice/airpurifier.ts +124 -143
- package/src/irdevice/camera.ts +58 -64
- package/src/irdevice/fan.ts +106 -123
- package/src/irdevice/irdevice.ts +116 -119
- package/src/irdevice/light.ts +119 -143
- package/src/irdevice/other.ts +417 -461
- package/src/irdevice/tv.ts +155 -177
- package/src/irdevice/vacuumcleaner.ts +54 -60
- package/src/irdevice/waterheater.ts +56 -63
- package/src/platform.ts +1462 -1678
- package/src/settings.ts +173 -170
- package/src/types/bledevicestatus.ts +252 -256
- package/src/types/devicelist.ts +79 -79
- package/src/types/deviceresponse.ts +12 -13
- package/src/types/devicestatus.ts +124 -124
- package/src/types/devicewebhookstatus.ts +126 -131
- package/src/types/irdevicelist.ts +10 -10
- package/src/types/pushbody.ts +5 -5
- package/src/utils.ts +64 -65
- package/tsconfig.json +10 -9
- package/.github/npm-version-script.cjs +0 -81
package/src/irdevice/irdevice.ts
CHANGED
|
@@ -2,41 +2,43 @@
|
|
|
2
2
|
*
|
|
3
3
|
* device.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
6
|
-
import { Devices } from '../settings.js';
|
|
5
|
+
import type { API, CharacteristicValue, HAP, Logging, PlatformAccessory, Service } from 'homebridge'
|
|
7
6
|
|
|
8
|
-
import type { SwitchBotPlatform } from '../platform.js'
|
|
9
|
-
import type {
|
|
10
|
-
import type {
|
|
11
|
-
|
|
7
|
+
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
|
+
import type { irDevicesConfig, SwitchBotPlatformConfig } from '../settings.js'
|
|
9
|
+
import type { irdevice } from '../types/irdevicelist.js'
|
|
10
|
+
|
|
11
|
+
import { request } from 'undici'
|
|
12
|
+
|
|
13
|
+
import { Devices } from '../settings.js'
|
|
12
14
|
|
|
13
15
|
export abstract class irdeviceBase {
|
|
14
|
-
public readonly api: API
|
|
15
|
-
public readonly log: Logging
|
|
16
|
-
public readonly config!: SwitchBotPlatformConfig
|
|
17
|
-
protected readonly hap: HAP
|
|
16
|
+
public readonly api: API
|
|
17
|
+
public readonly log: Logging
|
|
18
|
+
public readonly config!: SwitchBotPlatformConfig
|
|
19
|
+
protected readonly hap: HAP
|
|
18
20
|
|
|
19
21
|
// Config
|
|
20
|
-
protected deviceLogging!: string
|
|
21
|
-
protected disablePushOn!: boolean
|
|
22
|
-
protected disablePushOff!: boolean
|
|
23
|
-
protected disablePushDetail?: boolean
|
|
22
|
+
protected deviceLogging!: string
|
|
23
|
+
protected disablePushOn!: boolean
|
|
24
|
+
protected disablePushOff!: boolean
|
|
25
|
+
protected disablePushDetail?: boolean
|
|
24
26
|
|
|
25
27
|
constructor(
|
|
26
28
|
protected readonly platform: SwitchBotPlatform,
|
|
27
29
|
protected accessory: PlatformAccessory,
|
|
28
30
|
protected device: irdevice & irDevicesConfig,
|
|
29
31
|
) {
|
|
30
|
-
this.api = this.platform.api
|
|
31
|
-
this.log = this.platform.log
|
|
32
|
-
this.config = this.platform.config
|
|
33
|
-
this.hap = this.api.hap
|
|
32
|
+
this.api = this.platform.api
|
|
33
|
+
this.log = this.platform.log
|
|
34
|
+
this.config = this.platform.config
|
|
35
|
+
this.hap = this.api.hap
|
|
34
36
|
|
|
35
|
-
this.getDeviceLogSettings(device)
|
|
36
|
-
this.getDeviceConfigSettings(device)
|
|
37
|
-
this.getDeviceContext(accessory, device)
|
|
38
|
-
this.disablePushOnChanges(device)
|
|
39
|
-
this.disablePushOffChanges(device)
|
|
37
|
+
this.getDeviceLogSettings(device)
|
|
38
|
+
this.getDeviceConfigSettings(device)
|
|
39
|
+
this.getDeviceContext(accessory, device)
|
|
40
|
+
this.disablePushOnChanges(device)
|
|
41
|
+
this.disablePushOffChanges(device)
|
|
40
42
|
|
|
41
43
|
// Set accessory information
|
|
42
44
|
accessory
|
|
@@ -47,22 +49,22 @@ export abstract class irdeviceBase {
|
|
|
47
49
|
.setCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName)
|
|
48
50
|
.setCharacteristic(this.hap.Characteristic.Model, accessory.context.model ?? 'Unknown')
|
|
49
51
|
.setCharacteristic(this.hap.Characteristic.ProductData, device.deviceId)
|
|
50
|
-
.setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
|
|
52
|
+
.setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
async getDeviceLogSettings(device: irdevice & irDevicesConfig): Promise<void> {
|
|
54
56
|
if (this.platform.debugMode) {
|
|
55
|
-
this.deviceLogging = this.accessory.context.logging = 'debugMode'
|
|
56
|
-
await this.debugWarnLog(`Using Debug Mode Logging: ${this.deviceLogging}`)
|
|
57
|
+
this.deviceLogging = this.accessory.context.logging = 'debugMode'
|
|
58
|
+
await this.debugWarnLog(`Using Debug Mode Logging: ${this.deviceLogging}`)
|
|
57
59
|
} else if (device.logging) {
|
|
58
|
-
this.deviceLogging = this.accessory.context.logging = device.logging
|
|
59
|
-
await this.debugWarnLog(`Using Device Config Logging: ${this.deviceLogging}`)
|
|
60
|
+
this.deviceLogging = this.accessory.context.logging = device.logging
|
|
61
|
+
await this.debugWarnLog(`Using Device Config Logging: ${this.deviceLogging}`)
|
|
60
62
|
} else if (this.config.logging) {
|
|
61
|
-
this.deviceLogging = this.accessory.context.logging = this.config.logging
|
|
62
|
-
await this.debugWarnLog(`Using Platform Config Logging: ${this.deviceLogging}`)
|
|
63
|
+
this.deviceLogging = this.accessory.context.logging = this.config.logging
|
|
64
|
+
await this.debugWarnLog(`Using Platform Config Logging: ${this.deviceLogging}`)
|
|
63
65
|
} else {
|
|
64
|
-
this.deviceLogging = this.accessory.context.logging = 'standard'
|
|
65
|
-
await this.debugWarnLog(`Logging Not Set, Using: ${this.deviceLogging}`)
|
|
66
|
+
this.deviceLogging = this.accessory.context.logging = 'standard'
|
|
67
|
+
await this.debugWarnLog(`Logging Not Set, Using: ${this.deviceLogging}`)
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
|
|
@@ -79,7 +81,7 @@ export abstract class irdeviceBase {
|
|
|
79
81
|
device.disablePushOn === true && { disablePushOn: device.disablePushOn },
|
|
80
82
|
device.disablePushOff === true && { disablePushOff: device.disablePushOff },
|
|
81
83
|
device.disablePushDetail === true && { disablePushDetail: device.disablePushDetail },
|
|
82
|
-
)
|
|
84
|
+
)
|
|
83
85
|
const config = Object.assign(
|
|
84
86
|
{},
|
|
85
87
|
deviceConfig,
|
|
@@ -92,29 +94,29 @@ export abstract class irdeviceBase {
|
|
|
92
94
|
device.irtv,
|
|
93
95
|
device.irvc,
|
|
94
96
|
device.irwh,
|
|
95
|
-
)
|
|
97
|
+
)
|
|
96
98
|
if (Object.keys(config).length !== 0) {
|
|
97
|
-
this.debugSuccessLog(`Config: ${JSON.stringify(config)}`)
|
|
99
|
+
this.debugSuccessLog(`Config: ${JSON.stringify(config)}`)
|
|
98
100
|
}
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
async getDeviceContext(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): Promise<void> {
|
|
102
|
-
accessory.context.name = device.deviceName
|
|
103
|
-
accessory.context.model = device.remoteType
|
|
104
|
-
accessory.context.deviceId = device.deviceId
|
|
105
|
-
accessory.context.remoteType = device.remoteType
|
|
106
|
-
|
|
107
|
-
const deviceFirmwareVersion = device.firmware ?? accessory.context.version ?? this.platform.version ?? '0.0.0'
|
|
108
|
-
const version = deviceFirmwareVersion.toString()
|
|
109
|
-
await this.debugLog(`version: ${version?.replace(/^V|-.*$/g, '')}`)
|
|
110
|
-
let deviceVersion: string
|
|
104
|
+
accessory.context.name = device.deviceName
|
|
105
|
+
accessory.context.model = device.remoteType
|
|
106
|
+
accessory.context.deviceId = device.deviceId
|
|
107
|
+
accessory.context.remoteType = device.remoteType
|
|
108
|
+
|
|
109
|
+
const deviceFirmwareVersion = device.firmware ?? accessory.context.version ?? this.platform.version ?? '0.0.0'
|
|
110
|
+
const version = deviceFirmwareVersion.toString()
|
|
111
|
+
await this.debugLog(`version: ${version?.replace(/^V|-.*$/g, '')}`)
|
|
112
|
+
let deviceVersion: string
|
|
111
113
|
if (version?.includes('.') === false) {
|
|
112
|
-
const replace = version?.replace(/^V|-.*$/g, '')
|
|
113
|
-
const match = replace?.match(
|
|
114
|
-
const validVersion = match?.join('.')
|
|
115
|
-
deviceVersion = validVersion ?? '0.0.0'
|
|
114
|
+
const replace = version?.replace(/^V|-.*$/g, '')
|
|
115
|
+
const match = replace?.match(/./g)
|
|
116
|
+
const validVersion = match?.join('.')
|
|
117
|
+
deviceVersion = validVersion ?? '0.0.0'
|
|
116
118
|
} else {
|
|
117
|
-
deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
119
|
+
deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
118
120
|
}
|
|
119
121
|
accessory
|
|
120
122
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
@@ -122,118 +124,114 @@ export abstract class irdeviceBase {
|
|
|
122
124
|
.setCharacteristic(this.hap.Characteristic.SoftwareRevision, deviceVersion)
|
|
123
125
|
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
|
|
124
126
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
125
|
-
.updateValue(deviceVersion)
|
|
126
|
-
accessory.context.version = deviceVersion
|
|
127
|
-
this.debugSuccessLog(`version: ${accessory.context.version}`)
|
|
127
|
+
.updateValue(deviceVersion)
|
|
128
|
+
accessory.context.version = deviceVersion
|
|
129
|
+
this.debugSuccessLog(`version: ${accessory.context.version}`)
|
|
128
130
|
}
|
|
129
131
|
|
|
130
|
-
async pushChangeRequest(bodyChange: string): Promise<{ body: any
|
|
132
|
+
async pushChangeRequest(bodyChange: string): Promise<{ body: any, statusCode: any }> {
|
|
131
133
|
return await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
132
134
|
body: bodyChange,
|
|
133
135
|
method: 'POST',
|
|
134
136
|
headers: this.platform.generateHeaders(),
|
|
135
|
-
})
|
|
137
|
+
})
|
|
136
138
|
}
|
|
137
139
|
|
|
138
140
|
async successfulStatusCodes(statusCode: any, deviceStatus: any) {
|
|
139
|
-
return (statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)
|
|
141
|
+
return (statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)
|
|
140
142
|
}
|
|
141
143
|
|
|
142
144
|
/**
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
async updateCharacteristic(Service: Service, Characteristic: any,
|
|
153
|
-
CharacteristicValue: CharacteristicValue | undefined, CharacteristicName: string): Promise<void> {
|
|
145
|
+
* Update the characteristic value and log the change.
|
|
146
|
+
*
|
|
147
|
+
* @param Service Service
|
|
148
|
+
* @param Characteristic Characteristic
|
|
149
|
+
* @param CharacteristicValue CharacteristicValue | undefined
|
|
150
|
+
* @param CharacteristicName string
|
|
151
|
+
* @return: void
|
|
152
|
+
*
|
|
153
|
+
*/
|
|
154
|
+
async updateCharacteristic(Service: Service, Characteristic: any, CharacteristicValue: CharacteristicValue | undefined, CharacteristicName: string): Promise<void> {
|
|
154
155
|
if (CharacteristicValue === undefined) {
|
|
155
|
-
await this.debugLog(`${CharacteristicName}: ${CharacteristicValue}`)
|
|
156
|
+
await this.debugLog(`${CharacteristicName}: ${CharacteristicValue}`)
|
|
156
157
|
} else {
|
|
157
|
-
Service.updateCharacteristic(Characteristic, CharacteristicValue)
|
|
158
|
-
await this.debugLog(`updateCharacteristic ${CharacteristicName}: ${CharacteristicValue}`)
|
|
159
|
-
await this.debugWarnLog(`${CharacteristicName} context before: ${this.accessory.context[CharacteristicName]}`)
|
|
160
|
-
this.accessory.context[CharacteristicName] = CharacteristicValue
|
|
161
|
-
await this.debugWarnLog(`${CharacteristicName} context after: ${this.accessory.context[CharacteristicName]}`)
|
|
158
|
+
Service.updateCharacteristic(Characteristic, CharacteristicValue)
|
|
159
|
+
await this.debugLog(`updateCharacteristic ${CharacteristicName}: ${CharacteristicValue}`)
|
|
160
|
+
await this.debugWarnLog(`${CharacteristicName} context before: ${this.accessory.context[CharacteristicName]}`)
|
|
161
|
+
this.accessory.context[CharacteristicName] = CharacteristicValue
|
|
162
|
+
await this.debugWarnLog(`${CharacteristicName} context after: ${this.accessory.context[CharacteristicName]}`)
|
|
162
163
|
}
|
|
163
164
|
}
|
|
164
165
|
|
|
165
166
|
async pushStatusCodes(statusCode: any, deviceStatus: any) {
|
|
166
|
-
await this.debugWarnLog(`statusCode: ${statusCode}`)
|
|
167
|
-
await this.debugWarnLog(`deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
168
|
-
await this.debugWarnLog(`deviceStatus statusCode: ${deviceStatus.statusCode}`)
|
|
167
|
+
await this.debugWarnLog(`statusCode: ${statusCode}`)
|
|
168
|
+
await this.debugWarnLog(`deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
169
|
+
await this.debugWarnLog(`deviceStatus statusCode: ${deviceStatus.statusCode}`)
|
|
169
170
|
}
|
|
170
171
|
|
|
171
172
|
async successfulPushChange(statusCode: any, deviceStatus: any, bodyChange: any) {
|
|
172
|
-
this.debugSuccessLog(`statusCode: ${statusCode} & deviceStatus `
|
|
173
|
-
|
|
174
|
-
this.successLog('request to SwitchBot API,'
|
|
175
|
-
+ ` body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
173
|
+
this.debugSuccessLog(`statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`)
|
|
174
|
+
this.successLog(`request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`)
|
|
176
175
|
}
|
|
177
176
|
|
|
178
177
|
async pushChangeError(e: Error) {
|
|
179
|
-
this.errorLog(`failed pushChanges with ${this.device.connectionType}`
|
|
180
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
178
|
+
this.errorLog(`failed pushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
181
179
|
}
|
|
182
180
|
|
|
183
181
|
async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
|
|
184
182
|
if (device.disablePushOn === undefined) {
|
|
185
|
-
this.disablePushOn = false
|
|
183
|
+
this.disablePushOn = false
|
|
186
184
|
} else {
|
|
187
|
-
this.disablePushOn = device.disablePushOn
|
|
185
|
+
this.disablePushOn = device.disablePushOn
|
|
188
186
|
}
|
|
189
187
|
}
|
|
190
188
|
|
|
191
189
|
async disablePushOffChanges(device: irdevice & irDevicesConfig): Promise<void> {
|
|
192
190
|
if (device.disablePushOff === undefined) {
|
|
193
|
-
this.disablePushOff = false
|
|
191
|
+
this.disablePushOff = false
|
|
194
192
|
} else {
|
|
195
|
-
this.disablePushOff = device.disablePushOff
|
|
193
|
+
this.disablePushOff = device.disablePushOff
|
|
196
194
|
}
|
|
197
195
|
}
|
|
198
196
|
|
|
199
197
|
async disablePushDetailChanges(device: irdevice & irDevicesConfig): Promise<void> {
|
|
200
198
|
if (device.disablePushDetail === undefined) {
|
|
201
|
-
this.disablePushDetail = false
|
|
199
|
+
this.disablePushDetail = false
|
|
202
200
|
} else {
|
|
203
|
-
this.disablePushDetail = device.disablePushDetail
|
|
201
|
+
this.disablePushDetail = device.disablePushDetail
|
|
204
202
|
}
|
|
205
203
|
}
|
|
206
204
|
|
|
207
205
|
async commandType(): Promise<string> {
|
|
208
|
-
let commandType: string
|
|
206
|
+
let commandType: string
|
|
209
207
|
if (this.device.commandType && this.device.customize) {
|
|
210
|
-
commandType = this.device.commandType
|
|
208
|
+
commandType = this.device.commandType
|
|
211
209
|
} else if (this.device.customize) {
|
|
212
|
-
commandType = 'customize'
|
|
210
|
+
commandType = 'customize'
|
|
213
211
|
} else {
|
|
214
|
-
commandType = 'command'
|
|
212
|
+
commandType = 'command'
|
|
215
213
|
}
|
|
216
|
-
return commandType
|
|
214
|
+
return commandType
|
|
217
215
|
}
|
|
218
216
|
|
|
219
217
|
async commandOn(): Promise<string> {
|
|
220
|
-
let command: string
|
|
218
|
+
let command: string
|
|
221
219
|
if (this.device.customize && this.device.customOn) {
|
|
222
|
-
command = this.device.customOn
|
|
220
|
+
command = this.device.customOn
|
|
223
221
|
} else {
|
|
224
|
-
command = 'turnOn'
|
|
222
|
+
command = 'turnOn'
|
|
225
223
|
}
|
|
226
|
-
return command
|
|
224
|
+
return command
|
|
227
225
|
}
|
|
228
226
|
|
|
229
227
|
async commandOff(): Promise<string> {
|
|
230
|
-
let command: string
|
|
228
|
+
let command: string
|
|
231
229
|
if (this.device.customize && this.device.customOff) {
|
|
232
|
-
command = this.device.customOff
|
|
230
|
+
command = this.device.customOff
|
|
233
231
|
} else {
|
|
234
|
-
command = 'turnOff'
|
|
232
|
+
command = 'turnOff'
|
|
235
233
|
}
|
|
236
|
-
return command
|
|
234
|
+
return command
|
|
237
235
|
}
|
|
238
236
|
|
|
239
237
|
async statusCode(statusCode: number): Promise<void> {
|
|
@@ -255,15 +253,14 @@ export abstract class irdeviceBase {
|
|
|
255
253
|
422: 'Unprocessable Entity: The server cannot process the request, often due to exceeded API limits.',
|
|
256
254
|
429: 'Too Many Requests, exceeded the number of requests allowed for a given time window',
|
|
257
255
|
500: 'Internal Server Error, An unexpected error occurred. These errors should be rare',
|
|
258
|
-
}
|
|
256
|
+
}
|
|
259
257
|
if (statusCode === 171 && (this.device.hubDeviceId === this.device.deviceId || this.device.hubDeviceId === '000000000000')) {
|
|
260
|
-
this.debugErrorLog(`statusCode 171 changed to 161: hubDeviceId ${this.device.hubDeviceId} matches deviceId
|
|
261
|
-
|
|
262
|
-
statusCode = 161;
|
|
258
|
+
this.debugErrorLog(`statusCode 171 changed to 161: hubDeviceId ${this.device.hubDeviceId} matches deviceId ${this.device.deviceId}, device is its own hub.`)
|
|
259
|
+
statusCode = 161
|
|
263
260
|
}
|
|
264
|
-
const logMessage = statusMessages[statusCode] || `Unknown statusCode: ${statusCode}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug
|
|
265
|
-
const logMethod = [100, 200].includes(statusCode) ? 'debugLog' : statusMessages[statusCode] ? 'errorLog' : 'infoLog'
|
|
266
|
-
this[logMethod](`${logMessage}, statusCode: ${statusCode}`)
|
|
261
|
+
const logMessage = statusMessages[statusCode] || `Unknown statusCode: ${statusCode}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`
|
|
262
|
+
const logMethod = [100, 200].includes(statusCode) ? 'debugLog' : statusMessages[statusCode] ? 'errorLog' : 'infoLog'
|
|
263
|
+
this[logMethod](`${logMessage}, statusCode: ${statusCode}`)
|
|
267
264
|
}
|
|
268
265
|
|
|
269
266
|
/**
|
|
@@ -271,48 +268,48 @@ export abstract class irdeviceBase {
|
|
|
271
268
|
*/
|
|
272
269
|
async infoLog(...log: any[]): Promise<void> {
|
|
273
270
|
if (await this.enablingDeviceLogging()) {
|
|
274
|
-
this.log.info(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
|
|
271
|
+
this.log.info(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
|
|
275
272
|
}
|
|
276
273
|
}
|
|
277
274
|
|
|
278
275
|
async successLog(...log: any[]): Promise<void> {
|
|
279
276
|
if (await this.enablingDeviceLogging()) {
|
|
280
|
-
this.log.success(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
|
|
277
|
+
this.log.success(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
|
|
281
278
|
}
|
|
282
279
|
}
|
|
283
280
|
|
|
284
281
|
async debugSuccessLog(...log: any[]): Promise<void> {
|
|
285
282
|
if (await this.enablingDeviceLogging()) {
|
|
286
283
|
if (await this.loggingIsDebug()) {
|
|
287
|
-
this.log.success(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
|
|
284
|
+
this.log.success(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
|
|
288
285
|
}
|
|
289
286
|
}
|
|
290
287
|
}
|
|
291
288
|
|
|
292
289
|
async warnLog(...log: any[]): Promise<void> {
|
|
293
290
|
if (await this.enablingDeviceLogging()) {
|
|
294
|
-
this.log.warn(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
|
|
291
|
+
this.log.warn(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
|
|
295
292
|
}
|
|
296
293
|
}
|
|
297
294
|
|
|
298
295
|
async debugWarnLog(...log: any[]): Promise<void> {
|
|
299
296
|
if (await this.enablingDeviceLogging()) {
|
|
300
297
|
if (await this.loggingIsDebug()) {
|
|
301
|
-
this.log.warn(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
|
|
298
|
+
this.log.warn(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
|
|
302
299
|
}
|
|
303
300
|
}
|
|
304
301
|
}
|
|
305
302
|
|
|
306
303
|
async errorLog(...log: any[]): Promise<void> {
|
|
307
304
|
if (await this.enablingDeviceLogging()) {
|
|
308
|
-
this.log.error(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
|
|
305
|
+
this.log.error(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
|
|
309
306
|
}
|
|
310
307
|
}
|
|
311
308
|
|
|
312
309
|
async debugErrorLog(...log: any[]): Promise<void> {
|
|
313
310
|
if (await this.enablingDeviceLogging()) {
|
|
314
311
|
if (await this.loggingIsDebug()) {
|
|
315
|
-
this.log.error(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
|
|
312
|
+
this.log.error(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
|
|
316
313
|
}
|
|
317
314
|
}
|
|
318
315
|
}
|
|
@@ -320,18 +317,18 @@ export abstract class irdeviceBase {
|
|
|
320
317
|
async debugLog(...log: any[]): Promise<void> {
|
|
321
318
|
if (await this.enablingDeviceLogging()) {
|
|
322
319
|
if (this.deviceLogging === 'debug') {
|
|
323
|
-
this.log.info(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
|
|
320
|
+
this.log.info(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
|
|
324
321
|
} else if (this.deviceLogging === 'debugMode') {
|
|
325
|
-
this.log.debug(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
|
|
322
|
+
this.log.debug(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
|
|
326
323
|
}
|
|
327
324
|
}
|
|
328
325
|
}
|
|
329
326
|
|
|
330
327
|
async loggingIsDebug(): Promise<boolean> {
|
|
331
|
-
return this.deviceLogging === 'debugMode' || this.deviceLogging === 'debug'
|
|
328
|
+
return this.deviceLogging === 'debugMode' || this.deviceLogging === 'debug'
|
|
332
329
|
}
|
|
333
330
|
|
|
334
331
|
async enablingDeviceLogging(): Promise<boolean> {
|
|
335
|
-
return this.deviceLogging === 'debugMode' || this.deviceLogging === 'debug' || this.deviceLogging === 'standard'
|
|
332
|
+
return this.deviceLogging === 'debugMode' || this.deviceLogging === 'debug' || this.deviceLogging === 'standard'
|
|
336
333
|
}
|
|
337
|
-
}
|
|
334
|
+
}
|