How to use the sonos.search function in sonos

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 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 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: {
github nfarina / homebridge-sonos / index.js View on Github external
SonosAccessory.prototype.oldSearch = function() {

        sonosAccessories.push(this);

        var search = sonos.search(function(device, model) {
                this.log.debug("Found device at %s", device.host);

                var data = {ip: device.host, port: device.port, discoverycompleted: 'false'};
                device.getZoneAttrs(function (err, attrs) {
                        if (!err && attrs) {
                                _.extend(data, {CurrentZoneName: attrs.CurrentZoneName});
                        }
                        device.getTopology(function (err, topology) {
                                if (!err && topology) {
                                        topology.zones.forEach(function (group) {
                                                if (group.location == 'http://' + data.ip + ':' + data.port + '/xml/device_description.xml') {
                                                        _.extend(data, group);
                                                        data.discoverycompleted = 'true';
                                                }
                                                else {
                                                        var grpDevIP = group.location.substring(7, group.location.lastIndexOf(":"));
github bencevans / sonos-cli / lib / getInitialDevice.js View on Github external
module.exports = function getInitialDevice (timeoutTime, cb) {
  var search = sonos.search()
  search.once('DeviceAvailable', function (dev) {
    clearTimeout(timeout)
    search.socket.close()
    cb(null, dev)
  })
  var timeout = setTimeout(function () {
    search.socket.close()
    cb(new Error('Unable to find Sonos device'))
  }, timeoutTime)
}
github nfarina / homebridge-sonos / index.js View on Github external
SonosAccessory.prototype.search = function() {
  var search = sonos.search(function(device) {
    var host = device.host;
    this.log.debug("Found sonos device at %s", host);

    device.deviceDescription(function (err, description) {

        var zoneType = description["zoneType"];
        var roomName = description["roomName"];

        if (!SonosAccessory.zoneTypeIsPlayable(zoneType)) {
          this.log.debug("Sonos device %s is not playable (has an unknown zone type of %s); ignoring", host, zoneType);
          return;
        }

        if (roomName != this.room) {
          this.log.debug("Ignoring device %s because the room name '%s' does not match the desired name '%s'.", host, roomName, this.room);
          return;