Discovery works only on first atempt?

So problem, despite of having logging in the plug-new, that was never triggered 2nd time, was after all in the follow up function checking plugs online… :man_facepalming: :man_facepalming: :man_facepalming:

Working only 1st time

client.on('plug-online', (plug,) => {
                if (plug.model.match(myRegEx) && !devIds.hasOwnProperty(plug.deviceId) && !devIds.hasOwnProperty(plug.childId)) {

                    if (!discoveredDevicesArray.some(device => device.childId === childId)) {
                        this.log("New Socket found online: " + childName + " in " + plug.host + " id " + childId);
                        discoveredDevicesArray.push({
                            ip: plug.host,
                            name: childName,
                            deviceId: plug.deviceId,
                            childId: childId
                        });
                    }
                }
            });

Working everytime

            client.on('plug-online', (plug) => {
                logEvent('Found plug-online type', plug);
                
                if (plug.model.match(myRegEx) && !devIds.hasOwnProperty(plug.deviceId)) {
                    let deviceName = plug.alias || `Device ${plug.deviceId}`;
                    let childId = plug.childId || null; // null for non-child devices
            
                    if (!discoveredDevicesArray.some(device => device.deviceId === plug.deviceId && device.childId === childId)) {
                        this.log(`New Socket found online: ${deviceName} in ${plug.host} with Device ID: ${plug.deviceId} and Child ID: ${childId}`);
                        discoveredDevicesArray.push({
                            ip: plug.host,
                            name: deviceName,
                            deviceId: plug.deviceId,
                            childId: childId
                        });
                    }
                }
            });

What helped me - enabling debug code for the tplink-smarthome-api, which complained about :

[Mock One] plug.emitEvents() inUse: false relayState: false lastState: {"inUse":false,"relayState":false}
client.startDiscovery(): Error processing response: ReferenceError: childName is not defined
    at Client.<anonymous> (/app/drivers/hs300/driver.js:107:64)
    at Client.emit (node:events:529:35)
    at Client.emit (/app/node_modules/tplink-smarthome-api/lib/client.js:158:27)
    at process (/app/node_modules/tplink-smarthome-api/lib/client.js:414:22)
    at /app/node_modules/tplink-smarthome-api/lib/client.js:435:17
    at Array.forEach (<anonymous>)
    at Client.createOrUpdateDeviceFromSysInfo (/app/node_modules/tplink-smarthome-api/lib/client.js:433:30)
    at Socket.<anonymous> (/app/node_modules/tplink-smarthome-api/lib/client.js:342:26)
    at Socket.emit (node:events:517:28)
    at UDP.onMessage [as onmessage] (node:dgram:942:8)