Skip to main content

sonos_api/services/group_management/
mod.rs

1//! GroupManagement service for speaker group membership operations
2//!
3//! This service handles group membership operations (add/remove members, track buffering)
4//! for Sonos speaker groups. Operations should only be sent to the group coordinator.
5//!
6//! # Control Operations
7//! ```rust,ignore
8//! use sonos_api::services::group_management;
9//!
10//! let add_op = group_management::add_member("RINCON_123".to_string(), 1).build()?;
11//! client.execute("192.168.1.100", add_op)?;
12//! ```
13//!
14//! # Event Subscriptions
15//! ```rust,ignore
16//! let subscription = group_management::subscribe(&client, "192.168.1.100", "http://callback")?;
17//! ```
18//!
19//! # Event Handling
20//! ```rust,ignore
21//! use sonos_api::services::group_management::events::{GroupManagementEventParser, create_enriched_event};
22//! use sonos_api::events::EventSource;
23//!
24//! let parser = GroupManagementEventParser;
25//! let event_data = parser.parse_upnp_event(xml_content)?;
26//! let enriched = create_enriched_event(speaker_ip, event_source, event_data);
27//! ```
28//!
29//! # Important Notes
30//! - Operations should only be sent to the group coordinator
31
32pub mod events;
33pub mod operations;
34pub mod state;
35
36// Re-export operations for convenience
37pub use operations::*;
38
39// Re-export event types and parsers
40pub use events::{
41    create_enriched_event, create_enriched_event_with_registration_id, GroupManagementEvent,
42    GroupManagementEventParser,
43};
44pub use state::GroupManagementState;
45
46/// Service constant for GroupManagement
47pub const SERVICE: crate::Service = crate::Service::GroupManagement;
48
49/// Subscribe to GroupManagement events
50pub fn subscribe(
51    client: &crate::SonosClient,
52    ip: &str,
53    callback_url: &str,
54) -> crate::Result<crate::ManagedSubscription> {
55    client.subscribe(ip, SERVICE, callback_url)
56}
57
58/// Subscribe to GroupManagement events with custom timeout
59pub fn subscribe_with_timeout(
60    client: &crate::SonosClient,
61    ip: &str,
62    callback_url: &str,
63    timeout_seconds: u32,
64) -> crate::Result<crate::ManagedSubscription> {
65    client.subscribe_with_timeout(ip, SERVICE, callback_url, timeout_seconds)
66}
67
68#[cfg(test)]
69mod tests {
70    use super::*;
71
72    #[test]
73    fn test_module_service_constant() {
74        assert_eq!(SERVICE, crate::Service::GroupManagement);
75    }
76
77    #[test]
78    fn test_subscribe_function_exists() {
79        // Verify subscribe function signature compiles correctly
80        // This is a compile-time check - the function exists with correct types
81        let _: fn(&crate::SonosClient, &str, &str) -> crate::Result<crate::ManagedSubscription> =
82            subscribe;
83    }
84
85    #[test]
86    fn test_subscribe_with_timeout_function_exists() {
87        // Verify subscribe_with_timeout function signature compiles correctly
88        let _: fn(
89            &crate::SonosClient,
90            &str,
91            &str,
92            u32,
93        ) -> crate::Result<crate::ManagedSubscription> = subscribe_with_timeout;
94    }
95}