sonos-state
Internal state management crate for the Sonos SDK. Provides property storage, change detection, and event iteration.
Note: This is an internal crate. For the public API, use
sonos-sdkwhich provides a DOM-like interface for accessing speaker properties.
Overview
sonos-state provides the backing state management infrastructure for sonos-sdk. It handles:
- Property value storage and caching
- Change detection for watched properties
- Blocking iteration over change events
- UPnP event decoding and property updates
Architecture
sonos-sdk (Public API)
│
└── Speaker.volume.get() / fetch() / watch()
│
▼
sonos-state (Internal State Management)
│
├── StateManager (property storage + watch tracking)
├── ChangeIterator (blocking event iteration)
└── Property types (Volume, Mute, PlaybackState, etc.)
│
▼
state-store (Generic Storage Primitives)
Role in the SDK
The sonos-sdk crate provides the public-facing DOM-like API:
// Public API via sonos-sdk
let speaker = system.get_speaker_by_name?;
let volume = speaker.volume.get; // Uses sonos-state internally
speaker.volume.watch?; // Registers watch in sonos-state
Internally, sonos-sdk delegates to sonos-state:
speaker.volume.get()→state_manager.get_property::<Volume>(speaker_id)speaker.volume.watch()→state_manager.register_watch(speaker_id, "volume")system.iter()→state_manager.iter()
Key Components
StateManager
Central state management with property storage and watch tracking:
ChangeIterator
Blocking iterator over property change events:
Property Types
Sonos-specific property types with UPnP service metadata:
| Property | Service | Description |
|---|---|---|
Volume |
RenderingControl | Master volume (0-100) |
Mute |
RenderingControl | Mute state |
Bass, Treble |
RenderingControl | EQ settings |
Loudness |
RenderingControl | Loudness compensation |
PlaybackState |
AVTransport | Playing/Paused/Stopped |
Position |
AVTransport | Track position and duration |
CurrentTrack |
AVTransport | Track metadata |
GroupMembership |
ZoneGroupTopology | Group info |
Property Traits
// Generic trait from state-store
// Sonos-specific extension
Change Event Flow
- UPnP event received by
sonos-event-manager - Event decoded and property value extracted
StateManager::set_property()called with new value- If property is watched,
ChangeEventemitted to channel ChangeIteratordelivers event to consumer
Dependencies
state-store- Generic state management primitivessonos-api- UPnP operations and typessonos-discovery- Device discovery types
License
MIT License
See Also
sonos-sdk- Public DOM-like API (use this for applications)state-store- Generic state management primitivessonos-api- Low-level UPnP operations