Class: Winker::Group
- Inherits:
-
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
#id ⇒ Object
Returns the value of attribute id.
5
6
7
|
# File 'lib/winker/group.rb', line 5
def id
@id
end
|
#obj_data ⇒ Object
Returns the value of attribute obj_data.
5
6
7
|
# File 'lib/winker/group.rb', line 5
def obj_data
@obj_data
end
|
#type ⇒ Object
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)
Winker.update_group(@id, {desired_state: {powered: true, brightness: _brightness}})
end
|
#members ⇒ Object
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
|
#off ⇒ Object
24
25
26
|
# File 'lib/winker/group.rb', line 24
def off
Winker.update_group(@id, {desired_state: {powered: false}})
end
|
#on ⇒ Object
20
21
22
|
# File 'lib/winker/group.rb', line 20
def on
Winker.update_group(@id, {desired_state: {powered: true}})
end
|
#update(options) ⇒ Object