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
-
#reboot! ⇒ Light, LightCollection
Attempts to reboots the light(s).
-
#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
#reboot! ⇒ Light, LightCollection
Attempts to reboots the light(s). This method cannot guarantee the message was received.
203 204 205 |
# File 'lib/lifx/light_target.rb', line 203 def reboot! (Protocol::Device::Reboot.new) end |
#refresh ⇒ Light, LightCollection
Requests light(s) to report their state This method cannot guarantee the message was received.
175 176 177 178 |
# File 'lib/lifx/light_target.rb', line 175 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.
145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/lifx/light_target.rb', line 145 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.
168 169 170 |
# File 'lib/lifx/light_target.rb', line 168 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.
161 162 163 |
# File 'lib/lifx/light_target.rb', line 161 def turn_on set_power(:on) end |