Skip to content

Commit

Permalink
Merge pull request #784 from schontz/master
Browse files Browse the repository at this point in the history
Parse Bluetooth vendor IDs
  • Loading branch information
sebhildebrandt authored Dec 25, 2024
2 parents 1260778 + d4d00f0 commit e24054f
Show file tree
Hide file tree
Showing 2 changed files with 547 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/bluetooth.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const exec = require('child_process').exec;
const execSync = require('child_process').execSync;
const path = require('path');
const util = require('./util');
const bluetoothVendors = require('./bluetoothVendors');
const fs = require('fs');

let _platform = process.platform;
Expand Down Expand Up @@ -63,6 +64,11 @@ function parseBluetoothManufacturer(str) {
return result;
}

function parseBluetoothVendor(str) {
const id = parseInt(str);
if (!isNaN(id)) return bluetoothVendors[id];
}

function parseLinuxBluetoothInfo(lines, macAddr1, macAddr2) {
const result = {};

Expand All @@ -84,7 +90,7 @@ function parseDarwinBluetoothDevices(bluetoothObject, macAddr2) {

result.device = bluetoothObject.device_services || '';
result.name = bluetoothObject.device_name || '';
result.manufacturer = bluetoothObject.device_manufacturer || parseBluetoothManufacturer(bluetoothObject.device_name || '') || '';
result.manufacturer = bluetoothObject.device_manufacturer || parseBluetoothVendor(bluetoothObject.device_vendorID) || parseBluetoothManufacturer(bluetoothObject.device_name || '') || '';
result.macDevice = (bluetoothObject.device_addr || bluetoothObject.device_address || '').toLowerCase().replace(/-/g, ':');
result.macHost = macAddr2;
result.batteryPercent = bluetoothObject.device_batteryPercent || null;
Expand Down
Loading

0 comments on commit e24054f

Please sign in to comment.