Skip to content

Commit

Permalink
v3.8.1 (#1044)
Browse files Browse the repository at this point in the history
##
[3.8.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v3.8.1)
(2024-09-13)

### What's Changed
- Improved logging mechanism to avoid repetitive logs.
- Housekeeping and updated dependencies.

**Full Changelog**:
v3.8.0...v3.8.1
  • Loading branch information
donavanbecker committed Sep 13, 2024
1 parent 75340ab commit 5f80e6c
Show file tree
Hide file tree
Showing 11 changed files with 294 additions and 403 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

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

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

### What's Changed
- Improved logging mechanism to avoid repetitive logs.
- Housekeeping and updated dependencies.

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

## [3.8.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v3.8.0) (2024-09-11)

### What's Changed
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![discord-switchbot](https://badgen.net/discord/online-members/5wYTbwP4ha?icon=discord&label=discord)](https://discord.gg/5wYTbwP4ha)

<p>The Homebridge <a href="https://www.switch-bot.com">SwitchBot</a> plugin allows you to access your SwitchBot Device(s) from HomeKit with
<a href="https://homebridge.io">Homebridge</a>.
<a href="https://homebridge.io">Homebridge</a>.
</p>

</span>
Expand Down Expand Up @@ -56,20 +56,22 @@
1. `bluetoothctl` must be installed on the device, otherwise it cannot communicate via Bluetooth. Enable it with `sudo bluetoothctl power on`.

2. If errors occur, while enabling it, restart the process:

- `rfkill block bluetooth`
- `rfkill unblock bluetooth`

3. Also make sure, that the computer can discover the SwitchBot device:
3. Also make sure, that the computer can discover the SwitchBot device:

- `sudo bluetoothctl`
- `scan on`

This lists all discovered Bluetooth devices. The BLE address of the SwitchBot device should be included in this list, otherwise your computer does not discover it.

- ### If using MacOS
1. Manually grant Bluetooth access in System Settings UI for `Security & Privacy -> Privacy` to the node executable, eg `/usr/local/bin/node`
![Security & Privacy -> Privacy](assets/security-privacy-bluetooth.png)
(This is what is intended in documentation for the noble bluetooth package [prerequisites](https://github.com/abandonware/noble#prerequisites) by "Add terminal app", however for HomeBridge it is `node` that needs the permission granted, not `terminal`.
Without this step, then you will receive the following error when the swichbot plugin launches, which will cause Homebridge or the child bridge process to restart:
![Security & Privacy -> Privacy](assets/security-privacy-bluetooth.png)
(This is what is intended in documentation for the noble bluetooth package [prerequisites](https://github.com/abandonware/noble#prerequisites) by "Add terminal app", however for HomeBridge it is `node` that needs the permission granted, not `terminal`.
Without this step, then you will receive the following error when the swichbot plugin launches, which will cause Homebridge or the child bridge process to restart:
```
Error: Failed to initialize the Noble object: unauthorized
at Noble.<anonymous> (file:///usr/local/lib/node_modules/@switchbot/homebridge-switchbot/node_modules/node-switchbot/src/switchbot.ts:244:19)
Expand Down
1 change: 0 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export default antfu(
'import/order': 0,
'jsdoc/check-alignment': 'error',
'jsdoc/check-line-alignment': 'error',
'no-undef': 'error',
'perfectionist/sort-exports': 'error',
'perfectionist/sort-imports': [
'error',
Expand Down
575 changes: 241 additions & 334 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 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.0",
"version": "3.8.1",
"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 @@ -81,21 +81,21 @@
"async-mqtt": "^2.6.3",
"fakegato-history": "^0.6.5",
"homebridge-lib": "^7.0.8",
"node-switchbot": "2.3.0",
"node-switchbot": "2.4.0",
"rxjs": "^7.8.1",
"undici": "^6.19.8"
},
"devDependencies": {
"@antfu/eslint-config": "^3.5.1",
"@antfu/eslint-config": "^3.6.0",
"@types/aes-js": "^3.1.4",
"@types/debug": "^4.1.12",
"@types/fs-extra": "^11.0.4",
"@types/jest": "^29.5.12",
"@types/jest": "^29.5.13",
"@types/mdast": "^4.0.4",
"@types/node": "^22.5.4",
"@types/semver": "^7.5.8",
"@types/source-map-support": "^0.5.10",
"@vitest/coverage-v8": "^2.0.5",
"@vitest/coverage-v8": "^2.1.0",
"eslint": "^9.10.0",
"eslint-plugin-format": "^0.1.2",
"homebridge": "^1.8.4",
Expand All @@ -108,7 +108,7 @@
"typedoc": "^0.26.7",
"typescript": "^5.6.2",
"typescript-axios-wb": "^1.0.3",
"vitest": "^2.0.5"
"vitest": "^2.1.0"
},
"directories": {
"doc": "docs"
Expand Down
48 changes: 12 additions & 36 deletions src/device/curtain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class Curtain extends deviceBase {
serviceData!: curtainServiceData | curtain3ServiceData

// Target
hasLoggedStandby!: boolean
setNewTarget!: boolean
setNewTargetTimer!: NodeJS.Timeout

Expand Down Expand Up @@ -202,7 +203,7 @@ export class Curtain extends deviceBase {
accessory.context.OpenModeSwitch = this.OpenModeSwitch as object

// Initialize Open Mode Switch Service
this.OpenModeSwitch.Service.setCharacteristic(this.hap.Characteristic.Name, this.OpenModeSwitch.Name).getCharacteristic(this.hap.Characteristic.On).onGet(() => {
this.OpenModeSwitch.Service.setCharacteristic(this.hap.Characteristic.Name, this.OpenModeSwitch.Name).setCharacteristic(this.hap.Characteristic.ConfiguredName, this.OpenModeSwitch.Name).getCharacteristic(this.hap.Characteristic.On).onGet(() => {
return this.OpenModeSwitch?.On ?? false
})

Expand Down Expand Up @@ -230,7 +231,7 @@ export class Curtain extends deviceBase {
accessory.context.CloseModeSwitch = this.CloseModeSwitch as object

// Initialize Close Mode Switch Service
this.CloseModeSwitch.Service.setCharacteristic(this.hap.Characteristic.Name, this.CloseModeSwitch.Name).getCharacteristic(this.hap.Characteristic.On).onGet(() => {
this.CloseModeSwitch.Service.setCharacteristic(this.hap.Characteristic.Name, this.CloseModeSwitch.Name).setCharacteristic(this.hap.Characteristic.ConfiguredName, this.CloseModeSwitch.Name).getCharacteristic(this.hap.Characteristic.On).onGet(() => {
return this.CloseModeSwitch?.On ?? false
})

Expand Down Expand Up @@ -401,37 +402,7 @@ export class Curtain extends deviceBase {
await this.debugLog(`(slidePosition, battery, version) = OpenAPI:(${this.deviceStatus.slidePosition}, ${this.deviceStatus.battery}, ${this.deviceStatus.version}), current:(${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel}, ${this.accessory.context.version})`)
// CurrentPosition
this.WindowCovering.CurrentPosition = 100 - this.deviceStatus.slidePosition
await this.setMinMax()
await this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
if (this.setNewTarget || this.deviceStatus.moving) {
await this.infoLog('Checking Status ...')
this.curtainMoving = true
await this.setMinMax()
if (Number(this.WindowCovering.TargetPosition) > this.WindowCovering.CurrentPosition) {
await this.debugLog(`Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
await this.debugLog(`Increasing, PositionState: ${this.WindowCovering.PositionState}`)
} else if (Number(this.WindowCovering.TargetPosition) < this.WindowCovering.CurrentPosition) {
await this.debugLog(`Opening, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
await this.debugLog(`Decreasing, PositionState: ${this.WindowCovering.PositionState}`)
} else {
await this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`)
}
} else {
await this.infoLog('Standby ...')
this.curtainMoving = false
await this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`)
}
await this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition}, PositionState: ${this.WindowCovering.PositionState},`)
await this.getCurrentPostion()

// Brightness
if (!this.device.curtain?.hide_lightsensor && this.LightSensor?.Service) {
Expand Down Expand Up @@ -848,10 +819,12 @@ export class Curtain extends deviceBase {
return { setPositionMode, Mode }
}

async getCurrentPostion() {
async getCurrentPostion(): Promise<void> {
await this.setMinMax()
await this.debugLog(`CurrentPosition ${this.WindowCovering.CurrentPosition}`)
if (this.setNewTarget) {
this.hasLoggedStandby = this.hasLoggedStandby ?? false
if (this.setNewTarget || this.deviceStatus.moving) {
this.hasLoggedStandby = false
this.infoLog('Checking Status ...')
this.curtainMoving = true
await this.setMinMax()
Expand All @@ -872,7 +845,10 @@ export class Curtain extends deviceBase {
await this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`)
}
} else {
await this.infoLog('Standby ...')
if (!this.hasLoggedStandby) {
await this.infoLog('Standby ...')
this.hasLoggedStandby = true
}
this.curtainMoving = false
await this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition
Expand Down
4 changes: 2 additions & 2 deletions src/device/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ export class Hub extends deviceBase {

async BLEparseStatus(): Promise<void> {
await this.debugLog('BLEparseStatus')
await this.debugLog(`(temperature, humidity, lightLevel) = BLE:(${this.serviceData.temperature}, ${this.serviceData.humidity}, ${this.serviceData.lightLevel}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity}, ${this.LightSensor?.CurrentAmbientLightLevel})`)
await this.debugLog(`(temperature, humidity, lightLevel) = BLE:(${this.serviceData.celcius}, ${this.serviceData.humidity}, ${this.serviceData.lightLevel}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity}, ${this.LightSensor?.CurrentAmbientLightLevel})`)

// CurrentTemperature
if (!this.device.hub?.hide_temperature && this.TemperatureSensor?.Service) {
this.TemperatureSensor.CurrentTemperature = this.serviceData.temperature.c
this.TemperatureSensor.CurrentTemperature = this.serviceData.celcius
await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`)
}

Expand Down
4 changes: 2 additions & 2 deletions src/device/iosensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export class IOSensor extends deviceBase {

async BLEparseStatus(): Promise<void> {
await this.debugLog('BLEparseStatus')
await this.debugLog(`(battery, temperature, humidity) = BLE:(${this.serviceData.battery}, ${this.serviceData.temperature.c}, ${this.serviceData.humidity}), current:(${this.Battery.BatteryLevel}, ${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity})`)
await this.debugLog(`(battery, temperature, humidity) = BLE:(${this.serviceData.battery}, ${this.serviceData.celcius}, ${this.serviceData.humidity}), current:(${this.Battery.BatteryLevel}, ${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity})`)

// BatteryLevel
this.Battery.BatteryLevel = this.serviceData.battery
Expand All @@ -200,7 +200,7 @@ export class IOSensor extends deviceBase {

// Current Temperature
if (!this.device.meter?.hide_temperature && this.TemperatureSensor?.Service) {
const CELSIUS = this.serviceData.temperature.c < 0 ? 0 : this.serviceData.temperature.c > 100 ? 100 : this.serviceData.temperature.c
const CELSIUS = this.serviceData.celcius < 0 ? 0 : this.serviceData.celcius > 100 ? 100 : this.serviceData.celcius
this.TemperatureSensor.CurrentTemperature = CELSIUS
await this.debugLog(`Temperature: ${this.TemperatureSensor.CurrentTemperature}°c`)
}
Expand Down
4 changes: 2 additions & 2 deletions src/device/meter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class Meter extends deviceBase {

async BLEparseStatus(): Promise<void> {
await this.debugLog('BLEparseStatus')
await this.debugLog(`(scale, temperature, humidity) = BLE:(${this.serviceData.fahrenheit}, ${this.serviceData.temperature.c}, ${this.serviceData.humidity}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity})`)
await this.debugLog(`(scale, temperature, humidity) = BLE:(${this.serviceData.fahrenheit}, ${this.serviceData.celcius}, ${this.serviceData.humidity}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity})`)

// CurrentRelativeHumidity
if (!this.device.iosensor?.hide_humidity && this.HumiditySensor?.Service) {
Expand All @@ -183,7 +183,7 @@ export class Meter extends deviceBase {

// Current Temperature
if (!this.device.meter?.hide_temperature && this.TemperatureSensor?.Service) {
const CELSIUS = this.serviceData.temperature.c < 0 ? 0 : this.serviceData.temperature.c > 100 ? 100 : this.serviceData.temperature.c
const CELSIUS = this.serviceData.celcius < 0 ? 0 : this.serviceData.celcius > 100 ? 100 : this.serviceData.celcius
this.TemperatureSensor.CurrentTemperature = CELSIUS
await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`)
}
Expand Down
4 changes: 2 additions & 2 deletions src/device/meterplus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export class MeterPlus extends deviceBase {

async BLEparseStatus(): Promise<void> {
await this.debugLog('BLEparseStatus')
await this.debugLog(`(temperature, humidity) = BLE:(${this.serviceData.temperature.c}, ${this.serviceData.humidity}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity})`)
await this.debugLog(`(temperature, humidity) = BLE:(${this.serviceData.celcius}, ${this.serviceData.humidity}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity})`)

// CurrentRelativeHumidity
if (!this.device.iosensor?.hide_humidity && this.HumiditySensor?.Service) {
Expand All @@ -187,7 +187,7 @@ export class MeterPlus extends deviceBase {
}
// Current Temperature
if (!this.device.meter?.hide_temperature && this.TemperatureSensor?.Service) {
const CELSIUS = this.serviceData.temperature.c < 0 ? 0 : this.serviceData.temperature.c > 100 ? 100 : this.serviceData.temperature.c
const CELSIUS = this.serviceData.celcius < 0 ? 0 : this.serviceData.celcius > 100 ? 100 : this.serviceData.celcius
this.TemperatureSensor.CurrentTemperature = CELSIUS
await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`)
}
Expand Down
25 changes: 12 additions & 13 deletions src/types/bledevicestatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ export type meterServiceData = serviceData & {
model: SwitchBotBLEModel.Meter
modelName: SwitchBotBLEModelName.Meter
modelFriendlyName: SwitchBotBLEModelFriendlyName.Meter
temperature: temperature
fahrenheit: boolean
celcius: number
fahrenheit: number
fahrenheit_mode: boolean
humidity: number
battery: number
}
Expand All @@ -150,8 +151,9 @@ export type meterPlusServiceData = serviceData & {
model: SwitchBotBLEModel.MeterPlus
modelName: SwitchBotBLEModelName.MeterPlus
modelFriendlyName: SwitchBotBLEModelFriendlyName.MeterPlus
temperature: temperature
fahrenheit: boolean
celcius: number
fahrenheit: number
fahrenheit_mode: boolean
humidity: number
battery: number
}
Expand All @@ -160,8 +162,9 @@ export type outdoorMeterServiceData = serviceData & {
model: SwitchBotBLEModel.OutdoorMeter
modelName: SwitchBotBLEModelName.OutdoorMeter
modelFriendlyName: SwitchBotBLEModelFriendlyName.OutdoorMeter
temperature: temperature
fahrenheit: boolean
celcius: number
fahrenheit: number
fahrenheit_mode: boolean
humidity: number
battery: number
}
Expand Down Expand Up @@ -257,8 +260,9 @@ export type hub2ServiceData = serviceData & {
model: SwitchBotBLEModel.Hub2
modelName: SwitchBotBLEModelName.Hub2
modelFriendlyName: SwitchBotBLEModelFriendlyName.Hub2
temperature: temperature
fahrenheit: boolean
celcius: number
fahrenheit: number
fahrenheit_mode: boolean
humidity: number
lightLevel: number
}
Expand Down Expand Up @@ -297,8 +301,3 @@ export type robotVacuumCleanerServiceData = serviceData & {
state: string
battery: number
}

export interface temperature {
c: number
f: number
}

0 comments on commit 5f80e6c

Please sign in to comment.