Class: Domotics::Core::Element
Constant Summary
collapse
- @@data =
DataHash.new
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(args = {}) ⇒ Element
Returns a new instance of Element.
6
7
8
9
10
11
12
|
# File 'lib/domotics/core/element.rb', line 6
def initialize(args = {})
@room = args[:room]
@device = args[:device]
@room.register_element self, @name = args[:name]
@type ||= :element
set_state(self.state || :off)
end
|
Instance Attribute Details
Returns the value of attribute device.
4
5
6
|
# File 'lib/domotics/core/element.rb', line 4
def device
@device
end
|
Returns the value of attribute name.
4
5
6
|
# File 'lib/domotics/core/element.rb', line 4
def name
@name
end
|
Returns the value of attribute room.
4
5
6
|
# File 'lib/domotics/core/element.rb', line 4
def room
@room
end
|
Returns the value of attribute type.
4
5
6
|
# File 'lib/domotics/core/element.rb', line 4
def type
@type
end
|
Class Method Details
.data=(value) ⇒ Object
55
56
57
|
# File 'lib/domotics/core/element.rb', line 55
def self.data=(value)
@@data = value
end
|
Instance Method Details
41
42
43
|
# File 'lib/domotics/core/element.rb', line 41
def image
nil
end
|
37
38
39
|
# File 'lib/domotics/core/element.rb', line 37
def info
nil
end
|
#load_driver(args = {}) ⇒ Object
14
15
16
17
18
|
# File 'lib/domotics/core/element.rb', line 14
def load_driver(args = {})
return unless args[:device_type]
device_space = args[:device_type].to_s.split("_").map{ |x| x.capitalize }.join
self.class.class_eval(%(include Domotics::#{device_space}::#{args[:driver]}), __FILE__, __LINE__)
end
|
#set_state(value) ⇒ Object
45
46
47
48
|
# File 'lib/domotics/core/element.rb', line 45
def set_state(value)
@@data[self].state = value
@room.notify({ event: :state_set, element: self }) unless @type == :dimmer
end
|
20
21
22
|
# File 'lib/domotics/core/element.rb', line 20
def state
@@data[self].state
end
|
#state_changed(value) ⇒ Object
50
51
52
53
|
# File 'lib/domotics/core/element.rb', line 50
def state_changed(value)
@@data[self].state = value
@room.notify event: :state_changed, element: self
end
|
59
60
61
|
# File 'lib/domotics/core/element.rb', line 59
def to_s
"#{@room.name}@#{@name}(id:#{__id__})"
end
|
#verbose_state ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/domotics/core/element.rb', line 24
def verbose_state
{ @room.name =>
{ :elements =>
{ @name =>
{ :state => state,
:info => info,
:img => image,
}
}
}
}
end
|