Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
zigbeeConfig.devices.forEach(device => {
let ieeeAddr = device.ieeeAddr;
const deviceSetup = device;
deviceSetup['toggleStateIsOn'] = false;
switch (device.longPressFunctionality.type) {
case 'sonos':
deviceSetup['longPressAction'] = LongPressAction.SONOS;
deviceSetup['sonosDevice'] = new Sonos(device.longPressFunctionality.sonosIp);
break;
case 'wledBrightness':
deviceSetup['longPressAction'] = LongPressAction.WLED_BRIGHTNESS;
deviceSetup['wledIp'] = device.longPressFunctionality.wledIp;
break;
default:
console.log('Unknown device.longPressFunctionality.type ', device.longPressFunctionality);
}
buttons[ieeeAddr] = deviceSetup;
});
}).then((config) => {
if (config && config.addresses) {
for (const addr of config.addresses) {
const device = new Sonos(addr);
this.addDevice(device).catch(console.warn);
}
}
db.close();
}).catch((e) => {
console.error('Failed to open database:', e);
app.get('/sonos/state', function(req, res){
const sonos = new Sonos(devices[0]);
sonos.getCurrentState().then(state => {
console.log(state);
res.json(state);
});
})
return new Promise(function(resolve,reject) {
var sonosDevice = new sonosInstance(device.specs.address,1400)
sonosDevice.stop(function (err, result) {
if(result) {
resolve({stopped: true});
}
});
});
},
}, function(items) {
if (items.player_ip === '') {
return reject(new Error("Please set your sonos ip in the settings"));
}
SONOS_DEVICE = new Sonos(items.player_ip);
resolve(SONOS_DEVICE);
});
});
return new Promise(function(resolve,reject) {
var sonosDevice = new sonosInstance(device.specs.address,1400)
sonosDevice.currentTrack(function (err, result) {
resolve({
artist: result.artist,
track: result.title,
album: result.album,
length: result.duration,
currentPosition: result.position,
artUrl: result.albumArtURL
});
});
});
},
accessory.log.debug("Target Zone Group Coordinator identified as: %s", JSON.stringify(coordinator));
if (coordinator == undefined) {
accessory.log.debug("Removing coordinator device from %s", JSON.stringify(accessory.device));
accessory.device = coordinator;
}
else {
var bUpdate = false;
if (accessory.device != undefined) {
if (accessory.device.host != coordinator.ip) bUpdate = true;
}
else {
bUpdate = true;
}
if (bUpdate) {
accessory.log("Changing coordinator device from %s to %s (from sonos zone %s) for accessory '%s' in accessory room '%s'.", accessory.device.host, coordinator.ip, coordinator.CurrentZoneName, accessory.name, accessory.room);
accessory.device = new Sonos(coordinator.ip);
}
else {
accessory.log.debug("No coordinator device change required!");
}
}
});
}
device.getZoneInfo((err, info) => {
debug(`sonos found on ${ info.IPAddress } (${ attrs.CurrentZoneName })`)
new Device(attrs.CurrentZoneName, new sonos.Sonos(info.IPAddress))
})
})
return new Promise(function(resolve,reject) {
var sonosDevice = new sonosInstance(device.specs.address,1400)
sonosDevice.play(function (err, result) {
if(result) {
resolve({playing: true});
}
});
});
},
app.get('/sonos/volume', function(req, res){
const sonos = new Sonos(devices[0]);
sonos.getVolume()
.then((volume) => {
res.json(volume);
});
});