class Tradfri::Device

Constants

BULBS
COLOUR
COLOUR_COLD
COLOUR_NORMAL
COLOUR_WARM
DIMMER
DIMMER_MAX
DIMMER_MIN
LIGHT_CONTROL
NAME

I don’t know if/where these are officially documented

OFF
ON
ON_OFF

Public Instance Methods

bulb?() click to toggle source
# File lib/tradfri/device.rb, line 23
def bulb?
  info.has_key? LIGHT_CONTROL.to_s
end
cold() click to toggle source
# File lib/tradfri/device.rb, line 61
def cold
  change COLOUR => COLOUR_COLD
end
dim(brightness) click to toggle source
# File lib/tradfri/device.rb, line 57
def dim(brightness)
  change DIMMER => DIMMER_MIN + (brightness * (DIMMER_MAX - DIMMER_MIN)).round
end
info() click to toggle source
# File lib/tradfri/device.rb, line 31
def info
  data = gateway.get(uri)

  result =
    begin
      JSON.parse(data)
    rescue JSON::ParserError
      {}
    end

  case result
  when Hash
    result
  else
    {}
  end
end
name() click to toggle source
# File lib/tradfri/device.rb, line 27
def name
  info[NAME.to_s]
end
normal() click to toggle source
# File lib/tradfri/device.rb, line 65
def normal
  change COLOUR => COLOUR_NORMAL
end
off() click to toggle source
# File lib/tradfri/device.rb, line 53
def off
  change ON_OFF => OFF
end
on() click to toggle source
# File lib/tradfri/device.rb, line 49
def on
  change ON_OFF => ON
end
warm() click to toggle source
# File lib/tradfri/device.rb, line 69
def warm
  change COLOUR => COLOUR_WARM
end

Private Instance Methods

change(state) click to toggle source
# File lib/tradfri/device.rb, line 73
        def change(state)
  gateway.put uri, JSON.generate(LIGHT_CONTROL => [state])
end