NorthernMan54 / homebridge-yamaha-home

Homebridge plugin for my Yamaha Receiver optimized for use with the Home App and Alexa
27 stars 9 forks source link

Input Accessories and Multiple Receivers #34

Closed alexgarden closed 4 years ago

alexgarden commented 4 years ago

I'm pretty sure this is a bonehead config issue on my part... I have one RX-S601 with the network name, "Family" and six WXA-50's, each with a network name like "Deck", "Master", etc... Each of the WXA-50's has a zone name that corresponds to the network name.

So far so good. Works great.

When I try to set up "inputs_as_accessories", if I use the network name of the RX-S601 ("Family"), I don't get any log indication that such a setup was attempted. If I use "YamahaReceiver", there is an attempt to set up the input for each found device which results in a UUID collision on the second attempt.

Here is the config snippet:

{
            "platform": "yamaha-home",
            "discover_timeout": 5,
            "play_volume": -48,
            "setMainInputTo": "Spotify",
            "show_input_name": "yes",
            "zone_controllers_only_for": "Living, Kitchen, Office, Main, Deck, Dining, Master",
            "inputs_as_accessories": {
                "Family": {
                    "1": {
                        "name": "AppleTV-Test",
                        "setInputTo": "AppleTV"
                    }
                }
            }
        }

Really appreciate the great work on this plugin.

alexgarden commented 4 years ago

Also... would be helpful if I included the logs.

[5/11/2020, 6:15:06 AM] [yamaha-home] Initializing yamaha-home platform...
[5/11/2020, 6:15:06 AM] [yamaha-home] Getting Yamaha AVR devices.
[5/11/2020, 6:15:06 AM] Failed to find plugin to handle accessory Family Room TV
[5/11/2020, 6:15:06 AM] Removing orphaned accessory Family Room TV
[5/11/2020, 6:15:06 AM] [yamaha-home] Possible Yamaha device discovered Living [ '10.0.0.88' ]
[5/11/2020, 6:15:06 AM] [yamaha-home] Possible Yamaha device discovered Master [ '10.0.0.178' ]
[5/11/2020, 6:15:06 AM] [yamaha-home] Possible Yamaha device discovered Office [ '10.0.0.145' ]
[5/11/2020, 6:15:06 AM] [yamaha-home] Possible Yamaha device discovered Family [ '10.0.0.237' ]
[5/11/2020, 6:15:06 AM] [yamaha-home] Possible Yamaha device discovered Deck [ '10.0.0.51' ]
[5/11/2020, 6:15:06 AM] [yamaha-home] Possible Yamaha device discovered Dining [ '10.0.0.81' ]
[5/11/2020, 6:15:06 AM] [yamaha-home] Possible Yamaha device discovered Kitchen [ '10.0.0.55' ]
[5/11/2020, 6:15:06 AM] [yamaha-home] Found Yamaha WXA-50 - 08965D23, "Living"
[5/11/2020, 6:15:06 AM] [yamaha-home] Found Yamaha WXA-50 - 067E5213, "Master"
[5/11/2020, 6:15:06 AM] [yamaha-home] Found Yamaha WXA-50 - 07F27AF3, "Office"
[5/11/2020, 6:15:06 AM] [yamaha-home] Adding zone controller for Living
[5/11/2020, 6:15:06 AM] [yamaha-home] Adding zone controller for Office
[5/11/2020, 6:15:06 AM] [yamaha-home] Adding zone controller for Master
[5/11/2020, 6:15:06 AM] [yamaha-home] Found Yamaha WXA-50 - 089F5D63, "Dining"
[5/11/2020, 6:15:06 AM] [yamaha-home] Found Yamaha WXA-50 - 071E7EF3, "Kitchen"
[5/11/2020, 6:15:06 AM] [yamaha-home] Found Yamaha RX-S601 - 006B7853, "Family"
[5/11/2020, 6:15:06 AM] [yamaha-home] Found Yamaha WXA-50 - 07507E93, "Deck"
[5/11/2020, 6:15:06 AM] [yamaha-home] Adding zone controller for Dining
[5/11/2020, 6:15:06 AM] [yamaha-home] Adding zone controller for Kitchen
[5/11/2020, 6:15:06 AM] [yamaha-home] Adding zone controller for Main
[5/11/2020, 6:15:06 AM] [yamaha-home] Adding zone controller for Deck
[5/11/2020, 6:15:21 AM] [yamaha-home] Waited 10 seconds, stopping discovery.
[5/11/2020, 6:15:21 AM] [yamaha-home] Discovery finished, found 7 Yamaha AVR devices.
[5/11/2020, 6:15:21 AM] Initializing platform accessory 'Living'...
[5/11/2020, 6:15:21 AM] Initializing platform accessory 'Office'...
[5/11/2020, 6:15:21 AM] Initializing platform accessory 'Master'...
[5/11/2020, 6:15:21 AM] Initializing platform accessory 'Dining'...
[5/11/2020, 6:15:21 AM] Initializing platform accessory 'Kitchen'...
[5/11/2020, 6:15:21 AM] Initializing platform accessory 'Main'...
[5/11/2020, 6:15:21 AM] Initializing platform accessory 'Deck'...
alexgarden commented 4 years ago

Looking at the code, you must use "YamahaReceiver" as the tag after "inputs_as_accesories" to active the code block. It's hard coded.

I found a hacky workaround but I'm not an expert in node so might need some help here. If you look in index.js, in function setupFromService(service) there is code which loops through each device and sets up each input as an accessory. Here is the snippet:

// Conditional statement. If we have any inputs in config.json property "inputs_as_accessories" this will create those switches.
  // Functionality added via YamahaInputService contructor function
  if (this.inputAccessories.hasOwnProperty("YamahaReceiver")) {
     for (var key in this.inputAccessories) {
        var inputs = this.inputAccessories[key];
           for (var key in inputs) {
              var inputConfig = inputs[key];
              var input = parseInt(key);
              var accname = name + " " + inputConfig["name"];
              this.log.info("Making accessory \"" + accname + "\" for input " + input);
              var accessory = new YamahaInputService(this.log, inputConfig, accname, yamaha, sysConfig, input);
              accessories.push(accessory);
              if (accessories.length >= this.expectedDevices)
                timeoutFunction(); // We're done, call the timeout function now.
        }
     }
  }

Note I added this change, var accname = name + " " + inputConfig["name"]; which effectively makes each UUID distinct by appending the network name of the accessory to the input name. Good news, it works... Bad news, you end up with unnecessary clones of your input names.

I suspect this is a two second fix for someone who actually knows what they're doing.

NorthernMan54 commented 4 years ago

In your setup, are you trying to only have the accessories created against the RX-S601 ?

Have you tried just making this change?

  // Functionality added via YamahaInputService contructor function
  if (this.inputAccessories.hasOwnProperty(name)) {
     for (var key in this.inputAccessories) {

Sorry don't have access to my receiver so I can't check how this would work

This particular receiver I received as a pull request a few years ago, and never really reviewed the code beyond making sure it didn't crash everything.

alexgarden commented 4 years ago

Hey! Thanks for getting back to me.

You nailed it. I'm trying to create the accessories only once, and only against my AVR. The distributed audio on the WXA-50's is only for music. I see you basically replaced "YamahaReciever" with "name" <-- referring to the input name.

What will this change do? Wouldn't I need to specify somehow what "name" I'm looking for?

NorthernMan54 commented 4 years ago

Put name without quotes, and in the config.json use "Family" instead of "YamahaReceiver"

alexgarden commented 4 years ago

That worked perfectly. In my opinion, that should be the default behavior of the plugin. Really appreciate your help on this, sir. I think we can close this issue. LMK if you're going to post a fix.


From: Northern Man notifications@github.com Sent: Monday, May 11, 2020 3:46 PM To: NorthernMan54/homebridge-yamaha-home homebridge-yamaha-home@noreply.github.com Cc: alexgarden alex.garden@outlook.com; Author author@noreply.github.com Subject: Re: [NorthernMan54/homebridge-yamaha-home] Input Accessories and Multiple Receivers (#34)

Put name without quotes, and in the config.json use "Family" instead of "YamahaReceiver"

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FNorthernMan54%2Fhomebridge-yamaha-home%2Fissues%2F34%23issuecomment-627005596&data=02%7C01%7C%7C2e54e8fea20947f29e6408d7f5fd2344%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637248339868429197&sdata=8tXZOMbMkCzmnUCRYHbjChgwHMBWQzcGpppiYo%2BvGfM%3D&reserved=0, or unsubscribehttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FADKWF3NI4RJ7NCC5JXG5XM3RRB54FANCNFSM4M54YWWA&data=02%7C01%7C%7C2e54e8fea20947f29e6408d7f5fd2344%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637248339868429197&sdata=KY3UArrIpPZxJ7t1gEOeBq5x23Qd42MvVnyyeU6UG8o%3D&reserved=0.

NorthernMan54 commented 4 years ago

Okay, I will publish this

NorthernMan54 commented 4 years ago

Published