openhab-scripting 5.35.1 → 5.36.1

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.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/lib/openhab/console/irb.rb +105 -0
  3. data/lib/openhab/console/jline.rb +104 -0
  4. data/lib/openhab/console/registry.rb +12 -0
  5. data/lib/openhab/console/stdio.rb +178 -0
  6. data/lib/openhab/console.rb +5 -0
  7. data/lib/openhab/core/emulate_hash.rb +11 -11
  8. data/lib/openhab/core/entity_lookup.rb +2 -4
  9. data/lib/openhab/core/events/item_state_updated_event.rb +0 -3
  10. data/lib/openhab/core/events/item_time_series_updated_event.rb +0 -3
  11. data/lib/openhab/core/events/startlevel_event.rb +0 -3
  12. data/lib/openhab/core/events/timer_event.rb +0 -3
  13. data/lib/openhab/core/items/generic_item.rb +14 -154
  14. data/lib/openhab/core/items/group_item.rb +2 -2
  15. data/lib/openhab/core/items/image_item.rb +5 -21
  16. data/lib/openhab/core/items/item.rb +161 -7
  17. data/lib/openhab/core/items/persistence.rb +8 -10
  18. data/lib/openhab/core/items/provider.rb +1 -1
  19. data/lib/openhab/core/items/proxy.rb +33 -94
  20. data/lib/openhab/core/items/registry.rb +1 -1
  21. data/lib/openhab/core/items/semantics/enumerable.rb +1 -1
  22. data/lib/openhab/core/items/semantics/provider.rb +1 -5
  23. data/lib/openhab/core/items/semantics/semantic_tag.rb +0 -3
  24. data/lib/openhab/core/items/semantics.rb +105 -141
  25. data/lib/openhab/core/items/switch_item.rb +1 -1
  26. data/lib/openhab/core/items.rb +22 -22
  27. data/lib/openhab/core/lazy_array.rb +4 -4
  28. data/lib/openhab/core/profile_factory.rb +16 -25
  29. data/lib/openhab/core/provider.rb +3 -4
  30. data/lib/openhab/core/proxy.rb +160 -4
  31. data/lib/openhab/core/rules/registry.rb +2 -2
  32. data/lib/openhab/core/rules/rule.rb +4 -8
  33. data/lib/openhab/core/script_handling.rb +2 -2
  34. data/lib/openhab/core/sitemaps/provider.rb +1 -1
  35. data/lib/openhab/core/things/channel.rb +0 -28
  36. data/lib/openhab/core/things/profile_callback.rb +3 -3
  37. data/lib/openhab/core/things/proxy.rb +8 -51
  38. data/lib/openhab/core/things/registry.rb +1 -1
  39. data/lib/openhab/core/things/thing.rb +3 -5
  40. data/lib/openhab/core/types/command_description.rb +31 -0
  41. data/lib/openhab/core/types/date_time_type.rb +5 -10
  42. data/lib/openhab/core/types/decimal_type.rb +1 -1
  43. data/lib/openhab/core/types/hsb_type.rb +3 -5
  44. data/lib/openhab/core/types/point_type.rb +1 -1
  45. data/lib/openhab/core/types/quantity_type.rb +22 -2
  46. data/lib/openhab/core/types/raw_type.rb +10 -4
  47. data/lib/openhab/core/types/state_description.rb +54 -0
  48. data/lib/openhab/core/types/time_series.rb +0 -3
  49. data/lib/openhab/core/types.rb +2 -2
  50. data/lib/openhab/core/value_cache.rb +3 -3
  51. data/lib/openhab/core.rb +3 -5
  52. data/lib/openhab/core_ext/java/duration.rb +27 -8
  53. data/lib/openhab/core_ext/java/list.rb +1 -1
  54. data/lib/openhab/core_ext/java/local_date.rb +6 -2
  55. data/lib/openhab/core_ext/java/local_time.rb +4 -2
  56. data/lib/openhab/core_ext/java/map.rb +2 -2
  57. data/lib/openhab/core_ext/java/period.rb +9 -6
  58. data/lib/openhab/core_ext/java/temporal_amount.rb +5 -0
  59. data/lib/openhab/core_ext/java/zoned_date_time.rb +12 -6
  60. data/lib/openhab/core_ext/ruby/date.rb +8 -7
  61. data/lib/openhab/core_ext/ruby/date_time.rb +2 -2
  62. data/lib/openhab/core_ext/ruby/time.rb +2 -2
  63. data/lib/openhab/core_ext.rb +1 -1
  64. data/lib/openhab/dsl/config_description/builder.rb +1 -1
  65. data/lib/openhab/dsl/items/builder.rb +5 -13
  66. data/lib/openhab/dsl/items/ensure.rb +3 -5
  67. data/lib/openhab/dsl/items/timed_command.rb +4 -4
  68. data/lib/openhab/dsl/rules/automation_rule.rb +3 -3
  69. data/lib/openhab/dsl/rules/builder.rb +40 -52
  70. data/lib/openhab/dsl/rules/rule_triggers.rb +1 -1
  71. data/lib/openhab/dsl/rules/triggers/changed.rb +16 -15
  72. data/lib/openhab/dsl/rules/triggers/channel.rb +1 -1
  73. data/lib/openhab/dsl/rules/triggers/command.rb +2 -2
  74. data/lib/openhab/dsl/rules/triggers/conditions/duration.rb +4 -4
  75. data/lib/openhab/dsl/rules/triggers/cron/cron.rb +4 -14
  76. data/lib/openhab/dsl/rules/triggers/updated.rb +6 -6
  77. data/lib/openhab/dsl/rules/triggers/watch/watch_handler.rb +69 -124
  78. data/lib/openhab/dsl/sitemaps/builder.rb +7 -17
  79. data/lib/openhab/dsl/things/builder.rb +8 -8
  80. data/lib/openhab/dsl/timer_manager.rb +2 -2
  81. data/lib/openhab/dsl/version.rb +1 -1
  82. data/lib/openhab/dsl.rb +14 -15
  83. data/lib/openhab/log.rb +3 -3
  84. data/lib/openhab/osgi.rb +1 -1
  85. data/lib/openhab/rspec/helpers.rb +3 -3
  86. data/lib/openhab/rspec/hooks.rb +2 -8
  87. data/lib/openhab/rspec/jruby.rb +1 -1
  88. data/lib/openhab/rspec/karaf.rb +5 -27
  89. data/lib/openhab/rspec/mocks/persistence_service.rb +5 -5
  90. data/lib/openhab/yard/html_helper.rb +1 -1
  91. data/lib/openhab/yard.rb +1 -1
  92. metadata +11 -20
  93. data/lib/openhab/core/items/semantics/tag_class_methods.rb +0 -73
  94. data/lib/openhab/dsl/rules/triggers/cron/cron_handler.rb +0 -118
@@ -381,14 +381,8 @@ module OpenHAB
381
381
  ttp.class.field_reader :thingTypeTracker
382
382
  @thing_type_tracker = ttp.thingTypeTracker
383
383
  @thing_type_tracker.class.field_reader :openState
384
- begin
385
- org.openhab.core.config.core.xml.osgi.XmlDocumentBundleTracker::OpenState.field_reader :OPENED
386
- opened = org.openhab.core.config.core.xml.osgi.XmlDocumentBundleTracker::OpenState.OPENED
387
- rescue NameError
388
- # @deprecated OH3.4
389
- org.openhab.core.config.xml.osgi.XmlDocumentBundleTracker::OpenState.field_reader :OPENED
390
- opened = org.openhab.core.config.xml.osgi.XmlDocumentBundleTracker::OpenState.OPENED
391
- end
384
+ org.openhab.core.config.core.xml.osgi.XmlDocumentBundleTracker::OpenState.field_reader :OPENED
385
+ opened = org.openhab.core.config.core.xml.osgi.XmlDocumentBundleTracker::OpenState.OPENED
392
386
  sleep until @thing_type_tracker.openState == opened
393
387
  @bundle_context.bundles.each do |bundle|
394
388
  @thing_type_tracker.adding_bundle(bundle, nil)
@@ -399,14 +393,8 @@ module OpenHAB
399
393
  cdp.class.field_reader :configDescriptionTracker
400
394
  @config_description_tracker = cdp.configDescriptionTracker
401
395
  @config_description_tracker.class.field_reader :openState
402
- begin
403
- org.openhab.core.config.core.xml.osgi.XmlDocumentBundleTracker::OpenState.field_reader :OPENED
404
- opened = org.openhab.core.config.core.xml.osgi.XmlDocumentBundleTracker::OpenState.OPENED
405
- rescue NameError
406
- # @deprecated OH3.4
407
- org.openhab.core.config.xml.osgi.XmlDocumentBundleTracker::OpenState.field_reader :OPENED
408
- opened = org.openhab.core.config.xml.osgi.XmlDocumentBundleTracker::OpenState.OPENED
409
- end
396
+ org.openhab.core.config.core.xml.osgi.XmlDocumentBundleTracker::OpenState.field_reader :OPENED
397
+ opened = org.openhab.core.config.core.xml.osgi.XmlDocumentBundleTracker::OpenState.OPENED
410
398
  sleep until @config_description_tracker.openState == opened
411
399
  @bundle_context.bundles.each do |bundle|
412
400
  @config_description_tracker.adding_bundle(bundle, nil)
@@ -456,16 +444,6 @@ module OpenHAB
456
444
  )
457
445
 
458
446
  wait_for_service("org.openhab.core.thing.ThingManager") do |tm|
459
- begin
460
- # @deprecated OH3.4
461
- tm.class.field_accessor :bundleResolver
462
- tm.bundleResolver = Mocks::BundleResolver.instance
463
- rescue NameError
464
- # OH4
465
- # I think the mock BundleResolver registration above is sufficient.
466
- # It will be injected by OSGi and we don't need to override it again in OH4
467
- end
468
-
469
447
  require_relative "mocks/safe_caller"
470
448
  field = tm.class.java_class.declared_field :safeCaller
471
449
  field.accessible = true
@@ -548,7 +526,7 @@ module OpenHAB
548
526
 
549
527
  def wait_for_service(service_name, filter: nil, &block)
550
528
  if defined?(OSGi) &&
551
- (services = OSGi.services(service_name, filter: filter))
529
+ (services = OSGi.services(service_name, filter:))
552
530
  services.each(&block)
553
531
  end
554
532
 
@@ -103,26 +103,26 @@ module OpenHAB
103
103
  result
104
104
  end
105
105
 
106
- def get_item_info # rubocop:disable Naming/AccessorMethodName must match Java interface
106
+ def get_item_info # rubocop:disable Naming/AccessorMethodName -- must match Java interface
107
107
  @data.to_set do |(n, entries)|
108
108
  [n, entries.length, entries.first.timestamp, entries.last.timestamp]
109
109
  end
110
110
  end
111
111
 
112
- def get_default_strategies # rubocop:disable Naming/AccessorMethodName must match Java interface
112
+ def get_default_strategies # rubocop:disable Naming/AccessorMethodName -- must match Java interface
113
113
  [org.openhab.core.persistence.strategy.PersistenceStrategy::Globals::CHANGE]
114
114
  end
115
115
 
116
116
  private
117
117
 
118
- def query_internal(filter, &block)
118
+ def query_internal(filter, &)
119
119
  if filter.item_name
120
120
  return unless @data.key?(filter.item_name)
121
121
 
122
- query_item_internal(@data[filter.item_name], filter, &block)
122
+ query_item_internal(@data[filter.item_name], filter, &)
123
123
  else
124
124
  @data.each_value do |item_history|
125
- query_item_internal(item_history, filter, &block)
125
+ query_item_internal(item_history, filter, &)
126
126
  end
127
127
  end
128
128
  end
@@ -26,7 +26,7 @@ module OpenHAB
26
26
  end
27
27
 
28
28
  def html_markup_markdown(text)
29
- result = super(text)
29
+ result = super
30
30
 
31
31
  html = Nokogiri::HTML5.fragment(result)
32
32
  # re-link files in docs/*.md. They're written so they work on github without any
data/lib/openhab/yard.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Dir[File.expand_path("yard/**/*.rb", __dir__)].sort.each do |f|
3
+ Dir[File.expand_path("yard/**/*.rb", __dir__)].each do |f|
4
4
  require f
5
5
  end
6
6
 
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.35.1
4
+ version: 5.36.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian O'Connell
@@ -9,7 +9,7 @@ authors:
9
9
  - Jimmy Tanagra
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2025-02-25 00:00:00.000000000 Z
12
+ date: 2025-03-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -53,20 +53,6 @@ dependencies:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: '1.0'
56
- - !ruby/object:Gem::Dependency
57
- name: ruby2_keywords
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: '0.0'
63
- type: :runtime
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '0.0'
70
56
  - !ruby/object:Gem::Dependency
71
57
  name: cucumber
72
58
  requirement: !ruby/object:Gem::Requirement
@@ -229,6 +215,11 @@ executables: []
229
215
  extensions: []
230
216
  extra_rdoc_files: []
231
217
  files:
218
+ - lib/openhab/console.rb
219
+ - lib/openhab/console/irb.rb
220
+ - lib/openhab/console/jline.rb
221
+ - lib/openhab/console/registry.rb
222
+ - lib/openhab/console/stdio.rb
232
223
  - lib/openhab/core.rb
233
224
  - lib/openhab/core/abstract_uid.rb
234
225
  - lib/openhab/core/actions.rb
@@ -292,7 +283,6 @@ files:
292
283
  - lib/openhab/core/items/semantics/enumerable.rb
293
284
  - lib/openhab/core/items/semantics/provider.rb
294
285
  - lib/openhab/core/items/semantics/semantic_tag.rb
295
- - lib/openhab/core/items/semantics/tag_class_methods.rb
296
286
  - lib/openhab/core/items/state_storage.rb
297
287
  - lib/openhab/core/items/string_item.rb
298
288
  - lib/openhab/core/items/switch_item.rb
@@ -333,6 +323,7 @@ files:
333
323
  - lib/openhab/core/things/uid.rb
334
324
  - lib/openhab/core/timer.rb
335
325
  - lib/openhab/core/types.rb
326
+ - lib/openhab/core/types/command_description.rb
336
327
  - lib/openhab/core/types/comparable_type.rb
337
328
  - lib/openhab/core/types/date_time_type.rb
338
329
  - lib/openhab/core/types/decimal_type.rb
@@ -349,6 +340,7 @@ files:
349
340
  - lib/openhab/core/types/raw_type.rb
350
341
  - lib/openhab/core/types/refresh_type.rb
351
342
  - lib/openhab/core/types/rewind_fastforward_type.rb
343
+ - lib/openhab/core/types/state_description.rb
352
344
  - lib/openhab/core/types/stop_move_type.rb
353
345
  - lib/openhab/core/types/string_list_type.rb
354
346
  - lib/openhab/core/types/string_type.rb
@@ -408,7 +400,6 @@ files:
408
400
  - lib/openhab/dsl/rules/triggers/conditions/duration.rb
409
401
  - lib/openhab/dsl/rules/triggers/conditions/generic.rb
410
402
  - lib/openhab/dsl/rules/triggers/cron/cron.rb
411
- - lib/openhab/dsl/rules/triggers/cron/cron_handler.rb
412
403
  - lib/openhab/dsl/rules/triggers/trigger.rb
413
404
  - lib/openhab/dsl/rules/triggers/updated.rb
414
405
  - lib/openhab/dsl/rules/triggers/watch/watch_handler.rb
@@ -480,14 +471,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
480
471
  requirements:
481
472
  - - ">="
482
473
  - !ruby/object:Gem::Version
483
- version: 2.6.0
474
+ version: 3.1.4
484
475
  required_rubygems_version: !ruby/object:Gem::Requirement
485
476
  requirements:
486
477
  - - ">="
487
478
  - !ruby/object:Gem::Version
488
479
  version: '0'
489
480
  requirements: []
490
- rubygems_version: 3.6.5
481
+ rubygems_version: 3.6.6
491
482
  specification_version: 4
492
483
  summary: JRuby Helper Libraries for openHAB Scripting
493
484
  test_files: []
@@ -1,73 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OpenHAB
4
- module Core
5
- module Items
6
- module Semantics
7
- # @deprecated OH3.4 didn't have SemanticTag class
8
-
9
- #
10
- # Adds tag attributes to the semantic tag class
11
- #
12
- module TagClassMethods
13
- # @!visibility private
14
- java_import org.openhab.core.semantics.SemanticTags
15
-
16
- #
17
- # Returns the tag's string representation
18
- #
19
- # @return [String]
20
- #
21
- def to_s
22
- java_class.simple_name
23
- end
24
-
25
- #
26
- # Returns the tag's label
27
- #
28
- # @param [java.util.Locale] locale The locale that the label should be in, if available.
29
- # When nil, the system's default locale is used.
30
- #
31
- # @return [String] The tag's label
32
- #
33
- def label(locale = nil)
34
- SemanticTags.get_label(java_class, locale || java.util.Locale.default)
35
- end
36
-
37
- #
38
- # Returns the tag's synonyms
39
- #
40
- # @param [java.util.Locale] locale The locale that the label should be in, if available.
41
- # When nil, the system's default locale is used.
42
- #
43
- # @return [Array<String>] The list of synonyms in the requested locale.
44
- #
45
- def synonyms(locale = nil)
46
- unless SemanticTags.respond_to?(:get_synonyms)
47
- return java_class.get_annotation(org.openhab.core.semantics.TagInfo.java_class).synonyms
48
- .split(",").map(&:strip)
49
- end
50
-
51
- SemanticTags.get_synonyms(java_class, locale || java.util.Locale.default).to_a
52
- end
53
-
54
- #
55
- # Returns the tag's description
56
- #
57
- # @param [java.util.Locale] locale The locale that the description should be in, if available.
58
- # When nil, the system's default locale is used.
59
- #
60
- # @return [String] The tag's description
61
- #
62
- def description(locale = nil)
63
- unless SemanticTags.respond_to?(:get_description)
64
- return java_class.get_annotation(org.openhab.core.semantics.TagInfo.java_class).description
65
- end
66
-
67
- SemanticTags.get_description(java_class, locale || java.util.Locale.default)
68
- end
69
- end
70
- end
71
- end
72
- end
73
- end
@@ -1,118 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # @deprecated OH3.4 this module is not needed in OH4+
4
- return unless OpenHAB::Core.version < OpenHAB::Core::V4_0
5
-
6
- require "singleton"
7
-
8
- require_relative "cron"
9
-
10
- module OpenHAB
11
- module DSL
12
- module Rules
13
- module Triggers
14
- # @!visibility private
15
- #
16
- # Cron trigger handler that provides trigger ID
17
- #
18
- module CronHandler
19
- # Cron Trigger Handler that provides trigger IDs
20
- # Unfortunatly because the CronTriggerHandler in openHAB core is marked internal
21
- # the entire thing must be recreated here
22
- class CronTriggerHandler < org.openhab.core.automation.handler.BaseTriggerModuleHandler
23
- include org.openhab.core.scheduler.SchedulerRunnable
24
- include org.openhab.core.automation.handler.TimeBasedTriggerHandler
25
-
26
- # Provides access to protected fields
27
- field_accessor :callback
28
-
29
- # Creates a new CronTriggerHandler
30
- # @param [org.openhab.core.automation.Trigger] trigger openHAB trigger associated with handler
31
- #
32
- def initialize(trigger)
33
- @trigger = trigger
34
- @scheduler = OSGi.service("org.openhab.core.scheduler.CronScheduler")
35
- @schedule = nil
36
- @expression = trigger.configuration.get("cronExpression")
37
- super(trigger)
38
- end
39
-
40
- #
41
- # Set the callback to execute when cron trigger fires
42
- # @param [Object] callback to run
43
- #
44
- def setCallback(callback) # rubocop:disable Naming/MethodName
45
- synchronized do
46
- super(callback)
47
- @schedule = @scheduler.schedule(self, @expression)
48
- logger.trace { "Scheduled cron job '#{@expression}' for trigger '#{@trigger.id}'." }
49
- end
50
- end
51
-
52
- #
53
- # Get the temporal adjuster
54
- # @return [CronAdjuster]
55
- #
56
- def getTemporalAdjuster # rubocop:disable Naming/MethodName
57
- org.openhab.core.scheduler.CronAdjuster.new(@expression)
58
- end
59
-
60
- #
61
- # Execute the callback
62
- #
63
- def run
64
- callback&.triggered(@trigger, { "module" => @trigger.id })
65
- end
66
-
67
- #
68
- # Dispose of the handler
69
- # cancel the cron scheduled task
70
- #
71
- def dispose
72
- synchronized do
73
- super
74
- return unless @schedule
75
-
76
- @schedule.cancel(true)
77
- @schedule = nil
78
- end
79
- logger.trace { "cancelled job for trigger '#{@trigger.id}'." }
80
- end
81
- end
82
-
83
- # Implements the ScriptedTriggerHandlerFactory interface to create a new Cron Trigger Handler
84
- class CronTriggerHandlerFactory
85
- include Singleton
86
- include org.openhab.core.automation.module.script.rulesupport.shared.factories.ScriptedTriggerHandlerFactory
87
-
88
- def initialize
89
- Core.automation_manager.add_trigger_handler(
90
- Cron::CRON_TRIGGER_MODULE_ID,
91
- self
92
- )
93
-
94
- Core.automation_manager.add_trigger_type(org.openhab.core.automation.type.TriggerType.new(
95
- Cron::CRON_TRIGGER_MODULE_ID,
96
- nil,
97
- "A specific instant occurs",
98
- "Triggers when the specified instant occurs",
99
- nil,
100
- org.openhab.core.automation.Visibility::VISIBLE,
101
- nil
102
- ))
103
- logger.trace("Added script cron trigger handler")
104
- end
105
-
106
- # Invoked by openHAB core to get a trigger handler for the supplied trigger
107
- # @param [org.openhab.core.automation.Trigger] trigger
108
- #
109
- # @return [CronTriggerHandler] trigger handler for supplied trigger
110
- def get(trigger)
111
- CronTriggerHandler.new(trigger)
112
- end
113
- end
114
- end
115
- end
116
- end
117
- end
118
- end