Skip to content

Commit

Permalink
Discover devices multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
lprhodes committed Apr 26, 2017
1 parent dbc6722 commit be15340
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion helpers/getDevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,28 @@ const broadlink = new BroadlinkJS()

const discoveredDevices = {};

broadlink.discover();
const limit = 5;

const discoverDevices = (count = 0) => {
if (count >= 5) return;

broadlink.discover();
count++;

setTimeout(() => {
discoverDevices(count);
}, 5 * 1000)
}

discoverDevices();

broadlink.on('deviceReady', (device) => {
const macAddressParts = device.mac.toString('hex').match(/[\s\S]{1,2}/g) || []
const macAddress = macAddressParts.join(':')
device.host.macAddress = macAddress

if (discoveredDevices[device.host.address] || discoveredDevices[device.host.macAddress]) return;

console.log(`Discovered Broadlink RM device at ${device.host.address} (${device.host.macAddress})`)

discoveredDevices[device.host.address] = device;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homebridge-broadlink-rm",
"version": "2.0.11",
"version": "2.0.13",
"description": "Broadlink RM plugin (including the mini and pro) for homebridge: https://github.com/nfarina/homebridge",
"license": "ISC",
"keywords": [
Expand Down

0 comments on commit be15340

Please sign in to comment.