Skip to content

Commit

Permalink
v3.8.2 (#1049)
Browse files Browse the repository at this point in the history
## [3.8.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v3.8.2) (2024-09-19)

### What's Changed
- Improved macAddress format and finding of invalid formating.
- Fixed temperature reading issue for Hub 2, Indoor/Outdoor Sensor, Meter, & Meter Plus [#1024](#1024), Thanks [@azmke](https://github.com/azmke)
- Housekeeping and updated dependencies.

**Full Changelog**: v3.8.1...v3.8.2
  • Loading branch information
donavanbecker committed Sep 19, 2024
1 parent 5f80e6c commit 3ea2fde
Show file tree
Hide file tree
Showing 25 changed files with 1,204 additions and 956 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/)

## [3.8.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v3.8.2) (2024-09-19)

### What's Changed
- Improved macAddress format and finding of invalid formating.
- Fixed temperature reading issue for Hub 2, Indoor/Outdoor Sensor, Meter, & Meter Plus [#1024](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/1024), Thanks [@azmke](https://github.com/azmke)
- Housekeeping and updated dependencies.

**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v3.8.1...v3.8.2

## [3.8.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v3.8.1) (2024-09-13)

### What's Changed
Expand Down
553 changes: 277 additions & 276 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@switchbot/homebridge-switchbot",
"displayName": "SwitchBot",
"type": "module",
"version": "3.8.1",
"version": "3.8.2",
"description": "The SwitchBot plugin allows you to access your SwitchBot device(s) from HomeKit.",
"author": "SwitchBot <support@wondertechlabs.com> (https://github.com/SwitchBot)",
"contributors": [
Expand Down Expand Up @@ -86,29 +86,29 @@
"undici": "^6.19.8"
},
"devDependencies": {
"@antfu/eslint-config": "^3.6.0",
"@antfu/eslint-config": "^3.6.2",
"@types/aes-js": "^3.1.4",
"@types/debug": "^4.1.12",
"@types/fs-extra": "^11.0.4",
"@types/jest": "^29.5.13",
"@types/mdast": "^4.0.4",
"@types/node": "^22.5.4",
"@types/node": "^22.5.5",
"@types/semver": "^7.5.8",
"@types/source-map-support": "^0.5.10",
"@vitest/coverage-v8": "^2.1.0",
"@vitest/coverage-v8": "^2.1.1",
"eslint": "^9.10.0",
"eslint-plugin-format": "^0.1.2",
"homebridge": "^1.8.4",
"homebridge-config-ui-x": "4.58.0",
"jest": "^29.7.0",
"nodemon": "^3.1.4",
"npm-check-updates": "^17.1.1",
"nodemon": "^3.1.6",
"npm-check-updates": "^17.1.2",
"shx": "^0.3.4",
"ts-node": "^10.9.2",
"typedoc": "^0.26.7",
"typescript": "^5.6.2",
"typescript-axios-wb": "^1.0.3",
"vitest": "^2.1.0"
"vitest": "^2.1.1"
},
"directories": {
"doc": "docs"
Expand Down
83 changes: 47 additions & 36 deletions src/device/blindtilt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type { blindTiltWebhookContext } from '../types/devicewebhookstatus.js'
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot'
import { debounceTime, interval, skipWhile, Subject, take, tap } from 'rxjs'

import { BlindTiltMappingMode } from '../utils.js'
import { BlindTiltMappingMode, formatDeviceIdAsMac } from '../utils.js'
import { deviceBase } from './device.js'

export class BlindTilt extends deviceBase {
Expand Down Expand Up @@ -482,17 +482,22 @@ export class BlindTilt extends deviceBase {
await this.debugLog('registerPlatformBLE')
if (this.config.options?.BLE) {
await this.debugLog('is listening to Platform BLE.')
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase()
await this.debugLog(`bleMac: ${this.device.bleMac}`)
this.platform.bleEventHandler[this.device.bleMac] = async (context: blindTiltServiceData) => {
try {
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
this.serviceData = context
await this.BLEparseStatus()
await this.updateHomeKitCharacteristics()
} catch (e: any) {
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
try {
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
this.device.bleMac = formattedDeviceId
await this.debugLog(`bleMac: ${this.device.bleMac}`)
this.platform.bleEventHandler[this.device.bleMac] = async (context: blindTiltServiceData) => {
try {
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
this.serviceData = context
await this.BLEparseStatus()
await this.updateHomeKitCharacteristics()
} catch (e: any) {
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
}
}
} catch (error) {
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
}
} else {
await this.debugLog('is not listening to Platform BLE')
Expand Down Expand Up @@ -563,32 +568,38 @@ export class BlindTilt extends deviceBase {
if (this.WindowCovering.TargetPosition !== this.WindowCovering.CurrentPosition) {
await this.debugLog(`BLEpushChanges On: ${this.WindowCovering.TargetPosition} OnCached: ${this.WindowCovering.CurrentPosition}`)
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
await this.convertBLEAddress()
const { setPositionMode, Mode }: { setPositionMode: number, Mode: string } = await this.setPerformance()
await this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`)
if (switchbot !== false) {
switchbot
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
.then(async (device_list: any) => {
return await this.retryBLE({
max: await this.maxRetryBLE(),
fn: async () => {
return await device_list[0].runToPos(100 - Number(this.WindowCovering.TargetPosition), setPositionMode)
},
try {
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
this.device.bleMac = formattedDeviceId
await this.debugLog(`bleMac: ${this.device.bleMac}`)
const { setPositionMode, Mode }: { setPositionMode: number, Mode: string } = await this.setPerformance()
await this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`)
if (switchbot !== false) {
switchbot
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
.then(async (device_list: any) => {
return await this.retryBLE({
max: await this.maxRetryBLE(),
fn: async () => {
return await device_list[0].runToPos(100 - Number(this.WindowCovering.TargetPosition), setPositionMode)
},
})
})
})
.then(async () => {
await this.successLog(`TargetPostion: ${this.WindowCovering.TargetPosition} sent over SwitchBot BLE, sent successfully`)
await this.updateHomeKitCharacteristics()
})
.catch(async (e: any) => {
await this.apiError(e)
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
await this.BLEPushConnection()
})
} else {
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
await this.BLEPushConnection()
.then(async () => {
await this.successLog(`TargetPostion: ${this.WindowCovering.TargetPosition} sent over SwitchBot BLE, sent successfully`)
await this.updateHomeKitCharacteristics()
})
.catch(async (e: any) => {
await this.apiError(e)
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
await this.BLEPushConnection()
})
} else {
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
await this.BLEPushConnection()
}
} catch (error) {
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
}
} else {
await this.debugLog(`No changes (BLEpushChanges), TargetPosition: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
Expand Down
130 changes: 71 additions & 59 deletions src/device/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type { botWebhookContext } from '../types/devicewebhookstatus.js'
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot'
import { debounceTime, interval, skipWhile, Subject, take, tap } from 'rxjs'

import { formatDeviceIdAsMac } from '../utils.js'
import { deviceBase } from './device.js'

/**
Expand Down Expand Up @@ -575,17 +576,22 @@ export class Bot extends deviceBase {
await this.debugLog('registerPlatformBLE')
if (this.config.options?.BLE) {
await this.debugLog('is listening to Platform BLE.')
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase()
await this.debugLog(`bleMac: ${this.device.bleMac}`)
this.platform.bleEventHandler[this.device.bleMac] = async (context: botServiceData) => {
try {
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
this.serviceData = context
await this.BLEparseStatus()
await this.updateHomeKitCharacteristics()
} catch (e: any) {
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
try {
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
this.device.bleMac = formattedDeviceId
await this.debugLog(`bleMac: ${this.device.bleMac}`)
this.platform.bleEventHandler[this.device.bleMac] = async (context: botServiceData) => {
try {
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
this.serviceData = context
await this.BLEparseStatus()
await this.updateHomeKitCharacteristics()
} catch (e: any) {
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
}
}
} catch (error) {
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
}
} else {
await this.debugLog('is not listening to Platform BLE')
Expand Down Expand Up @@ -663,57 +669,63 @@ export class Bot extends deviceBase {
if (this.On !== this.accessory.context.On || this.allowPush) {
await this.debugLog(`BLEpushChanges On: ${this.On} OnCached: ${this.accessory.context.On}`)
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
await this.convertBLEAddress()
// if (switchbot !== false) {
await this.debugLog(`Bot Mode: ${this.botMode}`)
if (this.botMode === 'press') {
switchbot
.discover({ model: 'H', quick: true, id: this.device.bleMac })
.then(async (device_list: { press: (arg0: { id: string | undefined }) => any }[]) => {
await this.infoLog(`On: ${this.On}`)
return await device_list[0].press({ id: this.device.bleMac })
})
.then(async () => {
await this.successLog(`On: ${this.On} sent over SwitchBot BLE, sent successfully`)
await this.updateHomeKitCharacteristics()
setTimeout(async () => {
this.On = false
try {
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
this.device.bleMac = formattedDeviceId
await this.debugLog(`bleMac: ${this.device.bleMac}`)
// if (switchbot !== false) {
await this.debugLog(`Bot Mode: ${this.botMode}`)
if (this.botMode === 'press') {
switchbot
.discover({ model: 'H', quick: true, id: this.device.bleMac })
.then(async (device_list: { press: (arg0: { id: string | undefined }) => any }[]) => {
await this.infoLog(`On: ${this.On}`)
return await device_list[0].press({ id: this.device.bleMac })
})
.then(async () => {
await this.successLog(`On: ${this.On} sent over SwitchBot BLE, sent successfully`)
await this.updateHomeKitCharacteristics()
this.debugLog(`On: ${this.On}, Switch Timeout`)
}, 500)
})
.catch(async (e: any) => {
await this.apiError(e)
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
await this.BLEPushConnection()
})
} else if (this.botMode === 'switch') {
switchbot
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
.then(async (device_list: any) => {
this.infoLog(`On: ${this.On}`)
return await this.retryBLE({
max: await this.maxRetryBLE(),
fn: async () => {
if (this.On) {
return await device_list[0].turnOn({ id: this.device.bleMac })
} else {
return await device_list[0].turnOff({ id: this.device.bleMac })
}
},
setTimeout(async () => {
this.On = false
await this.updateHomeKitCharacteristics()
this.debugLog(`On: ${this.On}, Switch Timeout`)
}, 500)
})
})
.then(async () => {
await this.successLog(`On: ${this.On} sent over SwitchBot BLE, sent successfully`)
await this.updateHomeKitCharacteristics()
})
.catch(async (e: any) => {
await this.apiError(e)
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
await this.BLEPushConnection()
})
} else {
await this.errorLog(`Device Parameters not set for this Bot, please check the device configuration. Bot Mode: ${this.botMode}`)
.catch(async (e: any) => {
await this.apiError(e)
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
await this.BLEPushConnection()
})
} else if (this.botMode === 'switch') {
switchbot
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
.then(async (device_list: any) => {
this.infoLog(`On: ${this.On}`)
return await this.retryBLE({
max: await this.maxRetryBLE(),
fn: async () => {
if (this.On) {
return await device_list[0].turnOn({ id: this.device.bleMac })
} else {
return await device_list[0].turnOff({ id: this.device.bleMac })
}
},
})
})
.then(async () => {
await this.successLog(`On: ${this.On} sent over SwitchBot BLE, sent successfully`)
await this.updateHomeKitCharacteristics()
})
.catch(async (e: any) => {
await this.apiError(e)
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
await this.BLEPushConnection()
})
} else {
await this.errorLog(`Device Parameters not set for this Bot, please check the device configuration. Bot Mode: ${this.botMode}`)
}
} catch (error) {
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
}
} else {
await this.debugLog(`No Changes (BLEpushChanges), On: ${this.On} OnCached: ${this.accessory.context.On}`)
Expand Down
Loading

0 comments on commit 3ea2fde

Please sign in to comment.