1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//! High-level Sonos API for device control
//!
//! This crate provides a type-safe, trait-based API for controlling Sonos devices.
//! It uses the private `soap-client` crate for low-level SOAP communication.
//!
//! # UPnP Architecture
//!
//! This API correctly implements the UPnP architecture used by Sonos devices:
//!
//! - **Control Operations**: Commands like Play, Pause, SetVolume are sent to `/Control` endpoints
//! - **Event Subscriptions**: Subscriptions for state change notifications are sent to `/Event` endpoints
//!
//! These are completely separate and independent concepts that work together to provide
//! both control and monitoring capabilities.
//!
//! # Enhanced Operation Framework
//!
//! The operation framework provides composable, declarative UPnP operations with validation,
//! retry policies, and timeouts:
//!
//! ```rust,ignore
//! use sonos_api::{SonosClient, services::av_transport, services::rendering_control};
//! use sonos_api::operation::ValidationLevel;
//!
//! let client = SonosClient::new();
//!
//! // Simple operation execution
//! let play_op = av_transport::play("1".to_string())
//! .with_validation(ValidationLevel::Comprehensive)
//! .build()?;
//!
//! client.execute_enhanced("192.168.1.100", play_op)?;
//!
//! // Composed operations
//! let sequence = av_transport::play("1".to_string())
//! .build()?
//! .and_then(rendering_control::set_volume("Master".to_string(), 75).build()?);
//!
//! client.execute_sequence("192.168.1.100", sequence)?;
//! ```
//!
//! # Event Subscription Management
//!
//! UPnP event subscriptions allow you to receive real-time state change notifications
//! from Sonos devices. Subscriptions are managed separately from control operations:
//!
//! ## Client-Level Subscriptions
//!
//! Subscribe directly to any service using the client:
//!
//! ```rust,ignore
//! use sonos_api::{SonosClient, Service};
//!
//! let client = SonosClient::new();
//!
//! // Subscribe to AVTransport events (play/pause state changes)
//! let av_subscription = client.subscribe(
//! "192.168.1.100",
//! Service::AVTransport,
//! "http://192.168.1.50:8080/callback"
//! )?;
//!
//! // Subscribe to RenderingControl events (volume changes)
//! let rc_subscription = client.subscribe(
//! "192.168.1.100",
//! Service::RenderingControl,
//! "http://192.168.1.50:8080/callback"
//! )?;
//!
//! // Custom timeout (default is 1800 seconds)
//! let long_subscription = client.subscribe_with_timeout(
//! "192.168.1.100",
//! Service::AVTransport,
//! "http://192.168.1.50:8080/callback",
//! 7200 // 2 hours
//! )?;
//! ```
//!
//! ## Service-Level Subscription Helpers
//!
//! Each service module provides convenient subscription helpers:
//!
//! ```rust,ignore
//! use sonos_api::{SonosClient, services::av_transport, services::rendering_control};
//!
//! let client = SonosClient::new();
//!
//! // Subscribe to specific services using module helpers
//! let av_subscription = av_transport::subscribe(
//! &client,
//! "192.168.1.100",
//! "http://192.168.1.50:8080/callback"
//! )?;
//!
//! let rc_subscription = rendering_control::subscribe(
//! &client,
//! "192.168.1.100",
//! "http://192.168.1.50:8080/callback"
//! )?;
//!
//! // With custom timeout
//! let long_av_subscription = av_transport::subscribe_with_timeout(
//! &client,
//! "192.168.1.100",
//! "http://192.168.1.50:8080/callback",
//! 3600
//! )?;
//! ```
//!
//! ## Subscription Lifecycle Management
//!
//! All subscriptions return a `ManagedSubscription` that handles lifecycle management:
//!
//! ```rust,ignore
//! let subscription = client.subscribe(
//! "192.168.1.100",
//! Service::AVTransport,
//! "http://192.168.1.50:8080/callback"
//! )?;
//!
//! // Check if renewal is needed and renew if so
//! if subscription.needs_renewal() {
//! subscription.renew()?;
//! }
//!
//! // Clean up when done
//! subscription.unsubscribe()?;
//! ```
//!
//! The `ManagedSubscription` handles all lifecycle management including expiration tracking,
//! renewal logic, and proper cleanup.
//!
//! ## Control Operations and Subscriptions Together
//!
//! Control operations and subscriptions work independently but can be used together:
//!
//! ```rust,ignore
//! use sonos_api::{SonosClient, Service, services::av_transport};
//!
//! let client = SonosClient::new();
//!
//! // Set up event subscription first
//! let subscription = client.subscribe(
//! "192.168.1.100",
//! Service::AVTransport,
//! "http://192.168.1.50:8080/callback"
//! )?;
//!
//! // Execute control operations
//! let play_op = av_transport::play("1".to_string()).build()?;
//! client.execute_enhanced("192.168.1.100", play_op)?;
//!
//! // The subscription will receive events about state changes
//! // caused by the control operations
//! ```
// Enhanced operation framework
// Enhanced services
// New event handling framework
// Common types shared across the workspace
pub use ;
// Legacy exports for backward compatibility
pub use SonosClient;
pub use ;
pub use SonosOperation; // Legacy trait
pub use ;
pub use ManagedSubscription;
// New enhanced operation framework exports
pub use ;
// New event handling framework exports
pub use ;
// Enhanced services are available through the services module