Announcement

Collapse
No announcement yet.

A few link/unlink questions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    A few link/unlink questions

    Can I programatically determine if my sonos' are currently linked and what the proper unlink would be?

    And on a different note, if I link already linked speakers would I unlink just the last link or must I unlink each link I created?

    Wow, that even sounds confusing to me and I know what I'm trying to say.

    Here's an example of the second question.

    If I already have my bathroom and office speakers linked from a different subroutine and now I want to add my family room speaker I can create a new link without unlinking the existing link that contains my office speakers, bathroom speakers, and family room speakers.

    Now when I'm done done and I unlink the last link does is the initial link still there (and therefore I should unlink it, too) or does the single unlink of the bathroom, office, and living room also get rid of the first link?

    Finally, is there a command to unlink all and would this be the easiest way to ensure I have unlinked everything I have linked?

    Sorry for the confusing questions!

    #2
    Originally posted by sifuhall View Post
    Can I programatically determine if my sonos' are currently linked and what the proper unlink would be?

    And on a different note, if I link already linked speakers would I unlink just the last link or must I unlink each link I created?

    Wow, that even sounds confusing to me and I know what I'm trying to say.

    Here's an example of the second question.

    If I already have my bathroom and office speakers linked from a different subroutine and now I want to add my family room speaker I can create a new link without unlinking the existing link that contains my office speakers, bathroom speakers, and family room speakers.

    Now when I'm done done and I unlink the last link does is the initial link still there (and therefore I should unlink it, too) or does the single unlink of the bathroom, office, and living room also get rid of the first link?

    Finally, is there a command to unlink all and would this be the easiest way to ensure I have unlinked everything I have linked?

    Sorry for the confusing questions!
    Check the help file at the end.

    There are properties that you can query for each involved player. You would first pick up a handle to the plugin as follows:

    Dim pi As Object
    pi = hs.Plugin("SONOSCONTROLLER")
    If pi Is Nothing Then
    hs.writelog("Script", "empty")
    Exit Function
    End If

    Then you would retrieve the handle to the API for the involved playes as follows:

    Dim MusicApi
    Try
    MusicApi = pi.GetMusicAPI(ZoneName) ' specify here which Zone you want to use. You can use ZoneName as a string or ZoneIndex as Integer or String
    Catch ex As Exception
    hs.writelog("Script", "Music API not found")
    Exit Function
    End Try

    Now you can use properties:

    Public ReadOnly Property LinkedZoneSource As String ' Return empty if not linked to another source, else the Zone Name of the Source it is linked to
    Public ReadOnly Property LinkedZoneDestination As String()' Return empty if this zone is not a source (Master) else it returns an array with the destination zone player names

    Public ReadOnly Property ZoneIsLinked As Boolean ' Returns True when this zone is linked (slave) to another zone. Use LinkedZoneSource to find out to which Master it is linked
    Public Property SourcingZone As Boolean ' Returns True when this zone is source (Master) to other players Use LinkedZoneDestination to get list of slave players.

    Now use the returned player string with player UUID separated by semicollons ( ; ) and these are the players that are linked to this SourcingZone. So if you want to unlink all of the players, you would have to split the string, get the API for each players and call the UnLink procedure.

    As to your second question, you can add and remove players from a group of players without messing up the group. The only player you can not remove is the master of the group player.

    The procedures are:

    Public Sub Link(MasterZoneName As String)
    Public Sub Unlink()

    Hope this helps

    Dirk

    Comment


      #3
      Thanks for the reply, Dirk.

      I really love what you have done with this.

      Looks like I've really been dense about this and am having trouble getting my head around the proper way to link and unlink zones.


      In this case my master zone will always be Bathroom

      This is what I'm currently doing now.

      The zone Bathroom is playing and now I want to add the bedroom.

      I have the zone defined in the plugin link group table.

      I use this command to create the link:
      Code:
      hs.ExecX10("[1", "Value set", 10, 0)
      This works (so far so good!)

      Now, after some other things happen I need to add another zone to the group.

      This speaker is the office speaker and I have defined the group in the plugin link group table to include bathroom, bedroom, and office.

      I now use this command to create the link:

      Code:
      hs.ExecX10("[1", "Value set", 8, 0)
      Some time later I want to stop the music and undo what I did.

      At this point I'm using this code:
      Code:
      hs.ExecX10("[1", "Value set", 9, 0)

      But from reading your reply and the help file it seems there may be a better way (or at least a way that is easier to understand)?

      Thanks again for all the help!

      Comment


        #4
        Woo hoo!

        After playing around a bit with the information you provided this is making sense now.

        I understand much better how to dynamically link and unlink without using the defined link groups in the plugin screen.

        Thanks for all the help!

        Comment


          #5
          OK, unlinking is going well!

          But I do have an issue with creating new links.

          This is my code:

          Code:
          	Dim MusicApi As Object
          	Dim pi As Object
          	
          	pi = hs.Plugin("SONOSCONTROLLER")
          	
          	'link master bedroom speaker (slave) to bathroom speaker (master)
          	MusicApi = pi.GetMusicAPI("Master Bedroom")
          	MusicApi.Link("Bathroom")
          The error I'm getting is:
          Error = UPNP_E_INVALID_ARGUMENTS

          Comment


            #6
            Originally posted by sifuhall View Post
            OK, unlinking is going well!

            But I do have an issue with creating new links.

            This is my code:

            Code:
                Dim MusicApi As Object
                Dim pi As Object
                
                pi = hs.Plugin("SONOSCONTROLLER")
                
                'link master bedroom speaker (slave) to bathroom speaker (master)
                MusicApi = pi.GetMusicAPI("Master Bedroom")
                MusicApi.Link("Bathroom")
            The error I'm getting is:
            Error = UPNP_E_INVALID_ARGUMENTS
            Typically when you get this error, it may mean that the player is refusing to do what you ask it to do. For example, if you try to link a player to some source, but that source is actually linked to your player, it will refuse it (think network loop).

            Have you checked out the "regular" actions capabilities in HS? If you go to events, click on add event, click on actions, select sonoscontroller actions, you can now create actions to link/unlink. This should be much easier than scripting this stuff in VB. Also the hs.exec10 can be replaced with regular device actions.

            If the error persists, turn on debug flag and post/email the full log.

            Dirk

            Comment


              #7
              Thank you.

              Here is the code:
              Code:
              	public sub linktest(ByVal params As String)
                      Dim MusicApi As Object
              
                      Try
                          Dim pi As Object
                          pi = hs.Plugin("SONOSCONTROLLER")
              
                          If pi Is Nothing Then
                              hs.WriteLog("Script", "empty")
                              Exit Sub
                          End If
              
                          MusicApi = pi.GetMusicAPI("Kitchen")
              
              			MusicApi.link("Bathroom")
              
                      Catch ex As Exception
                          hs.WriteLog("Script", "Music API not found")
                          Exit Sub
                      End Try
              
              
                  End Sub
              And here is the log:

              10/21/2012 10:09:57 PM SonosController ZonegroupTopology callback ZonePlayer Kitchen: Var Name = ZoneGroupState
              10/21/2012 10:09:57 PM SonosController GroupManagement callback ZonePlayer Kitchen: Var Name = LocalGroupUUID Value = RINCON_000E58701B1401400:452
              10/21/2012 10:09:57 PM SonosController GroupManagement callback ZonePlayer Kitchen: Var Name = GroupCoordinatorIsLocal Value = True
              10/21/2012 10:09:57 PM SonosController ZonegroupTopology callback ZonePlayer Master Bedroom: Var Name = ZoneGroupState
              10/21/2012 10:09:57 PM SonosController ZonegroupTopology callback ZonePlayer Family Room: Var Name = ZoneGroupState
              10/21/2012 10:09:57 PM SonosController ZonegroupTopology callback ZonePlayer Bathroom: Var Name = ZoneGroupState
              10/21/2012 10:09:57 PM SonosController ERROR in PlayURI for zoneplayer = Kitchen with UPNP Error = UPNP_E_INVALID_ARGUMENTS . URI=x-rincon:uuid:RINCON_000E5870173601400, MetaData=, Error =System.Runtime.InteropServices.COMException (0x80040208): A user-supplied component or subscriber raised an exception (Exception from HRESULT: 0x80040208) at UPNPLib.IUPnPService.InvokeAction(String bstrActionName, Object vInActionArgs, Object& pvOutActionArgs) at HSPI_SONOSCONTROLLER.HSMusicAPI.PlayURI(String URI, String MetaData)
              10/21/2012 10:09:57 PM SonosController PlayURI called for zoneplayer Kitchen with strURI = x-rincon:uuid:RINCON_000E5870173601400 and MetaData =
              10/21/2012 10:09:57 PM SonosController Link called for Zone - Kitchen
              10/21/2012 10:09:57 PM SonosController GetMusicAPI (Integer) was called with Value: 4
              10/21/2012 10:09:56 PM Event Running script in background: hall_custom.vb("linktest", "")
              10/21/2012 10:09:56 PM Event Event Trigger "link test"

              Comment


                #8
                Originally posted by sifuhall View Post
                URI=x-rincon:uuid:RINCON_000E5870173601400
                This actually looks like a bug

                While I fix this, any reason why you use a script not "regular" actions?

                See attachment here
                Attached Files

                Comment


                  #9
                  Thanks for the quick reply.

                  I am linking and unlinking dynamically and found that scripting would be the best way to achieve this.

                  Comment


                    #10
                    Originally posted by sifuhall View Post
                    Thanks for the quick reply.

                    I am linking and unlinking dynamically and found that scripting would be the best way to achieve this.
                    New beta v.97 posted which should fix this. Let me know it did the trick
                    Dirk

                    Comment


                      #11
                      I'm still getting the same error.

                      Maybe I'm doing something wrong.

                      My plugin version is reported as:
                      1.0.0.97

                      My code is:

                      Code:
                      	public sub linktest(ByVal params As String)
                              Dim MusicApi As Object
                      
                              Try
                                  Dim pi As Object
                                  pi = hs.Plugin("SONOSCONTROLLER")
                      
                                  If pi Is Nothing Then
                                      hs.WriteLog("Script", "empty")
                                      Exit Sub
                                  End If
                      
                                  MusicApi = pi.GetMusicAPI("Kitchen")
                      
                      			MusicApi.link("Bathroom")
                      
                              Catch ex As Exception
                                  hs.WriteLog("Script", "Music API not found")
                                  Exit Sub
                              End Try
                      
                          End Sub
                      and my log shows:

                      10/24/2012 8:07:29 AM SonosController GroupManagement callback ZonePlayer Kitchen: Var Name = LocalGroupUUID Value = RINCON_000E58701B1401400:460
                      10/24/2012 8:07:29 AM SonosController GroupManagement callback ZonePlayer Kitchen: Var Name = GroupCoordinatorIsLocal Value = True
                      10/24/2012 8:07:29 AM SonosController ERROR in PlayURI for zoneplayer = Kitchen with UPNP Error = UPNP_E_INVALID_ARGUMENTS . URI=x-rincon:uuid:RINCON_000E5870173601400, MetaData=, Error =System.Runtime.InteropServices.COMException (0x80040208): A user-supplied component or subscriber raised an exception (Exception from HRESULT: 0x80040208) at UPNPLib.IUPnPService.InvokeAction(String bstrActionName, Object vInActionArgs, Object& pvOutActionArgs) at HSPI_SONOSCONTROLLER.HSMusicAPI.PlayURI(String URI, String MetaData)
                      10/24/2012 8:07:29 AM SonosController PlayURI called for zoneplayer Kitchen with strURI = x-rincon:uuid:RINCON_000E5870173601400 and MetaData =
                      10/24/2012 8:07:29 AM SonosController Link called for Zone - Kitchen
                      10/24/2012 8:07:29 AM SonosController GetMusicAPI (Integer) was called with Value: 4
                      10/24/2012 8:07:29 AM Event Running script in background: hall_custom.vb("linktest", "")
                      10/24/2012 8:07:29 AM Event Event Trigger "link test"
                      10/24/2012 8:07:23 AM SonosController BuildButtonValues: Found LinkgroupZoneSource = MBedroom-Bathroom
                      10/24/2012 8:07:23 AM SonosController BuildButtonValues: Found LinkgroupZoneSource = MBedroom-Bathroom-Kitchen
                      10/24/2012 8:07:23 AM SonosController BuildButtonValues: Found LinkgroupZoneSource = MBedroom-Bathroom-Office
                      10/24/2012 8:07:23 AM SonosController BuildButtonValues: Found LinkgroupZoneSource = WholeHouse
                      10/24/2012 8:07:23 AM SonosController BuildButtonValues: Found LinkgroupZoneSource = TTS
                      10/24/2012 8:07:23 AM SonosController BuildButtonString: Found LinkgroupZoneSource = MBedroom-Bathroom
                      10/24/2012 8:07:23 AM SonosController BuildButtonString: Found LinkgroupZoneSource = MBedroom-Bathroom-Kitchen
                      10/24/2012 8:07:23 AM SonosController BuildButtonString: Found LinkgroupZoneSource = MBedroom-Bathroom-Office
                      10/24/2012 8:07:23 AM SonosController BuildButtonString: Found LinkgroupZoneSource = WholeHouse
                      10/24/2012 8:07:23 AM SonosController BuildButtonString: Found LinkgroupZoneSource = TTS

                      Comment


                        #12
                        Originally posted by sifuhall View Post
                        I'm still getting the same error.

                        Maybe I'm doing something wrong.

                        My plugin version is reported as:
                        1.0.0.97
                        Let me check tonight. The change was pretty straight forward so I decided not to test it with a script, I guess I should have ... or the DLL is wrong but you wrote it shows in the start-up v97. I never emailed you a test DLL now did I?

                        Dirk

                        Comment


                          #13
                          Originally posted by dcorsus View Post
                          Let me check tonight. The change was pretty straight forward so I decided not to test it with a script, I guess I should have ... or the DLL is wrong but you wrote it shows in the start-up v97. I never emailed you a test DLL now did I?

                          Dirk
                          Nope, I downloaded the beta from the sticky thread.

                          Was that not the correct one?

                          Comment


                            #14
                            Originally posted by sifuhall View Post
                            Nope, I downloaded the beta from the sticky thread.

                            Was that not the correct one?
                            That's the correct one. On occasion, I email directly to users a DLL to try, I'm usually pretty good to make sure I step up the version numbers, was wondering whether I had sent you an earlier version, I didn't think so but just covering all bases.

                            I'll do a test using a script tonight and see what's happening.

                            Dirk

                            Comment


                              #15
                              Originally posted by sifuhall View Post
                              I'm still getting the same error.

                              Maybe I'm doing something wrong.

                              My plugin version is reported as:
                              1.0.0.97

                              My code is:

                              Code:
                                  public sub linktest(ByVal params As String)
                                      Dim MusicApi As Object
                              
                                      Try
                                          Dim pi As Object
                                          pi = hs.Plugin("SONOSCONTROLLER")
                              
                                          If pi Is Nothing Then
                                              hs.WriteLog("Script", "empty")
                                              Exit Sub
                                          End If
                              
                                          MusicApi = pi.GetMusicAPI("Kitchen")
                              
                                          MusicApi.link("Bathroom")
                              
                                      Catch ex As Exception
                                          hs.WriteLog("Script", "Music API not found")
                                          Exit Sub
                                      End Try
                              
                                  End Sub
                              and my log shows:
                              By the way, if you replace the player name with its UDN, I think everything will work. So "Bathroom", I believe would become "RINCON_000E5870173601400". The benefit would be that your scripts still work if you decide to change the zone name.

                              Dirk

                              Comment

                              Working...
                              X