Class: RZWaveWay::ZWaveDevice

Inherits:
Object
  • Object
show all
Includes:
CommandClasses, Logger, PropertiesCache
Defined in:
lib/rzwaveway/zwave_device.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PropertiesCache

#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

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/rzwaveway/zwave_device.rb', line 7

def id
  @id
end

#last_contact_timeObject (readonly)

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

#statusObject (readonly)

Returns the value of attribute status.



9
10
11
# File 'lib/rzwaveway/zwave_device.rb', line 9

def status
  @status
end

Instance Method Details

#contactObject



19
20
21
# File 'lib/rzwaveway/zwave_device.rb', line 19

def contact
  RZWaveWay::ZWay.instance.run_zway_no_operation(id)
end

#contacts_controller_periodically?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/rzwaveway/zwave_device.rb', line 23

def contacts_controller_periodically?
  support_commandclass? CommandClass::WAKEUP
end

#inspectObject



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

#notify_contacted(time) ⇒ Object



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

#refreshObject



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

#stateObject



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

Returns:

  • (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_sObject



67
68
69
# File 'lib/rzwaveway/zwave_device.rb', line 67

def to_s
  "#{id} (#{name}) - #{status} (#{Time.at(last_contact_time)})"
end

#update_statusObject



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 # times
      :inactive
    else
      :dead
    end
  else
    if elapsed_minutes_since_last_contact > 60 # minutes
      :dead
    elsif elapsed_minutes_since_last_contact > 5  # minutes
      :inactive
    else
      :alive
    end
  end
end