class BulbState

Constants

MAX_BRI
MAX_CT
MAX_HUE
MAX_SAT
MAX_XY
MIN_BRI
MIN_CT
MIN_HUE
MIN_SAT
MIN_TRANSITION_TIME
MIN_XY

Attributes

alert[R]
bri[R]
color_mode[R]
ct[R]
effect[R]
hue[R]
on[R]
reachable[R]
sat[R]
transition_time[R]
xy[R]

Public Class Methods

new( data = {} ) click to toggle source
# File lib/lights/bulbstate.rb, line 46
def initialize( data = {} ) 
  data = {} if data == nil
  @reachable = data["reachable"] 

  # bridge returns invaild values for state variables when reachable is false
  unless @reachable == false
    @on = data["on"]
    set_bri data["bri"]
    set_hue data["hue"]
    set_sat data["sat"]
    set_xy data["xy"]
    set_ct data["ct"]
    set_alert data["alert"]
    set_effect data["effect"]
    set_color_mode data["colormode"]
    set_transition_time data["transitiontime"]
  end
end

Public Instance Methods

alert=(value) click to toggle source
# File lib/lights/bulbstate.rb, line 76
def alert=(value) set_alert(value) end
bri=(value) click to toggle source
# File lib/lights/bulbstate.rb, line 106
def bri=(value); set_bri(value) end
color_mode=(value) click to toggle source
# File lib/lights/bulbstate.rb, line 65
def color_mode=(value) set_color_mode(value) end
ct=(value) click to toggle source
# File lib/lights/bulbstate.rb, line 115
def ct=(value); set_ct(value) end
data() click to toggle source
# File lib/lights/bulbstate.rb, line 177
def data 
  data = {}
  data["on"] = @on unless @on.nil?
  data["bri"] = @bri if @bri 
  data["hue"] = @hue if @hue 
  data["sat"] = @sat if @sat 
  data["xy"] = @xy if @xy 
  data["ct"] = @ct if @ct 
  data["alert"] = @alert if @alert 
  data["effect"] = @effect if @effect 
  data["colormode"] = @color_mode if @color_mode 
  data["reachable"] = @reachable unless @reachable.nil?
  data["transitiontime"] = @transition_time if @transition_time
  data 
end
effect=(value) click to toggle source
# File lib/lights/bulbstate.rb, line 87
def effect=(value) set_effect(value) end
hue=(value) click to toggle source
# File lib/lights/bulbstate.rb, line 137
def hue=(value); set_hue(value) end
on=(value) click to toggle source
# File lib/lights/bulbstate.rb, line 96
def on=(value) set_on(value) end
sat=(value) click to toggle source
# File lib/lights/bulbstate.rb, line 126
def sat=(value); set_sat(value) end
set_alert(value) click to toggle source
# File lib/lights/bulbstate.rb, line 77
def set_alert(value)
  if value.nil? || value == Alert::NONE \
      || value == Alert::SELECT \
      || value == Alert::LSELECT
    @alert = value
  else
    raise BulbStateValueTypeException, "Alert value has incorrect type. Requires 'none', 'select', or 'lselect'. Was #{value.inspect}"
  end
end
set_bri(value) click to toggle source
# File lib/lights/bulbstate.rb, line 107
def set_bri(value)
  if value.nil? || value.between?(MIN_BRI,MAX_BRI)
    @bri = value
  else
    raise BulbStateValueOutOfRangeException, "Brightness value out of range. Must be [#{MIN_BRI},#{MAX_BRI}]. Was #{value.inspect}"
  end
end
set_color_mode(value) click to toggle source
# File lib/lights/bulbstate.rb, line 66
def set_color_mode(value)
  if value.nil? || value == ColorMode::XY \
      || value == ColorMode::HS \
      || value == ColorMode::CT
    @color_mode = value
  else
    raise BulbStateValueTypeException, "Color mode value has incorrect type. Requires 'hs', 'xy', or 'ct'. Was #{value.inspect}"
  end
end
set_ct(value) click to toggle source
# File lib/lights/bulbstate.rb, line 116
def set_ct(value)
  if !value.nil? && (!value.is_a? Integer)
    raise BulbStateValueTypeException, "Color temperature value has incorrect type. Requires integer, got #{value.class}"
  elsif value.nil? || value.between?(MIN_CT,MAX_CT)
    @ct = value
  else
    raise BulbStateValueOutOfRangeException, "Color temperature value out of range. Must be [#{MIN_CT},#{MAX_CT}]. Was #{value.inspect}"
  end
end
set_effect(value) click to toggle source
# File lib/lights/bulbstate.rb, line 88
def set_effect(value)
  if value.nil? || value == Effect::NONE || value == Effect::COLORLOOP
    @effect = value
  else
    raise BulbStateValueTypeException, "Effect value has incorrect type. Requires 'none' or 'colorloop'. Was #{value.inspect}"
  end
end
set_hue(value) click to toggle source
# File lib/lights/bulbstate.rb, line 138
def set_hue(value)
  if !value.nil? && (!value.is_a? Integer)
    raise BulbStateValueTypeException, "Hue value has incorrect type. Requires integer, got #{value.class}"
  elsif value.nil? || value.between?(MIN_HUE,MAX_HUE)
    @hue = value
  else
    raise BulbStateValueOutOfRangeException, "Hue value out of range. Must be [#{MIN_HUE},#{MAX_HUE}]. Was #{value.inspect}"
  end
end
set_on(value) click to toggle source
# File lib/lights/bulbstate.rb, line 97
def set_on(value)
  # Tests if value is boolean
  if !!value == value
    @on = value
  else
    raise BulbStateValueTypeException, "On value has incorrect type. Requires boolean, got #{value.class}. Was #{value.inspect}"
  end
end
set_sat(value) click to toggle source
# File lib/lights/bulbstate.rb, line 127
def set_sat(value)
  if !value.nil? && (!value.is_a? Integer)
    raise BulbStateValueTypeException, "Saturation value has incorrect type. Requires integer, got #{value.class}"
  elsif value.nil? || value.between?(MIN_SAT,MAX_SAT)
    @sat = value
  else
    raise BulbStateValueOutOfRangeException, "Saturation alue out of range. Must be [#{MIN_SAT},#{MAX_SAT}]. Was #{value.inspect}"
  end
end
set_transition_time(value) click to toggle source
# File lib/lights/bulbstate.rb, line 149
def set_transition_time(value)
  if !value.nil? && (!value.is_a? Numeric)
    raise BulbStateValueTypeException, "Transition time value has incorrect type. Requires decimal, got #{value.class}"
  elsif value.nil? || value >= MIN_TRANSITION_TIME
    @transition_time = value
  else
    raise BulbStateValueOutOfRangeException, "Transition time value out of range. Must be > #{MIN_TRANSITION_TIME}. Was #{value.inspect}"
  end
end
set_xy(value) click to toggle source
# File lib/lights/bulbstate.rb, line 160
def set_xy(value)
  if !value.nil? && (!value.is_a? Array)
    raise BulbStateValueTypeException, "XY value has incorrect type. Requires array, got #{value.class}"
  elsif value.nil?
    return
  elsif value.length == 2 && value[0].is_a?(Numeric) \
          && value[1].is_a?(Numeric) &&  value[0].to_f >= MIN_XY \
          && value[0].to_f <= MAX_XY && value[1].to_f >= MIN_XY \
          && value[1].to_f <= MAX_XY
    @xy = []
    @xy[0] = value[0].to_f
    @xy[1] = value[1].to_f
  else
    raise BulbStateValueOutOfRangeException, "XY value out of range. Must be [#{MIN_XY},#{MAX_XY}]. Was #{value.inspect}"
  end
end
transition_time=(value) click to toggle source
# File lib/lights/bulbstate.rb, line 148
def transition_time=(value); set_transition_time(value) end
xy=(value) click to toggle source
# File lib/lights/bulbstate.rb, line 159
def xy=(value); set_xy(value) end