homebridge-bthome
Advanced tools
Comparing version 1.1.0-beta.0 to 1.1.0-beta.1
@@ -8,4 +8,4 @@ import { BluetoothDevice } from './types.js'; | ||
constructor(serviceUuid: string); | ||
getNobleInstance(): Promise<typeof import("@stoprocent/noble")>; | ||
start(timeout?: number): Promise<void>; | ||
stop(): Promise<void>; | ||
onDiscover(callback: (device: BluetoothDevice) => void): void; | ||
@@ -12,0 +12,0 @@ private onDiscoverInternal; |
@@ -1,4 +0,4 @@ | ||
import noble from '@stoprocent/noble'; | ||
import { EventEmitter } from 'events'; | ||
import { BluetoothError } from './types.js'; | ||
import { wrapError } from '../util/errors.js'; | ||
export class BluetoothScanner { | ||
@@ -12,3 +12,23 @@ static DISCOVER_EVENT = 'discover'; | ||
} | ||
async getNobleInstance() { | ||
try { | ||
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; | ||
// @ts-expect-error parameter is not used and can be undefined, but there's a wrong typescript definition in library | ||
socket.bindRaw(device); | ||
} | ||
const module = await import('@stoprocent/noble'); | ||
return module.default; | ||
} | ||
catch (error) { | ||
throw wrapError(error, BluetoothError, 'Failed to instantiate noble'); | ||
} | ||
} | ||
async start(timeout) { | ||
if (this.started) { | ||
return; | ||
} | ||
const noble = await this.getNobleInstance(); | ||
try { | ||
@@ -21,15 +41,5 @@ await noble.waitForPoweredOn(timeout); | ||
catch (error) { | ||
let message = 'Unknown bluetooth error'; | ||
if (error instanceof Error) { | ||
message = error.message; | ||
} | ||
throw new BluetoothError(message); | ||
throw wrapError(error, BluetoothError, 'Unknown bluetooth error'); | ||
} | ||
} | ||
async stop() { | ||
if (!this.started) { | ||
return; | ||
} | ||
return noble.stopScanningAsync(); | ||
} | ||
onDiscover(callback) { | ||
@@ -36,0 +46,0 @@ this.events.on(BluetoothScanner.DISCOVER_EVENT, callback); |
import crypto from 'crypto'; | ||
import { EventEmitter } from 'events'; | ||
import { BTHomeDecryptionError, BTHomeDecodingError, ButtonEvent } from './types.js'; | ||
import { wrapError } from '../util/errors.js'; | ||
export class BTHomeDevice { | ||
@@ -80,7 +81,3 @@ static UUID = 'FCD2'; | ||
catch (error) { | ||
let message = 'Unknown decryption error'; | ||
if (error instanceof Error) { | ||
message = error.message; | ||
} | ||
throw new BTHomeDecryptionError(message); | ||
throw wrapError(error, BTHomeDecryptionError, 'Unknown decryption error'); | ||
} | ||
@@ -87,0 +84,0 @@ } |
@@ -21,6 +21,2 @@ import { BTHomeAccessory } from './platformAccessory.js'; | ||
this.Characteristic = api.hap.Characteristic; | ||
this.api.on('shutdown', async () => { | ||
await this.scanner.stop(); | ||
this.log.debug('Bluetooth scanner stopped'); | ||
}); | ||
this.log.debug('Finished initializing platform:', this.config.platform); | ||
@@ -27,0 +23,0 @@ this.api.on('didFinishLaunching', () => { |
@@ -5,3 +5,3 @@ { | ||
"type": "module", | ||
"version": "1.1.0-beta.0", | ||
"version": "1.1.0-beta.1", | ||
"description": "A homebridge plugin that adds support for bluetooth devices that use BTHome protocol.", | ||
@@ -51,5 +51,8 @@ "author": "Boris Yonchev", | ||
"dependencies": { | ||
"@stoprocent/noble": "^1.18.2", | ||
"homebridge-lib": "^7.1.0" | ||
}, | ||
"optionalDependencies": { | ||
"@stoprocent/bluetooth-hci-socket": "^1.4.4", | ||
"@stoprocent/noble": "^1.18.2" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
62636
31
768
3
2
- Removed@stoprocent/noble@^1.18.2