@switchbot/homebridge-switchbot 3.8.2-beta.0 → 3.8.2-beta.2

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 (54) hide show
  1. package/dist/device/blindtilt.js.map +1 -1
  2. package/dist/device/bot.js.map +1 -1
  3. package/dist/device/ceilinglight.js.map +1 -1
  4. package/dist/device/colorbulb.js.map +1 -1
  5. package/dist/device/contact.js.map +1 -1
  6. package/dist/device/curtain.js.map +1 -1
  7. package/dist/device/device.js.map +1 -1
  8. package/dist/device/fan.js.map +1 -1
  9. package/dist/device/hub.js +2 -2
  10. package/dist/device/hub.js.map +1 -1
  11. package/dist/device/humidifier.js.map +1 -1
  12. package/dist/device/iosensor.js +2 -2
  13. package/dist/device/iosensor.js.map +1 -1
  14. package/dist/device/lightstrip.js.map +1 -1
  15. package/dist/device/lock.js.map +1 -1
  16. package/dist/device/meter.js +2 -2
  17. package/dist/device/meter.js.map +1 -1
  18. package/dist/device/meterplus.js +2 -2
  19. package/dist/device/meterplus.js.map +1 -1
  20. package/dist/device/motion.js.map +1 -1
  21. package/dist/device/plug.js.map +1 -1
  22. package/dist/device/robotvacuumcleaner.js.map +1 -1
  23. package/dist/device/waterdetector.js.map +1 -1
  24. package/dist/platform.d.ts.map +1 -1
  25. package/dist/platform.js +10 -3
  26. package/dist/platform.js.map +1 -1
  27. package/dist/types/bledevicestatus.d.ts +4 -4
  28. package/dist/utils.d.ts +3 -1
  29. package/dist/utils.d.ts.map +1 -1
  30. package/dist/utils.js +7 -3
  31. package/dist/utils.js.map +1 -1
  32. package/package.json +1 -1
  33. package/src/device/blindtilt.ts +2 -2
  34. package/src/device/bot.ts +2 -2
  35. package/src/device/ceilinglight.ts +2 -2
  36. package/src/device/colorbulb.ts +5 -5
  37. package/src/device/contact.ts +1 -1
  38. package/src/device/curtain.ts +3 -3
  39. package/src/device/device.ts +2 -2
  40. package/src/device/fan.ts +2 -2
  41. package/src/device/hub.ts +3 -3
  42. package/src/device/humidifier.ts +2 -2
  43. package/src/device/iosensor.ts +3 -3
  44. package/src/device/lightstrip.ts +4 -4
  45. package/src/device/lock.ts +2 -2
  46. package/src/device/meter.ts +3 -3
  47. package/src/device/meterplus.ts +3 -3
  48. package/src/device/motion.ts +1 -1
  49. package/src/device/plug.ts +2 -2
  50. package/src/device/robotvacuumcleaner.ts +2 -2
  51. package/src/device/waterdetector.ts +1 -1
  52. package/src/platform.ts +9 -3
  53. package/src/types/bledevicestatus.ts +4 -4
  54. package/src/utils.ts +7 -3
@@ -297,7 +297,7 @@ export class RobotVacuumCleaner extends deviceBase {
297
297
  if (this.config.options?.BLE) {
298
298
  await this.debugLog('is listening to Platform BLE.')
299
299
  try {
300
- const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
300
+ const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
301
301
  this.device.bleMac = formattedDeviceId
302
302
  await this.debugLog(`bleMac: ${this.device.bleMac}`)
303
303
  this.platform.bleEventHandler[this.device.bleMac] = async (context: robotVacuumCleanerServiceData) => {
@@ -390,7 +390,7 @@ export class RobotVacuumCleaner extends deviceBase {
390
390
  if (this.LightBulb.On !== this.accessory.context.On) {
391
391
  const switchbot = await this.platform.connectBLE(this.accessory, this.device)
392
392
  try {
393
- const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
393
+ const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
394
394
  this.device.bleMac = formattedDeviceId
395
395
  await this.debugLog(`bleMac: ${this.device.bleMac}`)
396
396
  if (switchbot !== false) {
@@ -297,7 +297,7 @@ export class WaterDetector extends deviceBase {
297
297
  if (this.config.options?.BLE) {
298
298
  await this.debugLog('is listening to Platform BLE.')
299
299
  try {
300
- const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
300
+ const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
301
301
  this.device.bleMac = formattedDeviceId
302
302
  await this.debugLog(`bleMac: ${this.device.bleMac}`)
303
303
  this.platform.bleEventHandler[this.device.bleMac] = async (context: waterLeakDetectorServiceData) => {
package/src/platform.ts CHANGED
@@ -58,7 +58,7 @@ import { TV } from './irdevice/tv.js'
58
58
  import { VacuumCleaner } from './irdevice/vacuumcleaner.js'
59
59
  import { WaterHeater } from './irdevice/waterheater.js'
60
60
  import { deleteWebhook, Devices, PLATFORM_NAME, PLUGIN_NAME, queryWebhook, setupWebhook, updateWebhook } from './settings.js'
61
- import { isBlindTiltDevice, isCurtainDevice, sleep } from './utils.js'
61
+ import { formatDeviceIdAsMac, isBlindTiltDevice, isCurtainDevice, sleep } from './utils.js'
62
62
 
63
63
  /**
64
64
  * HomebridgePlatform
@@ -593,8 +593,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
593
593
  for (const device of devices) {
594
594
  device.deviceType = device.configDeviceType
595
595
  device.deviceName = device.configDeviceName
596
- if (device.deviceType) {
597
- await this.createDevice(device)
596
+ try {
597
+ device.deviceId = formatDeviceIdAsMac(device.deviceId, true)
598
+ await this.debugLog(`deviceId: ${device.deviceId}`)
599
+ if (device.deviceType) {
600
+ await this.createDevice(device)
601
+ }
602
+ } catch (error) {
603
+ await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
598
604
  }
599
605
  }
600
606
  } else {
@@ -140,7 +140,7 @@ export type meterServiceData = serviceData & {
140
140
  model: SwitchBotBLEModel.Meter
141
141
  modelName: SwitchBotBLEModelName.Meter
142
142
  modelFriendlyName: SwitchBotBLEModelFriendlyName.Meter
143
- celcius: number
143
+ celsius: number
144
144
  fahrenheit: number
145
145
  fahrenheit_mode: boolean
146
146
  humidity: number
@@ -151,7 +151,7 @@ export type meterPlusServiceData = serviceData & {
151
151
  model: SwitchBotBLEModel.MeterPlus
152
152
  modelName: SwitchBotBLEModelName.MeterPlus
153
153
  modelFriendlyName: SwitchBotBLEModelFriendlyName.MeterPlus
154
- celcius: number
154
+ celsius: number
155
155
  fahrenheit: number
156
156
  fahrenheit_mode: boolean
157
157
  humidity: number
@@ -162,7 +162,7 @@ export type outdoorMeterServiceData = serviceData & {
162
162
  model: SwitchBotBLEModel.OutdoorMeter
163
163
  modelName: SwitchBotBLEModelName.OutdoorMeter
164
164
  modelFriendlyName: SwitchBotBLEModelFriendlyName.OutdoorMeter
165
- celcius: number
165
+ celsius: number
166
166
  fahrenheit: number
167
167
  fahrenheit_mode: boolean
168
168
  humidity: number
@@ -260,7 +260,7 @@ export type hub2ServiceData = serviceData & {
260
260
  model: SwitchBotBLEModel.Hub2
261
261
  modelName: SwitchBotBLEModelName.Hub2
262
262
  modelFriendlyName: SwitchBotBLEModelFriendlyName.Hub2
263
- celcius: number
263
+ celsius: number
264
264
  fahrenheit: number
265
265
  fahrenheit_mode: boolean
266
266
  humidity: number
package/src/utils.ts CHANGED
@@ -163,9 +163,11 @@ export function convertUnits(value: number, unit: string, convert?: string): num
163
163
  * Ensures the device ID does not already contain colons.
164
164
  *
165
165
  * @param deviceId - The device ID to format.
166
+ * @param cassSensative - If the MAC address should be case sensitive. Default is false, which will return the MAC address in lowercase.
166
167
  * @returns The formatted MAC address.
168
+ * @throws Will throw an error if the device ID is not a valid MAC address or a 12-character hexadecimal string.
167
169
  */
168
- export function formatDeviceIdAsMac(deviceId: string): string {
170
+ export function formatDeviceIdAsMac(deviceId: string, cassSensative?: boolean): string {
169
171
  if (typeof deviceId !== 'string') {
170
172
  throw new TypeError('Invalid device ID format. Device ID must be a string.')
171
173
  }
@@ -175,13 +177,15 @@ export function formatDeviceIdAsMac(deviceId: string): string {
175
177
  const macAddressRegex = /^(?:[0-9a-f]{2}:){5}[0-9a-f]{2}$/i
176
178
  const hexRegex = /^[0-9a-f]{12}$/i
177
179
 
180
+ // Check if the deviceId is already in a valid MAC address format
178
181
  if (macAddressRegex.test(deviceId)) {
179
- return deviceId.toLowerCase()
182
+ return cassSensative ? deviceId : deviceId.toLowerCase()
180
183
  }
181
184
 
182
185
  // Check if the deviceId is a valid 12-character hexadecimal string
183
186
  if (hexRegex.test(deviceId)) {
184
- return deviceId.match(/.{1,2}/g)!.join(':').toLowerCase()
187
+ const formattedDeviceId = deviceId.match(/.{1,2}/g)!.join(':')
188
+ return cassSensative ? formattedDeviceId : formattedDeviceId.toLowerCase()
185
189
  }
186
190
 
187
191
  throw new Error('Invalid device ID format. Must be a valid MAC address or a 12-character hexadecimal string.')