Class: Winker::Device

Constant Summary

Constants included from Winker::Devices::DeviceMethods

Winker::Devices::DeviceMethods::VALID_TYPES, Winker::Devices::DeviceMethods::WAIT_BLOCK_SLEEP, Winker::Devices::DeviceMethods::WAIT_BLOCK_TIMEOUT

Instance Attribute Summary

Attributes included from Winker::Devices::DeviceMethods

#id, #obj_data, #type, #updated_at

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Winker::Devices::Hub

extended

Methods included from Winker::Devices::Eggtray

#count, #days_left, #eggs_expired, #eggs_left, #eggs_warning, #expire_time, #warning_time

Methods included from Winker::Devices::UnknownDevice

extended

Methods included from Winker::Devices::SensorPod

extended, #humidity, #temp

Methods included from Winker::Devices::LightBulb

#brightness, #brightness=, #check_last_brightness, extended, #updates_finished?

Methods included from Winker::Devices::OnOff

#check_last_powered, #off, #off?, #on, #powered?, #updates_finished?

Methods included from Winker::Devices::GenericDevice

#refresh, #update

Methods included from Winker::Devices::DeviceMethods

#find_type_and_id, #wait_for_update

Constructor Details

#initialize(obj_data) ⇒ Device

Returns a new instance of Device.



17
18
19
20
21
# File 'lib/winker/device.rb', line 17

def initialize(obj_data)
  @obj_data = obj_data
  find_type_and_id
  self.extend(eval("Winker::Devices::#{@type.classify}")) if @type
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *arguments, &block) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/winker/device.rb', line 23

def method_missing(method_sym, *arguments, &block)
  if obj_data.respond_to?(method_sym)
    obj_data.send(method_sym, *arguments, &block)
  else
    super
  end
end

Class Method Details

.load_devices(data) ⇒ Object



13
14
15
# File 'lib/winker/device.rb', line 13

def self.load_devices(data)
  data.map{|d| Winker::Device.new(d)}
end