Module: LIFX::LAN::LightTarget
- Included in:
- Light, LightCollection
- Defined in:
- lib/lifx/lan/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. -
#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::LAN::Config.default_duration) ⇒ Light, LightCollection
Attempts to set the color of the light(s) to
color
asynchronously. -
#set_multizone_color(color, start_index: 0, end_index: 7, duration: LIFX::LAN::Config.default_duration) ⇒ Light, LightCollection
Attempts to set multiple zones on the light(s) to
color
asynchronously. -
#set_power(state) ⇒ Light, LightCollection
Attempts to set the power state to
state
asynchronously. -
#set_tile_colors(colors, tile_start_index: 0, length: 1, duration: LIFX::LAN::Config.default_duration) ⇒ Light, LightCollection
Attempts to set every pixel on the tile(s) to
colors
asynchronously. -
#sine(color, cycles: 1, period: 1.0, peak: 0.5, transient: true, stream: 0) ⇒ Object
Attempts to make the light(s) transition to
color
and back in a smooth sine wave. -
#tile_info ⇒ Hash
Raw tile info.
-
#triangle(color, cycles: 1, period: 1.0, peak: 0.5, 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.
-
#zone_count ⇒ Numeric
Number of zones supported.
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.
143 144 145 146 147 148 149 150 151 152 |
# File 'lib/lifx/lan/light_target.rb', line 143 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.
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/lifx/lan/light_target.rb', line 104 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, skew_ratio: 1 - duty_cycle, stream: stream, transient: transient, period: period) end |
#refresh ⇒ Light, LightCollection
Requests light(s) to report their state This method cannot guarantee the message was received.
224 225 226 227 |
# File 'lib/lifx/lan/light_target.rb', line 224 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.
179 180 181 182 183 184 185 186 187 188 |
# File 'lib/lifx/lan/light_target.rb', line 179 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::LAN::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.
13 14 15 16 17 18 19 20 |
# File 'lib/lifx/lan/light_target.rb', line 13 def set_color(color, duration: LIFX::LAN::Config.default_duration) (Protocol::Light::SetColor.new( color: color.to_hsbk, duration: (duration * MSEC_PER_SEC).to_i, stream: 0, )) self end |
#set_multizone_color(color, start_index: 0, end_index: 7, duration: LIFX::LAN::Config.default_duration) ⇒ Light, LightCollection
Attempts to set multiple zones on the light(s) to color
asynchronously.
This method cannot guarantee that the message was received.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/lifx/lan/light_target.rb', line 29 def set_multizone_color(color, start_index: 0, end_index: 7, duration: LIFX::LAN::Config.default_duration) (Protocol::MultiZone::SetColorZones.new( start_index: start_index, end_index: end_index, color: color.to_hsbk, duration: (duration * MSEC_PER_SEC).to_i, apply: 1, )) self end |
#set_power(state) ⇒ Light, LightCollection
Attempts to set the power state to state
asynchronously.
This method cannot guarantee the message was received.
194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/lifx/lan/light_target.rb', line 194 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 |
#set_tile_colors(colors, tile_start_index: 0, length: 1, duration: LIFX::LAN::Config.default_duration) ⇒ Light, LightCollection
Attempts to set every pixel on the tile(s) to colors
asynchronously.
This method cannot guarantee that the message was received.
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/lifx/lan/light_target.rb', line 47 def set_tile_colors(colors, tile_start_index: 0, length: 1, duration: LIFX::LAN::Config.default_duration) (Protocol::Tile::SetTileState64.new( colors: colors.map(&:to_hsbk), tile_start_index: tile_start_index, tile_length: [length, 1].min, x: 0, y: 0, width: 8, duration: (duration * MSEC_PER_SEC).to_i )) self end |
#sine(color, cycles: 1, period: 1.0, peak: 0.5, transient: true, stream: 0) ⇒ Object
Attempts to make the light(s) transition to color
and back in a smooth sine wave. Asynchronous.
124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/lifx/lan/light_target.rb', line 124 def sine(color, cycles: 1, period: 1.0, peak: 0.5, transient: true, stream: 0) set_waveform(color, waveform: Protocol::Light::Waveform::SINE, cycles: cycles, skew_ratio: peak, stream: stream, transient: transient, period: period) end |
#tile_info ⇒ Hash
Returns Raw tile info.
69 70 71 72 73 74 |
# File 'lib/lifx/lan/light_target.rb', line 69 def tile_info (Protocol::Tile::GetDeviceChain.new, wait_for: Protocol::Tile::StateDeviceChain) do |payload| payload end end |
#triangle(color, cycles: 1, period: 1.0, peak: 0.5, transient: true, stream: 0) ⇒ Object
Attempts to make the light(s) transition to color
linearly and back. Asynchronous.
160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/lifx/lan/light_target.rb', line 160 def triangle(color, cycles: 1, period: 1.0, peak: 0.5, transient: true, stream: 0) set_waveform(color, waveform: Protocol::Light::Waveform::TRIANGLE, cycles: cycles, skew_ratio: peak, 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.
217 218 219 |
# File 'lib/lifx/lan/light_target.rb', line 217 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.
210 211 212 |
# File 'lib/lifx/lan/light_target.rb', line 210 def turn_on set_power(:on) end |
#zone_count ⇒ Numeric
Returns Number of zones supported.
61 62 63 64 65 66 |
# File 'lib/lifx/lan/light_target.rb', line 61 def zone_count (Protocol::MultiZone::GetColorZones.new(start_index: 0, end_index: 0), wait_for: Protocol::MultiZone::StateZone) do |payload| payload.total_zones end end |