Files
Tobias Gesellchen 285f85efa2 feat: implement comprehensive music service account management with full golangci-lint compliance
This commit completes the music service account management implementation
and resolves all golangci-lint issues across the codebase.

Music Service Account Management:
• Add/remove accounts for all major streaming services (Spotify, Pandora, Amazon Music, Deezer, iHeartRadio)
• Support for network music libraries (NAS/UPnP/DLNA servers)
• Generic account management with service-specific convenience methods
• Full CLI integration with 14 account management commands
• Comprehensive test coverage with mock HTTP servers
• Complete API documentation and usage examples

New CLI Commands:
• account list - List configured accounts
• account add/remove - Generic account management
• account add-spotify/remove-spotify - Spotify Premium
• account add-pandora/remove-pandora - Pandora Music Service
• account add-amazon/remove-amazon - Amazon Music
• account add-deezer/remove-deezer - Deezer Premium
• account add-iheart/remove-iheart - iHeartRadio
• account add-nas/remove-nas - Network music libraries

New API Methods:
• SetMusicServiceAccount() / RemoveMusicServiceAccount() - Generic methods
• AddSpotifyAccount() / RemoveSpotifyAccount() - Convenience methods
• AddPandoraAccount() / RemovePandoraAccount() - Convenience methods
• AddAmazonMusicAccount() / RemoveAmazonMusicAccount() - Convenience methods
• AddDeezerAccount() / RemoveDeezerAccount() - Convenience methods
• AddIHeartRadioAccount() / RemoveIHeartRadioAccount() - Convenience methods
• AddStoredMusicAccount() / RemoveStoredMusicAccount() - Network libraries

golangci-lint Fixes (36 issues resolved):
• errcheck (3): Fixed unchecked w.Write() returns in tests
• gocritic (3): Rewrote if-else chains to switch statements
• gocyclo (6): Reduced cyclomatic complexity via helper function extraction
• govet (12): Removed unused test data and field assignments
• revive (6): Added package comments and fixed unused parameters
• staticcheck (2): Replaced deprecated strings.Title usage
• thelper (6): Added t.Helper() calls to test helper functions
• unused (1): Removed unused createTestApp() function
• whitespace/wsl_v5 (7): Fixed whitespace and formatting issues

Code Quality Improvements:
• All functions now have complexity < 15 (down from max 28)
• Consistent error handling and validation patterns
• Better separation of concerns with extracted helper functions
• Zero external dependencies added for simple fixes
• Comprehensive documentation with usage examples
• Full backward compatibility maintained

Files Added:
• pkg/models/account.go - Account management models
• pkg/models/account_test.go - Account model tests
• pkg/client/account_test.go - Account client tests
• cmd/soundtouch-cli/cmd_account.go - Account CLI commands
• examples/account-management/ - Complete usage example
• Updated docs/CLI-REFERENCE.md with account management section

The implementation provides a complete, production-ready music service
account management system with full CLI and programmatic API support.
2026-02-02 17:44:26 +01:00

154 lines
5.0 KiB
Go

// Package main demonstrates music service account management functionality for Bose SoundTouch devices.
package main
import (
"fmt"
"log"
"time"
"github.com/gesellix/bose-soundtouch/pkg/client"
"github.com/gesellix/bose-soundtouch/pkg/models"
)
func main() {
// Configure the SoundTouch client
config := &client.Config{
Host: "192.168.1.100", // Replace with your device IP
Port: 8090,
Timeout: 10 * time.Second,
}
// Create client
soundtouchClient := client.NewClient(config)
fmt.Printf("🎵 SoundTouch Music Service Account Management Example\n")
fmt.Printf("Device: %s:%d\n\n", config.Host, config.Port)
// Example 1: Add a Spotify account using convenience method
fmt.Println("📱 Adding Spotify Premium account...")
err := soundtouchClient.AddSpotifyAccount("user@spotify.com", "your_password")
if err != nil {
log.Printf("Failed to add Spotify account: %v", err)
} else {
fmt.Println("✅ Spotify account added successfully")
}
// Example 2: Add a Pandora account
fmt.Println("\n📻 Adding Pandora account...")
err = soundtouchClient.AddPandoraAccount("pandora_username", "pandora_password")
if err != nil {
log.Printf("Failed to add Pandora account: %v", err)
} else {
fmt.Println("✅ Pandora account added successfully")
}
// Example 3: Add Amazon Music account
fmt.Println("\n🛒 Adding Amazon Music account...")
err = soundtouchClient.AddAmazonMusicAccount("amazon_user", "amazon_password")
if err != nil {
log.Printf("Failed to add Amazon Music account: %v", err)
} else {
fmt.Println("✅ Amazon Music account added successfully")
}
// Example 4: Add a network music library (NAS/UPnP)
fmt.Println("\n🏠 Adding network music library...")
nasGUID := "d09708a1-5953-44bc-a413-123456789012/0" // Example UPnP server GUID
err = soundtouchClient.AddStoredMusicAccount(nasGUID, "My Home Music Server")
if err != nil {
log.Printf("Failed to add network music library: %v", err)
} else {
fmt.Println("✅ Network music library added successfully")
}
// Example 5: Add account using generic method with custom credentials
fmt.Println("\n🎧 Adding Deezer account using generic method...")
deezerCredentials := models.NewDeezerCredentials("deezer_user", "deezer_password")
err = soundtouchClient.SetMusicServiceAccount(deezerCredentials)
if err != nil {
log.Printf("Failed to add Deezer account: %v", err)
} else {
fmt.Println("✅ Deezer account added successfully")
}
// Example 6: Add a custom/unknown service
fmt.Println("\n🎶 Adding custom music service...")
customCredentials := models.NewMusicServiceCredentials("TIDAL", "Tidal HiFi", "tidal_user", "tidal_password")
err = soundtouchClient.SetMusicServiceAccount(customCredentials)
if err != nil {
log.Printf("Failed to add custom music service: %v", err)
} else {
fmt.Println("✅ Custom music service added successfully")
}
// Example 7: List current sources to see added accounts
fmt.Println("\n📋 Checking available sources...")
sources, err := soundtouchClient.GetSources()
if err != nil {
log.Printf("Failed to get sources: %v", err)
} else {
fmt.Printf("Available sources (%d total):\n", len(sources.SourceItem))
for _, source := range sources.SourceItem {
status := "🔴 Unavailable"
if source.Status == models.SourceStatusReady {
status = "🟢 Ready"
}
accountInfo := ""
if source.SourceAccount != "" && source.SourceAccount != source.Source {
accountInfo = fmt.Sprintf(" (%s)", source.SourceAccount)
}
fmt.Printf(" %s %s%s\n", status, source.GetDisplayName(), accountInfo)
}
}
// Example 8: Remove accounts
fmt.Println("\n🗑️ Removing accounts...")
// Remove Spotify account
err = soundtouchClient.RemoveSpotifyAccount("user@spotify.com")
if err != nil {
log.Printf("Failed to remove Spotify account: %v", err)
} else {
fmt.Println("✅ Spotify account removed successfully")
}
// Remove Deezer account using generic method
deezerRemovalCredentials := models.NewDeezerCredentials("deezer_user", "")
err = soundtouchClient.RemoveMusicServiceAccount(deezerRemovalCredentials)
if err != nil {
log.Printf("Failed to remove Deezer account: %v", err)
} else {
fmt.Println("✅ Deezer account removed successfully")
}
// Remove network music library
err = soundtouchClient.RemoveStoredMusicAccount(nasGUID, "My Home Music Server")
if err != nil {
log.Printf("Failed to remove network music library: %v", err)
} else {
fmt.Println("✅ Network music library removed successfully")
}
fmt.Println("\n🎉 Account management example completed!")
fmt.Println("\n💡 Tips:")
fmt.Println(" • Use 'account list' to see which services are configured")
fmt.Println(" • After adding accounts, use 'source list' to verify availability")
fmt.Println(" • Network libraries (NAS/UPnP) don't require passwords")
fmt.Println(" • Some services may need additional authentication via their mobile apps")
fmt.Println(" • Account credentials are stored securely on the SoundTouch device")
}