class Hue::Group
Constants
- GROUP_KEYS_MAP
- STATE_KEYS_MAP
Attributes
Bridge
the group is associated with
Brightness of the group. This is a scale from the minimum brightness the group is capable of, 0, to the maximum capable brightness, 255. Note a brightness of 0 is not off.
The Mired Color temperature of the light. 2012 connected lights are capable of 153 (6500K) to 500 (2000K).
Hue
of the group. This is a wrapping value between 0 and 65535. Both 0 and 65535 are red, 25500 is green and 46920 is blue.
Unique identification number.
A unique, editable name given to the group.
Saturation of the group. 255 is the most saturated (colored) and 0 is the least saturated (white).
A fixed name describing the type of group.
The x coordinate of a color in CIE color space. Between 0 and 1.
@see developers.meethue.com/coreconcepts.html#color_gets_more_complicated
The y coordinate of a color in CIE color space. Between 0 and 1.
@see developers.meethue.com/coreconcepts.html#color_gets_more_complicated
Public Class Methods
# File lib/hue/group.rb, line 48 def initialize(client, bridge, id = nil, data = {}) @client = client @bridge = bridge @id = id unpack(data) end
Public Instance Methods
# File lib/hue/group.rb, line 89 def <<(light_id) @light_ids << light_id set_group_state({:lights => @light_ids}) end
# File lib/hue/group.rb, line 121 def create! body = { :name => @name, :lights => @light_ids, } uri = URI.parse("http://#{@bridge.ip}/api/#{@client.username}/groups") http = Net::HTTP.new(uri.host) response = http.request_post(uri.path, JSON.dump(body)) json = JSON(response.body) @id = json[0]['success']['id'] end
# File lib/hue/group.rb, line 135 def destroy! uri = URI.parse(base_url) http = Net::HTTP.new(uri.host) response = http.delete(uri.path) json = JSON(response.body) @id = nil if json[0]['success'] end
# File lib/hue/group.rb, line 56 def each(&block) lights.each(&block) end
# File lib/hue/group.rb, line 60 def lights @lights ||= begin @light_ids.map do |light_id| @client.light(light_id) end end end
# File lib/hue/group.rb, line 73 def lights=(light_ids) light_ids.map! do |light_id| light_id.is_a?(Light) ? light_id.id : light_id.to_s end @light_ids = light_ids.uniq @lights = nil # resets the memoization set_group_state({:lights => @light_ids}) end
# File lib/hue/group.rb, line 68 def name=(name) resp = set_group_state({:name => name}) @name = new? ? name : resp[0]['success']["/groups/#{id}/name"] end
# File lib/hue/group.rb, line 143 def new? @id.nil? end
# File lib/hue/group.rb, line 115 def refresh json = JSON(Net::HTTP.get(URI.parse(base_url))) unpack(json) @lights = nil end
# File lib/hue/group.rb, line 84 def scene=(scene) scene_id = scene.is_a?(Scene) ? scene.id : scene set_group_state({:scene => scene_id}) end
# File lib/hue/group.rb, line 95 def set_group_state(attributes) return if new? body = translate_keys(attributes, GROUP_KEYS_MAP) uri = URI.parse(base_url) http = Net::HTTP.new(uri.host) response = http.request_put(uri.path, JSON.dump(body)) JSON(response.body) end
# File lib/hue/group.rb, line 105 def set_state(attributes) return if new? body = translate_keys(attributes, STATE_KEYS_MAP) uri = URI.parse("#{base_url}/action") http = Net::HTTP.new(uri.host) response = http.request_put(uri.path, JSON.dump(body)) JSON(response.body) end
Private Instance Methods
# File lib/hue/group.rb, line 177 def base_url "http://#{@bridge.ip}/api/#{@client.username}/groups/#{id}" end
# File lib/hue/group.rb, line 168 def unpack(data) unpack_hash(data, GROUP_KEYS_MAP) unless new? unpack_hash(@state, STATE_KEYS_MAP) @x, @y = @state['xy'] end end