Module: Winker::Devices::LightBulb

Includes:
OnOff
Included in:
Winker::Device
Defined in:
lib/winker/devices/light_bulb.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from OnOff

#check_last_powered, #off, #off?, #on, #powered?

Class Method Details

.extended(obj) ⇒ Object



18
19
20
# File 'lib/winker/devices/light_bulb.rb', line 18

def self.extended(obj)
  
end

Instance Method Details

#brightnessObject



22
23
24
25
# File 'lib/winker/devices/light_bulb.rb', line 22

def brightness
  check_last_brightness
  @obj_data.last_reading.brightness
end

#brightness=(_brightness) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/winker/devices/light_bulb.rb', line 27

def brightness=(_brightness)
  #set brightness level
  if _brightness == 0
    update(desired_state: {powered: "false", brightness: _brightness})
  else
    update(desired_state: {powered: "true", brightness: _brightness})
  end
end

#check_last_brightnessObject



12
13
14
15
16
# File 'lib/winker/devices/light_bulb.rb', line 12

def check_last_brightness
  wait_for_update( Proc.new{@updated_at < @obj_data.last_reading.brightness_updated_at.to_time}) do
    self.refresh
  end
end

#updates_finished?Boolean

Returns:

  • (Boolean)


6
7
8
9
10
# File 'lib/winker/devices/light_bulb.rb', line 6

def updates_finished?
  check_last_brightness
  check_last_powered
  return true
end