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
-
#half_sine(color, cycles: 1, period: 1.0, transient: true, stream: 0) ⇒ Object
Attempts to make the light(s) transition to
color
smoothly, then immediately back to its original color. -
#pulse(color, cycles: 1, duty_cycle: 0.5, transient: true, period: 1.0, stream: 0) ⇒ Object
Attempts to make the light(s) pulse
color
and then back to its original color. -
#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.
-
#saw(color, cycles: 1, period: 1.0, transient: true, stream: 0) ⇒ Object
Attempts to make the light(s) transition to
color
linearly, then instantly back. -
#set_color(color, duration: LIFX::Config.default_duration) ⇒ Light, LightCollection
Attempts to set the color of the light(s) to
color
asynchronously. -
#set_power(value) ⇒ Light, LightCollection
Attempts to set the power state to
value
asynchronously. -
#set_site_id(site_id) ⇒ void
private
Attempts to set the site id of the light.
-
#set_time(time = Time.now) ⇒ void
private
Attempts to set the device time on the targets.
-
#set_waveform(color, waveform:, cycles:, stream: 0, transient: true, period: 1.0, duty_cycle: 0.5, acknowledge: false) ⇒ Object
private
Attempts to apply a waveform to the light(s) asynchronously.
-
#sine(color, cycles: 1, period: 1.0, transient: true, stream: 0) ⇒ Object
Attempts to make the light(s) transition to
color
and back in a smooth sine wave. -
#triangle(color, cycles: 1, period: 1.0, transient: true, stream: 0) ⇒ Object
Attempts to make the light(s) transition to
color
linearly and back. -
#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
#half_sine(color, cycles: 1, period: 1.0, transient: true, stream: 0) ⇒ Object
Attempts to make the light(s) transition to color
smoothly, then immediately back to its original color. Asynchronous.
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/lifx/light_target.rb', line 86 def half_sine(color, cycles: 1, period: 1.0, transient: true, stream: 0) set_waveform(color, waveform: Protocol::Light::Waveform::HALF_SINE, cycles: cycles, stream: stream, transient: transient, period: period) end |
#pulse(color, cycles: 1, duty_cycle: 0.5, transient: true, period: 1.0, stream: 0) ⇒ Object
Attempts to make the light(s) pulse color
and then back to its original color. Asynchronous.
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/lifx/light_target.rb', line 49 def pulse(color, cycles: 1, duty_cycle: 0.5, transient: true, period: 1.0, stream: 0) set_waveform(color, waveform: Protocol::Light::Waveform::PULSE, cycles: cycles, duty_cycle: duty_cycle, stream: stream, transient: transient, period: period) end |
#reboot! ⇒ Light, LightCollection
Attempts to reboots the light(s). This method cannot guarantee the message was received.
185 186 187 |
# File 'lib/lifx/light_target.rb', line 185 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.
157 158 159 160 |
# File 'lib/lifx/light_target.rb', line 157 def refresh (Protocol::Light::Get.new) self end |
#saw(color, cycles: 1, period: 1.0, transient: true, stream: 0) ⇒ Object
Attempts to make the light(s) transition to color
linearly, then instantly back. Asynchronous.
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/lifx/light_target.rb', line 120 def saw(color, cycles: 1, period: 1.0, transient: true, stream: 0) set_waveform(color, waveform: Protocol::Light::Waveform::SAW, cycles: cycles, stream: stream, transient: transient, period: period) 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(value) ⇒ Light, LightCollection
Attempts to set the power state to value
asynchronously.
This method cannot guarantee the message was received.
135 136 137 138 |
# File 'lib/lifx/light_target.rb', line 135 def set_power(value) (Protocol::Device::SetPower.new(level: value)) self end |
#set_site_id(site_id) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Don't use this unless you know what you're doing.
This method returns an undefined value.
Attempts to set the site id of the light. Will clear label and tags. This method cannot guarantee message receipt.
168 169 170 |
# File 'lib/lifx/light_target.rb', line 168 def set_site_id(site_id) (Protocol::Device::SetSite.new(site: [site_id].pack('H*'))) end |
#set_time(time = Time.now) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Attempts to set the device time on the targets
177 178 179 |
# File 'lib/lifx/light_target.rb', line 177 def set_time(time = Time.now) (Protocol::Device::SetTime.new(time: (time.to_f * NSEC_IN_SEC).round)) end |
#set_waveform(color, waveform:, cycles:, stream: 0, transient: true, period: 1.0, duty_cycle: 0.5, acknowledge: false) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Don't use this directly.
Attempts to apply a waveform to the light(s) asynchronously.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/lifx/light_target.rb', line 24 def set_waveform(color, waveform:, cycles:, stream: 0, transient: true, period: 1.0, duty_cycle: 0.5, acknowledge: false) (Protocol::Light::SetWaveform.new( color: color.to_hsbk, waveform: waveform, cycles: cycles, stream: stream, transient: transient, period: (period * 1_000).to_i, duty_cycle: (duty_cycle * 65535).round - 32768 ), acknowledge: acknowledge) end |
#sine(color, cycles: 1, period: 1.0, transient: true, stream: 0) ⇒ Object
Attempts to make the light(s) transition to color
and back in a smooth sine wave. Asynchronous.
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/lifx/light_target.rb', line 68 def sine(color, cycles: 1, period: 1.0, transient: true, stream: 0) set_waveform(color, waveform: Protocol::Light::Waveform::SINE, cycles: cycles, duty_cycle: 0, stream: stream, transient: transient, period: period) end |
#triangle(color, cycles: 1, period: 1.0, transient: true, stream: 0) ⇒ Object
Attempts to make the light(s) transition to color
linearly and back. Asynchronous.
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/lifx/light_target.rb', line 103 def triangle(color, cycles: 1, period: 1.0, transient: true, stream: 0) set_waveform(color, waveform: Protocol::Light::Waveform::TRIANGLE, cycles: cycles, stream: stream, transient: transient, period: period) end |
#turn_off ⇒ Light, LightCollection
Attempts to turn the light(s) off asynchronously. This method cannot guarantee the message was received.
150 151 152 |
# File 'lib/lifx/light_target.rb', line 150 def turn_off set_power(0) end |
#turn_on ⇒ Light, LightCollection
Attempts to turn the light(s) on asynchronously. This method cannot guarantee the message was received.
143 144 145 |
# File 'lib/lifx/light_target.rb', line 143 def turn_on set_power(1) end |