Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

add persistence count_state_changes_since/between #125

Merged
merged 2 commits into from
Dec 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/openhab/core/items/persistence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def timestamp
PERSISTENCE_METHODS = (QUANTITY_METHODS +
%i[changed_since?
count_since
count_state_changes_since
evolution_rate
historic_state
maximum_since
Expand Down Expand Up @@ -249,6 +250,19 @@ def timestamp
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
# @return [Integer] The number of values persisted for this item.

# @!method count_state_changes_since(timestamp, service = nil)
# Returns the number of changes in historic data points from a point in time until now.
# @param [#to_zoned_date_time] timestamp The point in time from which to search
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
# @return [Integer] The number of values persisted for this item.

# @!method count_state_changes_between(start, finish, service = nil)
# Returns the number of changes in historic data points between two points in time.
# @param [#to_zoned_date_time] start The point in time from which to search
# @param [#to_zoned_date_time] finish The point in time to which to search
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
# @return [Integer] The number of values persisted for this item.

%i[persist last_update].each do |method|
define_method(method) do |service = nil|
service ||= persistence_service
Expand Down Expand Up @@ -301,6 +315,9 @@ def previous_state(service = nil, skip_equal: false)
end
end

alias_method :state_changes_since, :count_state_changes_since
alias_method :state_changes_between, :count_state_changes_between

private

#
Expand Down