openhab-scripting 5.49.0 → 5.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/openhab/core/items/generic_item.rb +14 -8
- data/lib/openhab/core/items/item.rb +3 -6
- data/lib/openhab/core/rules/tagged_array.rb +1 -1
- data/lib/openhab/core_ext/between.rb +2 -0
- data/lib/openhab/core_ext/java/instant.rb +1 -0
- data/lib/openhab/core_ext/java/local_date.rb +1 -0
- data/lib/openhab/core_ext/java/local_time.rb +1 -0
- data/lib/openhab/core_ext/java/month.rb +1 -0
- data/lib/openhab/core_ext/java/month_day.rb +1 -0
- data/lib/openhab/core_ext/java/time.rb +3 -0
- data/lib/openhab/core_ext/java/zoned_date_time.rb +1 -0
- data/lib/openhab/core_ext/ruby/date.rb +3 -0
- data/lib/openhab/core_ext/ruby/date_time.rb +3 -0
- data/lib/openhab/core_ext/ruby/time.rb +3 -0
- data/lib/openhab/core_ext/time_predicates.rb +28 -0
- data/lib/openhab/dsl/version.rb +1 -1
- data/lib/openhab/dsl.rb +2 -2
- data/lib/openhab/rspec/helpers.rb +16 -3
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b70d205b061cb7bea4228face2481a0ccdb11a9947c8b4194b972db0a15c6935
|
|
4
|
+
data.tar.gz: 60ac7bf7347d4027766fc0285e61bcb849203196e2d625e8181da4e04e96c220
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 13014e726aa0efe66e5e1034f31f0a5c6688c7e19373cd314dfc93145137ce9232b8fa710c889b69dc2f07f18b109649f73fb20e720bde56e5bee8b10168601e
|
|
7
|
+
data.tar.gz: 264e3d3d6b351e466b9317728fabf1f086addbd6318ab1a349d57b711a7d26559cf85d8619d8b41cd31969edf7af8dda844ffad128f6edce6cb00538fba8cf15
|
|
@@ -168,7 +168,7 @@ module OpenHAB
|
|
|
168
168
|
|
|
169
169
|
proxied_self = Proxy.new(self)
|
|
170
170
|
|
|
171
|
-
return yield(proxied_self) if
|
|
171
|
+
return yield(proxied_self) if proxied_self.instance_variable_get(:@modifying)
|
|
172
172
|
|
|
173
173
|
begin
|
|
174
174
|
provider = self.provider
|
|
@@ -178,15 +178,15 @@ module OpenHAB
|
|
|
178
178
|
provider = nil
|
|
179
179
|
logger.debug { "Forcing modifications to non-managed item #{name}" }
|
|
180
180
|
end
|
|
181
|
-
|
|
182
|
-
|
|
181
|
+
proxied_self.instance_variable_set(:@modified, false)
|
|
182
|
+
proxied_self.instance_variable_set(:@modifying, true)
|
|
183
183
|
|
|
184
184
|
r = yield(proxied_self)
|
|
185
185
|
|
|
186
|
-
provider&.update(self) if
|
|
186
|
+
provider&.update(self) if proxied_self.instance_variable_get(:@modified)
|
|
187
187
|
r
|
|
188
188
|
ensure
|
|
189
|
-
|
|
189
|
+
proxied_self.instance_variable_set(:@modifying, false)
|
|
190
190
|
end
|
|
191
191
|
end
|
|
192
192
|
|
|
@@ -197,7 +197,9 @@ module OpenHAB
|
|
|
197
197
|
modify do
|
|
198
198
|
next if label == value
|
|
199
199
|
|
|
200
|
-
|
|
200
|
+
proxied_self = Proxy.new(self)
|
|
201
|
+
|
|
202
|
+
proxied_self.instance_variable_set(:@modified, true)
|
|
201
203
|
set_label(value)
|
|
202
204
|
end
|
|
203
205
|
end
|
|
@@ -210,7 +212,9 @@ module OpenHAB
|
|
|
210
212
|
value = value&.to_s
|
|
211
213
|
next if category == value
|
|
212
214
|
|
|
213
|
-
|
|
215
|
+
proxied_self = Proxy.new(self)
|
|
216
|
+
|
|
217
|
+
proxied_self.instance_variable_set(:@modified, true)
|
|
214
218
|
set_category(value)
|
|
215
219
|
end
|
|
216
220
|
end
|
|
@@ -234,7 +238,9 @@ module OpenHAB
|
|
|
234
238
|
values = DSL::Items::Tags.normalize(*values)
|
|
235
239
|
next if values.to_set == tags.to_set
|
|
236
240
|
|
|
237
|
-
|
|
241
|
+
proxied_self = Proxy.new(self)
|
|
242
|
+
|
|
243
|
+
proxied_self.instance_variable_set(:@modified, true)
|
|
238
244
|
remove_all_tags
|
|
239
245
|
add_tags(values)
|
|
240
246
|
end
|
|
@@ -582,12 +582,9 @@ module OpenHAB
|
|
|
582
582
|
# @return [String]
|
|
583
583
|
def inspect
|
|
584
584
|
s = "#<OpenHAB::Core::Items::#{type}Item#{type_details} #{name} #{label.inspect} state=#{raw_state.inspect}"
|
|
585
|
-
|
|
586
|
-
if
|
|
587
|
-
|
|
588
|
-
s += " last_state_update=#{last_state_update}" if last_state_update
|
|
589
|
-
s += " last_state_change=#{last_state_change}" if last_state_change
|
|
590
|
-
end
|
|
585
|
+
s += " last_state=#{last_state.inspect}" if last_state
|
|
586
|
+
s += " last_state_update=#{last_state_update}" if last_state_update
|
|
587
|
+
s += " last_state_change=#{last_state_change}" if last_state_change
|
|
591
588
|
s += " category=#{category.inspect}" if category
|
|
592
589
|
s += " tags=#{tags.to_a.inspect}" unless tags.empty?
|
|
593
590
|
s += " groups=#{group_names}" unless group_names.empty?
|
|
@@ -16,6 +16,8 @@ module OpenHAB
|
|
|
16
16
|
# @param [Range] range A range to check
|
|
17
17
|
# @return [true,false]
|
|
18
18
|
#
|
|
19
|
+
# @see TimePredicates#within? to check if a time is within a certain distance of another time
|
|
20
|
+
#
|
|
19
21
|
def between?(min, max = nil)
|
|
20
22
|
range = if max
|
|
21
23
|
Range.new(min, max, false)
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "../time_predicates"
|
|
4
|
+
|
|
3
5
|
module OpenHAB
|
|
4
6
|
module CoreExt
|
|
5
7
|
module Java
|
|
@@ -24,6 +26,7 @@ module OpenHAB
|
|
|
24
26
|
|
|
25
27
|
# @!visibility private
|
|
26
28
|
def self.included(klass)
|
|
29
|
+
klass.prepend(OpenHAB::CoreExt::TimePredicates)
|
|
27
30
|
klass.singleton_class.prepend(ClassMethods)
|
|
28
31
|
klass.remove_method(:==)
|
|
29
32
|
klass.alias_method(:inspect, :to_s)
|
|
@@ -3,11 +3,14 @@
|
|
|
3
3
|
require "forwardable"
|
|
4
4
|
require "date"
|
|
5
5
|
|
|
6
|
+
require_relative "../time_predicates"
|
|
7
|
+
|
|
6
8
|
# Extensions to Date
|
|
7
9
|
class Date
|
|
8
10
|
extend Forwardable
|
|
9
11
|
include OpenHAB::CoreExt::Between
|
|
10
12
|
include OpenHAB::CoreExt::Ephemeris
|
|
13
|
+
include OpenHAB::CoreExt::TimePredicates
|
|
11
14
|
|
|
12
15
|
#
|
|
13
16
|
# Extends {#+} to allow adding a {java.time.temporal.TemporalAmount TemporalAmount}
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
require "date"
|
|
4
4
|
require "forwardable"
|
|
5
5
|
|
|
6
|
+
require_relative "../time_predicates"
|
|
7
|
+
|
|
6
8
|
# DateTime inherits from Date, but is more similar to Time semantically.
|
|
7
9
|
# So it avoid alias_method chain bombs, and to ensure the correct end methods
|
|
8
10
|
# exist here, we define the important methods from Time here as well.
|
|
@@ -12,6 +14,7 @@ class DateTime < Date
|
|
|
12
14
|
extend Forwardable
|
|
13
15
|
include OpenHAB::CoreExt::Between
|
|
14
16
|
include OpenHAB::CoreExt::Ephemeris
|
|
17
|
+
include OpenHAB::CoreExt::TimePredicates
|
|
15
18
|
|
|
16
19
|
# (see Time#plus_with_temporal)
|
|
17
20
|
def plus_with_temporal(other)
|
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
require "forwardable"
|
|
4
4
|
|
|
5
|
+
require_relative "../time_predicates"
|
|
6
|
+
|
|
5
7
|
# Extensions to Time
|
|
6
8
|
class Time
|
|
7
9
|
extend Forwardable
|
|
8
10
|
include OpenHAB::CoreExt::Between
|
|
9
11
|
include OpenHAB::CoreExt::Ephemeris
|
|
12
|
+
include OpenHAB::CoreExt::TimePredicates
|
|
10
13
|
|
|
11
14
|
#
|
|
12
15
|
# @!method +(other)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OpenHAB
|
|
4
|
+
module CoreExt
|
|
5
|
+
# Predicate helpers for date/time-like objects.
|
|
6
|
+
module TimePredicates
|
|
7
|
+
#
|
|
8
|
+
# Checks whether the object is within a maximum allowable distance (epsilon)
|
|
9
|
+
# of a specific anchor time.
|
|
10
|
+
#
|
|
11
|
+
# @example Check if a timestamp is within 5 minutes of right now
|
|
12
|
+
# event_time.within?(5.minutes)
|
|
13
|
+
#
|
|
14
|
+
# @example Check if a timestamp is within 30 seconds of an explicit execution deadline
|
|
15
|
+
# log_time.within?(30.seconds, of: deadline)
|
|
16
|
+
#
|
|
17
|
+
# @param [java.time.temporal.TemporalAmount, Numeric] epsilon the maximum allowable time difference/distance
|
|
18
|
+
# @param [ZonedDateTime, Time] of the anchor time to compare against (defaults to now)
|
|
19
|
+
# @return [true, false] true if the absolute difference between self and the anchor is less than epsilon
|
|
20
|
+
#
|
|
21
|
+
def within?(epsilon, of: ZonedDateTime.now)
|
|
22
|
+
# Convert times to a common float representation (like epoch seconds) to do the math
|
|
23
|
+
# Or use native Java duration differences if keeping it in the Java ecosystem
|
|
24
|
+
(of - self).to_f.abs < epsilon.to_f
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
data/lib/openhab/dsl/version.rb
CHANGED
data/lib/openhab/dsl.rb
CHANGED
|
@@ -737,8 +737,8 @@ module OpenHAB
|
|
|
737
737
|
# @example
|
|
738
738
|
# persistence(:influxdb) do
|
|
739
739
|
# Item1.persist
|
|
740
|
-
# Item1.changed_since(1.hour)
|
|
741
|
-
# Item1.average_since(12.hours)
|
|
740
|
+
# Item1.changed_since?(1.hour.ago)
|
|
741
|
+
# Item1.average_since(12.hours.ago)
|
|
742
742
|
# end
|
|
743
743
|
#
|
|
744
744
|
# @param [Object] service Persistence service either as a String or a Symbol
|
|
@@ -417,10 +417,23 @@ module OpenHAB
|
|
|
417
417
|
# end
|
|
418
418
|
#
|
|
419
419
|
def spec_log_lines
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
420
|
+
lines = []
|
|
421
|
+
|
|
422
|
+
# Give the underlying Log4j file channel up to ~50ms to flush its buffer to disk
|
|
423
|
+
5.times do
|
|
424
|
+
lines = File.open(log_file, "rb") do |f|
|
|
425
|
+
f.seek(@log_index) if @log_index
|
|
426
|
+
f.read.split("\n")
|
|
427
|
+
end
|
|
428
|
+
|
|
429
|
+
# If we read lines, break early. If it's still empty, yield execution to the
|
|
430
|
+
# JVM thread scheduler so the file appender thread can finish flushing.
|
|
431
|
+
break unless lines.empty?
|
|
432
|
+
|
|
433
|
+
sleep 0.01
|
|
423
434
|
end
|
|
435
|
+
|
|
436
|
+
lines
|
|
424
437
|
end
|
|
425
438
|
|
|
426
439
|
private
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: openhab-scripting
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 5.
|
|
4
|
+
version: 5.50.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brian O'Connell
|
|
@@ -255,6 +255,7 @@ files:
|
|
|
255
255
|
- lib/openhab/core_ext/ruby/range.rb
|
|
256
256
|
- lib/openhab/core_ext/ruby/symbol.rb
|
|
257
257
|
- lib/openhab/core_ext/ruby/time.rb
|
|
258
|
+
- lib/openhab/core_ext/time_predicates.rb
|
|
258
259
|
- lib/openhab/dsl.rb
|
|
259
260
|
- lib/openhab/dsl/config_description/builder.rb
|
|
260
261
|
- lib/openhab/dsl/debouncer.rb
|
|
@@ -360,7 +361,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
360
361
|
- !ruby/object:Gem::Version
|
|
361
362
|
version: '0'
|
|
362
363
|
requirements: []
|
|
363
|
-
rubygems_version: 4.0.
|
|
364
|
+
rubygems_version: 4.0.16
|
|
364
365
|
specification_version: 4
|
|
365
366
|
summary: JRuby Helper Libraries for openHAB Scripting
|
|
366
367
|
test_files: []
|