Class: NLHue::Group
Overview
A class representing a designated group of lights on a Hue bridge. Recommended use is to call NLHue::Bridge#groups.
Instance Attribute Summary
Attributes inherited from Target
#bridge, #id, #name, #transitiontime, #type
Instance Method Summary collapse
-
#handle_json(info) ⇒ Object
Updates this Group with data parsed from the Hue bridge.
-
#initialize(bridge, id, info = nil) ⇒ Group
constructor
bridge - The Bridge that controls this light.
-
#light_ids ⇒ Object
An array containing the IDs of the lights belonging to this group.
-
#lights ⇒ Object
Returns an array containing this group’s corresponding Light objects from the Bridge.
-
#recall_scene(scene) ⇒ Object
Recalls
scene
, which may be a Scene object or a scene ID String, on this group only. -
#state ⇒ Object
Returns a Hash containing the group’s info and most recently set state, with symbolized key names and hue scaled to 0..360.
-
#to_s ⇒ Object
“Group: [ID]: [name] ([num] lights)”.
Methods inherited from Target
#alert, #alert!, #alert=, #bri, #bri=, #clear_alert, #colormode, #ct, #ct=, #defer, #effect, #effect=, #hue, #hue=, #nodefer, #off!, #on!, #on=, #on?, #sat, #sat=, #send_changes, #submit, #to_h, #to_json, #update, #x, #x=, #xy, #xy=, #y, #y=
Constructor Details
#initialize(bridge, id, info = nil) ⇒ Group
14 15 16 17 18 |
# File 'lib/nlhue/group.rb', line 14 def initialize(bridge, id, info=nil) @lights ||= Set.new super bridge, id, info, :groups, 'action' end |
Instance Method Details
#handle_json(info) ⇒ Object
Updates this Group with data parsed from the Hue bridge.
21 22 23 24 25 26 27 28 |
# File 'lib/nlhue/group.rb', line 21 def handle_json(info) super info # A group returns no lights for a short time after creation if @info['lights'].is_a?(Array) && !@info['lights'].empty? @lights.replace @info['lights'].map(&:to_i) end end |
#light_ids ⇒ Object
An array containing the IDs of the lights belonging to this group.
44 45 46 |
# File 'lib/nlhue/group.rb', line 44 def light_ids @lights.to_a end |
#lights ⇒ Object
Returns an array containing this group’s corresponding Light objects from the Bridge.
37 38 39 40 |
# File 'lib/nlhue/group.rb', line 37 def lights lights = @bridge.lights @lights.map{|id| lights[id]} end |
#recall_scene(scene) ⇒ Object
Recalls scene
, which may be a Scene object or a scene ID String, on this group only. Any raw ID String will not be verified. If NLHue::Target#defer was called, the scene will not be recalled until #submit is called.
73 74 75 76 77 |
# File 'lib/nlhue/group.rb', line 73 def recall_scene(scene) scene = scene.id if scene.is_a?(Scene) raise 'Scene ID to recall must be a String' unless scene.is_a?(String) set('scene' => scene) end |
#state ⇒ Object
Returns a Hash containing the group’s info and most recently set state, with symbolized key names and hue scaled to 0..360. Example:
:id => 0,
:name => 'Lightset 0',
:type => 'LightGroup',
:lights => [0, 1, 2],
:on => false,
:bri => 220,
:ct => 500,
:x => 0.5,
:y => 0.5,
:hue => 193.5,
:sat => 255,
:colormode => 'hs'
65 66 67 |
# File 'lib/nlhue/group.rb', line 65 def state {lights: light_ids}.merge!(super) end |
#to_s ⇒ Object
“Group: [ID]: [name] ([num] lights)”
31 32 33 |
# File 'lib/nlhue/group.rb', line 31 def to_s "Group: #{@id}: #{@name} (#{@lights.length} lights}" end |