Class: OpenHAB::Core::Items::Persistence::PersistedState

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

Overview

A wrapper for HistoricItem that delegates to its state.

A PersistedState object can be directly used in arithmetic operations with State and other PersistedState objects.

Examples:

max = Power_Usage.maximum_since(LocalTime::MIDNIGHT)
logger.info "Highest power usage: #{max} occurred at #{max.timestamp}" if max > 5 | "kW"

Arithmetic operations

todays_rate = Energy_Prices.persisted_state(Date.today) # Energy_Prices' unit is "<CURRENCY>/kWh"
todays_cost = Daily_Energy_Consumption.state * todays_rate

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(historic_item, state = nil) ⇒ PersistedState

Returns a new instance of PersistedState.



96
97
98
99
# File 'lib/openhab/core/items/persistence.rb', line 96

def initialize(historic_item, state = nil)
  @historic_item = historic_item
  super(state || historic_item.state)
end

Instance Attribute Details

#nameString (readonly)

Returns Item name.

Returns:

  • (String)

    Item name



94
# File 'lib/openhab/core/items/persistence.rb', line 94

delegate %i[timestamp name] => :@historic_item

#stateTypes::State (readonly)

Returns:



86
# File 'lib/openhab/core/items/persistence.rb', line 86

alias_method :state, :__getobj__

#timestampZonedDateTime (readonly)

Returns:



# File 'lib/openhab/core/items/persistence.rb', line 88