@rhizomatics/signalk-bluetti-plugin 1.1.0-alpha → 1.1.1-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/device.js CHANGED
@@ -63,6 +63,11 @@ class BluettiDevice extends EventEmitter {
63
63
 
64
64
  async _connect() {
65
65
  if (this._stopped) return;
66
+ // Cancel any lingering BlueZ connection state (e.g. a previous attempt that
67
+ // timed out on our side but is still in progress inside BlueZ).
68
+ if (!this._connected) {
69
+ try { await this._device.disconnect(); } catch (_) {}
70
+ }
66
71
  this._log(`[${this._name}] Connecting to ${this._address} …`);
67
72
 
68
73
  // Clear any stale disconnect handler from a previous attempt.
package/lib/scanner.js CHANGED
@@ -70,17 +70,22 @@ class Scanner extends EventEmitter {
70
70
  return;
71
71
  }
72
72
  for (const addr of addresses) {
73
+ if (!this._scanning) break; // scanner stopped while we were iterating
73
74
  const normAddr = addr.toLowerCase().replace(/:/g, '');
74
75
  if (this._found.has(normAddr)) continue;
76
+ // Reserve the slot immediately to prevent concurrent _poll() calls from
77
+ // both processing the same address before either stores the device.
78
+ this._found.set(normAddr, null);
75
79
  try {
76
80
  const device = await this._adapter.getDevice(addr);
77
81
  const name = await Promise.resolve(device.getName()).catch(() => '') || '';
78
- if (!isBluettiDevice(name)) continue;
82
+ if (!this._scanning) break;
83
+ if (!isBluettiDevice(name)) { this._found.delete(normAddr); continue; }
79
84
  this._found.set(normAddr, { address: addr, name, device });
80
85
  this._log(`Discovered Bluetti device: ${name} [${addr}]`);
81
86
  this.emit('discovered', { address: addr, name, device });
82
87
  } catch (_) {
83
- // Device may have disappeared before we could read it; skip
88
+ this._found.delete(normAddr); // allow retry on transient D-Bus error
84
89
  }
85
90
  }
86
91
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhizomatics/signalk-bluetti-plugin",
3
- "version": "1.1.0-alpha",
3
+ "version": "1.1.1-alpha",
4
4
  "signalk": {
5
5
  "displayName": "Bluetti Monitoring"
6
6
  },