mirror of
https://github.com/skydiver/ewelink-api.git
synced 2025-12-24 06:28:30 +01:00
getDeviceIP: refactor
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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<string>}
|
||||
*/
|
||||
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;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user