Skip to content

Commit

Permalink
try to allow bluetooth on macs
Browse files Browse the repository at this point in the history
  • Loading branch information
bwp91 committed Dec 8, 2024
1 parent 4dc4fa2 commit 0175fbe
Show file tree
Hide file tree
Showing 6 changed files with 827 additions and 1,367 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This project tries to adhere to [Semantic Versioning](http://semver.org/). In pr
### Added

- add matter ignore list and config opt
- try to allow bluetooth on macs

## v10.13.0 (2024-12-08)

Expand Down
2 changes: 1 addition & 1 deletion lib/connection/ble.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Buffer } from 'node:buffer'

import btClient from '@abandonware/noble'
import btClient from '@stoprocent/noble'

import {
base64ToHex,
Expand Down
14 changes: 3 additions & 11 deletions lib/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,29 +507,22 @@ export default class {
throw new Error(platformLang.disabledInConfig)
}

const thisPlatform = process.platform

// Bluetooth not supported on Mac
if (thisPlatform === 'darwin') {
throw new Error(platformLang.bleMacNoSupp)
}

// See if the bluetooth client is available
/*
Noble sends the plugin into a crash loop if there is no bluetooth adapter available
This if statement follows the logic of Noble up to the offending socket.bindRaw(device)
Put inside a try/catch now to check for error and disable ble control for rest of plugin
*/
if (['linux', 'freebsd', 'win32'].includes(thisPlatform)) {
const { default: BluetoothHciSocket } = await import('@abandonware/bluetooth-hci-socket')
if (['linux', 'freebsd', 'win32'].includes(process.platform)) {
const { default: BluetoothHciSocket } = await import('@stoprocent/bluetooth-hci-socket')
const socket = new BluetoothHciSocket()
const device = process.env.NOBLE_HCI_DEVICE_ID
? Number.parseInt(process.env.NOBLE_HCI_DEVICE_ID, 10)
: undefined
socket.bindRaw(device)
}
try {
await import('@abandonware/noble')
await import('@stoprocent/noble')
} catch (err) {
throw new Error(platformLang.bleNoPackage)
}
Expand All @@ -542,7 +535,6 @@ export default class {
err.message = 'ERR_DLOPEN_FAILED'
}
this.log.warn('[BLE] %s %s.', platformLang.disableClient, parseError(err, [
platformLang.bleMacNoSupp,
platformLang.bleNoPackage,
platformLang.disabledInConfig,
'ENODEV, No such device',
Expand Down
1 change: 0 additions & 1 deletion lib/utils/lang-en.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export default {
availableWithDevices: n => `client enabled and found ${n} device(s)`,
beta: 'You are using a beta version of the plugin - you will experience more logging than normal',
brand: 'Govee',
bleMacNoSupp: 'not supported on mac devices',
bleNonControl: 'will be visible but uncontrollable as BLE not available',
bleNoPackage: 'required hardware/packages not available',
bleScanDisabled: 'sync for thermo-hygrometer sensors disabled as',
Expand Down
Loading

0 comments on commit 0175fbe

Please sign in to comment.