Skip to content

Switch & check for playbar TV input #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/sonos/endpoint/a_v_transport.rb
Original file line number Diff line number Diff line change
@@ -32,6 +32,12 @@ def now_playing
}
end

def is_tv?
response = send_transport_message('GetPositionInfo')
body = response.body[:get_position_info_response]
body[:track_uri] =~ /\Ax-sonos-htastream:/ ? true : false
end

def has_music?
!now_playing.nil?
end
@@ -54,6 +60,11 @@ def is_playing?
!['PAUSED_PLAYBACK', 'STOPPED'].include?(state)
end

# Returns true if speaker is quiescent. Playbar "playing" an unconnected TV counts as inactive.
def inactive?
is_playing? == false || (is_tv? == true && get_zone_info[:ht_audio_in] == "0")
end

# Pause the currently playing track.
def pause
parse_response send_transport_message('Pause')
@@ -88,6 +99,10 @@ def line_in(speaker)
set_av_transport_uri('x-rincon-stream:' + speaker.uid.sub('uuid:', ''))
end

def tv
set_av_transport_uri('x-sonos-htastream:%s:spdif' % uid.sub('uuid:', ''))
end

# Seeks to a given timestamp in the current track
# @param [Fixnum] seconds
def seek(seconds = 0)
4 changes: 4 additions & 0 deletions lib/sonos/endpoint/device.rb
Original file line number Diff line number Diff line change
@@ -16,6 +16,10 @@ def status_light_enabled=(enabled)
parse_response send_device_message('SetLEDState', enabled ? 'On' : 'Off')
end

def get_zone_info
send_device_message('GetZoneInfo', '').body[:get_zone_info_response]
end

# Create a stereo pair of two speakers.
# This does not take into account which type of players support bonding.
# Currently only S1/S3 (play:1/play:3) support this but future players may
4 changes: 4 additions & 0 deletions lib/sonos/system.rb
Original file line number Diff line number Diff line change
@@ -31,6 +31,10 @@ def play_all
end
end

def inactive?
speakers.all? &:inactive?
end

# Party Mode! Join all speakers into a single group.
def party_mode new_master = nil
return nil unless speakers.length > 1