Class: LifxHttp::LifxLight

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/lifx_http/lifx_light.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ LifxLight

Returns a new instance of LifxLight.



19
20
21
22
23
24
# File 'lib/lifx_http/lifx_light.rb', line 19

def initialize(data)
  @light_id = data["id"]
  @data = OpenStruct.new(data)
  @updated_at = Time.now
  @http_api = Api.with_default_selector(selector)
end

Instance Attribute Details

#light_idObject (readonly)

Returns the value of attribute light_id.



11
12
13
# File 'lib/lifx_http/lifx_light.rb', line 11

def light_id
  @light_id
end

Class Method Details

.get_lightsObject



13
14
15
16
17
# File 'lib/lifx_http/lifx_light.rb', line 13

def self.get_lights
  @lights ||= Api.with_default_selector("all").get_info.map do |data|
    LifxLight.new(data)
  end
end

Instance Method Details

#inspectObject



31
32
33
# File 'lib/lifx_http/lifx_light.rb', line 31

def inspect
  "#<#{self.class.name} light_id=#{light_id.inspect} label=#{label.inspect} connected=#{connected.inspect} power=#{power.inspect} color=#{color.inspect} brightness=#{brightness.inspect} product_name=#{product_name.inspect} last_seen=#{last_seen.inspect} seconds_since_seen=#{seconds_since_seen.inspect} @updated_at=#{@updated_at}>"
end

#update_infoObject



26
27
28
29
# File 'lib/lifx_http/lifx_light.rb', line 26

def update_info
  @data ||= OpenStruct.new(@http_api.get_info)
  @updated_at = Time.now
end