From d14f4691a651812cd98fb661531cfa13030206aa Mon Sep 17 00:00:00 2001 From: Tobias Gesellchen Date: Wed, 6 May 2026 08:23:04 +0200 Subject: [PATCH] fix(amazon): use email and AMAZON type to match old Bose cloud format (#212) Store the user's email address (not Amazon account ID) in sourceKey.account and set source type to "AMAZON" so the speaker firmware recognises Amazon Music sources the same way as the original Bose cloud. Co-authored-by: Claude Sonnet 4.6 --- pkg/service/handlers/handlers_marge_test.go | 2 +- pkg/service/handlers/handlers_mgmt.go | 8 ++++---- pkg/service/marge/marge.go | 6 +++++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/service/handlers/handlers_marge_test.go b/pkg/service/handlers/handlers_marge_test.go index 11f0b1e..ab944ce 100644 --- a/pkg/service/handlers/handlers_marge_test.go +++ b/pkg/service/handlers/handlers_marge_test.go @@ -309,7 +309,7 @@ func TestMargeAccountFullExcludesEmptyAmazonSource(t *testing.T) { t.Fatalf("Failed to write first device DeviceInfo.xml: %v", err) } if err := os.WriteFile(filepath.Join(firstDir, "Sources.xml"), []byte(` - + `), 0644); err != nil { diff --git a/pkg/service/handlers/handlers_mgmt.go b/pkg/service/handlers/handlers_mgmt.go index 92920b5..422dbfc 100644 --- a/pkg/service/handlers/handlers_mgmt.go +++ b/pkg/service/handlers/handlers_mgmt.go @@ -578,7 +578,7 @@ func (s *Server) bridgeAmazonToMarge(accountID string) { } for _, acc := range accounts { - log.Printf("[Amazon Bridge] Registering Amazon user %s in Marge for account %s", acc.UserID, accountID) + log.Printf("[Amazon Bridge] Registering Amazon user %s in Marge for account %s", acc.Email, accountID) // Build the AmazonSecret credential envelope expected by the speaker firmware. credMap := map[string]interface{}{ @@ -594,7 +594,7 @@ func (s *Server) bridgeAmazonToMarge(accountID string) { continue } - _, err = marge.AddSource(s.ds, accountID, acc.UserID, strconv.Itoa(constants.AmazonProviderID), string(credJSON), constants.CredentialTypeToken, acc.DisplayName) + _, err = marge.AddSource(s.ds, accountID, acc.Email, strconv.Itoa(constants.AmazonProviderID), string(credJSON), constants.CredentialTypeToken, acc.DisplayName) if err != nil { log.Printf("[Amazon Bridge] Failed to register source in Marge: %v", err) continue @@ -623,7 +623,7 @@ func (s *Server) bridgeAmazonToMarge(accountID string) { cfg.Host = d.IPAddress cfg.Timeout = 5 * time.Second c := client.NewClient(cfg) - creds := models.NewAmazonOAuthCredentials(acc.UserID, string(credJSON), acc.DisplayName) + creds := models.NewAmazonOAuthCredentials(acc.Email, string(credJSON), acc.DisplayName) if err := c.SetMusicServiceOAuthAccount(creds); err != nil { log.Printf("[Amazon Bridge] Failed to notify speaker %s via OAuth: %v", d.Name, err) @@ -633,7 +633,7 @@ func (s *Server) bridgeAmazonToMarge(accountID string) { log.Printf("[Amazon Bridge] Sync notification failed for speaker %s: %v", d.Name, err) log.Printf("[Amazon Bridge] Falling back to legacy account creation for speaker %s", d.Name) - legacyCreds := models.NewAmazonMusicCredentials(acc.UserID, string(credJSON)) + legacyCreds := models.NewAmazonMusicCredentials(acc.Email, string(credJSON)) if err := c.SetMusicServiceAccount(legacyCreds); err != nil { log.Printf("[Amazon Bridge] Legacy fallback failed for speaker %s: %v", d.Name, err) } else { diff --git a/pkg/service/marge/marge.go b/pkg/service/marge/marge.go index 6d34dc7..7663ea1 100644 --- a/pkg/service/marge/marge.go +++ b/pkg/service/marge/marge.go @@ -106,7 +106,11 @@ func ensureTimestamps(s *models.ConfiguredSource) { func ensureSourceType(s *models.ConfiguredSource) { if s.Type == "" || (s.SourceKey.Type != "" && s.SourceKey.Type != constants.ProviderAux && s.SourceKey.Type != constants.ProviderBluetooth) { - s.Type = "Audio" + if s.SourceKey.Type == constants.ProviderAmazon { + s.Type = constants.ProviderAmazon + } else { + s.Type = "Audio" + } } }