NorthernMan54 / homebridge-yamaha-zone-tv

12 stars 5 forks source link

Main sync for other then main Zone #1

Closed abko closed 5 years ago

abko commented 5 years ago

Hello @NorthernMan54, thanks for another great implementation!

Would it be possible to include a Main zone sync input for secondary zones?

When I switch to main zone sync via the Yamaha app and open the Home app I get the following log. I guess support for Main zone input would also resolved that.

yamaha-zone-tv getActiveIdentifier Input Zone_2 Main Zone Sync +12ms Unhandled rejection TypeError: Cannot read property 'Identifier' of undefined at /usr/local/lib/node_modules/homebridge-yamaha-zone-tv/index.js:361:13 at tryCatcher (/usr/local/lib/node_modules/homebridge-yamaha-zone-tv/node_modules/bluebird/js/release/util.js:16:23) at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/homebridge-yamaha-zone-tv/node_modules/bluebird/js/release/promise.js:512:31) at Promise._settlePromise (/usr/local/lib/node_modules/homebridge-yamaha-zone-tv/node_modules/bluebird/js/release/promise.js:569:18) at Promise._settlePromise0 (/usr/local/lib/node_modules/homebridge-yamaha-zone-tv/node_modules/bluebird/js/release/promise.js:614:10) at Promise._settlePromises (/usr/local/lib/node_modules/homebridge-yamaha-zone-tv/node_modules/bluebird/js/release/promise.js:694:18) at Promise._fulfill (/usr/local/lib/node_modules/homebridge-yamaha-zone-tv/node_modules/bluebird/js/release/promise.js:638:18) at Promise._resolveCallback (/usr/local/lib/node_modules/homebridge-yamaha-zone-tv/node_modules/bluebird/js/release/promise.js:432:57) at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/homebridge-yamaha-zone-tv/node_modules/bluebird/js/release/promise.js:524:17) at Promise._settlePromise (/usr/local/lib/node_modules/homebridge-yamaha-zone-tv/node_modules/bluebird/js/release/promise.js:569:18) at Promise._settlePromise0 (/usr/local/lib/node_modules/homebridge-yamaha-zone-tv/node_modules/bluebird/js/release/promise.js:614:10) at Promise._settlePromises (/usr/local/lib/node_modules/homebridge-yamaha-zone-tv/node_modules/bluebird/js/release/promise.js:694:18) at Promise._fulfill (/usr/local/lib/node_modules/homebridge-yamaha-zone-tv/node_modules/bluebird/js/release/promise.js:638:18) at Promise._resolveCallback (/usr/local/lib/node_modules/homebridge-yamaha-zone-tv/node_modules/bluebird/js/release/promise.js:454:14) at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/homebridge-yamaha-zone-tv/node_modules/bluebird/js/release/promise.js:524:17) at Promise._settlePromise (/usr/local/lib/node_modules/homebridge-yamaha-zone-tv/node_modules/bluebird/js/release/promise.js:569:18) at Promise._fulfillPromises (/usr/local/lib/node_modules/homebridge-yamaha-zone-tv/node_modules/bluebird/js/release/promise.js:669:14) at Promise._settlePromises (/usr/local/lib/node_modules/homebridge-yamaha-zone-tv/node_modules/bluebird/js/release/promise.js:695:18) at Promise._fulfill (/usr/local/lib/node_modules/homebridge-yamaha-zone-tv/node_modules/bluebird/js/release/promise.js:638:18) at Promise._resolveCallback (/usr/local/lib/node_modules/homebridge-yamaha-zone-tv/node_modules/bluebird/js/release/promise.js:432:57) at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/homebridge-yamaha-zone-tv/node_modules/bluebird/js/release/promise.js:524:17) at Promise._settlePromise (/usr/local/lib/node_modules/homebridge-yamaha-zone-tv/node_modules/bluebird/js/release/promise.js:569:18)

Thanks. Let me know if I can do anything to assist.

NorthernMan54 commented 5 years ago

I guessed and I think this will fix it, update to version v0.1.8

abko commented 5 years ago

@NorthernMan54 Thanks, I did a quick test before going to work, will look into it again this evening.

I noticed the 2nd zone TV does not have the inputs any longer and a new item called Main Zone Sync appears, displaying On all the time. No option to change it. Maybe I need a better look to understand the behaviour.

Would it be possible to have Main zone sync as an additional input on secondary Zones, similar to how it works in the Yamaha remote App?

Another idea, unrelated, but what do you think about the option to use Play/Pause as mute for inputs that can't be paused?

Thanks again. I'll let you know if I have more feedback this evening!

NorthernMan54 commented 5 years ago

@abko thinking about this further, and as main zone sync is not a feature of my receiver I won’t be able to do more with this. As I don’t have the ability look at how it works and test it, I’m stuck.

In my receiver, the similar feature is called Party Mode, and once you turn this on, all inputs change to say the same input as the main.

abko commented 5 years ago

Ok. Guess main zone sync is a refined version of Party mode when having more than two zones. Main zone sync is presented as just another input in the Yamaha app, but apparently not advertised by the software like that. Advantage of an input is that I can create a HomeKit Scene that forces the input to main zone sync. With the party mode implementation I guess that’s not possible. Anyway this evening I have a look at the options. I am still considering to learn into all this technology (java, nodejs, github, homebridge) to be able to contribute myself. I haven’t figured out what the best way is to start 😀

NorthernMan54 commented 5 years ago

In learning something new, having something to motivate yourself is good.

Sent from my iPad

On May 2, 2019, at 7:25 AM, abko notifications@github.com wrote:

Ok. Guess main zone sync is a refined version of Party mode when having more than two zones. Main zone sync is presented as just another input in the Yamaha app, but apparently not advertised by the software like that. Advantage of an input is that I can create a HomeKit Scene that forces the input to main zone sync. With the party mode implementation I guess that’s not possible. Anyway this evening I have a look at the options. I am still considering to learn into all this technology (java, nodejs, github, homebridge) to be able to contribute myself. I haven’t figured out what the best way is to start 😀

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

abko commented 5 years ago

In learning something new, having something to motivate yourself is good. Agree, I have to find the time and the right order to pick up things.

About Party mode, on my RX-A3060 it plays the input selected in the main zone on all zones, but also on all surround speakers in the main zone, so for example stereo input is played via all speakers. With main zone sync on a secondary zone the main zone remains in its original format.

I played a little bit with values for main zone sync in utils.js, but no success so far. Is there a way I could find out what is required to get it working? Can I extract something useful from the Web setup pages for my receiver?

NorthernMan54 commented 5 years ago

The values in util.js don’t really do anything. I had to add the "main zone sync” to file, as the code looks up the input returned from the receiver and uses the data for display in the home app. The only one that matters is Identifier, which is just a unique number. The other values don’t do anything.

On May 2, 2019, at 3:28 PM, abko notifications@github.com wrote:

In learning something new, having something to motivate yourself is good. Agree, I have to find the time and the right order to pick up things.

About Party mode, on my RX-A3060 it plays the input selected in the main zone on all zones, but also on all surround speakers in the main zone, so for example stereo input is played via all speakers. With main zone sync on a secondary zone the main zone remains in its original format.

I played a little bit with values for main zone sync in utils.js, but no success so far. Is there a way I could find out what is required to get it working? Can I extract something useful from the Web setup pages for my receiver?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NorthernMan54/homebridge-yamaha-zone-tv/issues/1#issuecomment-488801667, or mute the thread https://github.com/notifications/unsubscribe-auth/AEXEFGFR43BTAAOH6K63EE3PTM6HRANCNFSM4HJSPXTA.

NorthernMan54 commented 5 years ago

I went and read the manual for your receiver and how main zone sync works, and I think I need to explain a couple of limitations in the plugin which make things easier to understand the behavior.

First the list of available inputs are hard coded in the plugin itself, when I pulled this together I couldn’t find how to pull the list, so just grabbed what my receiver supported. This is the list in util.js. This was the problem you reported.

Second I don’t have any logic that controls what input option is available in each zone, so you could see main zone sync listed in the main zone.

Third, if you change receiver settings outside of the home app, the plugin may not be aware so what is displayed may not be accurate. This wasn’t a priority for me as I exclusively use the home app and Alexa. Changing rooms in the home app or restarting the home app should cause it to sync.

abko commented 5 years ago

Thanks. I did some more attempts and believe whether or not the input is populated dependants on having the Home app active or not and the state of the receiver, when starting Homebridge.

I did not find the exact logic, but when I kill the Home app, start Homebridge it seems to work as expected.

In my local copy I added the following condition to the forEach loop that populates the inputs: if (this.zone !== "Main_Zone"||input.ConfiguredName!="Main Zone Sync") Now I only get the Main Zone for secondary zones.

If you like that addition I can attempt to get my own fork, make the change etc.

NorthernMan54 commented 5 years ago

A pull request would be very much appreciated.

On May 3, 2019, at 7:53 AM, abko notifications@github.com wrote:

Thanks. I did some more attempts and believe whether or not the input is populated dependants on having the Home app active or not and the state of the receiver, when starting Homebridge.

I did not find the exact logic, but when I kill the Home app, start Homebridge it seems to work as expected.

In my local copy I added the following condition to the forEach loop that populates the inputs: if (this.zone !== "Main_Zone"||input.ConfiguredName!="Main Zone Sync") Now I only get the Main Zone for secondary zones.

If you like that addition I can attempt to get my own fork, make the change etc.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

abko commented 5 years ago

@NorthernMan54 I am starting to look into how to copy my fork to my local machine, test it etc. I have a local copy that works. I also implemented my idea of using pause/play to mute/unmute:

           else // any other input than Airplay or Spotify
            {
              // Mute
              debug("Mute: ", that.zone);
              if (basicInfo.isMuted(that.zone))
              {
                    debug("Mute Off: ", that.zone);
                    yamaha.muteOff(that.zone)
              }
              else
              {
                  debug("Mute On : ", that.zone);
                  yamaha.muteOn (that.zone)
              }
            }

Sorry for the novice questions, but in order to test my fork I need to place it in my global node modules folder and sync it with GitHub from there right, right?

Note it will probably be tomorrow to finish it due to other obligations.

I also have another idea I want to explore: using the Title for each input instead of the input name (e.g. AppleTV instead of AV2). And using the actual zone title instead of Main_zone, Zone_2. I have not figured out yet if that is possible. With my limited knowledge I have the impression this is not (yet) possible with HAP-NodeJS, but maybe I am misinterpreting it.

NorthernMan54 commented 5 years ago

In my setup, I clone the git repo to my desktop, do my coding and tell homebridge to look in the directory. See this for how

https://github.com/nfarina/homebridge#plugin-development

I then publish it to GitHub when done and tested.

In regards to device names, the Home app supports being able to edit them. The only thing is that I didn't enable storage of the edited names, so restarting homebridge will reset them.

abko commented 5 years ago

Thanks. I did the changes and created a Pull Request. Hope I did it all correct.

I also started to look into detecting inputs automatically. I found Yamaha.getAvailableSources in yamaha-nodejs. It only lists the physical inputs and is sharing the input names, not the titles. It is using yamaha.getSystemConfig.

I believe that function returns all that is needed. I was thinking of creating an array of objects that hold info for each input: name, title, identifier. I would iterate through the Input and Feature_Existence objects (see below) to find all possible inputs and store it in the array so all other code can use it. For none Main_zone zones I would add Main Zone Sync as well :-)

I have some (rusted) C++ and Objective C experience, the challenge is to understand how thinks work with JavaScript. I have not figured out how to create such an array per Zone object in JavaScript so it can be used in other Zone specific code.

I'll find some time later in the week to explore this further. Let me know if you like the idea.

For my receiver yamaha.getSystemConfig returns the following:


   [ { Config:
        [ { Model_Name: [ 'RX-A3060' ],
            System_ID: [ '06005753' ],
            Version: [ '2.65/2.40' ],
            Feature_Existence:
             [ { Main_Zone: [ '1' ],
                 Zone_2: [ '1' ],
                 Zone_3: [ '1' ],
                 Zone_4: [ '1' ],
                 Tuner: [ '1' ],
                 DAB: [ '0' ],
                 HD_Radio: [ '0' ],
                 Rhapsody: [ '0' ],
                 Napster: [ '1' ],
                 SiriusXM: [ '0' ],
                 Spotify: [ '1' ],
                 Pandora: [ '0' ],
                 JUKE: [ '1' ],
                 Qobuz: [ '1' ],
                 radiko_jp: [ '0' ],
                 TIDAL: [ '1' ],
                 Deezer: [ '1' ],
                 MusicCast_Link: [ '0' ],
                 SERVER: [ '1' ],
                 NET_RADIO: [ '1' ],
                 Bluetooth: [ '1' ],
                 USB: [ '1' ],
                 AirPlay: [ '1' ] } ],
            Name:
             [ { Input:
                  [ { PHONO: [ 'PHONO' ],
                      AV_1: [ 'Tele2' ],
                      AV_2: [ 'AppleTV' ],
                      AV_3: [ 'PS4 HDR' ],
                      AV_4: [ 'PS4 VR' ],
                      AV_5: [ 'AV5' ],
                      AV_6: [ 'AV6' ],
                      AV_7: [ 'AV7' ],
                      V_AUX: [ 'V-AUX' ],
                      AUDIO_1: [ 'Broadcast' ],
                      AUDIO_2: [ 'AUDIO2' ],
                      AUDIO_3: [ 'AUDIO3' ],
                      USB: [ 'USB' ] 
} ] } ] } ] } ] }```
NorthernMan54 commented 5 years ago

That looks really good. When I had added inputs I must have missed that function's availability. I would gladly take a pull request with this feature.

NorthernMan54 commented 5 years ago

Also, I added yourself as a collaborator on the repo as well. You should be able to now publish directly

abko commented 5 years ago

Thanks. I better do my homework right, not to break anything :-). I'll keep you posted on my progress.

abko commented 5 years ago

Hello @NorthernMan54, I have finished my first iteration of attempting auto detection of inputs. I pushed it to my Fork.

I mainly replaced util.Inputs with a new array inputs that uses the same format you created for util.Inputs. I am populating it upfront based on the responses from the earlier shared XML.

Unfortunately some of the returned Inputs/ Features don't follow the same naming as required for setting the inputs. I hard coded conversions for Tuner, V-AUX and NET_SERVER to make those work.

Additionally I am using the Titles instead of the Names returned by the XML. For example you can set a Title for AV1 to AppleTV. The update will than use AppleTV as input instead of AV1.

I am also using the above to determine whether or not to make them visible by default. If there is a custom name I am making it visible. All the Internet/ Network features identified will also be visible by default.

Before pulling it into your version, can you advise if you have any comments/ concerns?

I am a bit reluctant since I can only test against my own receiver and I am unexperienced with Javascript (Google is my friend ;-) ).

NorthernMan54 commented 5 years ago

@abko As long as it works, I have no concerns for what your changing ;-)

Your approach sounds really good, and should be fine. With the coding of this plugin, please keep in mind that I'm just like you and only have my personal receiver to test with, so it is a bit of trial and error. And if a problems occur with another receiver/user, they will raise an issue.

And please include you name in the credit section of the readme.

abko commented 5 years ago

Great. I'll work on it. I guess I should bump the version in package.json. I noticed earlier my local package.json has other dependency values than your version. Should I just use it as is or simply use your version with a bumped version number?

NorthernMan54 commented 5 years ago

My NPM publish script does this automagically

On May 9, 2019, at 1:16 PM, abko notifications@github.com wrote:

Great. I'll work on it. I guess I should bump the version in package.json. I noticed earlier my local package.json has other dependency values than your version. Should I just use it as is or simply use your version with a bumped version number?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.