mirror of
https://github.com/mtan93/homebridge.git
synced 2026-04-04 06:13:13 +01:00
Merge pull request #238 from SphtKr/yamahaavr-manual-ip
YamahaAVR manual address specification
This commit is contained in:
@@ -23,6 +23,7 @@ function YamahaAVRPlatform(log, config){
|
|||||||
this.setMainInputTo = config["setMainInputTo"];
|
this.setMainInputTo = config["setMainInputTo"];
|
||||||
this.expectedDevices = config["expected_devices"] || 100;
|
this.expectedDevices = config["expected_devices"] || 100;
|
||||||
this.discoveryTimeout = config["discovery_timeout"] || 30;
|
this.discoveryTimeout = config["discovery_timeout"] || 30;
|
||||||
|
this.manualAddresses = config["manual_addresses"] || {};
|
||||||
this.browser = mdns.createBrowser(mdns.tcp('http'), {resolverSequence: sequence});
|
this.browser = mdns.createBrowser(mdns.tcp('http'), {resolverSequence: sequence});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,25 +76,44 @@ YamahaAVRPlatform.prototype = {
|
|||||||
var accessories = [];
|
var accessories = [];
|
||||||
var timer, timeElapsed = 0, checkCyclePeriod = 5000;
|
var timer, timeElapsed = 0, checkCyclePeriod = 5000;
|
||||||
|
|
||||||
browser.on('serviceUp', function(service){
|
// Hmm... seems we need to prevent double-listing via manual and Bonjour...
|
||||||
|
var sysIds = {};
|
||||||
|
|
||||||
|
var setupFromService = function(service){
|
||||||
var name = service.name;
|
var name = service.name;
|
||||||
//console.log('Found HTTP service "' + name + '"');
|
//console.log('Found HTTP service "' + name + '"');
|
||||||
// We can't tell just from mdns if this is an AVR...
|
// We can't tell just from mdns if this is an AVR...
|
||||||
if (service.port != 80) return; // yamaha-nodejs assumes this, so finding one on another port wouldn't do any good anyway.
|
if (service.port != 80) return; // yamaha-nodejs assumes this, so finding one on another port wouldn't do any good anyway.
|
||||||
var yamaha = new Yamaha(service.host);
|
var yamaha = new Yamaha(service.host);
|
||||||
yamaha.getSystemConfig().then(function(sysConfig){
|
yamaha.getSystemConfig().then(
|
||||||
var sysModel = sysConfig.YAMAHA_AV.System[0].Config[0].Model_Name[0];
|
function(sysConfig){
|
||||||
var sysId = sysConfig.YAMAHA_AV.System[0].Config[0].System_ID[0];
|
var sysModel = sysConfig.YAMAHA_AV.System[0].Config[0].Model_Name[0];
|
||||||
that.log("Found Yamaha " + sysModel + " - " + sysId + ", \"" + name + "\"");
|
var sysId = sysConfig.YAMAHA_AV.System[0].Config[0].System_ID[0];
|
||||||
var accessory = new YamahaAVRAccessory(that.log, that.config, service, yamaha, sysConfig);
|
if(sysIds[sysId]){
|
||||||
accessories.push(accessory);
|
this.log("WARN: Got multiple systems with ID " + sysId + "! Omitting duplicate!");
|
||||||
if(accessories.length >= this.expectedDevices)
|
return;
|
||||||
timeoutFunction(); // We're done, call the timeout function now.
|
}
|
||||||
//callback([accessory]);
|
sysIds[sysId] = true;
|
||||||
}, function(err){
|
this.log("Found Yamaha " + sysModel + " - " + sysId + ", \"" + name + "\"");
|
||||||
return;
|
var accessory = new YamahaAVRAccessory(this.log, this.config, name, yamaha, sysConfig);
|
||||||
|
accessories.push(accessory);
|
||||||
|
if(accessories.length >= this.expectedDevices)
|
||||||
|
timeoutFunction(); // We're done, call the timeout function now.
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
}.bind(this);
|
||||||
|
|
||||||
|
// process manually specified devices...
|
||||||
|
for(var key in this.manualAddresses){
|
||||||
|
if(!this.manualAddresses.hasOwnProperty(key)) continue;
|
||||||
|
setupFromService({
|
||||||
|
name: key,
|
||||||
|
host: this.manualAddresses[key],
|
||||||
|
port: 80
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
|
browser.on('serviceUp', setupFromService);
|
||||||
browser.start();
|
browser.start();
|
||||||
|
|
||||||
// The callback can only be called once...so we'll have to find as many as we can
|
// The callback can only be called once...so we'll have to find as many as we can
|
||||||
@@ -119,15 +139,15 @@ YamahaAVRPlatform.prototype = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function YamahaAVRAccessory(log, config, mdnsService, yamaha, sysConfig) {
|
function YamahaAVRAccessory(log, config, name, yamaha, sysConfig) {
|
||||||
this.log = log;
|
this.log = log;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.mdnsService = mdnsService;
|
|
||||||
this.yamaha = yamaha;
|
this.yamaha = yamaha;
|
||||||
this.sysConfig = sysConfig;
|
this.sysConfig = sysConfig;
|
||||||
|
|
||||||
this.name = mdnsService.name;
|
this.nameSuffix = config["name_suffix"] || " Speakers";
|
||||||
this.serviceName = mdnsService.name + " Speakers";
|
this.name = name;
|
||||||
|
this.serviceName = name + this.nameSuffix;
|
||||||
this.setMainInputTo = config["setMainInputTo"];
|
this.setMainInputTo = config["setMainInputTo"];
|
||||||
this.playVolume = this.config["play_volume"];
|
this.playVolume = this.config["play_volume"];
|
||||||
this.minVolume = config["min_volume"] || -50.0;
|
this.minVolume = config["min_volume"] || -50.0;
|
||||||
|
|||||||
Reference in New Issue
Block a user