Class: RZWaveWay::ZWaveDevice
Instance Attribute Summary collapse
Instance Method Summary
collapse
#save_properties, #to_hash
Methods included from Logger
#log
Constructor Details
#initialize(id, data) ⇒ ZWaveDevice
Returns a new instance of ZWaveDevice.
11
12
13
14
15
16
17
|
# File 'lib/rzwaveway/zwave_device.rb', line 11
def initialize(id, data)
@id = id
@command_classes = {}
initialize_from data
update_status
log.info "Created device with name='#{name}' status=#{status} (id='#{id}')"
end
|
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
7
8
9
|
# File 'lib/rzwaveway/zwave_device.rb', line 7
def id
@id
end
|
Returns the value of attribute last_contact_time.
8
9
10
|
# File 'lib/rzwaveway/zwave_device.rb', line 8
def last_contact_time
@last_contact_time
end
|
#status ⇒ Object
Returns the value of attribute status.
9
10
11
|
# File 'lib/rzwaveway/zwave_device.rb', line 9
def status
@status
end
|
Instance Method Details
19
20
21
|
# File 'lib/rzwaveway/zwave_device.rb', line 19
def contact
RZWaveWay::ZWay.instance.run_zway_no_operation(id)
end
|
23
24
25
|
# File 'lib/rzwaveway/zwave_device.rb', line 23
def contacts_controller_periodically?
support_commandclass? CommandClass::WAKEUP
end
|
#inspect ⇒ Object
27
28
29
30
31
|
# File 'lib/rzwaveway/zwave_device.rb', line 27
def inspect
output = [to_s]
output += @command_classes.collect {|id, command_class| "#{id} - #{command_class}"}
output.join "\n"
end
|
50
51
52
53
54
|
# File 'lib/rzwaveway/zwave_device.rb', line 50
def notify_contacted(time)
if time > @last_contact_time
@last_contact_time = time
end
end
|
#process(updates) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/rzwaveway/zwave_device.rb', line 37
def process(updates)
updates_per_commandclass = group_per_commandclass updates
updates_per_commandclass.each do |cc, values|
if @command_classes.has_key? cc
@command_classes[cc].process(values) {|event| yield event}
else
log.warn "Could not find command class: '#{cc}'"
end
end
process_device_data(updates)
save_changes
end
|
#refresh ⇒ Object
56
57
58
59
60
|
# File 'lib/rzwaveway/zwave_device.rb', line 56
def refresh
@command_classes.values.each do |command_class|
command_class.refresh if command_class.respond_to? :refresh
end
end
|
#state ⇒ Object
62
63
64
65
|
# File 'lib/rzwaveway/zwave_device.rb', line 62
def state
hash = to_hash
@command_classes.values.each_with_object(hash) {|cc, hash| hash.merge!(cc.to_hash)}
end
|
#support_commandclass?(command_class_id) ⇒ Boolean
33
34
35
|
# File 'lib/rzwaveway/zwave_device.rb', line 33
def support_commandclass?(command_class_id)
@command_classes.has_key? command_class_id
end
|
#to_s ⇒ Object
67
68
69
|
# File 'lib/rzwaveway/zwave_device.rb', line 67
def to_s
"#{id} (#{name}) - #{status} (#{Time.at(last_contact_time)})"
end
|
#update_status ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/rzwaveway/zwave_device.rb', line 71
def update_status
@status = if contacts_controller_periodically?
if self.WakeUp.on_time?
:alive
elsif self.WakeUp.missed_contact_count < 10 :inactive
else
:dead
end
else
if elapsed_minutes_since_last_contact > 60 :dead
elsif elapsed_minutes_since_last_contact > 5 :inactive
else
:alive
end
end
end
|