Skip to content

Commit

Permalink
fix logic error for muting groups - look at groups, not streams
Browse files Browse the repository at this point in the history
  • Loading branch information
ahayworth committed Aug 11, 2021
1 parent 579c618 commit 111e759
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions autoconfig.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,26 @@
end
end

# For streams that are *not* playing, these groups should all be emptied out.
# It's otherwise possible to get into a state where a group is misconfigured with another, highly specific
# stream rather than silence. For example, in my home right now if I play to the "kitchen" group, the bedroom actually
# starts playing too. That's not correct unless and until the "whole house" style streams are active.
server.streams.select do |stream|
if !stream.playing? && @config['streams'].has_key?(stream.id)
server.groups.select do |group|
if group.stream.id == stream.id && !group.muted
@logger.info "MISCONFIGURED: #{group.stream.id}"
@logger.info <<~EOF
Going to mute group '#{group.id}' / '#{group.name}' / '#{group.stream.id}'!
EOF

# Muting is a little easier than figuring out how to actually empty
# out groups for snapcast...
group.muted = true
end
# Mute any incorrectly configured groups.
# An incorrectly-configured group is one which, at this point
# is pointing towards a managed stream, but that stream's
# configuration does not specify the client in question.
# We mute because frankly that's just a lot easier given
# the weird, idiosyncratic way that snapcast manages groups
# and streams and clients.
server.groups.each do |group|
# Is this a playing, managed groups? If so, check it.
if group.stream.playing? && @config['streams'].has_key?(group.stream.id)
group_client_list = group.clients.map(&:id).sort
config_client_list = @config['streams'][group.stream.id]['clients'].sort

if group_client_list != config_client_list
@logger.info "MISCONFIGURED: #{group.stream.id}"
@logger.info <<~EOF
Going to mute group '#{group.id}' / '#{group.name}' / '#{group.stream.id}'!
EOF

group.muted = true
end
end
end
Expand Down

0 comments on commit 111e759

Please sign in to comment.