class Hue::Bridge
Constants
- KEYS_MAP
Attributes
dhcp[R]
Whether the IP address of the bridge is obtained with DHCP.
gateway[R]
Gateway IP address of the bridge.
id[R]
ID of the bridge.
ip[R]
IP address of the bridge.
ip_whitelist[R]
An array of whitelisted user IDs.
mac_address[R]
MAC address of the bridge.
name[RW]
Name of the bridge. This is also its uPnP name, so will reflect the actual uPnP name after any conflicts have been resolved.
network_mask[R]
Network mask of the bridge.
proxy_address[R]
IP Address of the proxy server being used.
proxy_port[R]
Port of the proxy being used by the bridge. If set to 0 then a proxy is not being used.
software_update[R]
Contains information related to software updates.
software_version[R]
Software version of the bridge.
Public Class Methods
new(client, hash)
click to toggle source
# File lib/hue/bridge.rb, line 41 def initialize(client, hash) @client = client unpack(hash) end
Public Instance Methods
add_lights()
click to toggle source
# File lib/hue/bridge.rb, line 83 def add_lights uri = URI.parse("#{base_url}/lights") http = Net::HTTP.new(uri.host) response = http.request_post(uri.path, nil) (response.body).first end
groups()
click to toggle source
# File lib/hue/bridge.rb, line 90 def groups @groups ||= begin json = JSON(Net::HTTP.get(URI.parse("#{base_url}/groups"))) json.map do |id, data| Group.new(@client, self, id, data) end end end
has_portal_services?()
click to toggle source
This indicates whether the bridge is registered to synchronize data with a portal account.
# File lib/hue/bridge.rb, line 61 def has_portal_services? json = get_configuration json['portalservices'] end
lights()
click to toggle source
# File lib/hue/bridge.rb, line 74 def lights @lights ||= begin json = JSON(Net::HTTP.get(URI.parse(base_url))) json['lights'].map do |key, value| Light.new(@client, self, key, value) end end end
refresh()
click to toggle source
# File lib/hue/bridge.rb, line 66 def refresh json = get_configuration unpack(json) @lights = nil @groups = nil @scenes = nil end
scenes()
click to toggle source
# File lib/hue/bridge.rb, line 99 def scenes @scenes ||= begin json = JSON(Net::HTTP.get(URI.parse("#{base_url}/scenes"))) json.map do |id, data| Scene.new(@client, self, id, data) end end end
utc()
click to toggle source
Current time stored on the bridge.
# File lib/hue/bridge.rb, line 47 def utc json = get_configuration DateTime.parse(json['utc']) end
Private Instance Methods
base_url()
click to toggle source
# File lib/hue/bridge.rb, line 136 def base_url "http://#{ip}/api/#{@client.username}" end
get_configuration()
click to toggle source
# File lib/hue/bridge.rb, line 132 def get_configuration JSON(Net::HTTP.get(URI.parse("#{base_url}/config"))) end
unpack(hash)
click to toggle source
# File lib/hue/bridge.rb, line 124 def unpack(hash) KEYS_MAP.each do |local_key, remote_key| value = hash[remote_key.to_s] next unless value instance_variable_set("@#{local_key}", value) end end