@homebridge-plugins/homebridge-govee 11.32.2-beta.13 → 11.32.2-beta.15

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 CHANGED
@@ -28,6 +28,10 @@ All notable changes to `@homebridge-plugins/homebridge-govee` will be documented
28
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
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
30
  - refactor: point the H7151 and H7111 at the handlers they were byte-for-byte copies of
31
+ - refactor: build the ice maker size codes from the model rather than writing both orderings out by hand
32
+ - refactor: build the switch and outlet tiles of a multi-socket device from one handler instead of two copies of it
33
+ - fix: move the H7152 dehumidifier's speed slider when it reports a new speed, which until now only the H7150 and H7151 did
34
+ - refactor: point the H7101 and H7111 fans at the H7100 handler they matched command for command
31
35
 
32
36
  ## v11.32.1 (2026-08-02)
33
37
 
@@ -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 and H7151
11
+ H7150, H7151 and H7152
12
12
  {
13
13
  "mode": {
14
14
  "options": [
@@ -10,6 +10,16 @@ import {
10
10
  import platformLang from '../utils/lang-en.js'
11
11
  import { logUnknownData } from '../utils/report-unknown.js'
12
12
 
13
+ /*
14
+ The models on this handler and the modes each offers:
15
+
16
+ H7100, H7102, H7106 -> Sleep, Nature, Custom, Auto
17
+ H7101 -> Sleep, Nature, Turbo, Custom, Auto
18
+ H7111 -> Sleep, Nature, Custom, Auto
19
+ H1310, R1310 -> as the H7100, but its oscillation status message has
20
+ never been confirmed, so it is not read back
21
+ */
22
+
13
23
  export default class GoveeFanH7100 {
14
24
  constructor(platform, accessory) {
15
25
  // Set up variables from the platform
@@ -267,7 +277,7 @@ export default class GoveeFanH7100 {
267
277
  this.cacheSpeed = this.autoSpeed
268
278
  // Cache auto so we can tell it apart from "user asked for max speed"
269
279
  this.service.updateCharacteristic(this.hapChar.RotationSpeed, 100)
270
- this.accessory.log(`${platformLang.curSpeed} [auto]`)
280
+ this.accessory.log(`${platformLang.curSpeed} [auto -> 100%]`)
271
281
  }
272
282
  break
273
283
  }
@@ -1,8 +1,9 @@
1
- import { base64ToHex, getTwoItemPosition, hexToTwoItems, parseError } from '../utils/functions.js'
1
+ import { getDeviceCapabilities } from '../utils/device-capabilities.js'
2
+ import { base64ToHex, generateCodeFromHexValues, getTwoItemPosition, hexToTwoItems, parseError } from '../utils/functions.js'
2
3
  import platformLang from '../utils/lang-en.js'
3
4
  import { logUnknownData } from '../utils/report-unknown.js'
4
5
 
5
- export default class {
6
+ export default class GoveeIceMaker {
6
7
  constructor(platform, accessory) {
7
8
  // Set up variables from the platform
8
9
  this.hapChar = platform.api.hap.Characteristic
@@ -14,10 +15,15 @@ export default class {
14
15
  this.accessory = accessory
15
16
 
16
17
  // Ice size codes: small=1, medium=2, large=3 (matching OpenAPI workMode values)
18
+ // Small, medium and large are all `33 05 <size>`. Which byte means which
19
+ // size runs the opposite way on the older models, so the order comes from
20
+ // the model rather than being written out twice
21
+ const ascending = getDeviceCapabilities(accessory.context.gvModel).iceSizeAscending
22
+ const sizeBytes = ascending ? [0x01, 0x02, 0x03] : [0x03, 0x02, 0x01]
17
23
  this.sizeCodes = {
18
- 1: 'MwUDAAAAAAAAAAAAAAAAAAAAADU=', // small
19
- 2: 'MwUCAAAAAAAAAAAAAAAAAAAAADQ=', // medium
20
- 3: 'MwUBAAAAAAAAAAAAAAAAAAAAADc=', // large
24
+ 1: generateCodeFromHexValues([0x33, 0x05, sizeBytes[0]]), // small
25
+ 2: generateCodeFromHexValues([0x33, 0x05, sizeBytes[1]]), // medium
26
+ 3: generateCodeFromHexValues([0x33, 0x05, sizeBytes[2]]), // large
21
27
  }
22
28
 
23
29
  this.sizeLabels = {
@@ -204,7 +210,7 @@ export default class {
204
210
  }
205
211
  case 'aa05': {
206
212
  // Ice size report. The payload encoding is deliberately NOT decoded here:
207
- // sizeCodes runs small=0x03..large=0x01 while the OpenAPI path sends
213
+ // the size byte order differs by model while the OpenAPI path sends
208
214
  // workMode un-inverted, and which is authoritative is unresolved (#1329).
209
215
  // Claiming a mapping here could silently swap sizes, so this case exists
210
216
  // only to stop a routine status report being logged as a new scene code.
@@ -7,11 +7,9 @@ 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 deviceDehumidifierH7152 from './dehumidifier-H7152.js'
11
10
  import deviceDiffuserH7161 from './diffuser-H7161.js'
12
11
  import deviceFanH1370 from './fan-H1370.js'
13
12
  import deviceFanH7100 from './fan-H7100.js'
14
- import deviceFanH7101 from './fan-H7101.js'
15
13
  import deviceFanH7105 from './fan-H7105.js'
16
14
  import deviceFanH7107 from './fan-H7107.js'
17
15
  import deviceHeater1A from './heater1a.js'
@@ -24,13 +22,10 @@ import deviceHumidifierH7142 from './humidifier-H7142.js'
24
22
  import deviceHumidifierH7143 from './humidifier-H7143.js'
25
23
  import deviceHumidifierH7160 from './humidifier-H7160.js'
26
24
  import deviceIceMakerH7172 from './ice-maker-H7172.js'
27
- import deviceIceMakerH8121 from './ice-maker-H8121.js'
28
25
  import deviceKettle from './kettle.js'
29
26
  import deviceLightSwitch from './light-switch.js'
30
27
  import deviceLight from './light.js'
31
- import deviceOutletDouble from './outlet-double.js'
32
28
  import deviceOutletSingle from './outlet-single.js'
33
- import deviceOutletTriple from './outlet-triple.js'
34
29
  import devicePurifierH7120 from './purifier-H7120.js'
35
30
  import devicePurifierH7122 from './purifier-H7122.js'
36
31
  import devicePurifierH7123 from './purifier-H7123.js'
@@ -44,9 +39,9 @@ import deviceSensorPresence from './sensor-presence.js'
44
39
  import deviceSensorThermo4 from './sensor-thermo4.js'
45
40
  import deviceSensorThermoSwitch from './sensor-thermo-switch.js'
46
41
  import deviceSensorThermo from './sensor-thermo.js'
47
- import deviceSwitchDouble from './switch-double.js'
42
+ import deviceSwitchDouble, { asOutlet as deviceOutletDouble } from './switch-double.js'
48
43
  import deviceSwitchSingle from './switch-single.js'
49
- import deviceSwitchTriple from './switch-triple.js'
44
+ import deviceSwitchTriple, { asOutlet as deviceOutletTriple } from './switch-triple.js'
50
45
  import deviceTapSingle from './tap-single.js'
51
46
  import deviceTemplate from './template.js'
52
47
  import deviceTVSingle from './tv-single.js'
@@ -56,7 +51,7 @@ export default {
56
51
  deviceCoolerSingle,
57
52
  deviceDehumidifierH7150,
58
53
  deviceDehumidifierH7151: deviceDehumidifierH7150, // identical to the H7150
59
- deviceDehumidifierH7152,
54
+ deviceDehumidifierH7152: deviceDehumidifierH7150, // same device, and this gives it proper speed feedback
60
55
  deviceDiffuserH7161,
61
56
  deviceDiffuserH7162: deviceDiffuserH7161, // identical to the H7161
62
57
  deviceDehumidifierBasic,
@@ -67,10 +62,10 @@ export default {
67
62
  deviceFanH7100,
68
63
  deviceFanH7102: deviceFanH7100, // identical to the H7100
69
64
  deviceFanH7106: deviceFanH7100, // identical to the H7100
70
- deviceFanH7101,
65
+ deviceFanH7101: deviceFanH7100, // identical to the H7100, with a turbo mode it is never sent
71
66
  deviceFanH7105,
72
67
  deviceFanH7107,
73
- deviceFanH7111: deviceFanH7101, // same fan without the turbo mode, which is not sent
68
+ deviceFanH7111: deviceFanH7100, // same fan without the turbo mode, which is not sent
74
69
  deviceHeaterSingle,
75
70
  deviceHeater1A,
76
71
  deviceHeater1B,
@@ -90,8 +85,8 @@ export default {
90
85
  deviceIceMakerH7172,
91
86
  deviceIceMakerH717D: deviceIceMakerH7172, // identical to the H7172
92
87
  deviceIceMakerH8120: deviceIceMakerH7172, // identical to the H7172
93
- deviceIceMakerH8121,
94
- deviceIceMakerH8122: deviceIceMakerH8121, // identical to the H8121
88
+ deviceIceMakerH8121: deviceIceMakerH7172, // same handler; its size byte order comes from the model
89
+ deviceIceMakerH8122: deviceIceMakerH7172, // identical to the H8121
95
90
  deviceKettle,
96
91
  deviceLight,
97
92
  deviceLightSwitch,
@@ -8,8 +8,8 @@ import platformLang from '../utils/lang-en.js'
8
8
  // outright rather than accepted and silently dropped (#1323).
9
9
  const nightLightModels = ['H5089']
10
10
 
11
- export default class {
12
- constructor(platform, accessory) {
11
+ class MultiSwitchDouble {
12
+ constructor(platform, accessory, config) {
13
13
  // Set up variables from the platform
14
14
  this.hapChar = platform.api.hap.Characteristic
15
15
  this.hapErr = platform.api.hap.HapStatusError
@@ -19,12 +19,13 @@ export default class {
19
19
  // Set up variables from the accessory
20
20
  this.accessory = accessory
21
21
 
22
- // Remove outlet services if they exist
23
- if (this.accessory.getService('Outlet 1')) {
24
- this.accessory.removeService(this.accessory.getService('Outlet 1'))
22
+ // Drop the tiles of the other kind, left behind if this device has been
23
+ // shown as the other one before
24
+ if (this.accessory.getService(`${config.other} 1`)) {
25
+ this.accessory.removeService(this.accessory.getService(`${config.other} 1`))
25
26
  }
26
- if (this.accessory.getService('Outlet 2')) {
27
- this.accessory.removeService(this.accessory.getService('Outlet 2'))
27
+ if (this.accessory.getService(`${config.other} 2`)) {
28
+ this.accessory.removeService(this.accessory.getService(`${config.other} 2`))
28
29
  }
29
30
 
30
31
  // A model that used to be treated as a single switch or outlet leaves an
@@ -35,15 +36,15 @@ export default class {
35
36
  && [this.hapServ.Switch.UUID, this.hapServ.Outlet.UUID].includes(service.UUID))
36
37
  .forEach(service => this.accessory.removeService(service))
37
38
 
38
- // Add the switch services if they don't already exist
39
- this.service1 = this.accessory.getService('Switch 1')
40
- || this.accessory.addService(this.hapServ.Switch, 'Switch 1', 'switch1')
41
- this.service2 = this.accessory.getService('Switch 2')
42
- || this.accessory.addService(this.hapServ.Switch, 'Switch 2', 'switch2')
39
+ // Add this device's tiles if they are not there already
40
+ this.service1 = this.accessory.getService(`${config.label} 1`)
41
+ || this.accessory.addService(this.hapServ[config.label], `${config.label} 1`, `${config.subtype}1`)
42
+ this.service2 = this.accessory.getService(`${config.label} 2`)
43
+ || this.accessory.addService(this.hapServ[config.label], `${config.label} 2`, `${config.subtype}2`)
43
44
 
44
45
  if (!this.service1.testCharacteristic(this.hapChar.ConfiguredName)) {
45
46
  this.service1.addCharacteristic(this.hapChar.ConfiguredName)
46
- this.service1.updateCharacteristic(this.hapChar.ConfiguredName, 'Switch 1')
47
+ this.service1.updateCharacteristic(this.hapChar.ConfiguredName, `${config.label} 1`)
47
48
  }
48
49
  if (!this.service1.testCharacteristic(this.hapChar.ServiceLabelIndex)) {
49
50
  this.service1.addCharacteristic(this.hapChar.ServiceLabelIndex)
@@ -51,7 +52,7 @@ export default class {
51
52
  }
52
53
  if (!this.service2.testCharacteristic(this.hapChar.ConfiguredName)) {
53
54
  this.service2.addCharacteristic(this.hapChar.ConfiguredName)
54
- this.service2.updateCharacteristic(this.hapChar.ConfiguredName, 'Switch 2')
55
+ this.service2.updateCharacteristic(this.hapChar.ConfiguredName, `${config.label} 2`)
55
56
  }
56
57
  if (!this.service2.testCharacteristic(this.hapChar.ServiceLabelIndex)) {
57
58
  this.service2.addCharacteristic(this.hapChar.ServiceLabelIndex)
@@ -86,7 +87,7 @@ export default class {
86
87
 
87
88
  // Output the customised options to the log
88
89
  const opts = JSON.stringify({
89
- showAs: 'switch',
90
+ showAs: config.showAs,
90
91
  })
91
92
  platform.log('[%s] %s %s.', accessory.displayName, platformLang.devInitOpts, opts)
92
93
 
@@ -186,3 +187,21 @@ export default class {
186
187
  }
187
188
  }
188
189
  }
190
+
191
+ /**
192
+ * A double switch and a double outlet are the same device with a different tile
193
+ * in the Home app, chosen by the owner's `showAs` setting. Only the service
194
+ * type, the tile names and the logged option differ, so they share this and are
195
+ * built from it rather than from a copy of it.
196
+ */
197
+ function make(config) {
198
+ return class extends MultiSwitchDouble {
199
+ constructor(platform, accessory) {
200
+ super(platform, accessory, config)
201
+ }
202
+ }
203
+ }
204
+
205
+ export default make({ label: 'Switch', subtype: 'switch', other: 'Outlet', showAs: 'switch' })
206
+
207
+ export const asOutlet = make({ label: 'Outlet', subtype: 'outlet', other: 'Switch', showAs: 'outlet' })
@@ -1,8 +1,8 @@
1
1
  import { parseError } from '../utils/functions.js'
2
2
  import platformLang from '../utils/lang-en.js'
3
3
 
4
- export default class {
5
- constructor(platform, accessory) {
4
+ class MultiSwitchTriple {
5
+ constructor(platform, accessory, config) {
6
6
  // Set up variables from the platform
7
7
  this.hapChar = platform.api.hap.Characteristic
8
8
  this.hapErr = platform.api.hap.HapStatusError
@@ -12,24 +12,25 @@ export default class {
12
12
  // Set up variables from the accessory
13
13
  this.accessory = accessory
14
14
 
15
- // Remove outlet services if they exist
16
- if (this.accessory.getService('Outlet 1')) {
17
- this.accessory.removeService(this.accessory.getService('Outlet 1'))
15
+ // Drop the tiles of the other kind, left behind if this device has been
16
+ // shown as the other one before
17
+ if (this.accessory.getService(`${config.other} 1`)) {
18
+ this.accessory.removeService(this.accessory.getService(`${config.other} 1`))
18
19
  }
19
- if (this.accessory.getService('Outlet 2')) {
20
- this.accessory.removeService(this.accessory.getService('Outlet 2'))
20
+ if (this.accessory.getService(`${config.other} 2`)) {
21
+ this.accessory.removeService(this.accessory.getService(`${config.other} 2`))
21
22
  }
22
- if (this.accessory.getService('Outlet 3')) {
23
- this.accessory.removeService(this.accessory.getService('Outlet 3'))
23
+ if (this.accessory.getService(`${config.other} 3`)) {
24
+ this.accessory.removeService(this.accessory.getService(`${config.other} 3`))
24
25
  }
25
26
 
26
- // Add the switch services if they don't already exist
27
- this.service1 = this.accessory.getService('Switch 1')
28
- || this.accessory.addService(this.hapServ.Switch, 'Switch 1', 'switch1')
29
- this.service2 = this.accessory.getService('Switch 2')
30
- || this.accessory.addService(this.hapServ.Switch, 'Switch 2', 'switch2')
31
- this.service3 = this.accessory.getService('Switch 3')
32
- || this.accessory.addService(this.hapServ.Switch, 'Switch 3', 'switch3')
27
+ // Add this device's tiles if they are not there already
28
+ this.service1 = this.accessory.getService(`${config.label} 1`)
29
+ || this.accessory.addService(this.hapServ[config.label], `${config.label} 1`, `${config.subtype}1`)
30
+ this.service2 = this.accessory.getService(`${config.label} 2`)
31
+ || this.accessory.addService(this.hapServ[config.label], `${config.label} 2`, `${config.subtype}2`)
32
+ this.service3 = this.accessory.getService(`${config.label} 3`)
33
+ || this.accessory.addService(this.hapServ[config.label], `${config.label} 3`, `${config.subtype}3`)
33
34
 
34
35
  // Add the set handler to the switch on/off characteristic
35
36
  this.service1.getCharacteristic(this.hapChar.On).onSet(async (value) => {
@@ -47,7 +48,7 @@ export default class {
47
48
 
48
49
  // Output the customised options to the log
49
50
  const opts = JSON.stringify({
50
- showAs: 'switch',
51
+ showAs: config.showAs,
51
52
  })
52
53
  platform.log('[%s] %s %s.', accessory.displayName, platformLang.devInitOpts, opts)
53
54
 
@@ -158,3 +159,21 @@ export default class {
158
159
  }
159
160
  }
160
161
  }
162
+
163
+ /**
164
+ * A triple switch and a triple outlet are the same device with a different tile
165
+ * in the Home app, chosen by the owner's `showAs` setting. Only the service
166
+ * type, the tile names and the logged option differ, so they share this and are
167
+ * built from it rather than from a copy of it.
168
+ */
169
+ function make(config) {
170
+ return class extends MultiSwitchTriple {
171
+ constructor(platform, accessory) {
172
+ super(platform, accessory, config)
173
+ }
174
+ }
175
+ }
176
+
177
+ export default make({ label: 'Switch', subtype: 'switch', other: 'Outlet', showAs: 'switch' })
178
+
179
+ export const asOutlet = make({ label: 'Outlet', subtype: 'outlet', other: 'Switch', showAs: 'outlet' })
@@ -41,6 +41,12 @@ const modelOverrides = {
41
41
  H1310: { readsSwingStatus: false },
42
42
  R1310: { readsSwingStatus: false },
43
43
 
44
+ // Later ice makers number their ice sizes the natural way round. The older
45
+ // ones run the other way, small being the highest byte, so the two families
46
+ // share a handler and differ only here
47
+ H8121: { iceSizeAscending: true },
48
+ H8122: { iceSizeAscending: true },
49
+
44
50
  // AWS outlet uses 17/16 for on/off instead of 1/0
45
51
  H5080: { awsPowerOn: 17, awsPowerOff: 16 },
46
52
  H5083: { awsPowerOn: 17, awsPowerOff: 16 },
@@ -109,6 +115,7 @@ const defaults = {
109
115
  awsStatusCmdVersion: 2,
110
116
  awsBrightnessNoScale: false,
111
117
  readsSwingStatus: true,
118
+ iceSizeAscending: false,
112
119
  }
113
120
 
114
121
  export function getDeviceCapabilities(model, firmware) {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@homebridge-plugins/homebridge-govee",
3
3
  "alias": "Govee",
4
4
  "type": "module",
5
- "version": "11.32.2-beta.13",
5
+ "version": "11.32.2-beta.15",
6
6
  "description": "Homebridge plugin to integrate Govee devices into HomeKit.",
7
7
  "author": {
8
8
  "name": "bwp91",
@@ -1,186 +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
- })
117
-
118
- // Cache the new state and log if appropriate
119
- this.cacheSpeed = value
120
- this.accessory.log(`${platformLang.curSpeed} [${value}]`)
121
- } catch (err) {
122
- // Catch any errors during the process
123
- this.accessory.logWarn(`${platformLang.devNotUpdated} ${parseError(err)}`)
124
-
125
- // Throw a 'no response' error and set a timeout to revert this after 2 seconds
126
- setTimeout(() => {
127
- this.service.updateCharacteristic(this.hapChar.RotationSpeed, this.cacheSpeed)
128
- }, 2000)
129
- throw new this.hapErr(-70402)
130
- }
131
- }
132
-
133
- externalUpdate(params) {
134
- // Check for an ON/OFF change
135
- if (params.state && params.state !== this.cacheState) {
136
- this.cacheState = params.state
137
- this.service.updateCharacteristic(this.hapChar.On, this.cacheState === 'on')
138
-
139
- // Log the change
140
- this.accessory.log(`${platformLang.curState} [${this.cacheState}]`)
141
- }
142
-
143
- // Handle OpenAPI workMode
144
- if (params.workMode) {
145
- const mode = params.workMode.modeValue
146
- this.accessory.log(`${platformLang.curMode} [${mode}]`)
147
- }
148
-
149
- // Check for some other scene/mode change
150
- (params.commands || []).forEach((command) => {
151
- const hexString = base64ToHex(command)
152
- const hexParts = hexToTwoItems(hexString)
153
-
154
- // Return now if not a device query update code
155
- if (getTwoItemPosition(hexParts, 1) !== 'aa') {
156
- return
157
- }
158
-
159
- const deviceFunction = `${getTwoItemPosition(hexParts, 2)}${getTwoItemPosition(hexParts, 3)}`
160
-
161
- switch (deviceFunction) {
162
- case '0501':
163
- case '0502': {
164
- // Speed update
165
- const newSpeedValue = Number.parseInt(getTwoItemPosition(hexParts, 4), 16)
166
- if (newSpeedValue >= 1 && newSpeedValue <= 8) {
167
- if (newSpeedValue !== this.cacheSpeed) {
168
- this.cacheSpeed = newSpeedValue
169
- this.service.updateCharacteristic(this.hapChar.RotationSpeed, this.cacheSpeed)
170
- this.accessory.log(`${platformLang.curSpeed} [${this.cacheSpeed}]`)
171
- }
172
- }
173
- break
174
- }
175
- default:
176
- logUnknownData(this.accessory, {
177
- kind: 'scene',
178
- source: params.source,
179
- raw: command,
180
- hex: hexString,
181
- })
182
- break
183
- }
184
- })
185
- }
186
- }