homebridge-bthome
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -6,2 +6,3 @@ import { BluetoothDevice } from './types.js'; | ||
private readonly events; | ||
private started; | ||
constructor(serviceUuid: string); | ||
@@ -8,0 +9,0 @@ start(timeout?: number): Promise<void>; |
@@ -8,2 +8,3 @@ import noble from '@stoprocent/noble'; | ||
events = new EventEmitter(); | ||
started = false; | ||
constructor(serviceUuid) { | ||
@@ -13,6 +14,7 @@ this.serviceUuid = serviceUuid.toLocaleLowerCase(); | ||
async start(timeout) { | ||
noble.on('discover', this.onDiscoverInternal.bind(this)); | ||
try { | ||
await noble.waitForPoweredOn(timeout); | ||
noble.on('discover', this.onDiscoverInternal.bind(this)); | ||
await noble.startScanningAsync([this.serviceUuid], true); | ||
this.started = true; | ||
} | ||
@@ -28,2 +30,5 @@ catch (error) { | ||
async stop() { | ||
if (!this.started) { | ||
return; | ||
} | ||
return noble.stopScanningAsync(); | ||
@@ -30,0 +35,0 @@ } |
@@ -36,9 +36,13 @@ import { BTHomeAccessory } from './platformAccessory.js'; | ||
async discoverDevices() { | ||
if (!this.config.devices || this.config.devices.length === 0) { | ||
this.log.warn('No devices configured'); | ||
return; | ||
} | ||
try { | ||
await this.scanner.start(this.config.bluetooth?.powerOnTimeout); | ||
this.scanner.onDiscover(this.onDeviceDiscovered.bind(this)); | ||
await this.scanner.start(this.config.bluetooth?.powerOnTimeout); | ||
this.log.info('Bluetooth scanner started'); | ||
} | ||
catch (error) { | ||
this.log.error('Failed to initialize bluetooth scanner: ', error); | ||
this.log.error('Failed to initialize bluetooth scanner:', error); | ||
} | ||
@@ -45,0 +49,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"type": "module", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "A homebridge plugin that adds support for bluetooth devices that use BTHome protocol.", | ||
@@ -8,0 +8,0 @@ "author": "Boris Yonchev", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
59300
731