How to use sonos - 10 common examples

To help you get started, we’ve selected a few sonos examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github denysvitali / sonos-web / server.js View on Github external
function init() {
    sonos.DeviceDiscovery(function (device) {
        debug(`Found ZP at ${device.host}:${device.port}`);
        thePlayer = device;
        console.log(thePlayer.getName().then((name) => {
            SonosWeb.menu.playerName = name;
        }));
        //thePlayer.selectQueue();

        var listener = Listener;
        listener.startListener();

        listener.subscribeTo(device).then(result => {
            console.log('Manually subscribed to sonos events')
        })

        // Or start listening for events on the sonos itself, will call the listener in the background
        device.on('CurrentTrack', track => {
github Colorado4Wheeler / Homebridge / EPS Homebridge.indigoPlugin / Contents / Server Plugin / bin / hb / node-v8.4.0-darwin-x64 / lib / node_modules / homebridge-zp / lib / ZPPlatform.js View on Github external
ZPPlatform.prototype.findPlayers = function() {
  SonosModule.search({timeout: this.searchTimeout}, function(zp, model) {
    const deviceProperties = new SonosModule.Services.DeviceProperties(zp.host, zp.port);
    const zoneGroupTopology = new SonosModule.Services.ZoneGroupTopology(zp.host, zp.port);
    const alarmClock = new SonosModule.Services.AlarmClock(zp.host, zp.port);
    zp.model = model;
    deviceProperties.GetZoneAttributes({}, function(err, attrs) {
      if (err) {
        this.log.error('%s:%s: error %s', zp.host, zp.port, err);
      } else {
        zp.zone = attrs.CurrentZoneName;
        // this.log.debug('%s: zone attrs %j', zp.zone, attrs);
        deviceProperties.GetZoneInfo({}, function(err, info) {
          if (err) {
            this.log.error('%s: error %s', zp.zone, err);
          } else {
            // this.log.debug('%s: info %j', zp.zone, info);
            zp.id = 'RINCON_' + info.MACAddress.replace(/:/g, '') +
github Colorado4Wheeler / Homebridge / EPS Homebridge.indigoPlugin / Contents / Server Plugin / bin / hb / node-v8.4.0-darwin-x64 / lib / node_modules / homebridge-zp / lib / ZPPlatform.js View on Github external
SonosModule.search({timeout: this.searchTimeout}, function(zp, model) {
    const deviceProperties = new SonosModule.Services.DeviceProperties(zp.host, zp.port);
    const zoneGroupTopology = new SonosModule.Services.ZoneGroupTopology(zp.host, zp.port);
    const alarmClock = new SonosModule.Services.AlarmClock(zp.host, zp.port);
    zp.model = model;
    deviceProperties.GetZoneAttributes({}, function(err, attrs) {
      if (err) {
        this.log.error('%s:%s: error %s', zp.host, zp.port, err);
      } else {
        zp.zone = attrs.CurrentZoneName;
        // this.log.debug('%s: zone attrs %j', zp.zone, attrs);
        deviceProperties.GetZoneInfo({}, function(err, info) {
          if (err) {
            this.log.error('%s: error %s', zp.zone, err);
          } else {
            // this.log.debug('%s: info %j', zp.zone, info);
            zp.id = 'RINCON_' + info.MACAddress.replace(/:/g, '') +
                    ('00000' + zp.port).substr(-5, 5);
github Colorado4Wheeler / Homebridge / EPS Homebridge.indigoPlugin / Contents / Server Plugin / bin / hb / node-v8.4.0-darwin-x64 / lib / node_modules / homebridge-zp / lib / ZPPlatform.js View on Github external
SonosModule.search({timeout: this.searchTimeout}, function(zp, model) {
    const deviceProperties = new SonosModule.Services.DeviceProperties(zp.host, zp.port);
    const zoneGroupTopology = new SonosModule.Services.ZoneGroupTopology(zp.host, zp.port);
    const alarmClock = new SonosModule.Services.AlarmClock(zp.host, zp.port);
    zp.model = model;
    deviceProperties.GetZoneAttributes({}, function(err, attrs) {
      if (err) {
        this.log.error('%s:%s: error %s', zp.host, zp.port, err);
      } else {
        zp.zone = attrs.CurrentZoneName;
        // this.log.debug('%s: zone attrs %j', zp.zone, attrs);
        deviceProperties.GetZoneInfo({}, function(err, info) {
          if (err) {
            this.log.error('%s: error %s', zp.zone, err);
          } else {
            // this.log.debug('%s: info %j', zp.zone, info);
            zp.id = 'RINCON_' + info.MACAddress.replace(/:/g, '') +
                    ('00000' + zp.port).substr(-5, 5);
            zp.version = info.DisplaySoftwareVersion;
github htilly / zenmusic / index.js View on Github external
/* Initialize Logger */
const logger = winston.createLogger({
    level: logLevel,
    format: winston.format.json(),
    transports: [
        new winston.transports.Console({format: winston.format.combine(winston.format.colorize(), winston.format.simple())})
    ]
});

/* Initialize Sonos */
const SONOS = require('sonos')
const Sonos = SONOS.Sonos
const sonos = new Sonos(config.get('sonos'))

if (market !== 'US') {
  sonos.setSpotifyRegion(SONOS.SpotifyRegion.EU)
  logger.info('Setting Spotify region to EU...')
  logger.info("Market is: " + market)
}

/* Initialize Spotify instance */
const spotify = Spotify({clientId: clientId, clientSecret: clientSecret, market: market, logger: logger})

let gongCounter = 0
let gongScore = {}
const gongLimitPerUser = 1
const gongMessage = [
  'Is it really all that bad?',
  'Is it that distracting?',
  'How much is this worth to you?',
  'I agree. Who added this song anyway?',
  "Thanks! I didn't want to play this song in the first place...",
github jakkra / SmartMirror / util / zigbee.js View on Github external
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;
});
github tim-hellhake / sonos-adapter / adapter.js View on Github external
}).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);
github GPudgima / YT-SONOS / server / index.js View on Github external
app.get('/sonos/state', function(req, res){
    const sonos = new Sonos(devices[0]);
    sonos.getCurrentState().then(state => {
        console.log(state);
        res.json(state);
    });
})
github tomodwyer / airsonos / lib / diagnostics.js View on Github external
module.exports = function diagnostics() {
  console.log("AirSonos Diagnostics");
  console.log("node version\t", process.version);
  console.log("operating sys\t", process.platform, `(${process.arch})`);
  console.log("ip address\t", ip.address());

  console.log("\nSearching for Sonos devices on network...");

  sonos.search((device, model) => {
    let devInfo = "\n";
    devInfo += `Device \t${JSON.stringify(device)} (${model})\n`;
    device.getZoneAttrs((err, attrs) => {
      if (err) devInfo += "`- failed to retrieve zone attributes\n";
      devInfo += `\`- attrs: \t${JSON.stringify(attrs).replace(
        /",/g,
        '",\n\t\t'
      )}\n`;

      device.getZoneInfo((errors, info) => {
        const newInfo = info;
        if (errors) devInfo += "`- failed to retrieve zone information\n";
        delete newInfo.SerialNumber;
        newInfo.MACAddress = info.MACAddress.replace(
          /^([0-9A-F]{2}[:-]){5}/,
          "XX:XX:XX:XX:XX:"
github richardwillars / thinglator / drivers / homebox-driver-sonos.js View on Github external
return new Promise(function(resolve, reject) {
			var search = sonos.search()
			var devices = [];
			search.on('DeviceAvailable', function (deviceObj, model) {
			  deviceObj.getZoneAttrs(function (err, attrs) {
			    if (err) {
			    	console.log('failed to retrieve zone attributes');
			    }
			    deviceObj.getZoneInfo(function (err, info) {
			      if (err) {
			      	console.log('failed to retrieve zone information');
			      }
			      console.log(info);
			      var device = {
					deviceId: info.SerialNumber,
					name: attrs.CurrentZoneName,
					address: info.IPAddress,
					capabilities: {