Class: Hue::Bulb

Inherits:
Object
  • Object
show all
Includes:
Animations::Candle, Animations::Sunrise
Defined in:
lib/hue/bulb.rb

Constant Summary collapse

BRIGHTNESS_MAX =
255
NONE =
'none'
COLOR_LOOP =
'colorloop'

Constants included from Animations::Sunrise

Animations::Sunrise::SUN_STEPS, Animations::Sunrise::SUN_TIMES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Animations::Sunrise

#perform_sunrise, #perform_sunset

Methods included from Animations::Candle

#candle

Constructor Details

#initialize(bridge, light_id, options = {}) ⇒ Bulb

Returns a new instance of Bulb.



19
20
21
22
23
# File 'lib/hue/bulb.rb', line 19

def initialize(bridge, light_id, options = {})
  @bridge = bridge
  @id = light_id
  @options = options
end

Instance Attribute Details

#bridgeObject (readonly)

Returns the value of attribute bridge.



16
17
18
# File 'lib/hue/bulb.rb', line 16

def bridge
  @bridge
end

#idObject (readonly)

Returns the value of attribute id.



16
17
18
# File 'lib/hue/bulb.rb', line 16

def id
  @id
end

#optionsObject

Returns the value of attribute options.



17
18
19
# File 'lib/hue/bulb.rb', line 17

def options
  @options
end

Instance Method Details

#[](item) ⇒ Object



44
45
46
# File 'lib/hue/bulb.rb', line 44

def [](item)
  state[item.to_s]
end

#alertObject



139
140
141
# File 'lib/hue/bulb.rb', line 139

def alert
  self['alert']
end

#alert=(value) ⇒ Object



143
144
145
# File 'lib/hue/bulb.rb', line 143

def alert=(value)
  update_state(alert: value.to_s)
end


155
156
157
# File 'lib/hue/bulb.rb', line 155

def blink
  self.alert = 'lselect'
end

#blinking?Boolean

Returns:

  • (Boolean)


147
148
149
# File 'lib/hue/bulb.rb', line 147

def blinking?
  !solid?
end

#brightnessObject Also known as: bri



74
75
76
# File 'lib/hue/bulb.rb', line 74

def brightness
  self[:bri]
end

#brightness=(bri) ⇒ Object Also known as: bri=



80
81
82
83
84
85
86
87
# File 'lib/hue/bulb.rb', line 80

def brightness=(bri)
  if scale = Hue.percent_to_unit_interval(bri)
    update_state(bri: (scale * BRIGHTNESS_MAX).round)
  else
    update_state(bri: bri.to_i)
  end
  brightness
end

#brightness_in_unit_intervalObject



91
92
93
# File 'lib/hue/bulb.rb', line 91

def brightness_in_unit_interval
  brightness / BRIGHTNESS_MAX.to_f
end

#brightness_percentObject



95
96
97
# File 'lib/hue/bulb.rb', line 95

def brightness_percent
  (brightness_in_unit_interval * 100).round
end

#clear_effectObject



135
136
137
# File 'lib/hue/bulb.rb', line 135

def clear_effect
  self.effect = NONE
end

#colorObject



105
106
107
# File 'lib/hue/bulb.rb', line 105

def color
  set_color
end

#color=(col) ⇒ Object



109
110
111
112
# File 'lib/hue/bulb.rb', line 109

def color=(col)
  update_state(col.to_hash)
  set_color
end

#color_loopObject Also known as: colorloop



126
127
128
# File 'lib/hue/bulb.rb', line 126

def color_loop
  self.effect = COLOR_LOOP
end

#color_loop?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/hue/bulb.rb', line 131

def color_loop?
  COLOR_LOOP == self.effect
end

#color_modeObject Also known as: colormode



99
100
101
# File 'lib/hue/bulb.rb', line 99

def color_mode
  self[:colormode]
end

#effectObject



114
115
116
# File 'lib/hue/bulb.rb', line 114

def effect
  self['effect']
end

#effect=(value) ⇒ Object



118
119
120
# File 'lib/hue/bulb.rb', line 118

def effect=(value)
  update_state(effect: value.to_s)
end

#effect?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/hue/bulb.rb', line 122

def effect?
  NONE != self.effect
end

#flashObject



163
164
165
166
167
# File 'lib/hue/bulb.rb', line 163

def flash
  self.alert = 'select'
  # immediately update to expected state
  status['state']['alert'] = NONE
end

#infoObject



29
30
31
32
33
# File 'lib/hue/bulb.rb', line 29

def info
  status.select do |k, value|
    value.is_a?(String)
  end
end

#nameObject



48
49
50
# File 'lib/hue/bulb.rb', line 48

def name
  status['name']
end

#name=(_name) ⇒ Object



52
53
54
# File 'lib/hue/bulb.rb', line 52

def name=(_name)
  update(name: _name)
end

#offObject



69
70
71
72
# File 'lib/hue/bulb.rb', line 69

def off
  update_state(on: false)
  off?
end

#off?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/hue/bulb.rb', line 60

def off?
  !on?
end

#onObject



64
65
66
67
# File 'lib/hue/bulb.rb', line 64

def on
  update_state(on: true)
  on?
end

#on?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/hue/bulb.rb', line 56

def on?
  self[:on]
end

#refresh!Object



25
26
27
# File 'lib/hue/bulb.rb', line 25

def refresh!
  @status = bridge.get_light(id)
end

#solidObject



159
160
161
# File 'lib/hue/bulb.rb', line 159

def solid
  self.alert = NONE
end

#solid?Boolean

Returns:

  • (Boolean)


151
152
153
# File 'lib/hue/bulb.rb', line 151

def solid?
  NONE == alert
end

#stateObject



35
36
37
# File 'lib/hue/bulb.rb', line 35

def state
  status['state']
end

#state=(value) ⇒ Object

Free for all, no checking.



40
41
42
# File 'lib/hue/bulb.rb', line 40

def state=(value)
  update_state(value)
end

#transition_timeObject

transition time in seconds



170
171
172
# File 'lib/hue/bulb.rb', line 170

def transition_time
  (options[:transitiontime] || 0).to_f / 10
end

#transition_time=(time) ⇒ Object



174
175
176
# File 'lib/hue/bulb.rb', line 174

def transition_time=(time)
  self.options[:transitiontime] = (time.to_f * 10).to_i
end