Module: LIFX::LightTarget
- Included in:
- Light, LightCollection
- Defined in:
- lib/lifx/light_target.rb
Overview
LightTarget is a module that contains Light commands that can work with either a single Light or multiple Lights via a LightCollection
Constant Summary collapse
- MSEC_PER_SEC =
1000
- NSEC_IN_SEC =
1_000_000_000
Instance Method Summary collapse
-
#refresh ⇒ Light, LightCollection
Requests light(s) to report their state This method cannot guarantee the message was received.
-
#set_color(color, duration: LIFX::Config.default_duration) ⇒ Light, LightCollection
Attempts to set the color of the light(s) to
color
asynchronously. -
#set_power(state) ⇒ Light, LightCollection
Attempts to set the power state to
state
asynchronously. -
#turn_off ⇒ Light, LightCollection
Attempts to turn the light(s) off asynchronously.
-
#turn_on ⇒ Light, LightCollection
Attempts to turn the light(s) on asynchronously.
Instance Method Details
#refresh ⇒ Light, LightCollection
Requests light(s) to report their state This method cannot guarantee the message was received.
179 180 181 182 |
# File 'lib/lifx/light_target.rb', line 179 def refresh (Protocol::Light::Get.new) self end |
#set_color(color, duration: LIFX::Config.default_duration) ⇒ Light, LightCollection
Attempts to set the color of the light(s) to color
asynchronously.
This method cannot guarantee that the message was received.
12 13 14 15 16 17 18 19 |
# File 'lib/lifx/light_target.rb', line 12 def set_color(color, duration: LIFX::Config.default_duration) (Protocol::Light::Set.new( color: color.to_hsbk, duration: (duration * MSEC_PER_SEC).to_i, stream: 0, )) self end |
#set_power(state) ⇒ Light, LightCollection
Attempts to set the power state to state
asynchronously.
This method cannot guarantee the message was received.
149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/lifx/light_target.rb', line 149 def set_power(state) level = case state when :on 1 when :off 0 else raise ArgumentError.new("Must pass in either :on or :off") end (Protocol::Device::SetPower.new(level: level)) self end |
#turn_off ⇒ Light, LightCollection
Attempts to turn the light(s) off asynchronously. This method cannot guarantee the message was received.
172 173 174 |
# File 'lib/lifx/light_target.rb', line 172 def turn_off set_power(:off) end |
#turn_on ⇒ Light, LightCollection
Attempts to turn the light(s) on asynchronously. This method cannot guarantee the message was received.
165 166 167 |
# File 'lib/lifx/light_target.rb', line 165 def turn_on set_power(:on) end |