openhab-jrubyscripting 5.0.0.rc10 → 5.0.0.rc12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/openhab/core/actions/audio.rb +47 -0
- data/lib/openhab/core/actions/ephemeris.rb +39 -0
- data/lib/openhab/core/actions/exec.rb +51 -0
- data/lib/openhab/core/actions/http.rb +80 -0
- data/lib/openhab/core/actions/ping.rb +30 -0
- data/lib/openhab/core/actions/transformation.rb +32 -0
- data/lib/openhab/core/actions/voice.rb +36 -0
- data/lib/openhab/core/actions.rb +23 -120
- data/lib/openhab/core/{events → dto}/item_channel_link.rb +1 -4
- data/lib/openhab/core/{events → dto}/thing.rb +10 -12
- data/lib/openhab/core/dto.rb +11 -0
- data/lib/openhab/core/entity_lookup.rb +1 -1
- data/lib/openhab/core/events/abstract_event.rb +1 -0
- data/lib/openhab/core/events/abstract_item_registry_event.rb +36 -0
- data/lib/openhab/core/events/abstract_thing_registry_event.rb +40 -0
- data/lib/openhab/core/events/item_command_event.rb +1 -1
- data/lib/openhab/core/events/item_state_changed_event.rb +6 -6
- data/lib/openhab/core/events/item_state_event.rb +6 -6
- data/lib/openhab/core/events/thing_status_info_event.rb +8 -6
- data/lib/openhab/core/items/date_time_item.rb +3 -2
- data/lib/openhab/core/items/generic_item.rb +92 -1
- data/lib/openhab/core/items/item.rb +9 -8
- data/lib/openhab/core/items/metadata/hash.rb +1 -1
- data/lib/openhab/core/items/metadata/namespace_hash.rb +10 -2
- data/lib/openhab/core/items/metadata/provider.rb +2 -2
- data/lib/openhab/core/items/persistence.rb +99 -21
- data/lib/openhab/core/items/player_item.rb +1 -1
- data/lib/openhab/core/items/proxy.rb +20 -14
- data/lib/openhab/core/items/registry.rb +12 -1
- data/lib/openhab/core/items/state_storage.rb +2 -2
- data/lib/openhab/core/items.rb +3 -3
- data/lib/openhab/core/profile_factory.rb +3 -1
- data/lib/openhab/core/proxy.rb +130 -0
- data/lib/openhab/core/registry.rb +12 -2
- data/lib/openhab/core/rules.rb +1 -1
- data/lib/openhab/core/things/links/provider.rb +39 -1
- data/lib/openhab/core/things/proxy.rb +8 -0
- data/lib/openhab/core/things/registry.rb +4 -0
- data/lib/openhab/core/timer.rb +3 -19
- data/lib/openhab/core/types/date_time_type.rb +3 -2
- data/lib/openhab/core/types/decimal_type.rb +1 -1
- data/lib/openhab/core/types/un_def_type.rb +2 -2
- data/lib/openhab/core/value_cache.rb +1 -1
- data/lib/openhab/core.rb +3 -3
- data/lib/openhab/core_ext/ephemeris.rb +53 -0
- data/lib/openhab/core_ext/java/class.rb +1 -1
- data/lib/openhab/core_ext/java/duration.rb +27 -1
- data/lib/openhab/core_ext/java/local_date.rb +17 -7
- data/lib/openhab/core_ext/java/local_time.rb +13 -3
- data/lib/openhab/core_ext/java/month.rb +1 -1
- data/lib/openhab/core_ext/java/month_day.rb +15 -3
- data/lib/openhab/core_ext/java/period.rb +1 -1
- data/lib/openhab/core_ext/java/temporal_amount.rb +1 -1
- data/lib/openhab/core_ext/java/time.rb +5 -1
- data/lib/openhab/core_ext/java/zoned_date_time.rb +100 -2
- data/lib/openhab/core_ext/ruby/date.rb +4 -2
- data/lib/openhab/core_ext/ruby/date_time.rb +1 -0
- data/lib/openhab/core_ext/ruby/numeric.rb +6 -1
- data/lib/openhab/core_ext/ruby/time.rb +1 -0
- data/lib/openhab/dsl/debouncer.rb +259 -0
- data/lib/openhab/dsl/items/builder.rb +29 -14
- data/lib/openhab/dsl/items/timed_command.rb +31 -13
- data/lib/openhab/dsl/rules/automation_rule.rb +30 -44
- data/lib/openhab/dsl/rules/builder.rb +404 -39
- data/lib/openhab/dsl/rules/guard.rb +12 -54
- data/lib/openhab/dsl/rules/name_inference.rb +11 -0
- data/lib/openhab/dsl/rules/property.rb +3 -4
- data/lib/openhab/dsl/rules/terse.rb +4 -1
- data/lib/openhab/dsl/rules/triggers/conditions/duration.rb +5 -6
- data/lib/openhab/dsl/rules/triggers/cron/cron.rb +1 -0
- data/lib/openhab/dsl/rules/triggers/cron/cron_handler.rb +19 -31
- data/lib/openhab/dsl/rules/triggers/watch/watch.rb +1 -0
- data/lib/openhab/dsl/rules/triggers/watch/watch_handler.rb +22 -30
- data/lib/openhab/dsl/things/builder.rb +1 -1
- data/lib/openhab/dsl/thread_local.rb +1 -0
- data/lib/openhab/dsl/version.rb +1 -1
- data/lib/openhab/dsl.rb +251 -14
- data/lib/openhab/rspec/helpers.rb +3 -2
- data/lib/openhab/rspec/hooks.rb +6 -2
- data/lib/openhab/rspec/karaf.rb +7 -0
- data/lib/openhab/rspec/mocks/instance_method_stasher.rb +22 -0
- data/lib/openhab/rspec/mocks/space.rb +23 -0
- data/lib/openhab/rspec/mocks/timer.rb +33 -0
- data/lib/openhab/rspec/openhab/core/actions.rb +16 -4
- data/lib/openhab/rspec/openhab/core/items/proxy.rb +1 -13
- data/lib/openhab/rspec/suspend_rules.rb +1 -14
- data/lib/openhab/rspec.rb +9 -0
- data/lib/openhab/yard/base_helper.rb +19 -0
- data/lib/openhab/yard/code_objects/group_object.rb +9 -3
- data/lib/openhab/yard/coderay.rb +17 -0
- data/lib/openhab/yard/handlers/jruby/base.rb +10 -1
- data/lib/openhab/yard/handlers/jruby/java_import_handler.rb +3 -0
- data/lib/openhab/yard/html_helper.rb +49 -15
- data/lib/openhab/yard/markdown_helper.rb +135 -0
- data/lib/openhab/yard.rb +6 -0
- metadata +36 -4
@@ -10,7 +10,7 @@ module OpenHAB
|
|
10
10
|
# Adds methods to core openHAB ItemCommandEvent to make it more natural in Ruby
|
11
11
|
class ItemCommandEvent < ItemEvent
|
12
12
|
# @!attribute [r] command
|
13
|
-
# @return [
|
13
|
+
# @return [Command] The command sent to the item.
|
14
14
|
alias_method :command, :item_command
|
15
15
|
|
16
16
|
# @!method refresh?
|
@@ -14,26 +14,26 @@ module OpenHAB
|
|
14
14
|
include ItemState
|
15
15
|
|
16
16
|
#
|
17
|
-
# Check if state was == UNDEF
|
17
|
+
# Check if state was == {UNDEF}
|
18
18
|
#
|
19
|
-
# @return [true,false] True if the state is UNDEF, false otherwise
|
19
|
+
# @return [true,false] True if the state is {UNDEF}, false otherwise
|
20
20
|
#
|
21
21
|
def was_undef?
|
22
22
|
old_item_state == UNDEF
|
23
23
|
end
|
24
24
|
|
25
25
|
#
|
26
|
-
# Check if state was == NULL
|
26
|
+
# Check if state was == {NULL}
|
27
27
|
#
|
28
|
-
# @return [true,false] True if the state is NULL, false otherwise
|
28
|
+
# @return [true,false] True if the state is {NULL}, false otherwise
|
29
29
|
def was_null?
|
30
30
|
old_item_state == NULL
|
31
31
|
end
|
32
32
|
|
33
33
|
#
|
34
|
-
# Check if state was defined (not UNDEF or NULL)
|
34
|
+
# Check if state was defined (not {UNDEF} or {NULL})
|
35
35
|
#
|
36
|
-
# @return [true,false] True if state is not UNDEF or NULL
|
36
|
+
# @return [true,false] True if state is not {UNDEF} or {NULL}
|
37
37
|
#
|
38
38
|
def was?
|
39
39
|
!old_item_state.is_a?(UnDefType)
|
@@ -8,26 +8,26 @@ module OpenHAB
|
|
8
8
|
# Helpers common to {ItemStateEvent} and {ItemStateChangedEvent}.
|
9
9
|
module ItemState
|
10
10
|
#
|
11
|
-
# Check if the state == UNDEF
|
11
|
+
# Check if the state == {UNDEF}
|
12
12
|
#
|
13
|
-
# @return [true,false] True if the state is UNDEF, false otherwise
|
13
|
+
# @return [true,false] True if the state is {UNDEF}, false otherwise
|
14
14
|
#
|
15
15
|
def undef?
|
16
16
|
item_state == UNDEF
|
17
17
|
end
|
18
18
|
|
19
19
|
#
|
20
|
-
# Check if the state == NULL
|
20
|
+
# Check if the state == {NULL}
|
21
21
|
#
|
22
|
-
# @return [true,false] True if the state is NULL, false otherwise
|
22
|
+
# @return [true,false] True if the state is {NULL}, false otherwise
|
23
23
|
def null?
|
24
24
|
item_state == NULL
|
25
25
|
end
|
26
26
|
|
27
27
|
#
|
28
|
-
# Check if the state is defined (not UNDEF or NULL)
|
28
|
+
# Check if the state is defined (not {UNDEF} or {NULL})
|
29
29
|
#
|
30
|
-
# @return [true,false] True if state is not UNDEF or NULL
|
30
|
+
# @return [true,false] True if state is not {UNDEF} or {NULL}
|
31
31
|
#
|
32
32
|
def state?
|
33
33
|
!item_state.is_a?(UnDefType)
|
@@ -6,16 +6,18 @@ module OpenHAB
|
|
6
6
|
java_import org.openhab.core.thing.events.ThingStatusInfoChangedEvent,
|
7
7
|
org.openhab.core.thing.events.ThingStatusInfoEvent
|
8
8
|
|
9
|
-
#
|
9
|
+
#
|
10
|
+
# The {AbstractEvent} sent when a {Things::Thing Thing's} status has changed.
|
11
|
+
#
|
10
12
|
class ThingStatusInfoChangedEvent < AbstractEvent
|
11
13
|
# @!attribute [r] uid
|
12
|
-
# @return [Things::ThingUID] The UID of the
|
14
|
+
# @return [Things::ThingUID] The UID of the {Things::Thing Thing} that triggered this event.
|
13
15
|
alias_method :uid, :get_thing_uid
|
14
16
|
# @!attribute [r] was
|
15
|
-
# @return [
|
17
|
+
# @return [org.openhab.core.thing.ThingStatusInfo] The thing's prior status.
|
16
18
|
alias_method :was, :get_old_status_info
|
17
19
|
# @!attribute [r] status
|
18
|
-
# @return [
|
20
|
+
# @return [org.openhab.core.thing.ThingStatusInfo] The thing's status.
|
19
21
|
alias_method :status, :status_info
|
20
22
|
|
21
23
|
#
|
@@ -31,12 +33,12 @@ module OpenHAB
|
|
31
33
|
class ThingStatusInfoEvent < AbstractEvent
|
32
34
|
#
|
33
35
|
# @!attribute [r] uid
|
34
|
-
# @return [Things::ThingUID] The UID of the
|
36
|
+
# @return [Things::ThingUID] The UID of the {Things::Thing Thing} that triggered this event.
|
35
37
|
#
|
36
38
|
alias_method :uid, :get_thing_uid
|
37
39
|
#
|
38
40
|
# @!attribute [r] status
|
39
|
-
# @return [
|
41
|
+
# @return [org.openhab.core.thing.ThingStatusInfo] The thing's status.
|
40
42
|
#
|
41
43
|
alias_method :status, :status_info
|
42
44
|
|
@@ -45,9 +45,10 @@ module OpenHAB
|
|
45
45
|
# Time types need formatted as ISO8601
|
46
46
|
# @!visibility private
|
47
47
|
def format_type(command)
|
48
|
-
return
|
48
|
+
return command if command.is_a?(Types::DateTimeType)
|
49
|
+
return Types::DateTimeType.new(command.to_zoned_date_time) if command.respond_to?(:to_zoned_date_time)
|
50
|
+
return Types::DateTimeType.new(DSL.try_parse_time_like(command.to_str)) if command.respond_to?(:to_str)
|
49
51
|
|
50
|
-
command = command.iso8601 if command.respond_to?(:iso8601)
|
51
52
|
super
|
52
53
|
end
|
53
54
|
end
|
@@ -8,7 +8,7 @@ module OpenHAB
|
|
8
8
|
#
|
9
9
|
# The abstract base class for all items.
|
10
10
|
#
|
11
|
-
# @see
|
11
|
+
# @see org.openhab.core.items.GenericItem
|
12
12
|
#
|
13
13
|
class GenericItem
|
14
14
|
# @!parse include Item
|
@@ -49,6 +49,7 @@ module OpenHAB
|
|
49
49
|
# The item's descriptive label.
|
50
50
|
# @return [String, nil]
|
51
51
|
|
52
|
+
# @!visibility private
|
52
53
|
alias_method :hash, :hash_code
|
53
54
|
|
54
55
|
# @!attribute [r] raw_state
|
@@ -162,9 +163,99 @@ module OpenHAB
|
|
162
163
|
# make sure to use Type, because this method is used for both
|
163
164
|
# #update and #command
|
164
165
|
return type if type.is_a?(Types::Type)
|
166
|
+
return NULL if type.nil?
|
165
167
|
|
166
168
|
type.to_s
|
167
169
|
end
|
170
|
+
|
171
|
+
#
|
172
|
+
# Defers notifying openHAB of modifications to multiple attributes until the block is complete.
|
173
|
+
#
|
174
|
+
# @param [true, false] force When true, allow modifications to file-based items.
|
175
|
+
# Normally a FrozenError is raised when attempting to modify file-based items, since
|
176
|
+
# they will then be out-of-sync with the definition on disk. Advanced users may do this
|
177
|
+
# knowingly and intentionally though, so an escape hatch is provided to allow runtime
|
178
|
+
# modifications.
|
179
|
+
# @yield
|
180
|
+
# @return [Object] the block's return value
|
181
|
+
#
|
182
|
+
# @example Modify label and tags for an item
|
183
|
+
# MySwitch.modify do
|
184
|
+
# MySwitch.label = "New Label"
|
185
|
+
# MySwitch.tags = :labeled
|
186
|
+
# end
|
187
|
+
#
|
188
|
+
def modify(force: false)
|
189
|
+
raise ArgumentError, "you must pass a block to modify" unless block_given?
|
190
|
+
return yield if instance_variable_defined?(:@modifying) && @modifying
|
191
|
+
|
192
|
+
begin
|
193
|
+
provider = self.provider
|
194
|
+
if provider && !provider.is_a?(org.openhab.core.common.registry.ManagedProvider)
|
195
|
+
raise FrozenError, "Cannot modify item #{name} from provider #{provider.inspect}." unless force
|
196
|
+
|
197
|
+
provider = nil
|
198
|
+
logger.debug("Forcing modifications to non-managed item #{name}")
|
199
|
+
end
|
200
|
+
@modified = false
|
201
|
+
@modifying = true
|
202
|
+
|
203
|
+
r = yield
|
204
|
+
|
205
|
+
provider&.update(self) if @modified
|
206
|
+
r
|
207
|
+
ensure
|
208
|
+
@modifying = false
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
# @!attribute [rw] label
|
213
|
+
# The item's descriptive label.
|
214
|
+
# @return [String]
|
215
|
+
def label=(value)
|
216
|
+
modify do
|
217
|
+
next if label == value
|
218
|
+
|
219
|
+
@modified = true
|
220
|
+
set_label(value)
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
# @!attribute [rw] category
|
225
|
+
# The item's category.
|
226
|
+
# @return [String]
|
227
|
+
def category=(value)
|
228
|
+
modify do
|
229
|
+
value = value&.to_s
|
230
|
+
next if category == value
|
231
|
+
|
232
|
+
@modified = true
|
233
|
+
set_category(value)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
# @!attribute [rw] tags
|
238
|
+
# The item's tags
|
239
|
+
# @return [Array<String>]
|
240
|
+
# @overload tags
|
241
|
+
# Returns the item's tags.
|
242
|
+
# @return [Array<String>]
|
243
|
+
# @overload tags=(values)
|
244
|
+
# Sets the item's tags.
|
245
|
+
#
|
246
|
+
# To remove all tags, assign an empty array or nil.
|
247
|
+
# @param [Array<String,Symbol,Semantics::Tag>] values Tags to set.
|
248
|
+
# @return [void]
|
249
|
+
def tags=(values)
|
250
|
+
modify do
|
251
|
+
values = DSL::Items::ItemBuilder.normalize_tags(*values)
|
252
|
+
next if values.to_set == tags.to_set
|
253
|
+
|
254
|
+
@modified = true
|
255
|
+
remove_all_tags
|
256
|
+
add_tags(values)
|
257
|
+
end
|
258
|
+
end
|
168
259
|
end
|
169
260
|
end
|
170
261
|
end
|
@@ -24,10 +24,6 @@ module OpenHAB
|
|
24
24
|
# The item's name.
|
25
25
|
# @return [String]
|
26
26
|
|
27
|
-
# @!attribute [r] label
|
28
|
-
# The item's descriptive label.
|
29
|
-
# @return [String, nil]
|
30
|
-
|
31
27
|
# @!attribute [r] accepted_command_types
|
32
28
|
# @return [Array<Class>] An array of {Command}s that can be sent as commands to this item
|
33
29
|
|
@@ -35,7 +31,7 @@ module OpenHAB
|
|
35
31
|
# @return [Array<Class>] An array of {State}s that can be sent as commands to this item
|
36
32
|
|
37
33
|
#
|
38
|
-
# The item's {#label} if one is defined, otherwise
|
34
|
+
# The item's {GenericItem#label label} if one is defined, otherwise its {#name}.
|
39
35
|
#
|
40
36
|
# @return [String]
|
41
37
|
#
|
@@ -46,7 +42,7 @@ module OpenHAB
|
|
46
42
|
#
|
47
43
|
# @!attribute [r] groups
|
48
44
|
#
|
49
|
-
#
|
45
|
+
# Returns all groups that this item is part of
|
50
46
|
#
|
51
47
|
# @return [Array<Group>] All groups that this item is part of
|
52
48
|
#
|
@@ -81,7 +77,7 @@ module OpenHAB
|
|
81
77
|
# @example Access namespace1's configuration
|
82
78
|
# Item1.metadata["namespace1"]["config1"]
|
83
79
|
#
|
84
|
-
# @example Safely search for the specified value - no errors are raised, only nil returned if a key in the chain doesn
|
80
|
+
# @example Safely search for the specified value - no errors are raised, only nil returned if a key in the chain doesn't exist
|
85
81
|
# Item1.metadata.dig("namespace1", "config1") # => "foo"
|
86
82
|
# Item1.metadata.dig("namespace2", "config1") # => nil
|
87
83
|
#
|
@@ -189,7 +185,7 @@ module OpenHAB
|
|
189
185
|
#
|
190
186
|
# @return [Array<Thing>] An array of things or an empty array
|
191
187
|
def things
|
192
|
-
registry =
|
188
|
+
registry = Things::Links::Provider.registry
|
193
189
|
channels = registry.get_bound_channels(name).to_a
|
194
190
|
channels.map(&:thing_uid).uniq.map { |tuid| EntityLookup.lookup_thing(tuid) }.compact
|
195
191
|
end
|
@@ -206,6 +202,11 @@ module OpenHAB
|
|
206
202
|
"#{s}>"
|
207
203
|
end
|
208
204
|
|
205
|
+
# @return [org.openhab.core.common.registry.Provider]
|
206
|
+
def provider
|
207
|
+
Provider.registry.provider_for(self)
|
208
|
+
end
|
209
|
+
|
209
210
|
private
|
210
211
|
|
211
212
|
# Allows sub-classes to append additional details to the type in an inspect string
|
@@ -384,7 +384,7 @@ module OpenHAB
|
|
384
384
|
alias_method :to_s, :inspect
|
385
385
|
|
386
386
|
#
|
387
|
-
# @raise [
|
387
|
+
# @raise [FrozenError] if the provider is not a
|
388
388
|
# {org.openhab.core.common.registry.ManagedProvider ManagedProvider} that can be updated.
|
389
389
|
# @return [org.openhab.core.common.registry.ManagedProvider]
|
390
390
|
#
|
@@ -218,8 +218,12 @@ module OpenHAB
|
|
218
218
|
return @hash.each_key(&block) unless attached?
|
219
219
|
return to_enum(:each_key) unless block
|
220
220
|
|
221
|
-
Provider.registry.
|
222
|
-
|
221
|
+
if Provider.registry.respond_to?(:get_all_namespaces)
|
222
|
+
keys.each(&block)
|
223
|
+
else
|
224
|
+
Provider.registry.all.each do |meta|
|
225
|
+
yield meta.uid.namespace if meta.uid.item_name == @item_name
|
226
|
+
end
|
223
227
|
end
|
224
228
|
self
|
225
229
|
end
|
@@ -313,6 +317,10 @@ module OpenHAB
|
|
313
317
|
|
314
318
|
# @!visibility private
|
315
319
|
def keys
|
320
|
+
if Provider.registry.respond_to?(:get_all_namespaces)
|
321
|
+
return Provider.registry.get_all_namespaces(@item_name).to_a
|
322
|
+
end
|
323
|
+
|
316
324
|
each_key.to_a
|
317
325
|
end
|
318
326
|
|
@@ -32,8 +32,8 @@ module OpenHAB
|
|
32
32
|
# @return [void]
|
33
33
|
#
|
34
34
|
def remove_item_metadata(item_name)
|
35
|
-
@elements.delete_if do |
|
36
|
-
next unless
|
35
|
+
@elements.delete_if do |_k, v|
|
36
|
+
next unless v.uid.item_name == item_name
|
37
37
|
|
38
38
|
notify_listeners_about_removed_element(v)
|
39
39
|
true
|
@@ -48,6 +48,8 @@ module OpenHAB
|
|
48
48
|
# that state into a {QuantityType} as necessary.
|
49
49
|
#
|
50
50
|
class HistoricState < SimpleDelegator
|
51
|
+
# @!attribute [r] state
|
52
|
+
# @return [Types::State]
|
51
53
|
alias_method :state, :__getobj__
|
52
54
|
|
53
55
|
def initialize(state, historic_item)
|
@@ -70,9 +72,11 @@ module OpenHAB
|
|
70
72
|
variance_since].freeze
|
71
73
|
|
72
74
|
# All persistence methods that require a timestamp
|
75
|
+
# Note the _between methods are automatically created from the _since methods
|
73
76
|
PERSISTENCE_METHODS = (QUANTITY_METHODS +
|
74
77
|
%i[changed_since?
|
75
|
-
|
78
|
+
count_since
|
79
|
+
count_state_changes_since
|
76
80
|
historic_state
|
77
81
|
maximum_since
|
78
82
|
minimum_since
|
@@ -80,24 +84,24 @@ module OpenHAB
|
|
80
84
|
private_constant :QUANTITY_METHODS, :PERSISTENCE_METHODS
|
81
85
|
|
82
86
|
# @!method persist(service = nil)
|
83
|
-
#
|
87
|
+
# Persists the state of the item
|
84
88
|
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
85
89
|
# @return [void]
|
86
90
|
|
87
91
|
# @!method last_update(service = nil)
|
88
|
-
#
|
92
|
+
# Returns the time the item was last updated.
|
89
93
|
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
90
94
|
# @return [ZonedDateTime, nil] The timestamp of the last update
|
91
95
|
|
92
96
|
# @!method average_since(timestamp, service = nil)
|
93
|
-
#
|
97
|
+
# Returns the average value of the item's state since the given time
|
94
98
|
# @param [#to_zoned_date_time] timestamp The point in time from which to search
|
95
99
|
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
96
100
|
# @return [DecimalType, QuantityType, nil] The average value since `timestamp`,
|
97
101
|
# or nil if no previous state could be found.
|
98
102
|
|
99
103
|
# @!method average_between(start, finish, service = nil)
|
100
|
-
#
|
104
|
+
# Returns the average value of the item's state between two points in time
|
101
105
|
# @param [#to_zoned_date_time] start The point in time from which to search
|
102
106
|
# @param [#to_zoned_date_time] finish The point in time to which to search
|
103
107
|
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
@@ -105,14 +109,14 @@ module OpenHAB
|
|
105
109
|
# or nil if no previous state could be found.
|
106
110
|
|
107
111
|
# @!method delta_since(timestamp, service = nil)
|
108
|
-
#
|
112
|
+
# Returns the difference value of the item's state since the given time
|
109
113
|
# @param [#to_zoned_date_time] timestamp The point in time from which to search
|
110
114
|
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
111
115
|
# @return [DecimalType, QuantityType, nil] The difference value since `timestamp`,
|
112
116
|
# or nil if no previous state could be found.
|
113
117
|
|
114
118
|
# @!method delta_between(start, finish, service = nil)
|
115
|
-
#
|
119
|
+
# Returns the difference value of the item's state between two points in time
|
116
120
|
# @param [#to_zoned_date_time] start The point in time from which to search
|
117
121
|
# @param [#to_zoned_date_time] finish The point in time to which to search
|
118
122
|
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
@@ -120,14 +124,14 @@ module OpenHAB
|
|
120
124
|
# or nil if no previous state could be found.
|
121
125
|
|
122
126
|
# @!method deviation_since(timestamp, service = nil)
|
123
|
-
#
|
127
|
+
# Returns the standard deviation of the item's state since the given time
|
124
128
|
# @param [#to_zoned_date_time] timestamp The point in time from which to search
|
125
129
|
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
126
130
|
# @return [DecimalType, QuantityType, nil] The standard deviation since `timestamp`,
|
127
131
|
# or nil if no previous state could be found.
|
128
132
|
|
129
133
|
# @!method deviation_between(start, finish, service = nil)
|
130
|
-
#
|
134
|
+
# Returns the standard deviation of the item's state between two points in time
|
131
135
|
# @param [#to_zoned_date_time] start The point in time from which to search
|
132
136
|
# @param [#to_zoned_date_time] finish The point in time to which to search
|
133
137
|
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
@@ -135,14 +139,14 @@ module OpenHAB
|
|
135
139
|
# or nil if no previous state could be found.
|
136
140
|
|
137
141
|
# @!method sum_since(timestamp, service = nil)
|
138
|
-
#
|
142
|
+
# Returns the sum of the item's state since the given time
|
139
143
|
# @param [#to_zoned_date_time] timestamp The point in time from which to search
|
140
144
|
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
141
145
|
# @return [DecimalType, QuantityType, nil] The sum since `timestamp`,
|
142
146
|
# or nil if no previous state could be found.
|
143
147
|
|
144
148
|
# @!method sum_between(start, finish, service = nil)
|
145
|
-
#
|
149
|
+
# Returns the sum of the item's state between two points in time
|
146
150
|
# @param [#to_zoned_date_time] start The point in time from which to search
|
147
151
|
# @param [#to_zoned_date_time] finish The point in time to which to search
|
148
152
|
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
@@ -150,14 +154,14 @@ module OpenHAB
|
|
150
154
|
# or nil if no previous state could be found.
|
151
155
|
|
152
156
|
# @!method variance_since(timestamp, service = nil)
|
153
|
-
#
|
157
|
+
# Returns the variance of the item's state since the given time
|
154
158
|
# @param [#to_zoned_date_time] timestamp The point in time from which to search
|
155
159
|
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
156
160
|
# @return [DecimalType, QuantityType, nil] The variance since `timestamp`,
|
157
161
|
# or nil if no previous state could be found.
|
158
162
|
|
159
163
|
# @!method variance_between(start, finish, service = nil)
|
160
|
-
#
|
164
|
+
# Returns the variance of the item's state between two points in time
|
161
165
|
# @param [#to_zoned_date_time] start The point in time from which to search
|
162
166
|
# @param [#to_zoned_date_time] finish The point in time to which to search
|
163
167
|
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
@@ -178,28 +182,39 @@ module OpenHAB
|
|
178
182
|
# @return [true,false] True if the item's state changed between `start` and `finish`, False otherwise.
|
179
183
|
|
180
184
|
# @!method evolution_rate(timestamp, service = nil)
|
181
|
-
#
|
182
|
-
# @param [#to_zoned_date_time] timestamp The point in time from which to search
|
183
|
-
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
185
|
+
# Returns the evolution rate of the item's state
|
184
186
|
# @return [DecimalType, QuantityType, nil] The evolution rate since `timestamp`,
|
185
187
|
# or nil if no previous state could be found.
|
188
|
+
# @overload evolution_rate(timestamp, service = nil)
|
189
|
+
# Returns the evolution rate of the item's state since the given time
|
190
|
+
# @param [#to_zoned_date_time] timestamp The point in time from which to search
|
191
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
192
|
+
# @return [DecimalType, QuantityType, nil] The evolution rate since `timestamp`,
|
193
|
+
# or nil if no previous state could be found.
|
194
|
+
# @overload evolution_rate(start, finish, service = nil)
|
195
|
+
# Returns the evolution rate of the item's state between two points in time
|
196
|
+
# @param [#to_zoned_date_time] start The point in time from which to search
|
197
|
+
# @param [#to_zoned_date_time] finish The point in time to which to search
|
198
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
199
|
+
# @return [DecimalType, QuantityType, nil] The evolution rate between `start` and `finish`,
|
200
|
+
# or nil if no previous state could be found.
|
186
201
|
|
187
202
|
# @!method historic_state(timestamp, service = nil)
|
188
|
-
#
|
203
|
+
# Returns the the item's state at the given time
|
189
204
|
# @param [#to_zoned_date_time] timestamp The point in time at which to search
|
190
205
|
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
191
206
|
# @return [HistoricState, nil] The item's state at `timestamp`,
|
192
207
|
# or nil if no previous state could be found.
|
193
208
|
|
194
209
|
# @!method maximum_since(timestamp, service = nil)
|
195
|
-
#
|
210
|
+
# Returns the maximum value of the item's state since the given time
|
196
211
|
# @param [#to_zoned_date_time] timestamp The point in time from which to search
|
197
212
|
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
198
213
|
# @return [HistoricState, nil] The maximum value since `timestamp`,
|
199
214
|
# or nil if no previous state could be found.
|
200
215
|
|
201
216
|
# @!method maximum_between(start, finish, service = nil)
|
202
|
-
#
|
217
|
+
# Returns the maximum value of the item's state between two points in time
|
203
218
|
# @param [#to_zoned_date_time] start The point in time from which to search
|
204
219
|
# @param [#to_zoned_date_time] finish The point in time to which to search
|
205
220
|
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
@@ -207,14 +222,14 @@ module OpenHAB
|
|
207
222
|
# or nil if no previous state could be found.
|
208
223
|
|
209
224
|
# @!method minimum_since(timestamp, service = nil)
|
210
|
-
#
|
225
|
+
# Returns the minimum value of the item's state since the given time
|
211
226
|
# @param [#to_zoned_date_time] timestamp The point in time from which to search
|
212
227
|
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
213
228
|
# @return [HistoricState, nil] The minimum value since `timestamp`,
|
214
229
|
# or nil if no previous state could be found.
|
215
230
|
|
216
231
|
# @!method minimum_between(start, finish, service = nil)
|
217
|
-
#
|
232
|
+
# Returns the minimum value of the item's state between two points in time
|
218
233
|
# @param [#to_zoned_date_time] start The point in time from which to search
|
219
234
|
# @param [#to_zoned_date_time] finish The point in time to which to search
|
220
235
|
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
@@ -234,6 +249,32 @@ module OpenHAB
|
|
234
249
|
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
235
250
|
# @return [true,false] True if the item's state was updated between `start` and `finish`, False otherwise.
|
236
251
|
|
252
|
+
# @!method count_since(timestamp, service = nil)
|
253
|
+
# Returns the number of available historic data points from a point in time until now.
|
254
|
+
# @param [#to_zoned_date_time] timestamp The point in time from which to search
|
255
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
256
|
+
# @return [Integer] The number of values persisted for this item.
|
257
|
+
|
258
|
+
# @!method count_between(start, finish, service = nil)
|
259
|
+
# Returns the number of available historic data points between two points in time.
|
260
|
+
# @param [#to_zoned_date_time] start The point in time from which to search
|
261
|
+
# @param [#to_zoned_date_time] finish The point in time to which to search
|
262
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
263
|
+
# @return [Integer] The number of values persisted for this item.
|
264
|
+
|
265
|
+
# @!method count_state_changes_since(timestamp, service = nil)
|
266
|
+
# Returns the number of changes in historic data points from a point in time until now.
|
267
|
+
# @param [#to_zoned_date_time] timestamp The point in time from which to search
|
268
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
269
|
+
# @return [Integer] The number of values persisted for this item.
|
270
|
+
|
271
|
+
# @!method count_state_changes_between(start, finish, service = nil)
|
272
|
+
# Returns the number of changes in historic data points between two points in time.
|
273
|
+
# @param [#to_zoned_date_time] start The point in time from which to search
|
274
|
+
# @param [#to_zoned_date_time] finish The point in time to which to search
|
275
|
+
# @param [Symbol, String] service An optional persistence id instead of the default persistence service.
|
276
|
+
# @return [Integer] The number of values persisted for this item.
|
277
|
+
|
237
278
|
%i[persist last_update].each do |method|
|
238
279
|
define_method(method) do |service = nil|
|
239
280
|
service ||= persistence_service
|
@@ -286,6 +327,43 @@ module OpenHAB
|
|
286
327
|
end
|
287
328
|
end
|
288
329
|
|
330
|
+
# evolution_rate's "between" method is overloaded with the same name
|
331
|
+
method = :evolution_rate
|
332
|
+
define_method(method) do |start, finish_or_service = nil, service = nil|
|
333
|
+
if service.nil?
|
334
|
+
if finish_or_service.respond_to?(:to_zoned_date_time)
|
335
|
+
service = persistence_service
|
336
|
+
finish = finish_or_service
|
337
|
+
else
|
338
|
+
service = finish_or_service || persistence_service
|
339
|
+
finish = nil
|
340
|
+
end
|
341
|
+
else
|
342
|
+
finish = finish_or_service
|
343
|
+
end
|
344
|
+
|
345
|
+
result = if finish
|
346
|
+
Actions::PersistenceExtensions.public_send(
|
347
|
+
method,
|
348
|
+
self,
|
349
|
+
start.to_zoned_date_time,
|
350
|
+
finish.to_zoned_date_time,
|
351
|
+
service&.to_s
|
352
|
+
)
|
353
|
+
else
|
354
|
+
Actions::PersistenceExtensions.public_send(
|
355
|
+
method,
|
356
|
+
self,
|
357
|
+
start.to_zoned_date_time,
|
358
|
+
service&.to_s
|
359
|
+
)
|
360
|
+
end
|
361
|
+
wrap_result(result, method)
|
362
|
+
end
|
363
|
+
|
364
|
+
alias_method :state_changes_since, :count_state_changes_since
|
365
|
+
alias_method :state_changes_between, :count_state_changes_between
|
366
|
+
|
289
367
|
private
|
290
368
|
|
291
369
|
#
|
@@ -16,7 +16,7 @@ module OpenHAB
|
|
16
16
|
# @example Start playing on a player item
|
17
17
|
# Chromecast.play
|
18
18
|
# @example Check if a player is paused
|
19
|
-
# logger.warn("#{item.name} is paused) if Chromecast.paused?
|
19
|
+
# logger.warn("#{item.name} is paused") if Chromecast.paused?
|
20
20
|
#
|
21
21
|
class PlayerItem < GenericItem
|
22
22
|
# @!method play?
|