diff --git a/helpers/getDevice.js b/helpers/getDevice.js index 8f17c4ba..6892ae09 100644 --- a/helpers/getDevice.js +++ b/helpers/getDevice.js @@ -7,17 +7,19 @@ const startPing = (device) => { device.state = 'unknown'; setInterval(() => { - ping.sys.probe(device.host.address, (active) => { - if (!active && device.state === 'active') { - console.log(`Broadlink RM device at ${device.host.address} (${device.host.macAddress || ''}) is no longer reachable.`); + try { + ping.sys.probe(device.host.address, (active) => { + if (!active && device.state === 'active') { + console.log(`Broadlink RM device at ${device.host.address} (${device.host.macAddress || ''}) is no longer reachable.`); - device.state = 'inactive'; - } else if (active && device.state !== 'active') { - if (device.state === 'inactive') console.log(`Broadlink RM device at ${device.host.address} (${device.host.macAddress || ''}) has been re-discovered.`); + device.state = 'inactive'; + } else if (active && device.state !== 'active') { + if (device.state === 'inactive') console.log(`Broadlink RM device at ${device.host.address} (${device.host.macAddress || ''}) has been re-discovered.`); - device.state = 'active'; - } - }) + device.state = 'active'; + } + }) + } catch (err) {} }, pingFrequency); } diff --git a/helpers/ping.js b/helpers/ping.js index b68b4530..705dbf23 100644 --- a/helpers/ping.js +++ b/helpers/ping.js @@ -2,9 +2,13 @@ const ping = require('ping'); const pingIPAddress = (ipAddress, interval, callback) => { setInterval(() => { - ping.sys.probe(ipAddress, (isActive) => { - callback(isActive) - }) + try { + ping.sys.probe(ipAddress, (isActive) => { + callback(isActive) + }) + } catch (err) { + callback(false) + } }, interval * 1000); } diff --git a/yarn.lock b/yarn.lock index 92c28c16..bd0a5d13 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1657,9 +1657,9 @@ home-or-tmp@^2.0.0: os-homedir "^1.0.0" os-tmpdir "^1.0.1" -homebridge-platform-helper@1.0.7: - version "1.0.7" - resolved "https://registry.yarnpkg.com/homebridge-platform-helper/-/homebridge-platform-helper-1.0.7.tgz#014f53984a776573faa8cde6e34374e9ee460e63" +homebridge-platform-helper@1.0.8: + version "1.0.8" + resolved "https://registry.yarnpkg.com/homebridge-platform-helper/-/homebridge-platform-helper-1.0.8.tgz#42aa99d1d7a9e613614115a1855fde48ff320dcf" dependencies: node-persist "^2.0.10" semver "^5.3.0"