Class: HueBridge::LightBulp
- Inherits:
-
Object
- Object
- HueBridge::LightBulp
- 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
-
#power ⇒ Object
readonly
Returns the value of attribute power.
Instance Method Summary collapse
-
#alert ⇒ Boolean
Invokes the alert sequence on the light bulp.
-
#initialize(options = {}) ⇒ LightBulp
constructor
A new instance of LightBulp.
-
#off ⇒ Boolean
Turns the light bulp off and returns it’s state.
-
#on ⇒ Boolean
Turns the light bulp on and returns it’s state.
-
#set_color(opts = {}) ⇒ Boolean
Sets the color for the lightbulp.
-
#toggle ⇒ Boolean
Toggles the light bulp and returns it’s state.
Constructor Details
#initialize(options = {}) ⇒ LightBulp
Returns a new instance of LightBulp.
16 17 18 19 20 |
# File 'lib/hue_bridge/light_bulp.rb', line 16 def initialize( = {}) @light_bulp_id = .fetch(:light_bulp_id) @user_id = .fetch(:user_id) @ip = .fetch(:hue_bridge_ip) end |
Instance Attribute Details
#power ⇒ Object (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
#alert ⇒ Boolean
Invokes the alert sequence on the light bulp.
53 54 55 56 |
# File 'lib/hue_bridge/light_bulp.rb', line 53 def alert response = put('state', alert: 'lselect') response_successful?(response) end |
#off ⇒ Boolean
Turns the light bulp off and returns it’s state.
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 |
#on ⇒ Boolean
Turns the light bulp on and returns it’s state.
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.
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 |
#toggle ⇒ Boolean
Toggles the light bulp and returns it’s state.
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 |