Class: HueBridge::LightBulp

Inherits:
Object
  • Object
show all
Defined in:
lib/hue_bridge/light_bulp.rb

Overview

Represents a light bulp. It provides an interface to turn the light on, off and to toggle it.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ LightBulp

Returns a new instance of LightBulp.

Parameters:

  • options (Hash) (defaults to: {})

    LightBulp options

Options Hash (options):

  • :hue_bridge_ip (String)

    The Hue Bridge’s IP

  • :user_id (String)

    The user id to access the api

  • :light_bulp_id (Integer)

    The id of the light bulp



16
17
18
19
20
# File 'lib/hue_bridge/light_bulp.rb', line 16

def initialize(options = {})
  @light_bulp_id = options.fetch(:light_bulp_id)
  @user_id = options.fetch(:user_id)
  @ip = options.fetch(:hue_bridge_ip)
end

Instance Attribute Details

#powerObject (readonly)

Returns the value of attribute power.



9
10
11
# File 'lib/hue_bridge/light_bulp.rb', line 9

def power
  @power
end

Instance Method Details

#alertBoolean

Invokes the alert sequence on the light bulp.

Returns:

  • (Boolean)

    success of the operation



53
54
55
56
# File 'lib/hue_bridge/light_bulp.rb', line 53

def alert
  response = put('state', alert: 'lselect')
  response_successful?(response)
end

#offBoolean

Turns the light bulp off and returns it’s state.

Returns:

  • (Boolean)

    success of the operation



44
45
46
47
48
# File 'lib/hue_bridge/light_bulp.rb', line 44

def off
  response = put('state', on: false)
  set_power_from_response!(response)
  response_successful?(response)
end

#onBoolean

Turns the light bulp on and returns it’s state.

Returns:

  • (Boolean)

    success of the operation



35
36
37
38
39
# File 'lib/hue_bridge/light_bulp.rb', line 35

def on
  response = put('state', on: true)
  set_power_from_response!(response)
  response_successful?(response)
end

#set_color(opts = {}) ⇒ Boolean

Sets the color for the lightbulp.

Returns:

  • (Boolean)

    success of the operation

See Also:



62
63
64
65
66
67
# File 'lib/hue_bridge/light_bulp.rb', line 62

def set_color(opts = {})
  color = Color.new(opts)
  response = put('state', color.to_h)

  response_successful?(response)
end

#toggleBoolean

Toggles the light bulp and returns it’s state.

Returns:

  • (Boolean)

    success of the operation



25
26
27
28
29
30
# File 'lib/hue_bridge/light_bulp.rb', line 25

def toggle
  @power ||= false
  response = put('state', on: !@power)
  set_power_from_response!(response)
  response_successful?(response)
end