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) {
console.log("tradfri_deviceUpdated", device.instanceId, device.name)
if (device.type === tradfriLib.AccessoryTypes.lightbulb) {
// remember it
lightbulbs[device.instanceId] = device;
}
}
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)
}
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)
}
} else if (device.type === AccessoryTypes.remote) {
// fill and update the node-tradfri-client remote api object
// remember it
} else if (device.type === AccessoryTypes.motionSensor) {
// fill and update the node-tradfri-client motionsensor api object
// remember it
} else if (device.type === AccessoryTypes.blind) {
if (that.trApiBlinds[device.instanceId] === undefined) {
that.trApiBlinds[device.instanceId] = device
that.log.info('new Blind %s found', device.instanceId)
var tdevice = new TradfriBlind(that, device.instanceId) // (plugin, id)
that.mappedDevices[device.instanceId] = tdevice
}
} else {
// remember it
}
}
// 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)
}
} else if (device.type === AccessoryTypes.remote) {
// fill and update the node-tradfri-client remote api object
// remember it
} else if (device.type === AccessoryTypes.motionSensor) {
// fill and update the node-tradfri-client motionsensor api object
// remember it
} else if (device.type === AccessoryTypes.blind) {
if (that.trApiBlinds[device.instanceId] === undefined) {
that.trApiBlinds[device.instanceId] = device
that.log.info('new Blind %s found', device.instanceId)
var tdevice = new TradfriBlind(that, device.instanceId) // (plugin, id)
that.mappedDevices[device.instanceId] = tdevice
}
} else {
// remember it
// this.trApiLightbulbs = {}
// this.trApiGroups = {}
// this.trApiScenes = {}
if ((this.securityCode == undefined) && (this.securityID == undefined)) {
this.log.warn('No credentials')
return
}
if (this.tradfriUser == undefined) {
this.securityCode = undefined
}
this.tradfri = new TradfriClient(that.bridgeIp, function(message, severity) {
if (severity !== 'silly') {
that.log.debug('%s - %s', severity, message)
}
});
// Check if we have to authenticate
if ((this.securityCode == undefined) || (this.tradfriUser == undefined)) {
this.log.warn('we have to authenticate first')
this.tradfri.authenticate(this.securityID).then((identity, psk) => {
// work with the result
that.log.info('Identity is %s psk is %s', identity, psk)
that.tradfriUser = identity
that.securityCode = psk
that.configuration.setValueForPlugin(that.name, "tradfri_securityCode", that.securityCode);
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;
}
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;
}
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;
}
const { hostname, identity, psk } = require('./config.json');
const { TradfriClient } = require('node-tradfri-client');
const tradfri = new TradfriClient(hostname, {
customLogger: (msg, severity) => {
switch (severity) {
case 'silly':
break;
case 'debug':
console.log('\x1b[2m%s\x1b[0m', '[DEBUG]', msg);
break;
case 'info':
console.info('\x1b[34m%s\x1b[0m', '[INFO]', msg);
break;
case 'warn':
console.warn('\x1b[33m%s\x1b[0m', '[WARN]', msg);
break;
case 'error':
console.error('\x1b[31m%s\x1b[0m', '[ERROR]', msg);
break;
group.deviceIDs.forEach(deviceID => {
if ((groupType === 0) && (that.trApiDevices[deviceID] === AccessoryTypes.lightbulb)) {
groupType = 1;
}
if ((groupType === 0) && (that.trApiDevices[deviceID] === AccessoryTypes.blind)) {
groupType = 2;
}
});