Skip to content

Commit

Permalink
Add PersistedState#instant (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimtng authored Nov 27, 2024
1 parent 77c112c commit 9a5e94d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/openhab/core/items/persistence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,14 @@ class PersistedState < SimpleDelegator
# @!attribute [r] timestamp
# @return [ZonedDateTime]

# @!attribute [r] instant
# @return [Instant] The timestamp as an Instant
# @since openHAB 4.3

# @!attribute [r] name
# @return [String] Item name

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

def initialize(historic_item, state = nil)
@historic_item = historic_item
Expand Down
3 changes: 2 additions & 1 deletion lib/openhab/rspec/mocks/persistence_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ class PersistenceService
class HistoricItem
include org.openhab.core.persistence.HistoricItem

attr_reader :timestamp, :state, :name
attr_reader :timestamp, :instant, :state, :name

def initialize(timestamp, state, name)
@timestamp = timestamp
@state = state
@name = name
@instant = @timestamp.to_instant
end
end

Expand Down
2 changes: 2 additions & 0 deletions spec/openhab/core/items/persistence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ def initialize(timestamp, state, name)
expect(max).to be_a described_class::PersistedState
expect(max).to eql max.state
expect(max.timestamp).to be_a ZonedDateTime
# @deprecated OH 4.2 - Remove if guard when dropping oh 4.2 support
expect(max.instant).to be_a Instant if OpenHAB::Core.version >= OpenHAB::Core::V4_3
end

it "is inspectable" do
Expand Down

0 comments on commit 9a5e94d

Please sign in to comment.