@homebridge-plugins/homebridge-govee 11.32.2-beta.12 → 11.32.2-beta.13
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 +3 -0
- package/lib/device/dehumidifier-H7150.js +2 -2
- package/lib/device/fan-H7100.js +18 -2
- package/lib/device/fan-H7101.js +4 -3
- package/lib/device/ice-maker-H8121.js +3 -3
- package/lib/device/index.js +11 -17
- package/lib/device/purifier-H7120.js +7 -24
- package/lib/device/purifier-H7123.js +2 -2
- package/lib/device/{sensor-button.js → sensor-basic.js} +8 -1
- package/lib/utils/device-capabilities.js +8 -0
- package/package.json +1 -1
- package/lib/device/dehumidifier-H7151.js +0 -195
- package/lib/device/fan-H1310.js +0 -290
- package/lib/device/fan-H7111.js +0 -351
- package/lib/device/ice-maker-H8122.js +0 -228
- package/lib/device/purifier-H7121.js +0 -412
- package/lib/device/purifier-H7124.js +0 -510
- package/lib/device/sensor-contact.js +0 -27
package/CHANGELOG.md
CHANGED
|
@@ -25,6 +25,9 @@ All notable changes to `@homebridge-plugins/homebridge-govee` will be documented
|
|
|
25
25
|
- test: record what every supported model turns into, so a change can be shown to have altered nothing
|
|
26
26
|
- feat: work out what an appliance can do from what the device itself reports, so a model nobody has written down still gets the right controls
|
|
27
27
|
- feat: offer oscillation and the child lock on any appliance that reports having them, driven through govee's api rather than needing that model's command codes
|
|
28
|
+
- refactor: point three more models at a shared handler instead of a near-copy of the same file, keeping each one's behaviour exactly as it was
|
|
29
|
+
- fix: give the H7124 the air quality handling the H7123 already had, so a poor reading is named properly and stops being logged over and over (#1261)
|
|
30
|
+
- refactor: point the H7151 and H7111 at the handlers they were byte-for-byte copies of
|
|
28
31
|
|
|
29
32
|
## v11.32.1 (2026-08-02)
|
|
30
33
|
|
|
@@ -8,7 +8,7 @@ import platformLang from '../utils/lang-en.js'
|
|
|
8
8
|
import { logUnknownData } from '../utils/report-unknown.js'
|
|
9
9
|
|
|
10
10
|
/*
|
|
11
|
-
H7150
|
|
11
|
+
H7150 and H7151
|
|
12
12
|
{
|
|
13
13
|
"mode": {
|
|
14
14
|
"options": [
|
|
@@ -32,7 +32,7 @@ import { logUnknownData } from '../utils/report-unknown.js'
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
*/
|
|
35
|
-
export default class {
|
|
35
|
+
export default class GoveeDehumidifierH7150 {
|
|
36
36
|
constructor(platform, accessory) {
|
|
37
37
|
// Set up variables from the platform
|
|
38
38
|
this.hapChar = platform.api.hap.Characteristic
|
package/lib/device/fan-H7100.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getDeviceCapabilities } from '../utils/device-capabilities.js'
|
|
1
2
|
import {
|
|
2
3
|
base64ToHex,
|
|
3
4
|
fanSpeedToHkPercent,
|
|
@@ -9,7 +10,7 @@ import {
|
|
|
9
10
|
import platformLang from '../utils/lang-en.js'
|
|
10
11
|
import { logUnknownData } from '../utils/report-unknown.js'
|
|
11
12
|
|
|
12
|
-
export default class {
|
|
13
|
+
export default class GoveeFanH7100 {
|
|
13
14
|
constructor(platform, accessory) {
|
|
14
15
|
// Set up variables from the platform
|
|
15
16
|
this.hapChar = platform.api.hap.Characteristic
|
|
@@ -20,6 +21,10 @@ export default class {
|
|
|
20
21
|
// Set up variables from the accessory
|
|
21
22
|
this.accessory = accessory
|
|
22
23
|
|
|
24
|
+
// Which of the models on this handler have a confirmed meaning for the
|
|
25
|
+
// oscillation status message
|
|
26
|
+
this.readsSwingStatus = getDeviceCapabilities(accessory.context.gvModel).readsSwingStatus
|
|
27
|
+
|
|
23
28
|
// Codes etc
|
|
24
29
|
this.speedCodes = {
|
|
25
30
|
1: 'MwUBAQAAAAAAAAAAAAAAAAAAADY=',
|
|
@@ -267,7 +272,18 @@ export default class {
|
|
|
267
272
|
break
|
|
268
273
|
}
|
|
269
274
|
case '1f01': {
|
|
270
|
-
//
|
|
275
|
+
// Not every model on this handler is known to mean oscillation by
|
|
276
|
+
// this message, so one that has not been confirmed falls through and
|
|
277
|
+
// reports it instead - which is how it gets confirmed
|
|
278
|
+
if (!this.readsSwingStatus) {
|
|
279
|
+
logUnknownData(this.accessory, {
|
|
280
|
+
kind: 'scene',
|
|
281
|
+
source: params.source,
|
|
282
|
+
raw: command,
|
|
283
|
+
hex: hexString,
|
|
284
|
+
})
|
|
285
|
+
break
|
|
286
|
+
}
|
|
271
287
|
const newSwing = getTwoItemPosition(hexParts, 4) === '01' ? 'on' : 'off'
|
|
272
288
|
if (this.cacheSwing !== newSwing) {
|
|
273
289
|
this.cacheSwing = newSwing
|
package/lib/device/fan-H7101.js
CHANGED
|
@@ -10,7 +10,7 @@ import platformLang from '../utils/lang-en.js'
|
|
|
10
10
|
import { logUnknownData } from '../utils/report-unknown.js'
|
|
11
11
|
|
|
12
12
|
/*
|
|
13
|
-
H7101
|
|
13
|
+
H7101 and H7111
|
|
14
14
|
{
|
|
15
15
|
"mode": {
|
|
16
16
|
"options": [
|
|
@@ -53,6 +53,7 @@ import { logUnknownData } from '../utils/report-unknown.js'
|
|
|
53
53
|
|
|
54
54
|
// NOTES
|
|
55
55
|
H7101 -> Sleep, Nature, Turbo, Custom, Auto
|
|
56
|
+
H7111 -> Sleep, Nature, Custom, Auto (no turbo)
|
|
56
57
|
|
|
57
58
|
sleep
|
|
58
59
|
[31/10/2022, 20:52:08] [Govee] [Device1] [AWS] receiving update {"source":"AWS","result":1,"commands":["qgUFAAAAAAAAAAAAAAAAAAAAAKo=","qgUABQAAAAAAAAAAAAAAAAAAAKo="]}.
|
|
@@ -65,7 +66,7 @@ import { logUnknownData } from '../utils/report-unknown.js'
|
|
|
65
66
|
[31/10/2022, 20:52:43] [Govee] [Device1] new scene code: [qgUABgAAAAAAAAAAAAAAAAAAAKk=] [aa050006000000000000000000000000000000a9].
|
|
66
67
|
*/
|
|
67
68
|
|
|
68
|
-
export default class {
|
|
69
|
+
export default class GoveeFanH7101 {
|
|
69
70
|
constructor(platform, accessory) {
|
|
70
71
|
// Set up variables from the platform
|
|
71
72
|
this.hapChar = platform.api.hap.Characteristic
|
|
@@ -318,7 +319,7 @@ export default class {
|
|
|
318
319
|
this.cacheSpeed = this.autoSpeed
|
|
319
320
|
// Cache auto so we can tell it apart from "user asked for max speed"
|
|
320
321
|
this.service.updateCharacteristic(this.hapChar.RotationSpeed, 100)
|
|
321
|
-
this.accessory.log(`${platformLang.curSpeed} [auto]`)
|
|
322
|
+
this.accessory.log(`${platformLang.curSpeed} [auto -> 100%]`)
|
|
322
323
|
}
|
|
323
324
|
break
|
|
324
325
|
}
|
|
@@ -2,7 +2,7 @@ import { base64ToHex, getTwoItemPosition, hexToTwoItems, parseError } from '../u
|
|
|
2
2
|
import platformLang from '../utils/lang-en.js'
|
|
3
3
|
import { logUnknownData } from '../utils/report-unknown.js'
|
|
4
4
|
|
|
5
|
-
export default class {
|
|
5
|
+
export default class GoveeIceMakerH8121 {
|
|
6
6
|
constructor(platform, accessory) {
|
|
7
7
|
// Set up variables from the platform
|
|
8
8
|
this.hapChar = platform.api.hap.Characteristic
|
|
@@ -14,7 +14,7 @@ export default class {
|
|
|
14
14
|
this.accessory = accessory
|
|
15
15
|
|
|
16
16
|
// Ice size codes: small=1, medium=2, large=3, matching the OpenAPI workMode
|
|
17
|
-
// values. Unlike the H8120,
|
|
17
|
+
// values. Unlike the H8120, this generation's BLE size byte runs in the SAME
|
|
18
18
|
// direction as workMode (small=0x05 01 .. large=0x05 03), so the two paths
|
|
19
19
|
// agree here and no inversion is needed.
|
|
20
20
|
this.sizeCodes = {
|
|
@@ -89,7 +89,7 @@ export default class {
|
|
|
89
89
|
} else {
|
|
90
90
|
// Turn off. The OpenAPI workMode=0 path is authoritative; the BLE frame
|
|
91
91
|
// mirrors the H8120 ice-maker-off command (33 19 00) as a best effort
|
|
92
|
-
// and is pending confirmation from an
|
|
92
|
+
// and is pending confirmation from an owner of either model.
|
|
93
93
|
await this.platform.sendDeviceUpdate(this.accessory, {
|
|
94
94
|
cmd: 'ptReal',
|
|
95
95
|
value: 'MxkAAAAAAAAAAAAAAAAAAAAAACo=',
|
package/lib/device/index.js
CHANGED
|
@@ -7,16 +7,13 @@ import {
|
|
|
7
7
|
} from './appliance-basic.js'
|
|
8
8
|
import deviceCoolerSingle from './cooler-single.js'
|
|
9
9
|
import deviceDehumidifierH7150 from './dehumidifier-H7150.js'
|
|
10
|
-
import deviceDehumidifierH7151 from './dehumidifier-H7151.js'
|
|
11
10
|
import deviceDehumidifierH7152 from './dehumidifier-H7152.js'
|
|
12
11
|
import deviceDiffuserH7161 from './diffuser-H7161.js'
|
|
13
|
-
import deviceFanH1310 from './fan-H1310.js'
|
|
14
12
|
import deviceFanH1370 from './fan-H1370.js'
|
|
15
13
|
import deviceFanH7100 from './fan-H7100.js'
|
|
16
14
|
import deviceFanH7101 from './fan-H7101.js'
|
|
17
15
|
import deviceFanH7105 from './fan-H7105.js'
|
|
18
16
|
import deviceFanH7107 from './fan-H7107.js'
|
|
19
|
-
import deviceFanH7111 from './fan-H7111.js'
|
|
20
17
|
import deviceHeater1A from './heater1a.js'
|
|
21
18
|
import deviceHeater1B from './heater1b.js'
|
|
22
19
|
import deviceHeater2 from './heater2.js'
|
|
@@ -28,7 +25,6 @@ import deviceHumidifierH7143 from './humidifier-H7143.js'
|
|
|
28
25
|
import deviceHumidifierH7160 from './humidifier-H7160.js'
|
|
29
26
|
import deviceIceMakerH7172 from './ice-maker-H7172.js'
|
|
30
27
|
import deviceIceMakerH8121 from './ice-maker-H8121.js'
|
|
31
|
-
import deviceIceMakerH8122 from './ice-maker-H8122.js'
|
|
32
28
|
import deviceKettle from './kettle.js'
|
|
33
29
|
import deviceLightSwitch from './light-switch.js'
|
|
34
30
|
import deviceLight from './light.js'
|
|
@@ -36,15 +32,12 @@ import deviceOutletDouble from './outlet-double.js'
|
|
|
36
32
|
import deviceOutletSingle from './outlet-single.js'
|
|
37
33
|
import deviceOutletTriple from './outlet-triple.js'
|
|
38
34
|
import devicePurifierH7120 from './purifier-H7120.js'
|
|
39
|
-
import devicePurifierH7121 from './purifier-H7121.js'
|
|
40
35
|
import devicePurifierH7122 from './purifier-H7122.js'
|
|
41
36
|
import devicePurifierH7123 from './purifier-H7123.js'
|
|
42
|
-
import devicePurifierH7124 from './purifier-H7124.js'
|
|
43
37
|
import devicePurifierH7126 from './purifier-H7126.js'
|
|
44
38
|
import devicePurifierSingle from './purifier-single.js'
|
|
45
|
-
import
|
|
39
|
+
import deviceSensorBasic from './sensor-basic.js'
|
|
46
40
|
import deviceSensorCO2 from './sensor-co2.js'
|
|
47
|
-
import deviceSensorContact from './sensor-contact.js'
|
|
48
41
|
import deviceSensorLeak from './sensor-leak.js'
|
|
49
42
|
import deviceSensorMonitor from './sensor-monitor.js'
|
|
50
43
|
import deviceSensorPresence from './sensor-presence.js'
|
|
@@ -62,22 +55,22 @@ import deviceValveSingle from './valve-single.js'
|
|
|
62
55
|
export default {
|
|
63
56
|
deviceCoolerSingle,
|
|
64
57
|
deviceDehumidifierH7150,
|
|
65
|
-
deviceDehumidifierH7151,
|
|
58
|
+
deviceDehumidifierH7151: deviceDehumidifierH7150, // identical to the H7150
|
|
66
59
|
deviceDehumidifierH7152,
|
|
67
60
|
deviceDiffuserH7161,
|
|
68
61
|
deviceDiffuserH7162: deviceDiffuserH7161, // identical to the H7161
|
|
69
62
|
deviceDehumidifierBasic,
|
|
70
63
|
deviceFanBasic,
|
|
71
|
-
deviceFanH1310,
|
|
64
|
+
deviceFanH1310: deviceFanH7100, // same fan, minus a confirmed swing status message
|
|
72
65
|
deviceFanH1370,
|
|
73
|
-
deviceFanR1310:
|
|
66
|
+
deviceFanR1310: deviceFanH7100, // R1310 is the newer naming of the H1310
|
|
74
67
|
deviceFanH7100,
|
|
75
68
|
deviceFanH7102: deviceFanH7100, // identical to the H7100
|
|
76
69
|
deviceFanH7106: deviceFanH7100, // identical to the H7100
|
|
77
70
|
deviceFanH7101,
|
|
78
71
|
deviceFanH7105,
|
|
79
72
|
deviceFanH7107,
|
|
80
|
-
deviceFanH7111,
|
|
73
|
+
deviceFanH7111: deviceFanH7101, // same fan without the turbo mode, which is not sent
|
|
81
74
|
deviceHeaterSingle,
|
|
82
75
|
deviceHeater1A,
|
|
83
76
|
deviceHeater1B,
|
|
@@ -98,7 +91,7 @@ export default {
|
|
|
98
91
|
deviceIceMakerH717D: deviceIceMakerH7172, // identical to the H7172
|
|
99
92
|
deviceIceMakerH8120: deviceIceMakerH7172, // identical to the H7172
|
|
100
93
|
deviceIceMakerH8121,
|
|
101
|
-
deviceIceMakerH8122,
|
|
94
|
+
deviceIceMakerH8122: deviceIceMakerH8121, // identical to the H8121
|
|
102
95
|
deviceKettle,
|
|
103
96
|
deviceLight,
|
|
104
97
|
deviceLightSwitch,
|
|
@@ -107,19 +100,20 @@ export default {
|
|
|
107
100
|
deviceOutletTriple,
|
|
108
101
|
devicePurifierBasic,
|
|
109
102
|
devicePurifierH7120,
|
|
110
|
-
devicePurifierH7121,
|
|
103
|
+
devicePurifierH7121: devicePurifierH7120, // identical apart from its sleep mode value, which is not sent
|
|
111
104
|
devicePurifierH7122,
|
|
112
105
|
devicePurifierH7123,
|
|
113
|
-
devicePurifierH7124,
|
|
106
|
+
devicePurifierH7124: devicePurifierH7123, // same device; this also gives it the #1261 air quality fix
|
|
114
107
|
devicePurifierH7126,
|
|
115
108
|
devicePurifierH7127: devicePurifierH7126, // identical to the H7126
|
|
116
109
|
devicePurifierH7128: devicePurifierH7126, // identical to the H7126
|
|
117
110
|
devicePurifierH7129: devicePurifierH7126, // identical to the H7126
|
|
118
111
|
devicePurifierH712C: devicePurifierH7126, // identical to the H7126
|
|
119
112
|
devicePurifierSingle,
|
|
120
|
-
|
|
113
|
+
deviceSensorBasic,
|
|
114
|
+
deviceSensorButton: deviceSensorBasic, // nothing decoded yet, so it reports instead
|
|
121
115
|
deviceSensorCO2,
|
|
122
|
-
deviceSensorContact,
|
|
116
|
+
deviceSensorContact: deviceSensorBasic, // nothing decoded yet, so it reports instead
|
|
123
117
|
deviceSensorLeak,
|
|
124
118
|
deviceSensorMonitor,
|
|
125
119
|
deviceSensorPresence,
|
|
@@ -8,32 +8,15 @@ import platformLang from '../utils/lang-en.js'
|
|
|
8
8
|
import { logUnknownData } from '../utils/report-unknown.js'
|
|
9
9
|
|
|
10
10
|
/*
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"value": 1
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
"name": "Medium",
|
|
21
|
-
"value": 2
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
"name": "High",
|
|
25
|
-
"value": 3
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
"name": "Sleep mode",
|
|
29
|
-
"value": 5
|
|
30
|
-
}
|
|
31
|
-
]
|
|
32
|
-
}
|
|
33
|
-
}
|
|
11
|
+
The modes these purifiers report over the api. Low, medium and high are the
|
|
12
|
+
gear speeds the plugin drives; sleep is listed for reference and is the one
|
|
13
|
+
place the two models differ, so it must not be sent as a shared value.
|
|
14
|
+
|
|
15
|
+
H7120: Low 1, Medium 2, High 3, "Sleep mode" 5
|
|
16
|
+
H7121: Low 1, Medium 2, High 3, "Sleep" 16
|
|
34
17
|
*/
|
|
35
18
|
|
|
36
|
-
export default class {
|
|
19
|
+
export default class GoveePurifierH7120 {
|
|
37
20
|
constructor(platform, accessory) {
|
|
38
21
|
// Set up variables from the platform
|
|
39
22
|
this.cusChar = platform.cusChar
|
|
@@ -10,7 +10,7 @@ import platformLang from '../utils/lang-en.js'
|
|
|
10
10
|
import { logUnknownData } from '../utils/report-unknown.js'
|
|
11
11
|
|
|
12
12
|
/*
|
|
13
|
-
H7123
|
|
13
|
+
H7123 and H7124
|
|
14
14
|
{
|
|
15
15
|
"mode": {
|
|
16
16
|
"options": [
|
|
@@ -39,7 +39,7 @@ import { logUnknownData } from '../utils/report-unknown.js'
|
|
|
39
39
|
}
|
|
40
40
|
*/
|
|
41
41
|
|
|
42
|
-
export default class {
|
|
42
|
+
export default class GoveePurifierH7123 {
|
|
43
43
|
constructor(platform, accessory) {
|
|
44
44
|
// Set up variables from the platform
|
|
45
45
|
this.cusChar = platform.cusChar
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import platformLang from '../utils/lang-en.js'
|
|
2
2
|
import { logUnknownData } from '../utils/report-unknown.js'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* A sensor whose broadcasts are not decoded yet.
|
|
6
|
+
*
|
|
7
|
+
* It offers no tile, because a tile that never updates is worse than none. What
|
|
8
|
+
* it does is report every message it receives in one copy-paste line, so an
|
|
9
|
+
* owner can send in exactly what is needed to finish the model off.
|
|
10
|
+
*/
|
|
11
|
+
export default class GoveeSensorBasic {
|
|
5
12
|
constructor(platform, accessory) {
|
|
6
13
|
// Set up variables from the platform
|
|
7
14
|
this.hapChar = platform.api.hap.Characteristic
|
|
@@ -34,6 +34,13 @@ const modelOverrides = {
|
|
|
34
34
|
// and only the brightness scale is fixed here (#1332)
|
|
35
35
|
H6102: { bleBrightnessScale: 0x64 },
|
|
36
36
|
|
|
37
|
+
// The H1310 ceiling fan shares the H7100's handler, but its oscillation
|
|
38
|
+
// status message has never been confirmed to mean the same thing, so reading
|
|
39
|
+
// it back stays off. While it is off, an owner's fan reporting one produces a
|
|
40
|
+
// line in the log saying so - which is the evidence needed to turn this on
|
|
41
|
+
H1310: { readsSwingStatus: false },
|
|
42
|
+
R1310: { readsSwingStatus: false },
|
|
43
|
+
|
|
37
44
|
// AWS outlet uses 17/16 for on/off instead of 1/0
|
|
38
45
|
H5080: { awsPowerOn: 17, awsPowerOff: 16 },
|
|
39
46
|
H5083: { awsPowerOn: 17, awsPowerOff: 16 },
|
|
@@ -101,6 +108,7 @@ const defaults = {
|
|
|
101
108
|
bleWriteUuid: UUID.WRITE_DEFAULT,
|
|
102
109
|
awsStatusCmdVersion: 2,
|
|
103
110
|
awsBrightnessNoScale: false,
|
|
111
|
+
readsSwingStatus: true,
|
|
104
112
|
}
|
|
105
113
|
|
|
106
114
|
export function getDeviceCapabilities(model, firmware) {
|
package/package.json
CHANGED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
base64ToHex,
|
|
3
|
-
getTwoItemPosition,
|
|
4
|
-
hexToTwoItems,
|
|
5
|
-
parseError,
|
|
6
|
-
} from '../utils/functions.js'
|
|
7
|
-
import platformLang from '../utils/lang-en.js'
|
|
8
|
-
import { logUnknownData } from '../utils/report-unknown.js'
|
|
9
|
-
|
|
10
|
-
export default class {
|
|
11
|
-
constructor(platform, accessory) {
|
|
12
|
-
// Set up variables from the platform
|
|
13
|
-
this.hapChar = platform.api.hap.Characteristic
|
|
14
|
-
this.hapErr = platform.api.hap.HapStatusError
|
|
15
|
-
this.hapServ = platform.api.hap.Service
|
|
16
|
-
this.platform = platform
|
|
17
|
-
|
|
18
|
-
// Set up variables from the accessory
|
|
19
|
-
this.accessory = accessory
|
|
20
|
-
|
|
21
|
-
// Speed codes
|
|
22
|
-
this.value2Code = {
|
|
23
|
-
1: 'MwUBAQAAAAAAAAAAAAAAAAAAADY=',
|
|
24
|
-
2: 'MwUBAgAAAAAAAAAAAAAAAAAAADU=',
|
|
25
|
-
3: 'MwUBAwAAAAAAAAAAAAAAAAAAADQ=',
|
|
26
|
-
4: 'MwUBBAAAAAAAAAAAAAAAAAAAADM=',
|
|
27
|
-
5: 'MwUBBQAAAAAAAAAAAAAAAAAAADI=',
|
|
28
|
-
6: 'MwUBBgAAAAAAAAAAAAAAAAAAADE=',
|
|
29
|
-
7: 'MwUBBwAAAAAAAAAAAAAAAAAAADA=',
|
|
30
|
-
8: 'MwUBCAAAAAAAAAAAAAAAAAAAAD8=',
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Migrate old %-rotation speed to unitless
|
|
34
|
-
const existingFanService = this.accessory.getService(this.hapServ.Fan)
|
|
35
|
-
if (existingFanService) {
|
|
36
|
-
if (existingFanService.getCharacteristic(this.hapChar.RotationSpeed).props.unit === 'percentage') {
|
|
37
|
-
this.accessory.removeService(existingFanService)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Add the fan service if it doesn't already exist
|
|
42
|
-
this.service = this.accessory.getService(this.hapServ.Fan) || this.accessory.addService(this.hapServ.Fan)
|
|
43
|
-
|
|
44
|
-
// Add the set handler to the fan on/off characteristic
|
|
45
|
-
this.service
|
|
46
|
-
.getCharacteristic(this.hapChar.On)
|
|
47
|
-
.onSet(async value => this.internalStateUpdate(value))
|
|
48
|
-
this.cacheState = this.service.getCharacteristic(this.hapChar.On).value ? 'on' : 'off'
|
|
49
|
-
|
|
50
|
-
// Add the set handler to the fan rotation speed characteristic
|
|
51
|
-
this.service
|
|
52
|
-
.getCharacteristic(this.hapChar.RotationSpeed)
|
|
53
|
-
.setProps({
|
|
54
|
-
maxValue: 8,
|
|
55
|
-
minStep: 1,
|
|
56
|
-
minValue: 0,
|
|
57
|
-
unit: 'unitless',
|
|
58
|
-
})
|
|
59
|
-
.onSet(async value => this.internalSpeedUpdate(value))
|
|
60
|
-
this.cacheSpeed = this.service.getCharacteristic(this.hapChar.RotationSpeed).value
|
|
61
|
-
|
|
62
|
-
// Output the customised options to the log
|
|
63
|
-
const opts = JSON.stringify({})
|
|
64
|
-
platform.log('[%s] %s %s.', accessory.displayName, platformLang.devInitOpts, opts)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
async internalStateUpdate(value) {
|
|
68
|
-
try {
|
|
69
|
-
const newValue = value ? 'on' : 'off'
|
|
70
|
-
|
|
71
|
-
// Don't continue if the new value is the same as before
|
|
72
|
-
if (this.cacheState === newValue) {
|
|
73
|
-
return
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Send the request to the platform sender function
|
|
77
|
-
await this.platform.sendDeviceUpdate(this.accessory, {
|
|
78
|
-
cmd: 'stateHumi',
|
|
79
|
-
value: value ? 1 : 0,
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
// Cache the new state and log if appropriate
|
|
83
|
-
this.cacheState = newValue
|
|
84
|
-
this.accessory.log(`${platformLang.curState} [${newValue}]`)
|
|
85
|
-
} catch (err) {
|
|
86
|
-
// Catch any errors during the process
|
|
87
|
-
this.accessory.logWarn(`${platformLang.devNotUpdated} ${parseError(err)}`)
|
|
88
|
-
|
|
89
|
-
// Throw a 'no response' error and set a timeout to revert this after 2 seconds
|
|
90
|
-
setTimeout(() => {
|
|
91
|
-
this.service.updateCharacteristic(this.hapChar.On, this.cacheState === 'on')
|
|
92
|
-
}, 2000)
|
|
93
|
-
throw new this.hapErr(-70402)
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
async internalSpeedUpdate(value) {
|
|
98
|
-
try {
|
|
99
|
-
// Don't continue if the speed is 0
|
|
100
|
-
if (value === 0) {
|
|
101
|
-
return
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Don't continue if the speed value won't have effect
|
|
105
|
-
if (value === this.cacheSpeed) {
|
|
106
|
-
return
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Get the scene code for this value
|
|
110
|
-
const newCode = this.value2Code[value]
|
|
111
|
-
|
|
112
|
-
// Send the request to the platform sender function
|
|
113
|
-
await this.platform.sendDeviceUpdate(this.accessory, {
|
|
114
|
-
cmd: 'ptReal',
|
|
115
|
-
value: newCode,
|
|
116
|
-
openApi: this.accessory.context.openApiCapabilities?.workMode
|
|
117
|
-
? { instance: 'workMode', capabilityType: 'devices.capabilities.work_mode', value: { workMode: 1, modeValue: value } }
|
|
118
|
-
: undefined,
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
// Cache the new state and log if appropriate
|
|
122
|
-
this.cacheSpeed = value
|
|
123
|
-
this.accessory.log(`${platformLang.curSpeed} [${value}]`)
|
|
124
|
-
} catch (err) {
|
|
125
|
-
// Catch any errors during the process
|
|
126
|
-
this.accessory.logWarn(`${platformLang.devNotUpdated} ${parseError(err)}`)
|
|
127
|
-
|
|
128
|
-
// Throw a 'no response' error and set a timeout to revert this after 2 seconds
|
|
129
|
-
setTimeout(() => {
|
|
130
|
-
this.service.updateCharacteristic(this.hapChar.RotationSpeed, this.cacheSpeed)
|
|
131
|
-
}, 2000)
|
|
132
|
-
throw new this.hapErr(-70402)
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
externalUpdate(params) {
|
|
137
|
-
// Check for an ON/OFF change
|
|
138
|
-
if (params.state && params.state !== this.cacheState) {
|
|
139
|
-
this.cacheState = params.state
|
|
140
|
-
this.service.updateCharacteristic(this.hapChar.On, this.cacheState === 'on')
|
|
141
|
-
|
|
142
|
-
// Log the change
|
|
143
|
-
this.accessory.log(`${platformLang.curState} [${this.cacheState}]`)
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Handle OpenAPI workMode (speed)
|
|
147
|
-
if (params.workMode) {
|
|
148
|
-
const speed = params.workMode.modeValue
|
|
149
|
-
if (speed >= 1 && speed <= 8) {
|
|
150
|
-
if (speed !== this.cacheSpeed) {
|
|
151
|
-
this.cacheSpeed = speed
|
|
152
|
-
this.service.updateCharacteristic(this.hapChar.RotationSpeed, this.cacheSpeed)
|
|
153
|
-
this.accessory.log(`${platformLang.curSpeed} [${this.cacheSpeed}]`)
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// Check for some other scene/mode change
|
|
159
|
-
(params.commands || []).forEach((command) => {
|
|
160
|
-
const hexString = base64ToHex(command)
|
|
161
|
-
const hexParts = hexToTwoItems(hexString)
|
|
162
|
-
|
|
163
|
-
// Return now if not a device query update code
|
|
164
|
-
if (getTwoItemPosition(hexParts, 1) !== 'aa') {
|
|
165
|
-
return
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const deviceFunction = `${getTwoItemPosition(hexParts, 2)}${getTwoItemPosition(hexParts, 3)}`
|
|
169
|
-
|
|
170
|
-
switch (deviceFunction) {
|
|
171
|
-
case '0501':
|
|
172
|
-
case '0502': {
|
|
173
|
-
// Speed update
|
|
174
|
-
const newSpeedValue = Number.parseInt(getTwoItemPosition(hexParts, 4), 16)
|
|
175
|
-
if (newSpeedValue >= 1 && newSpeedValue <= 8) {
|
|
176
|
-
if (newSpeedValue !== this.cacheSpeed) {
|
|
177
|
-
this.cacheSpeed = newSpeedValue
|
|
178
|
-
this.service.updateCharacteristic(this.hapChar.RotationSpeed, this.cacheSpeed)
|
|
179
|
-
this.accessory.log(`${platformLang.curSpeed} [${this.cacheSpeed}]`)
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
break
|
|
183
|
-
}
|
|
184
|
-
default:
|
|
185
|
-
logUnknownData(this.accessory, {
|
|
186
|
-
kind: 'scene',
|
|
187
|
-
source: params.source,
|
|
188
|
-
raw: command,
|
|
189
|
-
hex: hexString,
|
|
190
|
-
})
|
|
191
|
-
break
|
|
192
|
-
}
|
|
193
|
-
})
|
|
194
|
-
}
|
|
195
|
-
}
|