Class: Hue::Bridge

Inherits:
Object
  • Object
show all
Defined in:
lib/hue/bridge.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, hash) ⇒ Bridge

Returns a new instance of Bridge.



41
42
43
44
# File 'lib/hue/bridge.rb', line 41

def initialize(client, hash)
  @client = client
  unpack(hash)
end

Instance Attribute Details

#dhcpObject (readonly)

Whether the IP address of the bridge is obtained with DHCP.



39
40
41
# File 'lib/hue/bridge.rb', line 39

def dhcp
  @dhcp
end

#gatewayObject (readonly)

Gateway IP address of the bridge.



36
37
38
# File 'lib/hue/bridge.rb', line 36

def gateway
  @gateway
end

#idObject (readonly)

ID of the bridge.



4
5
6
# File 'lib/hue/bridge.rb', line 4

def id
  @id
end

#ipObject (readonly)

IP address of the bridge.



11
12
13
# File 'lib/hue/bridge.rb', line 11

def ip
  @ip
end

#ip_whitelistObject (readonly)

An array of whitelisted user IDs.



30
31
32
# File 'lib/hue/bridge.rb', line 30

def ip_whitelist
  @ip_whitelist
end

#mac_addressObject (readonly)

MAC address of the bridge.



14
15
16
# File 'lib/hue/bridge.rb', line 14

def mac_address
  @mac_address
end

#nameObject

Name of the bridge. This is also its uPnP name, so will reflect the actual uPnP name after any conflicts have been resolved.



8
9
10
# File 'lib/hue/bridge.rb', line 8

def name
  @name
end

#network_maskObject (readonly)

Network mask of the bridge.



33
34
35
# File 'lib/hue/bridge.rb', line 33

def network_mask
  @network_mask
end

#proxy_addressObject (readonly)

IP Address of the proxy server being used.



17
18
19
# File 'lib/hue/bridge.rb', line 17

def proxy_address
  @proxy_address
end

#proxy_portObject (readonly)

Port of the proxy being used by the bridge. If set to 0 then a proxy is not being used.



21
22
23
# File 'lib/hue/bridge.rb', line 21

def proxy_port
  @proxy_port
end

#software_updateObject (readonly)

Contains information related to software updates.



27
28
29
# File 'lib/hue/bridge.rb', line 27

def software_update
  @software_update
end

#software_versionObject (readonly)

Software version of the bridge.



24
25
26
# File 'lib/hue/bridge.rb', line 24

def software_version
  @software_version
end

Instance Method Details

#add_lightsObject



80
81
82
83
84
85
# File 'lib/hue/bridge.rb', line 80

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

#groupsObject



87
88
89
90
91
92
93
94
# File 'lib/hue/bridge.rb', line 87

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?Boolean

This indicates whether the bridge is registered to synchronize data with a portal account.

Returns:

  • (Boolean)


61
62
63
64
# File 'lib/hue/bridge.rb', line 61

def has_portal_services?
  json = get_configuration
  json['portalservices']
end

#lightsObject



71
72
73
74
75
76
77
78
# File 'lib/hue/bridge.rb', line 71

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

Indicates whether the link button has been pressed within the last 30 seconds.

Returns:

  • (Boolean)


54
55
56
57
# File 'lib/hue/bridge.rb', line 54

def link_button_pressed?
  json = get_configuration
  json['linkbutton']
end

#refreshObject



66
67
68
69
# File 'lib/hue/bridge.rb', line 66

def refresh
  json = get_configuration
  unpack(json)
end

#scenesObject



96
97
98
99
100
101
102
103
# File 'lib/hue/bridge.rb', line 96

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

#utcObject

Current time stored on the bridge.



47
48
49
50
# File 'lib/hue/bridge.rb', line 47

def utc
  json = get_configuration
  DateTime.parse(json['utc'])
end