@switchbot/homebridge-switchbot 3.7.1-beta.8 → 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 +78 -3
- 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 +143 -170
- 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 +24 -23
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +471 -715
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +6 -3
- 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 +62 -55
- 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 +1467 -1683
- 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
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
*
|
|
3
3
|
* vacuumcleaner.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
6
|
|
|
7
|
-
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
|
-
import type { irDevicesConfig } from '../settings.js'
|
|
9
|
-
import type { irdevice } from '../types/irdevicelist.js'
|
|
10
|
-
|
|
7
|
+
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
|
+
import type { irDevicesConfig } from '../settings.js'
|
|
9
|
+
import type { irdevice } from '../types/irdevicelist.js'
|
|
10
|
+
|
|
11
|
+
import { irdeviceBase } from './irdevice.js'
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Platform Accessory
|
|
@@ -17,118 +18,111 @@ import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge
|
|
|
17
18
|
export class VacuumCleaner extends irdeviceBase {
|
|
18
19
|
// Services
|
|
19
20
|
private Switch: {
|
|
20
|
-
Name: CharacteristicValue
|
|
21
|
-
Service: Service
|
|
22
|
-
On: CharacteristicValue
|
|
23
|
-
}
|
|
21
|
+
Name: CharacteristicValue
|
|
22
|
+
Service: Service
|
|
23
|
+
On: CharacteristicValue
|
|
24
|
+
}
|
|
24
25
|
|
|
25
26
|
constructor(
|
|
26
27
|
readonly platform: SwitchBotPlatform,
|
|
27
28
|
accessory: PlatformAccessory,
|
|
28
29
|
device: irdevice & irDevicesConfig,
|
|
29
30
|
) {
|
|
30
|
-
super(platform, accessory, device)
|
|
31
|
+
super(platform, accessory, device)
|
|
31
32
|
// Set category
|
|
32
|
-
accessory.category = this.hap.Categories.OTHER
|
|
33
|
+
accessory.category = this.hap.Categories.OTHER
|
|
33
34
|
|
|
34
35
|
// Initialize Switch Service
|
|
35
|
-
accessory.context.Switch = accessory.context.Switch ?? {}
|
|
36
|
+
accessory.context.Switch = accessory.context.Switch ?? {}
|
|
36
37
|
this.Switch = {
|
|
37
38
|
Name: accessory.displayName,
|
|
38
39
|
Service: accessory.getService(this.hap.Service.Switch) ?? accessory.addService(this.hap.Service.Switch) as Service,
|
|
39
40
|
On: accessory.context.On ?? false,
|
|
40
|
-
}
|
|
41
|
-
accessory.context.Switch = this.Switch as object
|
|
41
|
+
}
|
|
42
|
+
accessory.context.Switch = this.Switch as object
|
|
42
43
|
|
|
43
|
-
this.Switch.Service
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
.onGet(() => {
|
|
47
|
-
return this.Switch.On;
|
|
48
|
-
})
|
|
49
|
-
.onSet(this.OnSet.bind(this));
|
|
44
|
+
this.Switch.Service.setCharacteristic(this.hap.Characteristic.Name, this.Switch.Name).getCharacteristic(this.hap.Characteristic.On).onGet(() => {
|
|
45
|
+
return this.Switch.On
|
|
46
|
+
}).onSet(this.OnSet.bind(this))
|
|
50
47
|
}
|
|
51
48
|
|
|
52
49
|
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
53
|
-
await this.debugLog(`On: ${value}`)
|
|
50
|
+
await this.debugLog(`On: ${value}`)
|
|
54
51
|
|
|
55
52
|
// Set the requested state
|
|
56
|
-
this.Switch.On = value
|
|
53
|
+
this.Switch.On = value
|
|
57
54
|
if (this.Switch.On) {
|
|
58
|
-
await this.pushOnChanges()
|
|
55
|
+
await this.pushOnChanges()
|
|
59
56
|
} else {
|
|
60
|
-
await this.pushOffChanges()
|
|
57
|
+
await this.pushOffChanges()
|
|
61
58
|
}
|
|
62
59
|
}
|
|
63
60
|
|
|
64
61
|
/**
|
|
65
62
|
* Pushes the requested changes to the SwitchBot API
|
|
66
|
-
* deviceType
|
|
67
|
-
* Vacuum Cleaner "command" "turnOff" "default"
|
|
68
|
-
* Vacuum Cleaner "command" "turnOn" "default"
|
|
63
|
+
* deviceType CommandType Command Parameter Description
|
|
64
|
+
* Vacuum Cleaner "command" "turnOff" "default" set to OFF state
|
|
65
|
+
* Vacuum Cleaner "command" "turnOn" "default" set to ON state
|
|
69
66
|
*/
|
|
70
67
|
async pushOnChanges(): Promise<void> {
|
|
71
|
-
await this.debugLog(
|
|
72
|
-
+ ` On: ${this.Switch.On}, disablePushOn: ${this.disablePushOn}`);
|
|
68
|
+
await this.debugLog(`pushOnChanges On: ${this.Switch.On}, disablePushOn: ${this.disablePushOn}`)
|
|
73
69
|
if (this.Switch.On && !this.disablePushOn) {
|
|
74
|
-
const commandType: string = await this.commandType()
|
|
75
|
-
const command: string = await this.commandOn()
|
|
70
|
+
const commandType: string = await this.commandType()
|
|
71
|
+
const command: string = await this.commandOn()
|
|
76
72
|
const bodyChange = JSON.stringify({
|
|
77
|
-
command
|
|
73
|
+
command,
|
|
78
74
|
parameter: 'default',
|
|
79
|
-
commandType
|
|
80
|
-
})
|
|
81
|
-
await this.pushChanges(bodyChange)
|
|
75
|
+
commandType,
|
|
76
|
+
})
|
|
77
|
+
await this.pushChanges(bodyChange)
|
|
82
78
|
}
|
|
83
79
|
}
|
|
84
80
|
|
|
85
81
|
async pushOffChanges(): Promise<void> {
|
|
86
|
-
await this.debugLog(
|
|
87
|
-
+ ` On: ${this.Switch.On}, disablePushOff: ${this.disablePushOff}`);
|
|
82
|
+
await this.debugLog(`pushOffChanges On: ${this.Switch.On}, disablePushOff: ${this.disablePushOff}`)
|
|
88
83
|
if (!this.Switch.On && !this.disablePushOff) {
|
|
89
|
-
const commandType: string = await this.commandType()
|
|
90
|
-
const command: string = await this.commandOff()
|
|
84
|
+
const commandType: string = await this.commandType()
|
|
85
|
+
const command: string = await this.commandOff()
|
|
91
86
|
const bodyChange = JSON.stringify({
|
|
92
|
-
command
|
|
87
|
+
command,
|
|
93
88
|
parameter: 'default',
|
|
94
|
-
commandType
|
|
95
|
-
})
|
|
96
|
-
await this.pushChanges(bodyChange)
|
|
89
|
+
commandType,
|
|
90
|
+
})
|
|
91
|
+
await this.pushChanges(bodyChange)
|
|
97
92
|
}
|
|
98
93
|
}
|
|
99
94
|
|
|
100
95
|
async pushChanges(bodyChange: any): Promise<void> {
|
|
101
|
-
await this.debugLog('pushChanges')
|
|
96
|
+
await this.debugLog('pushChanges')
|
|
102
97
|
if (this.device.connectionType === 'OpenAPI') {
|
|
103
|
-
await this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`)
|
|
98
|
+
await this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`)
|
|
104
99
|
try {
|
|
105
|
-
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
106
|
-
const deviceStatus: any = await body.json()
|
|
107
|
-
await this.pushStatusCodes(statusCode, deviceStatus)
|
|
100
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
101
|
+
const deviceStatus: any = await body.json()
|
|
102
|
+
await this.pushStatusCodes(statusCode, deviceStatus)
|
|
108
103
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
109
|
-
await this.successfulPushChange(statusCode, deviceStatus, bodyChange)
|
|
110
|
-
await this.updateHomeKitCharacteristics()
|
|
104
|
+
await this.successfulPushChange(statusCode, deviceStatus, bodyChange)
|
|
105
|
+
await this.updateHomeKitCharacteristics()
|
|
111
106
|
} else {
|
|
112
|
-
await this.statusCode(statusCode)
|
|
113
|
-
await this.statusCode(deviceStatus.statusCode)
|
|
107
|
+
await this.statusCode(statusCode)
|
|
108
|
+
await this.statusCode(deviceStatus.statusCode)
|
|
114
109
|
}
|
|
115
110
|
} catch (e: any) {
|
|
116
|
-
await this.apiError(e)
|
|
117
|
-
await this.pushChangeError(e)
|
|
111
|
+
await this.apiError(e)
|
|
112
|
+
await this.pushChangeError(e)
|
|
118
113
|
}
|
|
119
114
|
} else {
|
|
120
|
-
await this.warnLog(`Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`)
|
|
115
|
+
await this.warnLog(`Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`)
|
|
121
116
|
}
|
|
122
117
|
}
|
|
123
118
|
|
|
124
119
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
125
|
-
await this.debugLog('updateHomeKitCharacteristics')
|
|
120
|
+
await this.debugLog('updateHomeKitCharacteristics')
|
|
126
121
|
// On
|
|
127
|
-
await this.updateCharacteristic(this.Switch.Service, this.hap.Characteristic.On,
|
|
128
|
-
this.Switch.On, 'On');
|
|
122
|
+
await this.updateCharacteristic(this.Switch.Service, this.hap.Characteristic.On, this.Switch.On, 'On')
|
|
129
123
|
}
|
|
130
124
|
|
|
131
125
|
async apiError(e: any): Promise<void> {
|
|
132
|
-
this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, e)
|
|
126
|
+
this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, e)
|
|
133
127
|
}
|
|
134
128
|
}
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
*
|
|
3
3
|
* waterheater.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
6
|
|
|
7
|
-
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
|
-
import type { irDevicesConfig } from '../settings.js'
|
|
9
|
-
import type { irdevice } from '../types/irdevicelist.js'
|
|
10
|
-
|
|
7
|
+
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
|
+
import type { irDevicesConfig } from '../settings.js'
|
|
9
|
+
import type { irdevice } from '../types/irdevicelist.js'
|
|
10
|
+
|
|
11
|
+
import { irdeviceBase } from './irdevice.js'
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Platform Accessory
|
|
@@ -17,120 +18,112 @@ import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge
|
|
|
17
18
|
export class WaterHeater extends irdeviceBase {
|
|
18
19
|
// Services
|
|
19
20
|
private Valve: {
|
|
20
|
-
Name: CharacteristicValue
|
|
21
|
-
Service: Service
|
|
22
|
-
Active: CharacteristicValue
|
|
23
|
-
}
|
|
21
|
+
Name: CharacteristicValue
|
|
22
|
+
Service: Service
|
|
23
|
+
Active: CharacteristicValue
|
|
24
|
+
}
|
|
24
25
|
|
|
25
26
|
constructor(
|
|
26
27
|
readonly platform: SwitchBotPlatform,
|
|
27
28
|
accessory: PlatformAccessory,
|
|
28
29
|
device: irdevice & irDevicesConfig,
|
|
29
30
|
) {
|
|
30
|
-
super(platform, accessory, device)
|
|
31
|
+
super(platform, accessory, device)
|
|
31
32
|
// Set category
|
|
32
|
-
accessory.category = this.hap.Categories.FAUCET
|
|
33
|
+
accessory.category = this.hap.Categories.FAUCET
|
|
33
34
|
|
|
34
35
|
// Initialize Switch Service
|
|
35
|
-
accessory.context.Valve = accessory.context.Valve ?? {}
|
|
36
|
+
accessory.context.Valve = accessory.context.Valve ?? {}
|
|
36
37
|
this.Valve = {
|
|
37
38
|
Name: accessory.displayName,
|
|
38
39
|
Service: accessory.getService(this.hap.Service.Valve) ?? accessory.addService(this.hap.Service.Valve) as Service,
|
|
39
40
|
Active: accessory.context.Active ?? this.hap.Characteristic.Active.INACTIVE,
|
|
40
|
-
}
|
|
41
|
-
accessory.context.Valve = this.Valve as object
|
|
41
|
+
}
|
|
42
|
+
accessory.context.Valve = this.Valve as object
|
|
42
43
|
|
|
43
|
-
this.Valve.Service
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
.getCharacteristic(this.hap.Characteristic.Active)
|
|
47
|
-
.onGet(() => {
|
|
48
|
-
return this.Valve.Active;
|
|
49
|
-
})
|
|
50
|
-
.onSet(this.ActiveSet.bind(this));
|
|
44
|
+
this.Valve.Service.setCharacteristic(this.hap.Characteristic.Name, this.Valve.Name).setCharacteristic(this.hap.Characteristic.ValveType, this.hap.Characteristic.ValveType.GENERIC_VALVE).getCharacteristic(this.hap.Characteristic.Active).onGet(() => {
|
|
45
|
+
return this.Valve.Active
|
|
46
|
+
}).onSet(this.ActiveSet.bind(this))
|
|
51
47
|
}
|
|
52
48
|
|
|
53
49
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
54
|
-
await this.debugLog(`Active: ${value}`)
|
|
50
|
+
await this.debugLog(`Active: ${value}`)
|
|
55
51
|
|
|
56
|
-
this.Valve.Active = value
|
|
52
|
+
this.Valve.Active = value
|
|
57
53
|
if (this.Valve.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
58
|
-
await this.pushWaterHeaterOnChanges()
|
|
59
|
-
this.Valve.Service.setCharacteristic(this.hap.Characteristic.InUse, this.hap.Characteristic.InUse.IN_USE)
|
|
54
|
+
await this.pushWaterHeaterOnChanges()
|
|
55
|
+
this.Valve.Service.setCharacteristic(this.hap.Characteristic.InUse, this.hap.Characteristic.InUse.IN_USE)
|
|
60
56
|
} else {
|
|
61
|
-
await this.pushWaterHeaterOffChanges()
|
|
62
|
-
this.Valve.Service.setCharacteristic(this.hap.Characteristic.InUse, this.hap.Characteristic.InUse.NOT_IN_USE)
|
|
57
|
+
await this.pushWaterHeaterOffChanges()
|
|
58
|
+
this.Valve.Service.setCharacteristic(this.hap.Characteristic.InUse, this.hap.Characteristic.InUse.NOT_IN_USE)
|
|
63
59
|
}
|
|
64
60
|
}
|
|
65
61
|
|
|
66
62
|
/**
|
|
67
63
|
* Pushes the requested changes to the SwitchBot API
|
|
68
|
-
* deviceType
|
|
69
|
-
* WaterHeater "command" "turnOff" "default"
|
|
70
|
-
* WaterHeater "command" "turnOn" "default"
|
|
64
|
+
* deviceType Command Type Command Parameter Description
|
|
65
|
+
* WaterHeater "command" "turnOff" "default" set to OFF state
|
|
66
|
+
* WaterHeater "command" "turnOn" "default" set to ON state
|
|
71
67
|
*/
|
|
72
68
|
async pushWaterHeaterOnChanges(): Promise<void> {
|
|
73
|
-
await this.debugLog(`pushWaterHeaterOnChanges Active: ${this.Valve.Active}
|
|
74
|
-
+ ` disablePushOn: ${this.disablePushOn}`);
|
|
69
|
+
await this.debugLog(`pushWaterHeaterOnChanges Active: ${this.Valve.Active}, disablePushOn: ${this.disablePushOn}`)
|
|
75
70
|
if (this.Valve.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
76
|
-
const commandType: string = await this.commandType()
|
|
77
|
-
const command: string = await this.commandOn()
|
|
71
|
+
const commandType: string = await this.commandType()
|
|
72
|
+
const command: string = await this.commandOn()
|
|
78
73
|
const bodyChange = JSON.stringify({
|
|
79
|
-
command
|
|
74
|
+
command,
|
|
80
75
|
parameter: 'default',
|
|
81
|
-
commandType
|
|
82
|
-
})
|
|
83
|
-
await this.pushChanges(bodyChange)
|
|
76
|
+
commandType,
|
|
77
|
+
})
|
|
78
|
+
await this.pushChanges(bodyChange)
|
|
84
79
|
}
|
|
85
80
|
}
|
|
86
81
|
|
|
87
82
|
async pushWaterHeaterOffChanges(): Promise<void> {
|
|
88
|
-
await this.debugLog(`pushWaterHeaterOffChanges Active: ${this.Valve.Active}
|
|
89
|
-
+ ` disablePushOff: ${this.disablePushOff}`);
|
|
83
|
+
await this.debugLog(`pushWaterHeaterOffChanges Active: ${this.Valve.Active}, disablePushOff: ${this.disablePushOff}`)
|
|
90
84
|
if (this.Valve.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
|
|
91
|
-
const commandType: string = await this.commandType()
|
|
92
|
-
const command: string = await this.commandOff()
|
|
85
|
+
const commandType: string = await this.commandType()
|
|
86
|
+
const command: string = await this.commandOff()
|
|
93
87
|
const bodyChange = JSON.stringify({
|
|
94
|
-
command
|
|
88
|
+
command,
|
|
95
89
|
parameter: 'default',
|
|
96
|
-
commandType
|
|
97
|
-
})
|
|
98
|
-
await this.pushChanges(bodyChange)
|
|
90
|
+
commandType,
|
|
91
|
+
})
|
|
92
|
+
await this.pushChanges(bodyChange)
|
|
99
93
|
}
|
|
100
94
|
}
|
|
101
95
|
|
|
102
96
|
async pushChanges(bodyChange: any): Promise<void> {
|
|
103
|
-
await this.debugLog('pushChanges')
|
|
97
|
+
await this.debugLog('pushChanges')
|
|
104
98
|
if (this.device.connectionType === 'OpenAPI') {
|
|
105
|
-
this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`)
|
|
99
|
+
this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`)
|
|
106
100
|
try {
|
|
107
|
-
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
108
|
-
const deviceStatus: any = await body.json()
|
|
109
|
-
await this.pushStatusCodes(statusCode, deviceStatus)
|
|
101
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange)
|
|
102
|
+
const deviceStatus: any = await body.json()
|
|
103
|
+
await this.pushStatusCodes(statusCode, deviceStatus)
|
|
110
104
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
111
|
-
await this.successfulPushChange(statusCode, deviceStatus, bodyChange)
|
|
112
|
-
await this.updateHomeKitCharacteristics()
|
|
105
|
+
await this.successfulPushChange(statusCode, deviceStatus, bodyChange)
|
|
106
|
+
await this.updateHomeKitCharacteristics()
|
|
113
107
|
} else {
|
|
114
|
-
await this.statusCode(statusCode)
|
|
115
|
-
await this.statusCode(deviceStatus.statusCode)
|
|
108
|
+
await this.statusCode(statusCode)
|
|
109
|
+
await this.statusCode(deviceStatus.statusCode)
|
|
116
110
|
}
|
|
117
111
|
} catch (e: any) {
|
|
118
|
-
await this.apiError(e)
|
|
119
|
-
await this.pushChangeError(e)
|
|
112
|
+
await this.apiError(e)
|
|
113
|
+
await this.pushChangeError(e)
|
|
120
114
|
}
|
|
121
115
|
} else {
|
|
122
|
-
await this.warnLog(`Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`)
|
|
116
|
+
await this.warnLog(`Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`)
|
|
123
117
|
}
|
|
124
118
|
}
|
|
125
119
|
|
|
126
120
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
127
|
-
await this.debugLog('updateHomeKitCharacteristics')
|
|
121
|
+
await this.debugLog('updateHomeKitCharacteristics')
|
|
128
122
|
// Active
|
|
129
|
-
await this.updateCharacteristic(this.Valve.Service, this.hap.Characteristic.Active,
|
|
130
|
-
this.Valve.Active, 'Active');
|
|
123
|
+
await this.updateCharacteristic(this.Valve.Service, this.hap.Characteristic.Active, this.Valve.Active, 'Active')
|
|
131
124
|
}
|
|
132
125
|
|
|
133
126
|
async apiError({ e }: { e: any }): Promise<void> {
|
|
134
|
-
this.Valve.Service.updateCharacteristic(this.hap.Characteristic.Active, e)
|
|
127
|
+
this.Valve.Service.updateCharacteristic(this.hap.Characteristic.Active, e)
|
|
135
128
|
}
|
|
136
129
|
}
|