mirror of
https://github.com/gesellix/Bose-SoundTouch.git
synced 2026-08-19 00:56:16 +00:00
- Implement GET/POST /clockTime endpoints for device time management - Implement GET/POST /clockDisplay endpoints for clock display configuration - Implement GET /networkInfo endpoint with real API structure - Add comprehensive models for ClockTime, ClockDisplay, and NetworkInformation - Update NetworkInformation to match real SoundTouch API responses: * WiFi interfaces with SSID, frequency, signal strength, and connection state * Ethernet interfaces with connection state * Proper attribute-based XML structure matching actual device responses - Add CLI support for all system endpoints with detailed output formatting - Add comprehensive test coverage for all new models and client methods - Update documentation to reflect real API structure and capabilities - Anonymize all personal data (IP addresses, device IDs, device names) - Add SYSTEM-ENDPOINTS.md documentation with real-world examples Features: - Clock time sync with current system time or specific timestamps - Clock display configuration (enable/disable, format, brightness, auto-dim) - Rich network interface information with WiFi signal quality and frequency bands - Support for both WiFi and Ethernet SoundTouch devices - Validated against real SoundTouch 10 and SoundTouch 20 device responses All tests pass and builds successfully.
178 lines
4.6 KiB
Go
178 lines
4.6 KiB
Go
package models
|
|
|
|
import (
|
|
"encoding/xml"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// ClockDisplay represents the device's clock display settings
|
|
type ClockDisplay struct {
|
|
XMLName xml.Name `xml:"clockDisplay"`
|
|
DeviceID string `xml:"deviceID,attr,omitempty"`
|
|
Enabled bool `xml:"enabled,attr,omitempty"`
|
|
Format string `xml:"format,attr,omitempty"`
|
|
Brightness int `xml:"brightness,attr,omitempty"`
|
|
AutoDim bool `xml:"autoDim,attr,omitempty"`
|
|
TimeZone string `xml:"timeZone,attr,omitempty"`
|
|
Value string `xml:",chardata"`
|
|
}
|
|
|
|
// ClockFormat represents supported clock display formats
|
|
type ClockFormat string
|
|
|
|
const (
|
|
ClockFormat12Hour ClockFormat = "12"
|
|
ClockFormat24Hour ClockFormat = "24"
|
|
ClockFormatAuto ClockFormat = "auto"
|
|
)
|
|
|
|
// IsEnabled returns true if the clock display is enabled
|
|
func (c *ClockDisplay) IsEnabled() bool {
|
|
return c.Enabled
|
|
}
|
|
|
|
// GetFormat returns the clock display format (12/24 hour)
|
|
func (c *ClockDisplay) GetFormat() string {
|
|
if c.Format == "" {
|
|
return "12" // Default to 12-hour format
|
|
}
|
|
return c.Format
|
|
}
|
|
|
|
// GetFormatDescription returns a human-readable format description
|
|
func (c *ClockDisplay) GetFormatDescription() string {
|
|
switch strings.ToLower(c.Format) {
|
|
case "12":
|
|
return "12-hour format (AM/PM)"
|
|
case "24":
|
|
return "24-hour format"
|
|
case "auto":
|
|
return "Auto format (system default)"
|
|
default:
|
|
return "12-hour format (AM/PM)" // Default
|
|
}
|
|
}
|
|
|
|
// GetBrightness returns the display brightness level (0-100)
|
|
func (c *ClockDisplay) GetBrightness() int {
|
|
if c.Brightness < 0 {
|
|
return 0
|
|
}
|
|
if c.Brightness > 100 {
|
|
return 100
|
|
}
|
|
return c.Brightness
|
|
}
|
|
|
|
// GetBrightnessLevel returns a descriptive brightness level
|
|
func (c *ClockDisplay) GetBrightnessLevel() string {
|
|
brightness := c.GetBrightness()
|
|
switch {
|
|
case brightness == 0:
|
|
return "Off"
|
|
case brightness <= 25:
|
|
return "Low"
|
|
case brightness <= 50:
|
|
return "Medium"
|
|
case brightness <= 75:
|
|
return "High"
|
|
default:
|
|
return "Maximum"
|
|
}
|
|
}
|
|
|
|
// IsAutoDimEnabled returns true if auto-dim is enabled
|
|
func (c *ClockDisplay) IsAutoDimEnabled() bool {
|
|
return c.AutoDim
|
|
}
|
|
|
|
// GetTimeZone returns the timezone setting
|
|
func (c *ClockDisplay) GetTimeZone() string {
|
|
return c.TimeZone
|
|
}
|
|
|
|
// GetDeviceID returns the device ID
|
|
func (c *ClockDisplay) GetDeviceID() string {
|
|
return c.DeviceID
|
|
}
|
|
|
|
// IsEmpty returns true if the clock display has no configuration
|
|
func (c *ClockDisplay) IsEmpty() bool {
|
|
return !c.Enabled && c.Format == "" && c.Brightness == 0 && c.TimeZone == ""
|
|
}
|
|
|
|
// ClockDisplayRequest represents a request to configure clock display settings
|
|
type ClockDisplayRequest struct {
|
|
XMLName xml.Name `xml:"clockDisplay"`
|
|
Enabled *bool `xml:"enabled,attr,omitempty"`
|
|
Format string `xml:"format,attr,omitempty"`
|
|
Brightness *int `xml:"brightness,attr,omitempty"`
|
|
AutoDim *bool `xml:"autoDim,attr,omitempty"`
|
|
TimeZone string `xml:"timeZone,attr,omitempty"`
|
|
}
|
|
|
|
// NewClockDisplayRequest creates a new clock display configuration request
|
|
func NewClockDisplayRequest() *ClockDisplayRequest {
|
|
return &ClockDisplayRequest{}
|
|
}
|
|
|
|
// SetEnabled sets whether the clock display is enabled
|
|
func (r *ClockDisplayRequest) SetEnabled(enabled bool) *ClockDisplayRequest {
|
|
r.Enabled = &enabled
|
|
return r
|
|
}
|
|
|
|
// SetFormat sets the clock display format (12/24 hour)
|
|
func (r *ClockDisplayRequest) SetFormat(format ClockFormat) *ClockDisplayRequest {
|
|
r.Format = string(format)
|
|
return r
|
|
}
|
|
|
|
// SetBrightness sets the display brightness (0-100)
|
|
func (r *ClockDisplayRequest) SetBrightness(brightness int) *ClockDisplayRequest {
|
|
if brightness < 0 {
|
|
brightness = 0
|
|
}
|
|
if brightness > 100 {
|
|
brightness = 100
|
|
}
|
|
r.Brightness = &brightness
|
|
return r
|
|
}
|
|
|
|
// SetAutoDim sets whether auto-dim is enabled
|
|
func (r *ClockDisplayRequest) SetAutoDim(autoDim bool) *ClockDisplayRequest {
|
|
r.AutoDim = &autoDim
|
|
return r
|
|
}
|
|
|
|
// SetTimeZone sets the timezone
|
|
func (r *ClockDisplayRequest) SetTimeZone(timeZone string) *ClockDisplayRequest {
|
|
r.TimeZone = timeZone
|
|
return r
|
|
}
|
|
|
|
// Validate checks if the clock display request is valid
|
|
func (r *ClockDisplayRequest) Validate() error {
|
|
if r.Format != "" {
|
|
format := strings.ToLower(r.Format)
|
|
if format != "12" && format != "24" && format != "auto" {
|
|
return fmt.Errorf("invalid format '%s': must be '12', '24', or 'auto'", r.Format)
|
|
}
|
|
}
|
|
|
|
if r.Brightness != nil {
|
|
if *r.Brightness < 0 || *r.Brightness > 100 {
|
|
return fmt.Errorf("brightness must be between 0 and 100, got %d", *r.Brightness)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// HasChanges returns true if the request has any configuration changes
|
|
func (r *ClockDisplayRequest) HasChanges() bool {
|
|
return r.Enabled != nil || r.Format != "" || r.Brightness != nil || r.AutoDim != nil || r.TimeZone != ""
|
|
}
|