11use std:: collections:: BTreeMap ;
2- use std:: time:: Duration ;
32use std:: sync:: Arc ;
3+ use std:: time:: Duration ;
44
55use anyhow:: { Context , Result } ;
66use futures:: TryStreamExt ;
@@ -140,7 +140,7 @@ impl SonosService {
140140 cmd = self . cmd_rx. recv( ) => {
141141 if let Some ( c) = cmd {
142142 let mut needs_refresh = false ;
143-
143+
144144 // Process the first command
145145 match self . handle_command( c) . await {
146146 Ok ( r) => if r { needs_refresh = true ; } ,
@@ -155,10 +155,8 @@ impl SonosService {
155155 }
156156 }
157157
158- if needs_refresh {
159- if let Err ( e) = self . refresh_state( ) . await {
160- warn!( "Failed to refresh state after commands: {}" , e) ;
161- }
158+ if needs_refresh && let Err ( e) = self . refresh_state( ) . await {
159+ warn!( "Failed to refresh state after commands: {}" , e) ;
162160 }
163161 } else {
164162 warn!( "Command channel was closed: exiting..." ) ;
@@ -264,8 +262,7 @@ impl SonosService {
264262<EnqueuedURIMetaData>{}</EnqueuedURIMetaData>
265263<DesiredFirstTrackNumberEnqueued>0</DesiredFirstTrackNumberEnqueued>
266264<EnqueueAsNext>1</EnqueueAsNext>"# ,
267- favorite. uri,
268- favorite. metadata
265+ favorite. uri, favorite. metadata
269266 ) ;
270267
271268 match speaker. action ( & service, "AddURIToQueue" , & payload) . await {
@@ -284,7 +281,9 @@ impl SonosService {
284281 } else {
285282 // For individual tracks, use queue_next
286283 debug ! ( "Using queue_next for track..." ) ;
287- speaker. queue_next ( & unescaped_uri, & unescaped_metadata) . await ?;
284+ speaker
285+ . queue_next ( & unescaped_uri, & unescaped_metadata)
286+ . await ?;
288287 speaker. next ( ) . await ?;
289288 info ! ( "Successfully started playing: {}" , favorite. title) ;
290289 }
@@ -302,11 +301,15 @@ impl SonosService {
302301 }
303302
304303 async fn refresh_state ( & mut self ) -> Result < ( ) > {
305- let uuid = self . groups . get ( self . selected_group )
304+ let uuid = self
305+ . groups
306+ . get ( self . selected_group )
306307 . map ( |g| g. coordinator . clone ( ) )
307308 . context ( "No selected group" ) ?;
308-
309- let speaker = self . speakers_by_uuid . get ( & uuid)
309+
310+ let speaker = self
311+ . speakers_by_uuid
312+ . get ( & uuid)
310313 . context ( "Speaker not found" ) ?
311314 . clone ( ) ;
312315
@@ -465,13 +468,7 @@ fn parse_favorite_playlists(xml: &str) -> Vec<FavoritePlaylist> {
465468 for item in items {
466469 // Extract URI from <res> tag
467470 let uri = extract_tag_content ( item, "<res" , "</res>" )
468- . and_then ( |res_block| {
469- if let Some ( start) = res_block. find ( '>' ) {
470- Some ( & res_block[ start + 1 ..] )
471- } else {
472- None
473- }
474- } )
471+ . and_then ( |res_block| res_block. find ( '>' ) . map ( |start| & res_block[ start + 1 ..] ) )
475472 . unwrap_or ( "" ) ;
476473
477474 // Filter for playlists only (check URI patterns and upnp:class)
0 commit comments