openhab-jrubyscripting 5.0.0.rc11 → 5.0.0.rc.13
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/actions/exec.rb +41 -41
- data/lib/openhab/core/actions/transformation.rb +3 -3
- data/lib/openhab/core/actions.rb +1 -1
- data/lib/openhab/core/events/item_command_event.rb +31 -31
- data/lib/openhab/core/events/item_state_changed_event.rb +41 -18
- data/lib/openhab/core/events/item_state_event.rb +46 -18
- data/lib/openhab/core/items/date_time_item.rb +3 -2
- data/lib/openhab/core/items/generic_item.rb +119 -1
- data/lib/openhab/core/items/item.rb +63 -9
- 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 +48 -4
- data/lib/openhab/core/items/provider.rb +4 -0
- data/lib/openhab/core/items/registry.rb +10 -1
- data/lib/openhab/core/items/semantics/enumerable.rb +29 -6
- data/lib/openhab/core/items/state_storage.rb +2 -2
- data/lib/openhab/core/items.rb +6 -13
- data/lib/openhab/core/provider.rb +2 -2
- data/lib/openhab/core/proxy.rb +5 -0
- data/lib/openhab/core/registry.rb +12 -2
- data/lib/openhab/core/rules/provider.rb +0 -15
- data/lib/openhab/core/rules.rb +1 -1
- data/lib/openhab/core/script_handling.rb +8 -8
- data/lib/openhab/core/things/links/provider.rb +38 -0
- data/lib/openhab/core/things/provider.rb +4 -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 +1 -1
- data/lib/openhab/core/types/decimal_type.rb +4 -9
- data/lib/openhab/core/types/hsb_type.rb +2 -2
- data/lib/openhab/core/types/quantity_type.rb +4 -9
- data/lib/openhab/core/types/string_type.rb +1 -1
- data/lib/openhab/core/types/type.rb +8 -28
- data/lib/openhab/core/types.rb +16 -3
- data/lib/openhab/core.rb +3 -3
- data/lib/openhab/core_ext/java/duration.rb +2 -0
- data/lib/openhab/core_ext/java/local_date.rb +15 -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 +13 -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 +15 -2
- data/lib/openhab/core_ext/ruby/date.rb +2 -2
- data/lib/openhab/core_ext/ruby/{class.rb → module.rb} +3 -3
- data/lib/openhab/core_ext/ruby/numeric.rb +6 -1
- data/lib/openhab/dsl/items/builder.rb +25 -12
- data/lib/openhab/dsl/items/ensure.rb +8 -6
- data/lib/openhab/dsl/rules/automation_rule.rb +2 -23
- data/lib/openhab/dsl/rules/builder.rb +47 -2
- data/lib/openhab/dsl/rules/terse.rb +15 -13
- data/lib/openhab/dsl/timer_manager.rb +1 -1
- data/lib/openhab/dsl/version.rb +1 -1
- data/lib/openhab/dsl.rb +38 -11
- data/lib/openhab/osgi.rb +1 -3
- data/lib/openhab/rspec/helpers.rb +3 -5
- data/lib/openhab/rspec/hooks.rb +1 -0
- data/lib/openhab/rspec/mocks/timer.rb +33 -0
- data/lib/openhab/rspec.rb +9 -0
- metadata +23 -9
@@ -20,27 +20,29 @@ module OpenHAB
|
|
20
20
|
class << self
|
21
21
|
# @!visibility private
|
22
22
|
# @!macro def_terse_rule
|
23
|
-
# @!method $1(*args, name :nil, id: nil, **kwargs, &block)
|
23
|
+
# @!method $1(*args, name :nil, id: nil, on_load: false, **kwargs, &block)
|
24
24
|
# Create a new rule with a $1 trigger.
|
25
25
|
# @param name [String] The name for the rule.
|
26
26
|
# @param id [String] The ID for the rule.
|
27
|
+
# @param on_load [true, false] If the rule should _also_ trigger immediately when the script loads.
|
27
28
|
# @yield The execution block for the rule.
|
28
29
|
# @return [void]
|
29
30
|
# @see BuilderDSL#$1
|
30
31
|
def def_terse_rule(trigger)
|
31
32
|
class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
|
32
|
-
def #{trigger}(*args, name: nil, id: nil, **kwargs, &block) # def changed(*args, name: nil, id: nil, **kwargs, &block)
|
33
|
-
raise ArgumentError, "Block is required" unless block
|
34
|
-
|
35
|
-
id ||= NameInference.infer_rule_id_from_block(block)
|
36
|
-
script = block.source rescue nil
|
37
|
-
caller_binding = block.binding
|
38
|
-
rule name, id: id, script: script, binding: caller_binding do
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
33
|
+
def #{trigger}(*args, name: nil, id: nil, on_load: false, **kwargs, &block) # def changed(*args, name: nil, id: nil, on_load: false, **kwargs, &block)
|
34
|
+
raise ArgumentError, "Block is required" unless block # raise ArgumentError, "Block is required" unless block
|
35
|
+
#
|
36
|
+
id ||= NameInference.infer_rule_id_from_block(block) # id ||= NameInference.infer_rule_id_from_block(block)
|
37
|
+
script = block.source rescue nil # script = block.source rescue nil
|
38
|
+
caller_binding = block.binding # caller_binding = block.binding
|
39
|
+
rule name, id: id, script: script, binding: caller_binding do # rule name, id: id, script: script, binding: caller_binding do
|
40
|
+
self.on_load if on_load # self.on_load if on_load
|
41
|
+
#{trigger}(*args, **kwargs) # changed(*args, **kwargs)
|
42
|
+
run(&block) # run(&block)
|
43
|
+
end # end
|
44
|
+
end # end
|
45
|
+
module_function #{trigger.inspect} # module_function :changed
|
44
46
|
RUBY
|
45
47
|
end
|
46
48
|
end
|
data/lib/openhab/dsl/version.rb
CHANGED
data/lib/openhab/dsl.rb
CHANGED
@@ -30,6 +30,12 @@ module OpenHAB
|
|
30
30
|
# include this before Core::Actions so that Core::Action's method_missing
|
31
31
|
# takes priority
|
32
32
|
include Core::EntityLookup
|
33
|
+
#
|
34
|
+
# @!parse
|
35
|
+
# include Core::Actions
|
36
|
+
# include Core::ScriptHandling
|
37
|
+
# include Rules::Terse
|
38
|
+
#
|
33
39
|
[Core::Actions, Core::ScriptHandling, Rules::Terse].each do |mod|
|
34
40
|
# make these available both as regular and class methods
|
35
41
|
include mod
|
@@ -152,8 +158,6 @@ module OpenHAB
|
|
152
158
|
#
|
153
159
|
# @see Core::ValueCache ValueCache
|
154
160
|
#
|
155
|
-
# @since openHAB 3.4.0
|
156
|
-
#
|
157
161
|
def shared_cache
|
158
162
|
$sharedCache
|
159
163
|
end
|
@@ -475,6 +479,11 @@ module OpenHAB
|
|
475
479
|
debounce(for: duration, id: id, &block)
|
476
480
|
end
|
477
481
|
|
482
|
+
# (see Core::Actions::Transformation.transform)
|
483
|
+
def transform(type, function, value)
|
484
|
+
Transformation.transform(type, function, value)
|
485
|
+
end
|
486
|
+
|
478
487
|
#
|
479
488
|
# Limit how often the given block executes to the specified interval.
|
480
489
|
#
|
@@ -523,9 +532,6 @@ module OpenHAB
|
|
523
532
|
# end # the states will be restored here
|
524
533
|
#
|
525
534
|
def store_states(*items)
|
526
|
-
items = items.flatten.map do |item|
|
527
|
-
item.respond_to?(:__getobj__) ? item.__getobj__ : item
|
528
|
-
end
|
529
535
|
states = Core::Items::StateStorage.from_items(*items)
|
530
536
|
if block_given?
|
531
537
|
yield
|
@@ -604,18 +610,39 @@ module OpenHAB
|
|
604
610
|
# Item1.average_since(12.hours)
|
605
611
|
# end
|
606
612
|
#
|
607
|
-
# @
|
608
|
-
#
|
609
|
-
# @param [Object] service service either as a String or a Symbol
|
613
|
+
# @param [Object] service Persistence service either as a String or a Symbol
|
610
614
|
# @yield [] Block executed in context of the supplied persistence service
|
611
615
|
# @return [Object] The return value from the block.
|
612
616
|
#
|
617
|
+
# @see persistence!
|
618
|
+
# @see OpenHAB::Core::Items::Persistence
|
619
|
+
#
|
613
620
|
def persistence(service)
|
614
|
-
old =
|
615
|
-
Thread.current[:openhab_persistence_service] = service
|
621
|
+
old = persistence!(service)
|
616
622
|
yield
|
617
623
|
ensure
|
618
|
-
|
624
|
+
persistence!(old)
|
625
|
+
end
|
626
|
+
|
627
|
+
#
|
628
|
+
# Permanently sets the default persistence service for the current thread
|
629
|
+
#
|
630
|
+
# @note This method is only intended for use at the top level of rule
|
631
|
+
# scripts. If it's used within library methods, or hap-hazardly within
|
632
|
+
# rules, things can get very confusing because the prior state won't be
|
633
|
+
# properly restored.
|
634
|
+
#
|
635
|
+
# @param [Object] service Persistence service either as a String or a Symbol. When nil, use
|
636
|
+
# the system's default persistence service.
|
637
|
+
# @return [Object,nil] The previous persistence service settings, or nil when using the system's default.
|
638
|
+
#
|
639
|
+
# @see persistence
|
640
|
+
# @see OpenHAB::Core::Items::Persistence
|
641
|
+
#
|
642
|
+
def persistence!(service = nil)
|
643
|
+
old = Thread.current[:openhab_persistence_service]
|
644
|
+
Thread.current[:openhab_persistence_service] = service
|
645
|
+
old
|
619
646
|
end
|
620
647
|
|
621
648
|
#
|
data/lib/openhab/osgi.rb
CHANGED
@@ -52,10 +52,8 @@ module OpenHAB
|
|
52
52
|
)
|
53
53
|
end
|
54
54
|
|
55
|
-
private
|
56
|
-
|
57
55
|
# @!attribute [r] bundle_context
|
58
|
-
# @return [org.osgi.framework.BundleContext] OSGi bundle context
|
56
|
+
# @return [org.osgi.framework.BundleContext] OSGi bundle context for ScriptExtension Class
|
59
57
|
def bundle_context
|
60
58
|
@bundle_context ||= bundle.bundle_context
|
61
59
|
end
|
@@ -12,9 +12,6 @@ module OpenHAB
|
|
12
12
|
# @example Corresponds to `transform/compass.script`
|
13
13
|
# OpenHAB::Transform.compass("30", param: "7")
|
14
14
|
#
|
15
|
-
# @example Corresponds to `transform/ruby/compass.script`
|
16
|
-
# OpenHAB::Transform::Ruby.compass("59 °")
|
17
|
-
|
18
15
|
module Transform
|
19
16
|
class << self
|
20
17
|
# @!visibility private
|
@@ -265,12 +262,13 @@ module OpenHAB
|
|
265
262
|
# @return [void]
|
266
263
|
#
|
267
264
|
def load_rules
|
268
|
-
|
265
|
+
automation_paths = Array(::RSpec.configuration.openhab_automation_search_paths)
|
266
|
+
|
269
267
|
lib_dirs = rubylib_dirs.map { |d| File.join(d, "") }
|
270
268
|
lib_dirs << File.join(gem_home, "")
|
271
269
|
|
272
270
|
SuspendRules.suspend_rules do
|
273
|
-
files = Dir["#{
|
271
|
+
files = automation_paths.map { |p| Dir["#{p}/**/*.rb"] }.flatten
|
274
272
|
files.reject! do |f|
|
275
273
|
lib_dirs.any? { |l| f.start_with?(l) }
|
276
274
|
end
|
data/lib/openhab/rspec/hooks.rb
CHANGED
@@ -17,6 +17,39 @@ module OpenHAB
|
|
17
17
|
end
|
18
18
|
ZonedDateTime.singleton_class.prepend(MockedZonedDateTime)
|
19
19
|
|
20
|
+
# @!visibility private
|
21
|
+
module MockedLocalDate
|
22
|
+
def now
|
23
|
+
mocked_time_stack_item = Timecop.top_stack_item
|
24
|
+
return super unless mocked_time_stack_item
|
25
|
+
|
26
|
+
mocked_time_stack_item.time.to_zoned_date_time.to_local_date
|
27
|
+
end
|
28
|
+
end
|
29
|
+
LocalDate.singleton_class.prepend(MockedLocalDate)
|
30
|
+
|
31
|
+
# @!visibility private
|
32
|
+
module MockedLocalTime
|
33
|
+
def now
|
34
|
+
mocked_time_stack_item = Timecop.top_stack_item
|
35
|
+
return super unless mocked_time_stack_item
|
36
|
+
|
37
|
+
mocked_time_stack_item.time.to_zoned_date_time.to_local_time
|
38
|
+
end
|
39
|
+
end
|
40
|
+
LocalTime.singleton_class.prepend(MockedLocalTime)
|
41
|
+
|
42
|
+
# @!visibility private
|
43
|
+
module MockedMonthDay
|
44
|
+
def now
|
45
|
+
mocked_time_stack_item = Timecop.top_stack_item
|
46
|
+
return super unless mocked_time_stack_item
|
47
|
+
|
48
|
+
mocked_time_stack_item.time.to_zoned_date_time.to_month_day
|
49
|
+
end
|
50
|
+
end
|
51
|
+
MonthDay.singleton_class.prepend(MockedMonthDay)
|
52
|
+
|
20
53
|
# extend Timecop to support Java time classes
|
21
54
|
# @!visibility private
|
22
55
|
module TimeCopStackItem
|
data/lib/openhab/rspec.rb
CHANGED
@@ -15,3 +15,12 @@ require_relative "rspec/configuration"
|
|
15
15
|
require_relative "rspec/helpers"
|
16
16
|
require_relative "rspec/karaf"
|
17
17
|
require_relative "rspec/hooks"
|
18
|
+
|
19
|
+
return unless defined?(RSpec)
|
20
|
+
|
21
|
+
RSpec.configure do |c|
|
22
|
+
c.add_setting :openhab_automation_search_paths, default: [
|
23
|
+
"#{org.openhab.core.OpenHAB.config_folder}/automation/ruby",
|
24
|
+
"#{org.openhab.core.OpenHAB.config_folder}/automation/jsr223"
|
25
|
+
]
|
26
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openhab-jrubyscripting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0.0.
|
4
|
+
version: 5.0.0.rc.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cody Cutrer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '1.2'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: gem-release
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.2'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.2'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: guard-rubocop
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -453,9 +467,9 @@ files:
|
|
453
467
|
- lib/openhab/core_ext/java/unit.rb
|
454
468
|
- lib/openhab/core_ext/java/zoned_date_time.rb
|
455
469
|
- lib/openhab/core_ext/ruby/array.rb
|
456
|
-
- lib/openhab/core_ext/ruby/class.rb
|
457
470
|
- lib/openhab/core_ext/ruby/date.rb
|
458
471
|
- lib/openhab/core_ext/ruby/date_time.rb
|
472
|
+
- lib/openhab/core_ext/ruby/module.rb
|
459
473
|
- lib/openhab/core_ext/ruby/numeric.rb
|
460
474
|
- lib/openhab/core_ext/ruby/range.rb
|
461
475
|
- lib/openhab/core_ext/ruby/symbol.rb
|
@@ -537,14 +551,14 @@ files:
|
|
537
551
|
- lib/openhab/yard/tags/constant_directive.rb
|
538
552
|
- lib/openhab/yard/tags/group_directive.rb
|
539
553
|
- lib/openhab/yard/tags/library.rb
|
540
|
-
homepage: https://
|
554
|
+
homepage: https://openhab.github.io/openhab-jruby/
|
541
555
|
licenses:
|
542
556
|
- EPL-2.0
|
543
557
|
metadata:
|
544
|
-
homepage_uri: https://
|
545
|
-
source_code_uri: https://github.com/
|
546
|
-
documentation_uri: https://
|
547
|
-
changelog_uri: https://
|
558
|
+
homepage_uri: https://openhab.github.io/openhab-jruby/
|
559
|
+
source_code_uri: https://github.com/openhab/openhab-jruby
|
560
|
+
documentation_uri: https://openhab.github.io/openhab-jruby/
|
561
|
+
changelog_uri: https://openhab.github.io/openhab-jruby/file.CHANGELOG.html
|
548
562
|
rubygems_mfa_required: 'true'
|
549
563
|
post_install_message:
|
550
564
|
rdoc_options: []
|
@@ -561,7 +575,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
561
575
|
- !ruby/object:Gem::Version
|
562
576
|
version: 1.3.1
|
563
577
|
requirements: []
|
564
|
-
rubygems_version: 3.3.
|
578
|
+
rubygems_version: 3.3.26
|
565
579
|
signing_key:
|
566
580
|
specification_version: 4
|
567
581
|
summary: JRuby Helper Libraries for openHAB Scripting
|