<s> """<STR_LIT>""" <EOL> import logging <EOL> import soco <EOL> from pi import scanning_proxy <EOL> CURRENTLY_PLAYING_KEYS = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:title>' ) <EOL> class Sonos ( scanning_proxy . ScanningProxy ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , refresh_period , callback ) : <EOL> super ( Sonos , self ) . __init__ ( refresh_period ) <EOL> self . _callback = callback <EOL> self . _devices = { } <EOL> self . _previous_details = { } <EOL> def _scan_once ( self ) : <EOL> devices = soco . discover ( ) <EOL> if devices is None : <EOL> return <EOL> devices = list ( devices ) <EOL> logging . info ( '<STR_LIT>' , len ( devices ) ) <EOL> for device in devices : <EOL> uid = device . uid <EOL> self . _devices [ uid ] = device <EOL> speaker_info = device . get_speaker_info ( ) <EOL> currently_playing = device . get_current_track_info ( ) <EOL> current_transport_info = device . get_current_transport_info ( ) <EOL> details = { <EOL> '<STR_LIT>' : uid , <EOL> '<STR_LIT>' : speaker_info [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : { k : currently_playing . get ( k , None ) <EOL> for k in CURRENTLY_PLAYING_KEYS } , <EOL> '<STR_LIT:state>' : current_transport_info [ '<STR_LIT>' ] , <EOL> } <EOL> if self . _previous_details . get ( uid , None ) != details : <EOL> self . _callback ( '<STR_LIT>' , '<STR_LIT>' % uid , details ) <EOL> self . _previous_details [ uid ] = details </s>
