Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse Bluetooth vendor IDs #784

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/bluetooth.js
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 @@ -61,6 +62,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 @@ -82,7 +88,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