From 108a3b1114136539049bbe192a1861e535ac4fff Mon Sep 17 00:00:00 2001 From: Jimmy Tanagra Date: Sun, 11 Dec 2022 22:11:32 +1000 Subject: [PATCH 1/2] add persistence count_state_changes_since/between https://github.com/openhab/openhab-core/pull/3211 --- lib/openhab/core/items/persistence.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/openhab/core/items/persistence.rb b/lib/openhab/core/items/persistence.rb index b22f157ca..e735c5736 100644 --- a/lib/openhab/core/items/persistence.rb +++ b/lib/openhab/core/items/persistence.rb @@ -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 @@ -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 From 91ce414665f9c9c1a65656020a1c0faaf91e4097 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Mon, 12 Dec 2022 11:50:24 -0700 Subject: [PATCH 2/2] add simplified alias for state_changes_* --- lib/openhab/core/items/persistence.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/openhab/core/items/persistence.rb b/lib/openhab/core/items/persistence.rb index e735c5736..83eab441e 100644 --- a/lib/openhab/core/items/persistence.rb +++ b/lib/openhab/core/items/persistence.rb @@ -315,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 #