Module: Hue::Animations::Sunrise

Included in:
Bulb
Defined in:
lib/hue/animations/sunrise.rb

Constant Summary collapse

SUN_STEPS =
[ 1.5, 2, 3, 1, 4, 2.5 ]
SUN_TIMES =
[ 3,   3, 3, 1, 2, 1]

Instance Method Summary collapse

Instance Method Details

#perform_sunrise(total_time_in_minutes = 18) ⇒ Object

Experimental Sunrise/Sunset action this will transition from off and warm light to on and daytime light in a curve that mimics the actual sunrise.



14
15
16
17
18
19
20
21
# File 'lib/hue/animations/sunrise.rb', line 14

def perform_sunrise(total_time_in_minutes = 18)
  # total_time / 18 steps == time_per_step
  # the multiplier should be 600 * time per step
  minutes_per_step = total_time_in_minutes / 18.0
  multiplier = (minutes_per_step * 60 * 10).to_i

  perform_sun_transition total_time_in_minutes, sunrise_steps(multiplier)
end

#perform_sunset(total_time_in_minutes = 18) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/hue/animations/sunrise.rb', line 38

def perform_sunset(total_time_in_minutes = 18)
  multiplier = sunrise_multiplier total_time_in_minutes
  steps = sunset_steps(multiplier)
  if on?
    puts "ON! #{steps[0][:bri]} :: #{brightness} :: #{brightness > steps[0][:bri]}"
    while brightness <= steps[0][:bri]
      steps.shift
    end
  end
  steps.each_with_index do |step, i|
    update step.merge(on: true)
    sleep(step[:transitiontime] / 10.0)
  end
  off
end