Class: Wizrb::Lighting::Scenes::Scene

Inherits:
Object
  • Object
show all
Defined in:
lib/wizrb/lighting/scenes/scene.rb

Direct Known Subclasses

SpookyScene

Instance Method Summary collapse

Constructor Details

#initialize(group, stop_delay: 1, save: true) ⇒ Scene

Returns a new instance of Scene.



9
10
11
12
13
14
15
16
# File 'lib/wizrb/lighting/scenes/scene.rb', line 9

def initialize(group, stop_delay: 1, save: true)
  validate!(group)
  @group = group
  @stop_delay = stop_delay
  @save = save
  @running = false
  @thread = nil
end

Instance Method Details

#startObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/wizrb/lighting/scenes/scene.rb', line 18

def start
  @running = true
  @thread = Thread.new do
    save_state if @save
    before_start
    step while @running
    after_stop
  ensure
    restore_state if @save
  end
end

#stopObject



30
31
32
33
34
# File 'lib/wizrb/lighting/scenes/scene.rb', line 30

def stop
  @running = false
  sleep(@stop_delay)
  @thread.terminate
end