sonos 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af1c1b8f83305ffe42a1b10d381588515d48cbc9
4
- data.tar.gz: 29057282b16426b582c13e3ad0e0f3bd2ced837b
3
+ metadata.gz: df9944fdb181f7e979b67372e6457be32ddb7995
4
+ data.tar.gz: b865559508e5b6ddf95a92b3d34a8935a659af3e
5
5
  SHA512:
6
- metadata.gz: c82f4e8c4cc8f88dbf015c2b485c621998a8ef26619911f8963cb4e8903170f7d4b92ddfeb7a94f170bd3a6c2d0439fb32910cf677b4dc9057f8492fce299e43
7
- data.tar.gz: 537ed42bad05889053b4969cd46292ee9e5e491581a4e04a4a4131fb79995eb81bd9f4e16cb7cdb9a5dd2e0d1611c4a9c2b88030e6607b8134fcc2c9b61d6063
6
+ metadata.gz: 23639b6d07de2b63b13ac2b7a4f40be1a22ffc421595cc781dcdcdb4150ec0d00f95586d48b8a13fed8f4929d864665e3d015be8b912d1921be788b31fa35028
7
+ data.tar.gz: ffc6f16907f7d7c2e010f193c5254cf4e7228cff3e37bb938f15981816ab6c88d50438df9c6686be87bab32bbe2c116991294e589112f1fcca9ec565c5799ae6
@@ -59,6 +59,14 @@ speaker.save_queue 'Jams'
59
59
  speaker.clear_queue
60
60
  ```
61
61
 
62
+ Or go into what the official control from Sonos, Inc. calls "Party
63
+ Mode": put all speakers into a single group
64
+
65
+ ``` ruby
66
+ system.party_mode
67
+ system.party_over
68
+ ```
69
+
62
70
  ### Topology
63
71
 
64
72
  `Sonos.discover` finds the first speaker it can. We can get all of the Sonos devices (including Bridges, etc) by calling `Sonos.system.devices`. To get the groups, call `Sonos.system.groups`.
@@ -17,17 +17,27 @@ module Sonos
17
17
  end
18
18
  end
19
19
 
20
- desc 'pause_all', 'Pauses all Sonos speaker groups'
20
+ desc 'pause_all', 'Pause all speaker groups.'
21
21
  def pause_all
22
22
  system.pause_all
23
23
  end
24
24
 
25
- desc 'play_all', 'Resumes playing all Sonos speaker groups'
25
+ desc 'play_all', 'Resume playing all speaker groups.'
26
26
  def play_all
27
27
  system.play_all
28
28
  end
29
29
 
30
- desc 'groups', 'List all Sonos groups'
30
+ desc 'party_mode', 'Start a party! Put all speakers in the same group.'
31
+ def party_mode
32
+ system.party_mode
33
+ end
34
+
35
+ desc 'party_over', 'No more party :( Put all speakers in their own group.'
36
+ def party_over
37
+ system.party_over
38
+ end
39
+
40
+ desc 'groups', 'List all groups'
31
41
  def groups
32
42
  system.groups.each do |group|
33
43
  puts group.master_speaker.name.ljust(20) + group.master_speaker.ip
@@ -40,6 +50,14 @@ module Sonos
40
50
  end
41
51
  end
42
52
 
53
+ desc 'speaker [name] [command] [args]', 'Control a speaker'
54
+ def speaker(name, command, *args)
55
+ speakers = system.speakers.select { |s| s.name.downcase == name.downcase }
56
+ puts "Could not find speaker" and return if speakers.length == 0
57
+
58
+ speakers.each { |s| s.send command, *args }
59
+ end
60
+
43
61
  private
44
62
 
45
63
  def system
@@ -9,11 +9,7 @@ module Sonos
9
9
  # Initialize the system
10
10
  # @param [Array] the system topology. If this is nil, it will autodiscover.
11
11
  def initialize(topology = Discovery.new.topology)
12
- @topology = topology
13
- @groups = []
14
- @devices = @topology.collect(&:device)
15
-
16
- construct_groups
12
+ rescan topology
17
13
  end
18
14
 
19
15
  # Returns all speakers
@@ -35,15 +31,51 @@ module Sonos
35
31
  end
36
32
  end
37
33
 
38
- private
34
+ # Party Mode! Join all speakers into a single group.
35
+ def party_mode new_master = nil
36
+ return nil unless speakers.length > 1
37
+
38
+ new_master = find_party_master if new_master.nil?
39
+
40
+ party_over
41
+ speakers.each do |slave|
42
+ next if slave.uid == new_master.uid
43
+ slave.join new_master
44
+ end
45
+ rescan @topology
46
+ end
47
+
48
+ def find_party_master
49
+ # 1: If there are any pre-existing groups playing something, use
50
+ # the lowest-numbered group's master
51
+ groups.each do |group|
52
+ return group.master_speaker if group.master_speaker.has_music?
53
+ end
39
54
 
40
- def send_to_all_speakers(action)
41
- if self.groups.length > 0
42
- self.groups.each { |group| group.send action }
43
- else
44
- self.speakers.each { |speaker| speaker.send action }
55
+ # 2: Lowest-number speaker that's playing something
56
+ speakers.each do |speaker|
57
+ return speaker if speaker.has_music?
45
58
  end
59
+
60
+ # 3: lowest-numbered speaker
61
+ speakers[0]
46
62
  end
63
+
64
+ # Party's over :(
65
+ def party_over
66
+ groups.each { |g| g.disband }
67
+ rescan @topology
68
+ end
69
+
70
+ def rescan(topology = Discovery.new.topology)
71
+ @topology = topology
72
+ @groups = []
73
+ @devices = @topology.collect(&:device)
74
+
75
+ construct_groups
76
+ end
77
+
78
+ private
47
79
 
48
80
  def construct_groups
49
81
  # Loop through all of the unique groups
@@ -1,3 +1,3 @@
1
1
  module Sonos
2
- VERSION = '0.3.2'
2
+ VERSION = '0.3.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sonos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Soffes
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-28 00:00:00.000000000 Z
12
+ date: 2013-06-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: savon