Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const foundIps = Object.keys(discoveredEncryptedDevices);
adapter.log.debug(deviceId + ': Try to initialize encrypted device with received UDP messages (#IPs: ' + foundIps.length + '): version=' + knownDevices[deviceId].version + ', key=' + knownDevices[deviceId].localKey);
const parser = new MessageParser({version: knownDevices[deviceId].version || 3.3, key: knownDevices[deviceId].localKey});
for (let ip of foundIps) {
if (discoveredEncryptedDevices[ip] === true) continue;
let data;
try {
data = parser.parse(discoveredEncryptedDevices[ip])[0];
}
catch (err) {
adapter.log.debug(deviceId + ': Error on decrypt try: ' + err);
continue;
}
if (!data.payload || !data.payload.gwId || (data.commandByte !== CommandType.UDP && data.commandByte !== CommandType.UDP_NEW)) {
adapter.log.debug(deviceId + ': No relevant Data for decrypt try: ' + JSON.stringify(data));
continue;
}
if (data.payload.gwId === deviceId) {
discoveredEncryptedDevices[data.payload.ip] = true;
initDevice(data.payload.gwId, data.payload.productKey, data.payload, ['name'], callback);
return true;
}
}
adapter.log.info(deviceId + ': None of the discovered devices matches :-(');
callback && callback();
}