Class: Domoticz::Device
- Inherits:
-
Object
show all
- Defined in:
- lib/domoticz/device.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *arguments, &block) ⇒ Object
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/domoticz/device.rb', line 30
def method_missing(method_sym, *arguments, &block)
hash = Hash[@data.map { |k, v| [k.downcase, v] }]
key = method_sym.to_s.downcase
if hash.has_key?(key)
hash[key]
else
super
end
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
4
5
6
|
# File 'lib/domoticz/device.rb', line 4
def data
@data
end
|
#idx ⇒ Object
Returns the value of attribute idx.
3
4
5
|
# File 'lib/domoticz/device.rb', line 3
def idx
@idx
end
|
Class Method Details
.find_by_id(id) ⇒ Object
41
42
43
|
# File 'lib/domoticz/device.rb', line 41
def self.find_by_id(id)
all.find { |d| d.idx == id.to_s }
end
|
.new_from_json(json) ⇒ Object
51
52
53
54
55
56
|
# File 'lib/domoticz/device.rb', line 51
def self.new_from_json(json)
device = self.new
device.data = json
device.idx = json["idx"]
device
end
|
Instance Method Details
#dimmer? ⇒ Boolean
26
27
28
|
# File 'lib/domoticz/device.rb', line 26
def dimmer?
isDimmer
end
|
#off! ⇒ Object
14
15
16
|
# File 'lib/domoticz/device.rb', line 14
def off!
Domoticz.perform_api_request("type=command¶m=switchlight&idx=#{idx}&switchcmd=Off")
end
|
#on! ⇒ Object
10
11
12
|
# File 'lib/domoticz/device.rb', line 10
def on!
Domoticz.perform_api_request("type=command¶m=switchlight&idx=#{idx}&switchcmd=On")
end
|
#seconds_since_update ⇒ Object
6
7
8
|
# File 'lib/domoticz/device.rb', line 6
def seconds_since_update
Time.now - Time.parse(lastupdate)
end
|
#temperature ⇒ Object
22
23
24
|
# File 'lib/domoticz/device.rb', line 22
def temperature
temp
end
|
#toggle! ⇒ Object
18
19
20
|
# File 'lib/domoticz/device.rb', line 18
def toggle!
Domoticz.perform_api_request("type=command¶m=switchlight&idx=#{idx}&switchcmd=Toggle")
end
|