class TPLink::Light

Control TPLink Dimmable lights @example

light.on # turn on light
light.off # turn off light

# turn on light and set brightness to 50%
light.on
light.on(50)

Public Instance Methods

off() click to toggle source

Turn light off

# File lib/tp_link/light.rb, line 21
def off
  transition_light_state(0, 100)
end
on(b = 100) click to toggle source

Turn light on @param b [Integer<1-100>] Set light intensity between 1 and 100

# File lib/tp_link/light.rb, line 15
def on(b = 100)
  transition_light_state(1, b) if self.off?
  transition_light_state(1, b)
end
toggle() click to toggle source

Toggle device (turn off if on, on if off)

# File lib/tp_link/light.rb, line 26
def toggle
  if on?
    off
  else
    on
  end
end

Private Instance Methods

transition_light_state(o, b) click to toggle source
# File lib/tp_link/light.rb, line 36
def transition_light_state(o, b)
  @parent.send_data(self,
                    "smartlife.iot.smartbulb.lightingservice": {
                      "transition_light_state": {
                        "on_off": o,
                        "brightness": b
                      }
                    })
end