@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.
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.js +2 -2
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.js +2 -2
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.js +2 -2
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.js +2 -2
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +10 -3
- package/dist/platform.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +4 -4
- package/dist/utils.d.ts +3 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +7 -3
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/device/blindtilt.ts +2 -2
- package/src/device/bot.ts +2 -2
- package/src/device/ceilinglight.ts +2 -2
- package/src/device/colorbulb.ts +5 -5
- package/src/device/contact.ts +1 -1
- package/src/device/curtain.ts +3 -3
- package/src/device/device.ts +2 -2
- package/src/device/fan.ts +2 -2
- package/src/device/hub.ts +3 -3
- package/src/device/humidifier.ts +2 -2
- package/src/device/iosensor.ts +3 -3
- package/src/device/lightstrip.ts +4 -4
- package/src/device/lock.ts +2 -2
- package/src/device/meter.ts +3 -3
- package/src/device/meterplus.ts +3 -3
- package/src/device/motion.ts +1 -1
- package/src/device/plug.ts +2 -2
- package/src/device/robotvacuumcleaner.ts +2 -2
- package/src/device/waterdetector.ts +1 -1
- package/src/platform.ts +9 -3
- package/src/types/bledevicestatus.ts +4 -4
- 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
|
-
|
|
597
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.')
|