mirror of
https://github.com/gesellix/Bose-SoundTouch.git
synced 2026-08-24 14:47:23 +00:00
Fix WebSocket XML tag issue by removing unused WebSocketMessage struct
The WebSocketMessage struct was causing a lint error due to invalid xml:",any" tag. Investigation revealed this struct was unused in actual WebSocket parsing - the ParseWebSocketEvent() function works directly with WebSocketEvent struct. Changes: - Removed unused WebSocketMessage struct and its GetEventType() method - Removed corresponding tests - WebSocket functionality verified working (all tests pass) - Actual parsing uses WebSocketEvent which has proper XML tags This resolves the SA5008 lint warning while maintaining full WebSocket functionality.
This commit is contained in:
@@ -77,45 +77,6 @@ type WebSocketEvent struct {
|
||||
Timestamp time.Time `json:"timestamp"` // Added by client for tracking
|
||||
}
|
||||
|
||||
// WebSocketMessage represents a single event message within the updates
|
||||
type WebSocketMessage struct {
|
||||
XMLName xml.Name `json:"-"`
|
||||
EventType WebSocketEventType `json:"eventType"`
|
||||
Content interface{} `json:"content"`
|
||||
}
|
||||
|
||||
// GetEventType returns the event type based on the XML element name
|
||||
func (m *WebSocketMessage) GetEventType() WebSocketEventType {
|
||||
switch m.XMLName.Local {
|
||||
case "nowPlayingUpdated":
|
||||
return EventTypeNowPlaying
|
||||
case "volumeUpdated":
|
||||
return EventTypeVolumeUpdated
|
||||
case "connectionStateUpdated":
|
||||
return EventTypeConnectionState
|
||||
case "presetUpdated":
|
||||
return EventTypePresetUpdated
|
||||
case "zoneUpdated":
|
||||
return EventTypeZoneUpdated
|
||||
case "bassUpdated":
|
||||
return EventTypeBassUpdated
|
||||
case "clockTimeUpdated":
|
||||
return EventTypeClockTimeUpdated
|
||||
case "clockDisplayUpdated":
|
||||
return EventTypeClockDisplayUpdated
|
||||
case "nameUpdated":
|
||||
return EventTypeNameUpdated
|
||||
case "errorUpdated":
|
||||
return EventTypeErrorUpdated
|
||||
case "recentsUpdated":
|
||||
return EventTypeRecentsUpdated
|
||||
case "languageUpdated":
|
||||
return EventTypeLanguageUpdated
|
||||
default:
|
||||
return EventTypeUnknown
|
||||
}
|
||||
}
|
||||
|
||||
// GetEvents returns all events present in this WebSocket event
|
||||
func (e *WebSocketEvent) GetEvents() []interface{} {
|
||||
var events []interface{}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -38,38 +37,6 @@ func TestWebSocketEventType_String(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWebSocketMessage_GetEventType(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
xmlName xml.Name
|
||||
expected WebSocketEventType
|
||||
}{
|
||||
{"NowPlaying", xml.Name{Local: "nowPlayingUpdated"}, EventTypeNowPlaying},
|
||||
{"VolumeUpdated", xml.Name{Local: "volumeUpdated"}, EventTypeVolumeUpdated},
|
||||
{"ConnectionState", xml.Name{Local: "connectionStateUpdated"}, EventTypeConnectionState},
|
||||
{"PresetUpdated", xml.Name{Local: "presetUpdated"}, EventTypePresetUpdated},
|
||||
{"ZoneUpdated", xml.Name{Local: "zoneUpdated"}, EventTypeZoneUpdated},
|
||||
{"BassUpdated", xml.Name{Local: "bassUpdated"}, EventTypeBassUpdated},
|
||||
{"ClockTimeUpdated", xml.Name{Local: "clockTimeUpdated"}, EventTypeClockTimeUpdated},
|
||||
{"ClockDisplayUpdated", xml.Name{Local: "clockDisplayUpdated"}, EventTypeClockDisplayUpdated},
|
||||
{"NameUpdated", xml.Name{Local: "nameUpdated"}, EventTypeNameUpdated},
|
||||
{"ErrorUpdated", xml.Name{Local: "errorUpdated"}, EventTypeErrorUpdated},
|
||||
{"RecentsUpdated", xml.Name{Local: "recentsUpdated"}, EventTypeRecentsUpdated},
|
||||
{"LanguageUpdated", xml.Name{Local: "languageUpdated"}, EventTypeLanguageUpdated},
|
||||
{"Unknown", xml.Name{Local: "unknownEvent"}, EventTypeUnknown},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
msg := WebSocketMessage{XMLName: tt.xmlName}
|
||||
result := msg.GetEventType()
|
||||
if result != tt.expected {
|
||||
t.Errorf("WebSocketMessage.GetEventType() = %v, want %v", result, tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestConnectionState_IsConnected(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user