Fix golangci-lint findings and improve code quality

Move example files to separate packages to avoid main redeclaration. Fix cyclomatic complexity and variable shadowing. Address errcheck and wsl linting issues. Update tests to handle capabilities and fix panics. Apply consistent formatting with gofmt.
This commit is contained in:
Tobias Gesellchen
2026-01-11 00:39:58 +01:00
parent 1f47c763dc
commit 369ebc42fe
11 changed files with 388 additions and 161 deletions
+132 -27
View File
@@ -44,6 +44,13 @@ func TestClient_GetAudioDSPControls(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/capabilities" {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(`<capabilities><capability name="audiodspcontrols"/></capabilities>`))
return
}
if r.Method != "GET" {
t.Errorf("Expected GET request, got %s", r.Method)
}
@@ -53,7 +60,7 @@ func TestClient_GetAudioDSPControls(t *testing.T) {
}
w.WriteHeader(tt.responseStatus)
w.Write([]byte(tt.responseBody))
_, _ = w.Write([]byte(tt.responseBody))
}))
defer server.Close()
@@ -64,6 +71,7 @@ func TestClient_GetAudioDSPControls(t *testing.T) {
if err == nil {
t.Errorf("Expected error but got none")
}
return
}
@@ -125,13 +133,23 @@ func TestClient_SetAudioDSPControls(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
callCount := 0
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
callCount++
// Handle capabilities check
if r.URL.Path == "/capabilities" {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(`<capabilities><capability name="audiodspcontrols"/></capabilities>`))
return
}
// First call might be GET for validation
if r.Method == "GET" && r.URL.Path == "/audiodspcontrols" {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`<audiodspcontrols audiomode="NORMAL" videosyncaudiodelay="0" supportedaudiomodes="NORMAL|DIALOG|SURROUND|MUSIC"/>`))
_, _ = w.Write([]byte(`<audiodspcontrols audiomode="NORMAL" videosyncaudiodelay="0" supportedaudiomodes="NORMAL|DIALOG|SURROUND|MUSIC"/>`))
return
}
@@ -145,7 +163,7 @@ func TestClient_SetAudioDSPControls(t *testing.T) {
}
w.WriteHeader(tt.responseStatus)
w.Write([]byte(tt.responseBody))
_, _ = w.Write([]byte(tt.responseBody))
}))
defer server.Close()
@@ -167,17 +185,27 @@ func TestClient_SetAudioDSPControls(t *testing.T) {
func TestClient_SetAudioMode(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Handle capabilities check
if r.URL.Path == "/capabilities" {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(`<capabilities><capability name="audiodspcontrols"/></capabilities>`))
return
}
// First call might be GET for validation
if r.Method == "GET" && r.URL.Path == "/audiodspcontrols" {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`<audiodspcontrols audiomode="NORMAL" videosyncaudiodelay="0" supportedaudiomodes="NORMAL|DIALOG|SURROUND|MUSIC"/>`))
_, _ = w.Write([]byte(`<audiodspcontrols audiomode="NORMAL" videosyncaudiodelay="0" supportedaudiomodes="NORMAL|DIALOG|SURROUND|MUSIC"/>`))
return
}
// POST call for setting
if r.Method == "POST" && r.URL.Path == "/audiodspcontrols" {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`<status>OK</status>`))
_, _ = w.Write([]byte(`<status>OK</status>`))
return
}
@@ -186,8 +214,8 @@ func TestClient_SetAudioMode(t *testing.T) {
defer server.Close()
client := createTestClient(server.URL)
err := client.SetAudioMode("MUSIC")
err := client.SetAudioMode("MUSIC")
if err != nil {
t.Errorf("Expected no error but got: %v", err)
}
@@ -228,18 +256,19 @@ func TestClient_SetVideoSyncAudioDelay(t *testing.T) {
if err == nil {
t.Errorf("Expected error but got none")
}
return
}
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`<status>OK</status>`))
_, _ = w.Write([]byte(`<status>OK</status>`))
}))
defer server.Close()
client := createTestClient(server.URL)
err := client.SetVideoSyncAudioDelay(tt.delay)
err := client.SetVideoSyncAudioDelay(tt.delay)
if err != nil {
t.Errorf("Expected no error but got: %v", err)
}
@@ -289,6 +318,13 @@ func TestClient_GetAudioProductToneControls(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/capabilities" {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(`<capabilities><capability name="audioproducttonecontrols"/></capabilities>`))
return
}
if r.Method != "GET" {
t.Errorf("Expected GET request, got %s", r.Method)
}
@@ -298,7 +334,7 @@ func TestClient_GetAudioProductToneControls(t *testing.T) {
}
w.WriteHeader(tt.responseStatus)
w.Write([]byte(tt.responseBody))
_, _ = w.Write([]byte(tt.responseBody))
}))
defer server.Close()
@@ -309,6 +345,7 @@ func TestClient_GetAudioProductToneControls(t *testing.T) {
if err == nil {
t.Errorf("Expected error but got none")
}
return
}
@@ -374,13 +411,22 @@ func TestClient_SetAudioProductToneControls(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Handle capabilities check
if r.URL.Path == "/capabilities" {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(`<capabilities><capability name="audioproducttonecontrols"/></capabilities>`))
return
}
// First call might be GET for validation
if r.Method == "GET" && r.URL.Path == "/audioproducttonecontrols" {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`<audioproducttonecontrols>
_, _ = w.Write([]byte(`<audioproducttonecontrols>
<bass value="0" minValue="-10" maxValue="10" step="1"/>
<treble value="0" minValue="-5" maxValue="5" step="1"/>
</audioproducttonecontrols>`))
return
}
@@ -394,7 +440,7 @@ func TestClient_SetAudioProductToneControls(t *testing.T) {
}
w.WriteHeader(tt.responseStatus)
w.Write([]byte(tt.responseBody))
_, _ = w.Write([]byte(tt.responseBody))
}))
defer server.Close()
@@ -416,20 +462,30 @@ func TestClient_SetAudioProductToneControls(t *testing.T) {
func TestClient_SetAdvancedBass(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Handle capabilities check
if r.URL.Path == "/capabilities" {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(`<capabilities><capability name="audioproducttonecontrols"/></capabilities>`))
return
}
// First call might be GET for validation
if r.Method == "GET" && r.URL.Path == "/audioproducttonecontrols" {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`<audioproducttonecontrols>
_, _ = w.Write([]byte(`<audioproducttonecontrols>
<bass value="0" minValue="-10" maxValue="10" step="1"/>
<treble value="0" minValue="-5" maxValue="5" step="1"/>
</audioproducttonecontrols>`))
return
}
// POST call for setting
if r.Method == "POST" && r.URL.Path == "/audioproducttonecontrols" {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`<status>OK</status>`))
_, _ = w.Write([]byte(`<status>OK</status>`))
return
}
@@ -438,8 +494,8 @@ func TestClient_SetAdvancedBass(t *testing.T) {
defer server.Close()
client := createTestClient(server.URL)
err := client.SetAdvancedBass(5)
err := client.SetAdvancedBass(5)
if err != nil {
t.Errorf("Expected no error but got: %v", err)
}
@@ -447,20 +503,30 @@ func TestClient_SetAdvancedBass(t *testing.T) {
func TestClient_SetAdvancedTreble(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Handle capabilities check
if r.URL.Path == "/capabilities" {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(`<capabilities><capability name="audioproducttonecontrols"/></capabilities>`))
return
}
// First call might be GET for validation
if r.Method == "GET" && r.URL.Path == "/audioproducttonecontrols" {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`<audioproducttonecontrols>
_, _ = w.Write([]byte(`<audioproducttonecontrols>
<bass value="0" minValue="-10" maxValue="10" step="1"/>
<treble value="0" minValue="-5" maxValue="5" step="1"/>
</audioproducttonecontrols>`))
return
}
// POST call for setting
if r.Method == "POST" && r.URL.Path == "/audioproducttonecontrols" {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`<status>OK</status>`))
_, _ = w.Write([]byte(`<status>OK</status>`))
return
}
@@ -469,8 +535,8 @@ func TestClient_SetAdvancedTreble(t *testing.T) {
defer server.Close()
client := createTestClient(server.URL)
err := client.SetAdvancedTreble(-2)
err := client.SetAdvancedTreble(-2)
if err != nil {
t.Errorf("Expected no error but got: %v", err)
}
@@ -518,6 +584,13 @@ func TestClient_GetAudioProductLevelControls(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/capabilities" {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(`<capabilities><capability name="audioproductlevelcontrols"/></capabilities>`))
return
}
if r.Method != "GET" {
t.Errorf("Expected GET request, got %s", r.Method)
}
@@ -527,7 +600,7 @@ func TestClient_GetAudioProductLevelControls(t *testing.T) {
}
w.WriteHeader(tt.responseStatus)
w.Write([]byte(tt.responseBody))
_, _ = w.Write([]byte(tt.responseBody))
}))
defer server.Close()
@@ -538,6 +611,7 @@ func TestClient_GetAudioProductLevelControls(t *testing.T) {
if err == nil {
t.Errorf("Expected error but got none")
}
return
}
@@ -605,13 +679,22 @@ func TestClient_SetAudioProductLevelControls(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Handle capabilities check
if r.URL.Path == "/capabilities" {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(`<capabilities><capability name="audioproductlevelcontrols"/></capabilities>`))
return
}
// First call might be GET for validation
if r.Method == "GET" && r.URL.Path == "/audioproductlevelcontrols" {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`<audioproductlevelcontrols>
_, _ = w.Write([]byte(`<audioproductlevelcontrols>
<frontCenterSpeakerLevel value="0" minValue="-10" maxValue="10" step="1"/>
<rearSurroundSpeakersLevel value="0" minValue="-8" maxValue="8" step="1"/>
</audioproductlevelcontrols>`))
return
}
@@ -625,7 +708,7 @@ func TestClient_SetAudioProductLevelControls(t *testing.T) {
}
w.WriteHeader(tt.responseStatus)
w.Write([]byte(tt.responseBody))
_, _ = w.Write([]byte(tt.responseBody))
}))
defer server.Close()
@@ -647,20 +730,30 @@ func TestClient_SetAudioProductLevelControls(t *testing.T) {
func TestClient_SetFrontCenterSpeakerLevel(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Handle capabilities check
if r.URL.Path == "/capabilities" {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(`<capabilities><capability name="audioproductlevelcontrols"/></capabilities>`))
return
}
// First call might be GET for validation
if r.Method == "GET" && r.URL.Path == "/audioproductlevelcontrols" {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`<audioproductlevelcontrols>
_, _ = w.Write([]byte(`<audioproductlevelcontrols>
<frontCenterSpeakerLevel value="0" minValue="-10" maxValue="10" step="1"/>
<rearSurroundSpeakersLevel value="0" minValue="-8" maxValue="8" step="1"/>
</audioproductlevelcontrols>`))
return
}
// POST call for setting
if r.Method == "POST" && r.URL.Path == "/audioproductlevelcontrols" {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`<status>OK</status>`))
_, _ = w.Write([]byte(`<status>OK</status>`))
return
}
@@ -669,8 +762,8 @@ func TestClient_SetFrontCenterSpeakerLevel(t *testing.T) {
defer server.Close()
client := createTestClient(server.URL)
err := client.SetFrontCenterSpeakerLevel(5)
err := client.SetFrontCenterSpeakerLevel(5)
if err != nil {
t.Errorf("Expected no error but got: %v", err)
}
@@ -678,20 +771,30 @@ func TestClient_SetFrontCenterSpeakerLevel(t *testing.T) {
func TestClient_SetRearSurroundSpeakersLevel(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Handle capabilities check
if r.URL.Path == "/capabilities" {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(`<capabilities><capability name="audioproductlevelcontrols"/></capabilities>`))
return
}
// First call might be GET for validation
if r.Method == "GET" && r.URL.Path == "/audioproductlevelcontrols" {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`<audioproductlevelcontrols>
_, _ = w.Write([]byte(`<audioproductlevelcontrols>
<frontCenterSpeakerLevel value="0" minValue="-10" maxValue="10" step="1"/>
<rearSurroundSpeakersLevel value="0" minValue="-8" maxValue="8" step="1"/>
</audioproductlevelcontrols>`))
return
}
// POST call for setting
if r.Method == "POST" && r.URL.Path == "/audioproductlevelcontrols" {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`<status>OK</status>`))
_, _ = w.Write([]byte(`<status>OK</status>`))
return
}
@@ -700,8 +803,8 @@ func TestClient_SetRearSurroundSpeakersLevel(t *testing.T) {
defer server.Close()
client := createTestClient(server.URL)
err := client.SetRearSurroundSpeakersLevel(-3)
err := client.SetRearSurroundSpeakersLevel(-3)
if err != nil {
t.Errorf("Expected no error but got: %v", err)
}
@@ -742,6 +845,7 @@ func TestClient_AudioEndpoints_NetworkError(t *testing.T) {
bass := 5
treble := -2
err = client.SetAudioProductToneControls(&bass, &treble)
if err == nil {
t.Errorf("Expected network error for SetAudioProductToneControls but got none")
@@ -764,6 +868,7 @@ func TestClient_AudioEndpoints_NetworkError(t *testing.T) {
frontCenter := 2
rearSurround := -1
err = client.SetAudioProductLevelControls(&frontCenter, &rearSurround)
if err == nil {
t.Errorf("Expected network error for SetAudioProductLevelControls but got none")
+3
View File
@@ -1075,6 +1075,7 @@ func (c *Client) GetAudioDSPControls() (*models.AudioDSPControls, error) {
}
var dspControls models.AudioDSPControls
err = c.get("/audiodspcontrols", &dspControls)
return &dspControls, err
@@ -1146,6 +1147,7 @@ func (c *Client) GetAudioProductToneControls() (*models.AudioProductToneControls
}
var toneControls models.AudioProductToneControls
err = c.get("/audioproducttonecontrols", &toneControls)
return &toneControls, err
@@ -1199,6 +1201,7 @@ func (c *Client) GetAudioProductLevelControls() (*models.AudioProductLevelContro
}
var levelControls models.AudioProductLevelControls
err = c.get("/audioproductlevelcontrols", &levelControls)
return &levelControls, err
+17 -1
View File
@@ -296,6 +296,18 @@ func TestClient_SetClockDisplay(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.expectError && tt.statusCode == 0 {
// For client-side validation errors, we don't need a server
client := createTestClient("http://localhost:8080")
err := client.SetClockDisplay(tt.request)
if err == nil {
t.Error("Expected error, got none")
}
return
}
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/clockDisplay" {
t.Errorf("Expected path '/clockDisplay', got '%s'", r.URL.Path)
@@ -305,7 +317,11 @@ func TestClient_SetClockDisplay(t *testing.T) {
t.Errorf("Expected POST method, got '%s'", r.Method)
}
w.WriteHeader(tt.statusCode)
if tt.statusCode != 0 {
w.WriteHeader(tt.statusCode)
} else {
w.WriteHeader(http.StatusOK)
}
}))
defer server.Close()
+22 -14
View File
@@ -94,9 +94,11 @@ func TestClient_AddZoneSlave(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var receivedMethod string
var receivedPath string
var receivedBody string
var (
receivedMethod string
receivedPath string
receivedBody string
)
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
receivedMethod = r.Method
@@ -104,12 +106,12 @@ func TestClient_AddZoneSlave(t *testing.T) {
if r.Method == "POST" {
body := make([]byte, r.ContentLength)
r.Body.Read(body)
_, _ = r.Body.Read(body)
receivedBody = string(body)
}
w.WriteHeader(tt.responseStatus)
w.Write([]byte(tt.responseBody))
_, _ = w.Write([]byte(tt.responseBody))
}))
defer server.Close()
@@ -122,6 +124,7 @@ func TestClient_AddZoneSlave(t *testing.T) {
if err == nil {
t.Errorf("Expected error but got none")
}
return
}
@@ -171,7 +174,7 @@ func TestClient_AddZoneSlaveByDeviceID(t *testing.T) {
// Read and verify body
body := make([]byte, r.ContentLength)
r.Body.Read(body)
_, _ = r.Body.Read(body)
bodyStr := string(body)
if !strings.Contains(bodyStr, `MASTER123`) {
@@ -188,7 +191,7 @@ func TestClient_AddZoneSlaveByDeviceID(t *testing.T) {
}
w.WriteHeader(http.StatusOK)
w.Write([]byte(`<status>OK</status>`))
_, _ = w.Write([]byte(`<status>OK</status>`))
}))
defer server.Close()
@@ -255,9 +258,11 @@ func TestClient_RemoveZoneSlave(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var receivedMethod string
var receivedPath string
var receivedBody string
var (
receivedMethod string
receivedPath string
receivedBody string
)
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
receivedMethod = r.Method
@@ -265,12 +270,12 @@ func TestClient_RemoveZoneSlave(t *testing.T) {
if r.Method == "POST" {
body := make([]byte, r.ContentLength)
r.Body.Read(body)
_, _ = r.Body.Read(body)
receivedBody = string(body)
}
w.WriteHeader(tt.responseStatus)
w.Write([]byte(tt.responseBody))
_, _ = w.Write([]byte(tt.responseBody))
}))
defer server.Close()
@@ -283,6 +288,7 @@ func TestClient_RemoveZoneSlave(t *testing.T) {
if err == nil {
t.Errorf("Expected error but got none")
}
return
}
@@ -332,7 +338,7 @@ func TestClient_RemoveZoneSlaveByDeviceID(t *testing.T) {
// Read and verify body
body := make([]byte, r.ContentLength)
r.Body.Read(body)
_, _ = r.Body.Read(body)
bodyStr := string(body)
if !strings.Contains(bodyStr, `MASTER123`) {
@@ -344,7 +350,7 @@ func TestClient_RemoveZoneSlaveByDeviceID(t *testing.T) {
}
w.WriteHeader(http.StatusOK)
w.Write([]byte(`<status>OK</status>`))
_, _ = w.Write([]byte(`<status>OK</status>`))
}))
defer server.Close()
@@ -507,6 +513,7 @@ func TestZoneSlaveRequest_HelperMethods(t *testing.T) {
request.AddSlave("SLAVE456", "192.168.1.101")
str := request.String()
expected := "Zone slave operation: master=MASTER123, slave=SLAVE456 (192.168.1.101)"
if str != expected {
t.Errorf("Expected string '%s', got '%s'", expected, str)
@@ -518,6 +525,7 @@ func TestZoneSlaveRequest_HelperMethods(t *testing.T) {
request.AddSlave("SLAVE456", "")
str := request.String()
expected := "Zone slave operation: master=MASTER123, slave=SLAVE456"
if str != expected {
t.Errorf("Expected string '%s', got '%s'", expected, str)
+20
View File
@@ -129,6 +129,7 @@ func (adsp *AudioDSPControls) GetSupportedAudioModes() []string {
if adsp.SupportedAudioModes == "" {
return []string{}
}
return strings.Split(adsp.SupportedAudioModes, "|")
}
@@ -140,12 +141,14 @@ func (adsp *AudioDSPControls) IsAudioModeSupported(mode string) bool {
return true
}
}
return false
}
// String returns a human-readable string representation of DSP controls
func (adsp *AudioDSPControls) String() string {
supportedModes := strings.Join(adsp.GetSupportedAudioModes(), ", ")
return fmt.Sprintf("Audio Mode: %s, Video Sync Delay: %d ms, Supported Modes: [%s]",
adsp.AudioMode, adsp.VideoSyncAudioDelay, supportedModes)
}
@@ -171,6 +174,7 @@ func (bc *BassControlSetting) ValidateBass(value int) error {
if value < bc.MinValue || value > bc.MaxValue {
return fmt.Errorf("bass value %d is outside valid range [%d, %d]", value, bc.MinValue, bc.MaxValue)
}
return nil
}
@@ -179,9 +183,11 @@ func (bc *BassControlSetting) ClampValue(value int) int {
if value < bc.MinValue {
return bc.MinValue
}
if value > bc.MaxValue {
return bc.MaxValue
}
return value
}
@@ -190,6 +196,7 @@ func (tc *TrebleControlSetting) ValidateTreble(value int) error {
if value < tc.MinValue || value > tc.MaxValue {
return fmt.Errorf("treble value %d is outside valid range [%d, %d]", value, tc.MinValue, tc.MaxValue)
}
return nil
}
@@ -198,9 +205,11 @@ func (tc *TrebleControlSetting) ClampValue(value int) int {
if value < tc.MinValue {
return tc.MinValue
}
if value > tc.MaxValue {
return tc.MaxValue
}
return value
}
@@ -249,6 +258,7 @@ func (fc *FrontCenterLevelSetting) ValidateLevel(value int) error {
if value < fc.MinValue || value > fc.MaxValue {
return fmt.Errorf("front-center speaker level %d is outside valid range [%d, %d]", value, fc.MinValue, fc.MaxValue)
}
return nil
}
@@ -257,9 +267,11 @@ func (fc *FrontCenterLevelSetting) ClampLevel(value int) int {
if value < fc.MinValue {
return fc.MinValue
}
if value > fc.MaxValue {
return fc.MaxValue
}
return value
}
@@ -268,6 +280,7 @@ func (rs *RearSurroundLevelSetting) ValidateLevel(value int) error {
if value < rs.MinValue || value > rs.MaxValue {
return fmt.Errorf("rear-surround speaker level %d is outside valid range [%d, %d]", value, rs.MinValue, rs.MaxValue)
}
return nil
}
@@ -276,9 +289,11 @@ func (rs *RearSurroundLevelSetting) ClampLevel(value int) int {
if value < rs.MinValue {
return rs.MinValue
}
if value > rs.MaxValue {
return rs.MaxValue
}
return value
}
@@ -337,15 +352,19 @@ func (ac *AudioCapabilities) HasAdvancedAudioControls() bool {
// GetAvailableControls returns a list of available advanced audio controls
func (ac *AudioCapabilities) GetAvailableControls() []string {
var controls []string
if ac.DSPControls {
controls = append(controls, "DSP Controls")
}
if ac.ProductToneControls {
controls = append(controls, "Tone Controls")
}
if ac.ProductLevelControls {
controls = append(controls, "Level Controls")
}
return controls
}
@@ -356,5 +375,6 @@ func (ac *AudioCapabilities) String() string {
}
controls := ac.GetAvailableControls()
return fmt.Sprintf("Available controls: %s", strings.Join(controls, ", "))
}
+3
View File
@@ -160,6 +160,7 @@ func TestAudioDSPControlsRequest_Validate(t *testing.T) {
t.Errorf("Expected error but got none")
return
}
if !strings.Contains(err.Error(), tt.errorMsg) {
t.Errorf("Expected error message to contain '%s', got '%s'", tt.errorMsg, err.Error())
}
@@ -330,6 +331,7 @@ func TestAudioProductToneControlsRequest_Validate(t *testing.T) {
t.Errorf("Expected error but got none")
return
}
if !strings.Contains(err.Error(), tt.errorMsg) {
t.Errorf("Expected error message to contain '%s', got '%s'", tt.errorMsg, err.Error())
}
@@ -455,6 +457,7 @@ func TestAudioProductLevelControlsRequest_Validate(t *testing.T) {
t.Errorf("Expected error but got none")
return
}
if !strings.Contains(err.Error(), tt.errorMsg) {
t.Errorf("Expected error message to contain '%s', got '%s'", tt.errorMsg, err.Error())
}
+2
View File
@@ -452,6 +452,7 @@ func (zsr *ZoneSlaveRequest) GetSlaveDeviceID() string {
if len(zsr.Members) > 0 {
return zsr.Members[0].DeviceID
}
return ""
}
@@ -460,6 +461,7 @@ func (zsr *ZoneSlaveRequest) GetSlaveIP() string {
if len(zsr.Members) > 0 {
return zsr.Members[0].IP
}
return ""
}
+8
View File
@@ -151,6 +151,7 @@ func TestZoneSlaveRequest_HelperMethods(t *testing.T) {
request.AddSlave("SLAVE456", "192.168.1.101")
deviceID := request.GetSlaveDeviceID()
expected := "SLAVE456"
if deviceID != expected {
t.Errorf("Expected device ID '%s', got '%s'", expected, deviceID)
@@ -171,6 +172,7 @@ func TestZoneSlaveRequest_HelperMethods(t *testing.T) {
request.AddSlave("SLAVE456", "192.168.1.101")
ip := request.GetSlaveIP()
expected := "192.168.1.101"
if ip != expected {
t.Errorf("Expected IP '%s', got '%s'", expected, ip)
@@ -208,6 +210,7 @@ func TestZoneSlaveRequest_String(t *testing.T) {
setup: func() *ZoneSlaveRequest {
req := NewZoneSlaveRequest("MASTER123")
req.AddSlave("SLAVE456", "192.168.1.101")
return req
},
expected: "Zone slave operation: master=MASTER123, slave=SLAVE456 (192.168.1.101)",
@@ -217,6 +220,7 @@ func TestZoneSlaveRequest_String(t *testing.T) {
setup: func() *ZoneSlaveRequest {
req := NewZoneSlaveRequest("MASTER123")
req.AddSlave("SLAVE456", "")
return req
},
expected: "Zone slave operation: master=MASTER123, slave=SLAVE456",
@@ -330,12 +334,14 @@ func TestZoneSlaveRequest_XMLUnmarshaling(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var request ZoneSlaveRequest
err := xml.Unmarshal([]byte(tt.xmlData), &request)
if tt.expectError {
if err == nil {
t.Errorf("Expected error but got none")
}
return
}
@@ -381,6 +387,7 @@ func TestZoneSlaveEntry_XMLMarshaling(t *testing.T) {
}
xmlStr := string(xmlData)
expected := `<member ipaddress="192.168.1.101">SLAVE456</member>`
if xmlStr != expected {
t.Errorf("Expected XML '%s', got '%s'", expected, xmlStr)
@@ -399,6 +406,7 @@ func TestZoneSlaveEntry_XMLMarshaling(t *testing.T) {
}
xmlStr := string(xmlData)
expected := `<member>SLAVE456</member>`
if xmlStr != expected {
t.Errorf("Expected XML '%s', got '%s'", expected, xmlStr)