@switchbot/homebridge-switchbot 5.2.9-beta.1 → 5.2.9

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.
Files changed (86) hide show
  1. package/dist/devices/genericDevice.d.ts.map +1 -1
  2. package/dist/devices/genericDevice.js +528 -118
  3. package/dist/devices/genericDevice.js.map +1 -1
  4. package/dist/homebridge-ui/public/js/advanced-settings.d.ts.map +1 -1
  5. package/dist/homebridge-ui/public/js/advanced-settings.js +3 -1
  6. package/dist/homebridge-ui/public/js/advanced-settings.js.map +1 -1
  7. package/dist/homebridge-ui/public/js/advanced-settings.ts +3 -1
  8. package/dist/homebridge-ui/public/js/api.d.ts.map +1 -1
  9. package/dist/homebridge-ui/public/js/api.js +21 -7
  10. package/dist/homebridge-ui/public/js/api.js.map +1 -1
  11. package/dist/homebridge-ui/public/js/api.ts +21 -7
  12. package/dist/homebridge-ui/public/js/app.js +74 -16
  13. package/dist/homebridge-ui/public/js/app.js.map +2 -2
  14. package/dist/homebridge-ui/public/js/credentials.d.ts.map +1 -1
  15. package/dist/homebridge-ui/public/js/credentials.js +9 -3
  16. package/dist/homebridge-ui/public/js/credentials.js.map +1 -1
  17. package/dist/homebridge-ui/public/js/credentials.ts +9 -3
  18. package/dist/homebridge-ui/public/js/devices-delete.d.ts.map +1 -1
  19. package/dist/homebridge-ui/public/js/devices-delete.js +6 -2
  20. package/dist/homebridge-ui/public/js/devices-delete.js.map +1 -1
  21. package/dist/homebridge-ui/public/js/devices-delete.ts +6 -2
  22. package/dist/homebridge-ui/public/js/devices.d.ts.map +1 -1
  23. package/dist/homebridge-ui/public/js/devices.js +3 -1
  24. package/dist/homebridge-ui/public/js/devices.js.map +1 -1
  25. package/dist/homebridge-ui/public/js/devices.ts +3 -1
  26. package/dist/homebridge-ui/public/js/discovery.d.ts.map +1 -1
  27. package/dist/homebridge-ui/public/js/discovery.js +89 -25
  28. package/dist/homebridge-ui/public/js/discovery.js.map +1 -1
  29. package/dist/homebridge-ui/public/js/discovery.ts +89 -25
  30. package/dist/homebridge-ui/public/js/modals.d.ts.map +1 -1
  31. package/dist/homebridge-ui/public/js/modals.js +13 -3
  32. package/dist/homebridge-ui/public/js/modals.js.map +1 -1
  33. package/dist/homebridge-ui/public/js/modals.ts +13 -3
  34. package/dist/homebridge-ui/public/js/render.d.ts.map +1 -1
  35. package/dist/homebridge-ui/public/js/render.js +67 -17
  36. package/dist/homebridge-ui/public/js/render.js.map +1 -1
  37. package/dist/homebridge-ui/public/js/render.ts +67 -17
  38. package/dist/homebridge-ui/public/js/toast.d.ts.map +1 -1
  39. package/dist/homebridge-ui/public/js/toast.js +6 -2
  40. package/dist/homebridge-ui/public/js/toast.js.map +1 -1
  41. package/dist/homebridge-ui/public/js/toast.ts +6 -2
  42. package/docs/variables/default.html +1 -1
  43. package/package.json +9 -9
  44. package/src/devices/genericDevice.ts +529 -129
  45. package/src/homebridge-ui/public/js/advanced-settings.ts +3 -1
  46. package/src/homebridge-ui/public/js/api.ts +21 -7
  47. package/src/homebridge-ui/public/js/credentials.ts +9 -3
  48. package/src/homebridge-ui/public/js/devices-delete.ts +6 -2
  49. package/src/homebridge-ui/public/js/devices.ts +3 -1
  50. package/src/homebridge-ui/public/js/discovery.ts +89 -25
  51. package/src/homebridge-ui/public/js/modals.ts +13 -3
  52. package/src/homebridge-ui/public/js/render.ts +67 -17
  53. package/src/homebridge-ui/public/js/toast.ts +6 -2
  54. package/test/client/node-switchbot-commands.spec.ts +44 -8
  55. package/test/client/switchbot-client-debounce.spec.ts +24 -3
  56. package/test/client/switchbot-client-discovery.spec.ts +26 -5
  57. package/test/client/switchbot-client-keys.spec.ts +30 -7
  58. package/test/client/switchbot-client-openapi.spec.ts +6 -1
  59. package/test/client/switchbotClient.spec.ts +30 -6
  60. package/test/device/bot-hap.spec.ts +131 -22
  61. package/test/device/curtain-ble-position.spec.ts +15 -3
  62. package/test/device/deviceBase.spec.ts +6 -1
  63. package/test/device/deviceFactory-edge.spec.ts +12 -2
  64. package/test/device/deviceFactory.spec.ts +6 -1
  65. package/test/device/fan-swing.spec.ts +9 -2
  66. package/test/device/genericDevice-blepoll.spec.ts +17 -3
  67. package/test/device/getstate-cache.spec.ts +37 -6
  68. package/test/device/getstate-returns-status.spec.ts +65 -13
  69. package/test/device/lock-users.spec.ts +24 -7
  70. package/test/device/matter-descriptors.spec.ts +6 -1
  71. package/test/device/matter-device-state.spec.ts +6 -1
  72. package/test/device/meter-battery.spec.ts +86 -14
  73. package/test/device/meter-co2.spec.ts +65 -10
  74. package/test/device/model-identities.spec.ts +6 -1
  75. package/test/device/water-detector-battery.spec.ts +19 -3
  76. package/test/device/water-detector-leak.spec.ts +6 -1
  77. package/test/helpers/matter-harness.ts +21 -4
  78. package/test/platform/accessory-restore.spec.ts +18 -3
  79. package/test/platform/hap-cache-restart.spec.ts +66 -13
  80. package/test/platform/matter-childbridge.spec.ts +16 -3
  81. package/test/platform/matter-integration.spec.ts +6 -1
  82. package/test/platform/matter-registration.spec.ts +47 -10
  83. package/test/platform/platform-edge.spec.ts +13 -3
  84. package/test/platform/platform.integration.spec.ts +16 -3
  85. package/test/utils/utils.spec.ts +42 -8
  86. package/.github/npm-version-script-esm.js +0 -103
@@ -16,7 +16,12 @@ import { PLATFORM_NAME, PLUGIN_NAME } from '../../src/settings.js'
16
16
  import { SwitchBotHAPPlatform } from '../../src/SwitchBotHAPPlatform.js'
17
17
  import { normalizeTypeForMatter } from '../../src/utils.js'
18
18
 
19
- const log = { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() }
19
+ const log = {
20
+ info: vi.fn(),
21
+ warn: vi.fn(),
22
+ error: vi.fn(),
23
+ debug: vi.fn(),
24
+ }
20
25
  const INFO = Service.AccessoryInformation.UUID
21
26
 
22
27
  async function startOnce(cache: any[] | undefined, devices: { id: string, type: string, name: string }[], mutate?: (json: any) => void) {
@@ -25,11 +30,18 @@ async function startOnce(cache: any[] | undefined, devices: { id: string, type:
25
30
  a._associatedPlugin = PLUGIN_NAME
26
31
  a._associatedPlatform = PLATFORM_NAME
27
32
  })
28
- const api = { hap: { Service, Characteristic, uuid }, platformAccessory: PlatformAccessory, registerPlatformAccessories: vi.fn((_p, _q, accs) => register(accs)), updatePlatformAccessories: vi.fn() }
33
+ const api = {
34
+ hap: { Service, Characteristic, uuid },
35
+ platformAccessory: PlatformAccessory,
36
+ registerPlatformAccessories: vi.fn((_p, _q, accs) => register(accs)),
37
+ updatePlatformAccessories: vi.fn(),
38
+ }
29
39
  const platform = Object.create(SwitchBotHAPPlatform.prototype) as any
30
40
  platform.api = api
31
41
  platform.log = log
32
- platform.config = { devices: devices.map(d => ({ deviceId: d.id, configDeviceType: d.type })) }
42
+ platform.config = {
43
+ devices: devices.map(d => ({ deviceId: d.id, configDeviceType: d.type })),
44
+ }
33
45
  platform.hapPushTargets = new Map()
34
46
  platform.accessories = new Map()
35
47
  for (const json of cache ?? []) {
@@ -40,14 +52,26 @@ async function startOnce(cache: any[] | undefined, devices: { id: string, type:
40
52
  const list = []
41
53
  for (const d of devices) {
42
54
  const type = normalizeTypeForMatter(d.type)
43
- const _client = { getDeviceStatus: vi.fn(async () => ({})), setDeviceState: vi.fn(async () => ({ success: true })), getDevice: vi.fn(async () => undefined) }
44
- const created = await createDevice({ id: d.id, type, deviceType: d.type, name: d.name, log } as any, { log, devices: platform.config.devices, _client } as any, false)
55
+ const _client = {
56
+ getDeviceStatus: vi.fn(async () => ({})),
57
+ setDeviceState: vi.fn(async () => ({ success: true })),
58
+ getDevice: vi.fn(async () => undefined),
59
+ }
60
+ const created = await createDevice({
61
+ id: d.id,
62
+ type,
63
+ deviceType: d.type,
64
+ name: d.name,
65
+ log,
66
+ } as any, { log, devices: platform.config.devices, _client } as any, false)
45
67
  list.push({ created, d, type })
46
68
  }
47
69
  log.warn.mockClear()
48
70
  await platform.registerHAPAccessories(list)
49
71
  expect(log.warn).not.toHaveBeenCalled()
50
- return [...platform.accessories.values()].map((a: any) => PlatformAccessory.serialize(a))
72
+ return [
73
+ ...platform.accessories.values(),
74
+ ].map((a: any) => PlatformAccessory.serialize(a))
51
75
  }
52
76
 
53
77
  describe('hAP accessory cache across restarts (#1424)', () => {
@@ -77,17 +101,34 @@ describe('hAP accessory cache across restarts (#1424)', () => {
77
101
  it('repairs a cache that is already missing AccessoryInformation, so the bridge can start', async () => {
78
102
  const dir = mkdtempSync(join(tmpdir(), 'switchbot-cache-'))
79
103
  const good = await startOnce(undefined, devices)
80
- const broken = good.map(a => ({ ...a, services: a.services.filter((s: any) => s.UUID !== INFO) }))
81
- const otherPlugin = { ...broken[0], plugin: 'homebridge-other', UUID: uuid.generate('other') }
104
+ const broken = good.map(a => ({
105
+ ...a,
106
+ services: a.services.filter((s: any) => s.UUID !== INFO),
107
+ }))
108
+ const otherPlugin = {
109
+ ...broken[0],
110
+ plugin: 'homebridge-other',
111
+ UUID: uuid.generate('other'),
112
+ }
82
113
  const file = join(dir, 'cachedAccessories.0EF8A6716C95')
83
114
  writeFileSync(file, JSON.stringify([...broken, otherPlugin]))
84
115
  expect(() => PlatformAccessory.deserialize(broken[0])).toThrow('getCharacteristic')
85
116
 
86
117
  const messages: string[] = []
87
- const api: any = { hap, user: { cachedAccessoryPath: () => dir } }
118
+ const api: any = {
119
+ hap,
120
+ user: {
121
+ cachedAccessoryPath: () => dir,
122
+ },
123
+ }
88
124
  const results = repairCachedAccessories(api, m => messages.push(m))
89
125
 
90
- expect(results).toEqual([{ file, repaired: ['Curtain3-1', 'Plug-1'] }])
126
+ expect(results).toEqual([
127
+ {
128
+ file,
129
+ repaired: ['Curtain3-1', 'Plug-1'],
130
+ },
131
+ ])
91
132
  expect(messages[0]).toContain('Repaired 2 cached accessories')
92
133
  expect(readdirSync(dir)).toContain('cachedAccessories.0EF8A6716C95.switchbot-repair.bak')
93
134
  const repaired = JSON.parse(readFileSync(file, 'utf8'))
@@ -101,12 +142,24 @@ describe('hAP accessory cache across restarts (#1424)', () => {
101
142
 
102
143
  it('ignores missing directories, backups and unreadable files', () => {
103
144
  const dir = mkdtempSync(join(tmpdir(), 'switchbot-cache-'))
104
- writeFileSync(join(dir, '.cachedAccessories.bak'), JSON.stringify([{ plugin: PLUGIN_NAME, services: [] }]))
145
+ writeFileSync(join(dir, '.cachedAccessories.bak'), JSON.stringify([
146
+ { plugin: PLUGIN_NAME, services: [] },
147
+ ]))
105
148
  writeFileSync(join(dir, 'cachedAccessories'), '{not json')
106
149
  const messages: string[] = []
107
- expect(repairCachedAccessories({ hap, user: { cachedAccessoryPath: () => dir } } as any, m => messages.push(m))).toEqual([])
150
+ expect(repairCachedAccessories({
151
+ hap,
152
+ user: {
153
+ cachedAccessoryPath: () => dir,
154
+ },
155
+ } as any, m => messages.push(m))).toEqual([])
108
156
  expect(messages).toHaveLength(1)
109
- expect(repairCachedAccessories({ hap, user: { cachedAccessoryPath: () => join(dir, 'missing') } } as any)).toEqual([])
157
+ expect(repairCachedAccessories({
158
+ hap,
159
+ user: {
160
+ cachedAccessoryPath: () => join(dir, 'missing'),
161
+ },
162
+ } as any)).toEqual([])
110
163
  expect(repairCachedAccessories({} as any)).toEqual([])
111
164
  })
112
165
  })
@@ -10,13 +10,23 @@ describe('matter child bridge accessory restoration', () => {
10
10
  registerAccessory(acc: any) { (this as any)._accessoryCache.push(acc) }
11
11
  }
12
12
 
13
- const logger = { info: () => {}, warn: () => {}, error: () => {}, debug: () => {} }
13
+ const logger = {
14
+ info: () => {},
15
+ warn: () => {},
16
+ error: () => {},
17
+ debug: () => {},
18
+ }
14
19
  const config = {}
15
20
  const api = {}
16
21
 
17
22
  it('should restore child bridge accessories from cache', () => {
18
23
  const platform = new TestMatterPlatform(logger, config, api)
19
- platform.setCache([{ uuid: 'matter-child-1', context: { type: 'Bot' } }])
24
+ platform.setCache([
25
+ {
26
+ uuid: 'matter-child-1',
27
+ context: { type: 'Bot' },
28
+ },
29
+ ])
20
30
  const restored = platform.getRestored()
21
31
  expect(restored).toHaveLength(1)
22
32
  expect(restored[0].uuid).toBe('matter-child-1')
@@ -25,7 +35,10 @@ describe('matter child bridge accessory restoration', () => {
25
35
  it('should register a new child bridge accessory', () => {
26
36
  const platform = new TestMatterPlatform(logger, config, api)
27
37
  platform.setCache([])
28
- const newAcc = { uuid: 'matter-child-2', context: { type: 'Curtain' } }
38
+ const newAcc = {
39
+ uuid: 'matter-child-2',
40
+ context: { type: 'Curtain' },
41
+ }
29
42
  platform.registerAccessory(newAcc)
30
43
  const restored = platform.getRestored()
31
44
  expect(restored).toHaveLength(1)
@@ -13,7 +13,12 @@ describe('matter integration platform', () => {
13
13
  getDevices() { return (this as any)._devices || [] }
14
14
  }
15
15
 
16
- const logger = { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() }
16
+ const logger = {
17
+ info: vi.fn(),
18
+ warn: vi.fn(),
19
+ error: vi.fn(),
20
+ debug: vi.fn(),
21
+ }
17
22
  const config = {}
18
23
  const api = {}
19
24
 
@@ -5,7 +5,9 @@ import { SwitchBotMatterPlatform } from '../../src/SwitchBotMatterPlatform.js'
5
5
  function makeApi(failFor?: string) {
6
6
  const registered = new Set<string>()
7
7
  const matter = {
8
- uuid: { generate: (id: string) => `uuid-${id}` },
8
+ uuid: {
9
+ generate: (id: string) => `uuid-${id}`,
10
+ },
9
11
  deviceTypes: {},
10
12
  registerPlatformAccessories: vi.fn(async (_p: string, _n: string, accessories: any[]) => {
11
13
  for (const a of accessories) {
@@ -21,12 +23,25 @@ function makeApi(failFor?: string) {
21
23
  updatePlatformAccessories: vi.fn(async () => {}),
22
24
  unregisterPlatformAccessories: vi.fn(async () => {}),
23
25
  }
24
- return { api: { matter, on: vi.fn() } as any, matter }
26
+ return {
27
+ api: {
28
+ matter,
29
+ on: vi.fn(),
30
+ } as any,
31
+ matter,
32
+ }
25
33
  }
26
34
 
27
35
  function created(name: string) {
28
36
  return {
29
- created: { createAccessory: async () => ({ name, clusters: { onOff: { onOff: false } } }) },
37
+ created: {
38
+ createAccessory: async () => ({
39
+ name,
40
+ clusters: {
41
+ onOff: { onOff: false },
42
+ },
43
+ }),
44
+ },
30
45
  d: { id: name, name },
31
46
  type: 'plug',
32
47
  useMatter: true,
@@ -34,14 +49,24 @@ function created(name: string) {
34
49
  }
35
50
  }
36
51
 
37
- const log = { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn(), success: vi.fn() } as any
52
+ const log = {
53
+ info: vi.fn(),
54
+ warn: vi.fn(),
55
+ error: vi.fn(),
56
+ debug: vi.fn(),
57
+ success: vi.fn(),
58
+ } as any
38
59
 
39
60
  describe('matter accessory registration', () => {
40
61
  it('updates instead of re-registering on a second load (config reload)', async () => {
41
62
  const { api, matter } = makeApi()
42
63
  const platform = new SwitchBotMatterPlatform(log, { platform: 'SwitchBot' } as any, api)
43
- await platform.registerMatterAccessories([created('a')])
44
- await platform.registerMatterAccessories([created('a')])
64
+ await platform.registerMatterAccessories([
65
+ created('a'),
66
+ ])
67
+ await platform.registerMatterAccessories([
68
+ created('a'),
69
+ ])
45
70
  expect(matter.registerPlatformAccessories).toHaveBeenCalledTimes(1)
46
71
  expect(matter.updatePlatformAccessories).toHaveBeenCalledTimes(1)
47
72
  })
@@ -49,8 +74,15 @@ describe('matter accessory registration', () => {
49
74
  it('registers cache-restored accessories so handlers attach', async () => {
50
75
  const { api, matter } = makeApi()
51
76
  const platform = new SwitchBotMatterPlatform(log, { platform: 'SwitchBot' } as any, api)
52
- platform.configureMatterAccessory({ UUID: 'uuid-a', displayName: 'a', context: { deviceId: 'a' }, _restoredFromCache: true })
53
- await platform.registerMatterAccessories([created('a')])
77
+ platform.configureMatterAccessory({
78
+ UUID: 'uuid-a',
79
+ displayName: 'a',
80
+ context: { deviceId: 'a' },
81
+ _restoredFromCache: true,
82
+ })
83
+ await platform.registerMatterAccessories([
84
+ created('a'),
85
+ ])
54
86
  expect(matter.registerPlatformAccessories).toHaveBeenCalledTimes(1)
55
87
  expect(matter.registerPlatformAccessories.mock.calls[0][2][0].handlers).toBeDefined()
56
88
  })
@@ -58,11 +90,16 @@ describe('matter accessory registration', () => {
58
90
  it('one failing accessory does not stop the others', async () => {
59
91
  const { api, matter } = makeApi('uuid-a')
60
92
  const platform = new SwitchBotMatterPlatform(log, { platform: 'SwitchBot' } as any, api)
61
- await platform.registerMatterAccessories([created('a'), created('b')])
93
+ await platform.registerMatterAccessories([
94
+ created('a'),
95
+ created('b'),
96
+ ])
62
97
  const uuids = matter.registerPlatformAccessories.mock.calls.map(c => c[2][0].UUID)
63
98
  expect(uuids).toEqual(['uuid-a', 'uuid-b'])
64
99
  // 'a' failed, so it is registered (not updated) on the next attempt
65
- await platform.registerMatterAccessories([created('a')])
100
+ await platform.registerMatterAccessories([
101
+ created('a'),
102
+ ])
66
103
  expect(matter.registerPlatformAccessories).toHaveBeenCalledTimes(3)
67
104
  })
68
105
  })
@@ -11,7 +11,10 @@ const mockLogger = {
11
11
  success: () => {},
12
12
  log: () => {},
13
13
  }
14
- const mockApi = { isMatterAvailable: () => false, isMatterEnabled: () => false } as any
14
+ const mockApi = {
15
+ isMatterAvailable: () => false,
16
+ isMatterEnabled: () => false,
17
+ } as any
15
18
 
16
19
  describe('platform edge cases', () => {
17
20
  const platforms = [
@@ -55,12 +58,19 @@ describe('platform edge cases', () => {
55
58
  })
56
59
 
57
60
  it('should fallback gracefully if isMatterAvailable returns true but isMatterEnabled returns false', () => {
58
- const api = { ...mockApi, isMatterAvailable: () => true, isMatterEnabled: () => false }
61
+ const api = {
62
+ ...mockApi,
63
+ isMatterAvailable: () => true,
64
+ isMatterEnabled: () => false,
65
+ }
59
66
  expect(() => new Platform(mockLogger, { platform: 'SwitchBot' }, api)).not.toThrow()
60
67
  })
61
68
 
62
69
  it('should fallback gracefully if isMatterAvailable returns false', () => {
63
- const api = { ...mockApi, isMatterAvailable: () => false }
70
+ const api = {
71
+ ...mockApi,
72
+ isMatterAvailable: () => false,
73
+ }
64
74
  expect(() => new Platform(mockLogger, { platform: 'SwitchBot' }, api)).not.toThrow()
65
75
  })
66
76
 
@@ -10,13 +10,23 @@ describe('hAP platform integration', () => {
10
10
  registerAccessory(acc: any) { (this as any)._accessoryCache.push(acc) }
11
11
  }
12
12
 
13
- const logger = { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() }
13
+ const logger = {
14
+ info: vi.fn(),
15
+ warn: vi.fn(),
16
+ error: vi.fn(),
17
+ debug: vi.fn(),
18
+ }
14
19
  const config = {}
15
20
  const api = {}
16
21
 
17
22
  it('should restore accessories from cache', () => {
18
23
  const platform = new TestHAPPlatform(logger, config, api)
19
- platform.setCache([{ uuid: 'hap-acc-1', context: { type: 'Bot' } }])
24
+ platform.setCache([
25
+ {
26
+ uuid: 'hap-acc-1',
27
+ context: { type: 'Bot' },
28
+ },
29
+ ])
20
30
  const restored = platform.getRestored()
21
31
  expect(restored).toHaveLength(1)
22
32
  expect(restored[0].uuid).toBe('hap-acc-1')
@@ -25,7 +35,10 @@ describe('hAP platform integration', () => {
25
35
  it('should register a new accessory', () => {
26
36
  const platform = new TestHAPPlatform(logger, config, api)
27
37
  platform.setCache([])
28
- const newAcc = { uuid: 'hap-acc-2', context: { type: 'Curtain' } }
38
+ const newAcc = {
39
+ uuid: 'hap-acc-2',
40
+ context: { type: 'Curtain' },
41
+ }
29
42
  platform.registerAccessory(newAcc)
30
43
  const restored = platform.getRestored()
31
44
  expect(restored).toHaveLength(1)
@@ -32,17 +32,33 @@ describe('utils', () => {
32
32
  // The config from #1424: credentials and options in the v4 layout, read by a v5 plugin that
33
33
  // only looked at openApiToken/openApiSecret/enableBLE, so the OpenAPI was never configured.
34
34
  it('normalizeConfig reads v4 credentials and options when the v5 keys are missing', () => {
35
- const devices = [{ deviceId: 'EA552551B763', configDeviceType: 'Curtain3' }]
35
+ const devices = [
36
+ { deviceId: 'EA552551B763', configDeviceType: 'Curtain3' },
37
+ ]
36
38
  const result = normalizeConfig({
37
39
  platform: 'SwitchBot',
38
40
  credentials: { token: 'TOKEN', secret: 'SECRET', notice: 'Keep your Token & Secret a secret!' },
39
- options: { BLE: false, discoverBLE: false, refreshRate: 180, logging: 'standard', devices },
41
+ options: {
42
+ BLE: false,
43
+ discoverBLE: false,
44
+ refreshRate: 180,
45
+ logging: 'standard',
46
+ devices,
47
+ },
40
48
  } as any)
41
- expect(result).toMatchObject({ openApiToken: 'TOKEN', openApiSecret: 'SECRET', enableBLE: false, openApiRefreshRate: 180, devices })
49
+ expect(result).toMatchObject({
50
+ openApiToken: 'TOKEN',
51
+ openApiSecret: 'SECRET',
52
+ enableBLE: false,
53
+ openApiRefreshRate: 180,
54
+ devices,
55
+ })
42
56
  })
43
57
 
44
58
  it('normalizeConfig prefers the v5 keys over v4 ones', () => {
45
- const devices = [{ deviceId: 'A' }]
59
+ const devices = [
60
+ { deviceId: 'A' },
61
+ ]
46
62
  const result = normalizeConfig({
47
63
  openApiToken: 'NEW',
48
64
  openApiSecret: 'NEWSECRET',
@@ -50,15 +66,30 @@ describe('utils', () => {
50
66
  openApiRefreshRate: 600,
51
67
  devices,
52
68
  credentials: { token: 'OLD', secret: 'OLDSECRET' },
53
- options: { BLE: false, refreshRate: 60, devices: [{ deviceId: 'B' }] },
69
+ options: {
70
+ BLE: false,
71
+ refreshRate: 60,
72
+ devices: [
73
+ { deviceId: 'B' },
74
+ ],
75
+ },
54
76
  } as any)
55
- expect(result).toMatchObject({ openApiToken: 'NEW', openApiSecret: 'NEWSECRET', enableBLE: true, openApiRefreshRate: 600, devices })
77
+ expect(result).toMatchObject({
78
+ openApiToken: 'NEW',
79
+ openApiSecret: 'NEWSECRET',
80
+ enableBLE: true,
81
+ openApiRefreshRate: 600,
82
+ devices,
83
+ })
56
84
  })
57
85
 
58
86
  it('createPlatformProxy instantiates MatterPlatform if available and enabled', () => {
59
87
  const HAP = vi.fn()
60
88
  const Matter = vi.fn()
61
- const api = { isMatterAvailable: () => true, isMatterEnabled: () => true }
89
+ const api = {
90
+ isMatterAvailable: () => true,
91
+ isMatterEnabled: () => true,
92
+ }
62
93
  const config = { enableMatter: true, preferMatter: true }
63
94
  const Proxy = createPlatformProxy(HAP, Matter)
64
95
  new Proxy('log', config, api)
@@ -69,7 +100,10 @@ describe('utils', () => {
69
100
  it('createPlatformProxy falls back to HAPPlatform if Matter not available', () => {
70
101
  const HAP = vi.fn()
71
102
  const Matter = vi.fn()
72
- const api = { isMatterAvailable: () => false, isMatterEnabled: () => false }
103
+ const api = {
104
+ isMatterAvailable: () => false,
105
+ isMatterEnabled: () => false,
106
+ }
73
107
  const config = { enableMatter: true, preferMatter: true }
74
108
  const Proxy = createPlatformProxy(HAP, Matter)
75
109
  new Proxy('log', config, api)
@@ -1,103 +0,0 @@
1
- #!/bin/env node
2
-
3
- /**
4
- * This scripts queries the npm registry to pull out the latest version for a given tag.
5
- */
6
-
7
- import assert from 'node:assert'
8
- import child_process from 'node:child_process'
9
- import fs from 'node:fs'
10
- import process from 'node:process'
11
-
12
- const BRANCH_VERSION_PATTERN = /^([A-Z]+)-(\d+\.\d+\.\d+)$/i
13
-
14
- // Load the contents of the package.json file
15
- const packageJSON = JSON.parse(fs.readFileSync('package.json', 'utf8'))
16
-
17
- const refArgument = process.argv[2]
18
- const tagArgument = process.argv[3] || 'latest'
19
-
20
- if (!refArgument) {
21
- console.error('ref argument is missing')
22
- console.error('Usage: npm-version-script-esm.js <ref> [tag]')
23
- process.exit(1)
24
- }
25
-
26
- /**
27
- * Queries the NPM registry for the latest version for the provided base version and tag.
28
- * If the tag is latest, then the base version is returned if it exists. For other tags, the latest
29
- * version found for that base version and tag is returned.
30
- * @param baseVersion The base version to query for, e.g. 2.0.0
31
- * @param tag The tag to query for, e.g. beta or latest
32
- * @returns {string} Returns the version, or '' if not found
33
- */
34
- function getTagVersionFromNpm(baseVersion, tag) {
35
- try {
36
- return JSON.parse(child_process.execSync(`npm info ${packageJSON.name} versions --json`).toString('utf8').trim())
37
- // find all published versions for this base version and tag
38
- .filter(v => tag === 'latest'
39
- ? v === baseVersion
40
- : v.startsWith(`${baseVersion}-${tag}.`))
41
- .reduce((_, current) => current, '') // choose the last as they're sorted in ascending order, or '' if there are none
42
- } catch (e) {
43
- console.error(`Failed to query the npm registry for the latest version for tag: ${tag}`, e)
44
- // throw e;
45
- return ''
46
- }
47
- }
48
-
49
- function desiredTargetVersion(ref) {
50
- // ref is a GitHub action ref string
51
- if (ref.startsWith('refs/pull/')) {
52
- throw new Error('The version script was executed inside a PR!')
53
- }
54
-
55
- assert(ref.startsWith('refs/heads/'))
56
- const branchName = ref.slice('refs/heads/'.length)
57
-
58
- const results = branchName.match(BRANCH_VERSION_PATTERN)
59
- if (results !== null) {
60
- if (results[1] !== tagArgument) {
61
- console.warn(`The base branch name (${results[1]}) differs from the tag name ${tagArgument}`)
62
- }
63
-
64
- return results[2]
65
- }
66
-
67
- throw new Error(`Malformed branch name for ref: ${ref}. Can't derive the base version. Use a branch name like: beta-x.x.x or alpha-x.x.x`)
68
- }
69
-
70
- // derive the base version from the branch ref
71
- const baseVersion = desiredTargetVersion(refArgument)
72
-
73
- // query the npm registry for the latest version of the provided tag name
74
- const latestReleasedVersion = getTagVersionFromNpm(baseVersion, tagArgument) // e.g. 0.7.0-beta.12
75
-
76
- let publishTag
77
-
78
- if (latestReleasedVersion) {
79
- console.warn(`Latest published version for ${baseVersion} with tag ${tagArgument} is ${latestReleasedVersion}`)
80
- publishTag = latestReleasedVersion // set this released beta or alpha to be incremented
81
- } else {
82
- console.warn(`No published versions for ${baseVersion} with tag ${tagArgument}`)
83
- publishTag = baseVersion // start off with a new beta or alpha version
84
- }
85
-
86
- if (packageJSON.version !== publishTag) {
87
- // report the change for CI
88
- console.warn(`Changing version in package.json from ${packageJSON.version} to ${publishTag}`)
89
-
90
- // save the package.json
91
- // JSON.stringify does not end with a newline, but npm writes both of these
92
- // files with one. Leaving it off makes the file fail an eol-last lint rule,
93
- // which breaks any repo whose prepublishOnly lints the whole tree.
94
- packageJSON.version = publishTag
95
- fs.writeFileSync('package.json', `${JSON.stringify(packageJSON, null, 2)}\n`)
96
-
97
- // perform the same change to the package-lock.json
98
- const packageLockJSON = JSON.parse(fs.readFileSync('package-lock.json', 'utf8'))
99
- packageLockJSON.version = publishTag
100
- fs.writeFileSync('package-lock.json', `${JSON.stringify(packageLockJSON, null, 2)}\n`)
101
- } else {
102
- console.warn(`Leaving version in package.json at ${packageJSON.version}`)
103
- }