Class: Winker::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/winker/group.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj_data) ⇒ Group

Returns a new instance of Group.



11
12
13
14
# File 'lib/winker/group.rb', line 11

def initialize(obj_data)
  @obj_data = obj_data
  @id = @obj_data.group_id
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



38
39
40
41
42
43
44
45
# File 'lib/winker/group.rb', line 38

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

Instance Attribute Details

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/winker/group.rb', line 5

def id
  @id
end

#obj_dataObject

Returns the value of attribute obj_data.



5
6
7
# File 'lib/winker/group.rb', line 5

def obj_data
  @obj_data
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/winker/group.rb', line 5

def type
  @type
end

Class Method Details

.load_groups(data) ⇒ Object



7
8
9
# File 'lib/winker/group.rb', line 7

def self.load_groups(data)
  data.map{|d| Winker::Group.new(d)}
end

Instance Method Details

#brightness=(_brightness) ⇒ Object



33
34
35
36
# File 'lib/winker/group.rb', line 33

def brightness=(_brightness)
  #set brightness level
  Winker.update_group(@id, {desired_state: {powered: true, brightness: _brightness}})
end

#membersObject



16
17
18
# File 'lib/winker/group.rb', line 16

def members
  devices.select{|d| @obj_data.members.map{|m| m[:object_id]}.include?(d.id)}
end

#offObject



24
25
26
# File 'lib/winker/group.rb', line 24

def off
  Winker.update_group(@id, {desired_state: {powered: false}})
end

#onObject



20
21
22
# File 'lib/winker/group.rb', line 20

def on
  Winker.update_group(@id, {desired_state: {powered: true}})
end

#update(options) ⇒ Object



28
29
30
31
# File 'lib/winker/group.rb', line 28

def update(options)
  @updated_at = Time.now + Winker.server_time_dif
  Winker.update_group(@id, options)
end