Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function tradfri_deviceUpdated(device) {
that.trApiDevices[device.instanceId] = device.type
if (device.type === AccessoryTypes.lightbulb) {
// Create the Devices or update them
if (!that.trApiLightbulbs[device.instanceId]) {
// fill the node-tradfri-client lights api object
that.trApiLightbulbs[device.instanceId] = device
that.log.info('new Lamp %s found', device.instanceId)
var tdevice = new TradfriDevice(that, device.instanceId) // (plugin, id)
that.mappedDevices[device.instanceId] = tdevice
} else {
// update the node-tradfri-client lights api object
that.trApiLightbulbs[device.instanceId] = device
that.log.debug('update Lamp %s', device.instanceId)
}
function marshallDevice({ client, ...device }) {
switch (device.type) {
case AccessoryTypes.motionSensor:
device.sensorList = device.sensorList.map(({ client, ...sensor }) => sensor);
break;
case AccessoryTypes.lightbulb:
case 1:
device.lightList = (device.lightList || []).map(({ client, _accessory, ...light }) => light);
break;
case AccessoryTypes.remote:
device.switchList = device.switchList.map(({ client, ...remote }) => remote);
break;
default:
console.log('Not mapped', device);
}
return device;
}
group.deviceIDs.forEach(deviceID => {
if ((groupType === 0) && (that.trApiDevices[deviceID] === AccessoryTypes.lightbulb)) {
groupType = 1;
}
if ((groupType === 0) && (that.trApiDevices[deviceID] === AccessoryTypes.blind)) {
groupType = 2;
}
});