Class: Tradfri::Device

Inherits:
Struct
  • Object
show all
Defined in:
lib/tradfri/device.rb

Constant Summary collapse

LIGHT_CONTROL =
3311
ON_OFF =
5850
OFF =
0
ON =
1
DIMMER =
5851
DIMMER_MIN =
0
DIMMER_MAX =
255
COLOUR =
5706
COLOUR_COLD =
'f5faf6'
COLOUR_NORMAL =
'f1e0b5'
COLOUR_WARM =
'efd275'
NAME =

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

9001
BULBS =

TODO discover this

15001

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#gatewayObject

Returns the value of attribute gateway

Returns:

  • (Object)

    the current value of gateway



4
5
6
# File 'lib/tradfri/device.rb', line 4

def gateway
  @gateway
end

#uriObject

Returns the value of attribute uri

Returns:

  • (Object)

    the current value of uri



4
5
6
# File 'lib/tradfri/device.rb', line 4

def uri
  @uri
end

Instance Method Details

#bulb?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/tradfri/device.rb', line 23

def bulb?
  info.has_key? LIGHT_CONTROL.to_s
end

#coldObject



61
62
63
# File 'lib/tradfri/device.rb', line 61

def cold
  change COLOUR => COLOUR_COLD
end

#dim(brightness) ⇒ Object



57
58
59
# File 'lib/tradfri/device.rb', line 57

def dim(brightness)
  change DIMMER => DIMMER_MIN + (brightness * (DIMMER_MAX - DIMMER_MIN)).round
end

#infoObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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

#nameObject



27
28
29
# File 'lib/tradfri/device.rb', line 27

def name
  info[NAME.to_s]
end

#normalObject



65
66
67
# File 'lib/tradfri/device.rb', line 65

def normal
  change COLOUR => COLOUR_NORMAL
end

#offObject



53
54
55
# File 'lib/tradfri/device.rb', line 53

def off
  change ON_OFF => OFF
end

#onObject



49
50
51
# File 'lib/tradfri/device.rb', line 49

def on
  change ON_OFF => ON
end

#warmObject



69
70
71
# File 'lib/tradfri/device.rb', line 69

def warm
  change COLOUR => COLOUR_WARM
end