diff --git a/src/data/errors.js b/src/data/errors.js index 32004be..52a045d 100644 --- a/src/data/errors.js +++ b/src/data/errors.js @@ -11,6 +11,7 @@ const errors = { const customErrors = { ch404: 'Device channel does not exist', unknown: 'An unknown error occurred', + noARP: 'No ARP information found. You need to generate the ARP file.', noDevice: 'No device found', noDevices: 'No devices found', noPower: 'No power usage data found', diff --git a/src/mixins/getDeviceIP.js b/src/mixins/getDeviceIP.js index db2e109..fdcea75 100644 --- a/src/mixins/getDeviceIP.js +++ b/src/mixins/getDeviceIP.js @@ -1,3 +1,5 @@ +const errors = require('../data/errors'); + module.exports = { /** * Get local IP address from a given MAC @@ -6,10 +8,16 @@ module.exports = { * @returns {Promise} */ getDeviceIP(device) { - const mac = device.extra.extra.staMac; + if (!this.arpTable) { + throw new Error(errors.noARP); + } + + const mac = device.extra.staMac; + const arpItem = this.arpTable.find( - item => item.mac.toLowerCase() === mac.toLowerCase() + (item) => item.mac.toLowerCase() === mac.toLowerCase() ); + return arpItem.ip; }, };