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.



100
101
102
103
# File 'lib/openhab/core/items/persistence.rb', line 100

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

Instance Attribute Details

#instantInstant (readonly)

Returns The timestamp as an Instant.

Returns:

  • (Instant)

    The timestamp as an Instant

Since:

  • openHAB 4.3



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

#nameString (readonly)

Returns Item name.

Returns:

  • (String)

    Item name



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

delegate %i[timestamp instant 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