Class: OpenHAB::Core::Items::StateStorage

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/openhab/core/items/state_storage.rb

Overview

Delegates state storage to a Hash providing methods to operate with states

Instance Method Summary collapse

Instance Method Details

#changed?true, false

Detect if any items have changed states since being stored

Returns:

  • (true, false)

    True if any items have changed states, false otherwise



47
48
49
# File 'lib/openhab/core/items/state_storage.rb', line 47

def changed?
  any? { |item, value| item.state != value }
end

#restorevoid

This method returns an undefined value.

Restore the stored states of all items



29
30
31
# File 'lib/openhab/core/items/state_storage.rb', line 29

def restore
  $events.restore_states(to_h)
end

#restore_changesvoid

This method returns an undefined value.

Restore states for items that have changed



38
39
40
# File 'lib/openhab/core/items/state_storage.rb', line 38

def restore_changes
  $events.restore_states(select { |item, value| item.state != value })
end