Skip to main content

Crate sonos_state

Crate sonos_state 

Source
Expand description

Internal implementation detail of sonos-sdk. Not intended for direct use.

Sonos State Management

A sync-first state management system for Sonos devices.

§Features

  • Sync API: All operations are synchronous - no async/await required
  • Type-safe State: Strongly typed properties with automatic change detection
  • Change Events: Blocking iterator over property changes
  • Watch Pattern: Register for property changes, iterate to receive them

§Quick Start

use sonos_state::{StateManager, Volume, SpeakerId};
use sonos_discovery;

// Create state manager (sync - no .await!)
let manager = StateManager::new()?;

// Add discovered devices
let devices = sonos_discovery::get();
manager.add_devices(devices)?;

// Get current property value
let speaker_id = SpeakerId::new("RINCON_123");
if let Some(vol) = manager.get_property::<Volume>(&speaker_id) {
    println!("Current volume: {}%", vol.0);
}

// Watch for changes
manager.register_watch(&speaker_id, "volume");

// Blocking iteration over changes
for event in manager.iter() {
    println!("{} changed on {}", event.property_key, event.speaker_id);
    if let Some(vol) = manager.get_property::<Volume>(&event.speaker_id) {
        println!("New volume: {}%", vol.0);
    }
}

§Non-blocking Iteration

// Check for events without blocking
for event in manager.iter().try_iter() {
    println!("Event: {:?}", event);
}

// Wait with timeout
if let Some(event) = manager.iter().recv_timeout(Duration::from_secs(1)) {
    println!("Got event: {:?}", event);
}

Re-exports§

pub use state::ChangeEvent;
pub use state::ChangeSource;
pub use state::EventInitFn;
pub use state::StateManager;
pub use state::StateManagerBuilder;
pub use state::WriteOutcome;
pub use state::WriteStamp;
pub use iter::ChangeIterator;
pub use property::Bass;
pub use property::CurrentTrack;
pub use property::GroupInfo;
pub use property::GroupMembership;
pub use property::GroupMute;
pub use property::GroupVolume;
pub use property::GroupVolumeChangeable;
pub use property::Loudness;
pub use property::Mute;
pub use property::PlaybackState;
pub use property::Position;
pub use property::Scope;
pub use property::SonosProperty;
pub use property::Topology;
pub use property::Treble;
pub use property::Volume;
pub use model::SpeakerInfo;
pub use decoder::decode_event;
pub use decoder::decode_topology_event;
pub use decoder::parse_track_metadata;
pub use decoder::DecodedChanges;
pub use decoder::PropertyChange;
pub use decoder::TopologyChanges;
pub use error::Result;
pub use error::StateError;

Modules§

decoder
Event decoder - converts EnrichedEvent to typed property changes
error
Error types for sonos-state
iter
Sync-first change iterator for property updates
model
Model types for sonos-state
prelude
Commonly used types for convenient importing
property
Property trait and built-in properties for Sonos state management
speaker
Speaker-related types and utilities
state
Sync-first State Management for Sonos devices

Structs§

GroupId
Unique identifier for a zone group
SpeakerId
Unique identifier for a Sonos speaker

Traits§

Property
Marker trait for properties that can be stored and watched