Class: RZWaveWay::Property

Inherits:
Object
  • Object
show all
Defined in:
lib/rzwaveway/property.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Property

Returns a new instance of Property.



6
7
8
9
10
# File 'lib/rzwaveway/property.rb', line 6

def initialize(options)
  @previous_value = @value = options[:value]
  @previous_update_time = @update_time = options[:update_time]
  @read_only = options[:read_only]
end

Instance Attribute Details

#update_timeObject (readonly)

Returns the value of attribute update_time.



4
5
6
# File 'lib/rzwaveway/property.rb', line 4

def update_time
  @update_time
end

#valueObject (readonly)

Returns the value of attribute value.



3
4
5
# File 'lib/rzwaveway/property.rb', line 3

def value
  @value
end

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/rzwaveway/property.rb', line 12

def changed?
  @previous_value != @value
end

#read_only?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/rzwaveway/property.rb', line 16

def read_only?
  @read_only == true
end

#saveObject



20
21
22
23
# File 'lib/rzwaveway/property.rb', line 20

def save
  @previous_value = @value
  @previous_update_time = @update_time
end

#to_hashObject



25
26
27
28
29
30
31
# File 'lib/rzwaveway/property.rb', line 25

def to_hash
  {
    read_only: read_only?,
    value: @value,
    update_time: @update_time
  }
end

#update(value, update_time) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rzwaveway/property.rb', line 33

def update(value, update_time)
  if @update_time <= update_time
    @update_time = update_time
    if @value != value
      @value = value
      true
    else
      false
    end
  else
    false
  end
end