openhab-scripting 4.47.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (281) hide show
  1. checksums.yaml +4 -4
  2. data/lib/openhab/core/actions/audio.rb +47 -0
  3. data/lib/openhab/core/actions/ephemeris.rb +39 -0
  4. data/lib/openhab/core/actions/exec.rb +51 -0
  5. data/lib/openhab/core/actions/http.rb +80 -0
  6. data/lib/openhab/core/actions/ping.rb +30 -0
  7. data/lib/openhab/core/actions/transformation.rb +32 -0
  8. data/lib/openhab/core/actions/voice.rb +36 -0
  9. data/lib/openhab/core/actions.rb +82 -0
  10. data/lib/openhab/core/dependency_tracking.rb +34 -0
  11. data/lib/openhab/core/dto/item_channel_link.rb +33 -0
  12. data/lib/openhab/core/dto/thing.rb +27 -0
  13. data/lib/openhab/core/dto.rb +11 -0
  14. data/lib/openhab/core/entity_lookup.rb +152 -70
  15. data/lib/openhab/core/events/abstract_event.rb +18 -0
  16. data/lib/openhab/core/events/abstract_item_registry_event.rb +36 -0
  17. data/lib/openhab/core/events/abstract_thing_registry_event.rb +40 -0
  18. data/lib/openhab/core/events/item_command_event.rb +78 -0
  19. data/lib/openhab/core/events/item_event.rb +22 -0
  20. data/lib/openhab/core/events/item_state_changed_event.rb +75 -0
  21. data/lib/openhab/core/events/item_state_event.rb +79 -0
  22. data/lib/openhab/core/events/thing_status_info_event.rb +55 -0
  23. data/lib/openhab/core/events.rb +10 -0
  24. data/lib/openhab/core/items/accepted_data_types.rb +29 -0
  25. data/lib/openhab/core/items/color_item.rb +52 -0
  26. data/lib/openhab/core/items/contact_item.rb +52 -0
  27. data/lib/openhab/core/items/date_time_item.rb +59 -0
  28. data/lib/openhab/core/items/dimmer_item.rb +148 -0
  29. data/lib/openhab/core/items/generic_item.rb +292 -0
  30. data/lib/openhab/core/items/group_item.rb +176 -0
  31. data/lib/openhab/{dsl → core}/items/image_item.rb +35 -29
  32. data/lib/openhab/core/items/item.rb +273 -0
  33. data/lib/openhab/core/items/location_item.rb +34 -0
  34. data/lib/openhab/core/items/metadata/hash.rb +433 -0
  35. data/lib/openhab/core/items/metadata/namespace_hash.rb +475 -0
  36. data/lib/openhab/core/items/metadata/provider.rb +48 -0
  37. data/lib/openhab/core/items/metadata.rb +11 -0
  38. data/lib/openhab/core/items/number_item.rb +62 -0
  39. data/lib/openhab/core/items/numeric_item.rb +22 -0
  40. data/lib/openhab/core/items/persistence.rb +416 -0
  41. data/lib/openhab/core/items/player_item.rb +66 -0
  42. data/lib/openhab/core/items/provider.rb +44 -0
  43. data/lib/openhab/core/items/proxy.rb +136 -0
  44. data/lib/openhab/core/items/registry.rb +86 -0
  45. data/lib/openhab/core/items/rollershutter_item.rb +68 -0
  46. data/lib/openhab/core/items/semantics/enumerable.rb +177 -0
  47. data/lib/openhab/core/items/semantics.rb +473 -0
  48. data/lib/openhab/core/items/state_storage.rb +53 -0
  49. data/lib/openhab/core/items/string_item.rb +28 -0
  50. data/lib/openhab/core/items/switch_item.rb +78 -0
  51. data/lib/openhab/core/items.rb +108 -0
  52. data/lib/openhab/{dsl → core}/lazy_array.rb +9 -3
  53. data/lib/openhab/core/profile_factory.rb +132 -0
  54. data/lib/openhab/core/provider.rb +230 -0
  55. data/lib/openhab/core/proxy.rb +130 -0
  56. data/lib/openhab/core/registry.rb +40 -0
  57. data/lib/openhab/core/rules/module.rb +26 -0
  58. data/lib/openhab/core/rules/provider.rb +25 -0
  59. data/lib/openhab/core/rules/registry.rb +76 -0
  60. data/lib/openhab/core/rules/rule.rb +150 -0
  61. data/lib/openhab/core/rules.rb +25 -0
  62. data/lib/openhab/core/script_handling.rb +78 -20
  63. data/lib/openhab/core/things/channel.rb +48 -0
  64. data/lib/openhab/core/things/channel_uid.rb +51 -0
  65. data/lib/openhab/core/things/item_channel_link.rb +33 -0
  66. data/lib/openhab/core/things/links/provider.rb +78 -0
  67. data/lib/openhab/core/things/profile_callback.rb +52 -0
  68. data/lib/openhab/core/things/provider.rb +29 -0
  69. data/lib/openhab/core/things/proxy.rb +87 -0
  70. data/lib/openhab/core/things/registry.rb +73 -0
  71. data/lib/openhab/core/things/thing.rb +194 -0
  72. data/lib/openhab/core/things.rb +22 -0
  73. data/lib/openhab/core/timer.rb +148 -0
  74. data/lib/openhab/{dsl → core}/types/comparable_type.rb +5 -3
  75. data/lib/openhab/{dsl → core}/types/date_time_type.rb +55 -127
  76. data/lib/openhab/{dsl → core}/types/decimal_type.rb +50 -48
  77. data/lib/openhab/{dsl → core}/types/hsb_type.rb +35 -83
  78. data/lib/openhab/core/types/increase_decrease_type.rb +34 -0
  79. data/lib/openhab/core/types/next_previous_type.rb +34 -0
  80. data/lib/openhab/{dsl → core}/types/numeric_type.rb +20 -7
  81. data/lib/openhab/core/types/on_off_type.rb +46 -0
  82. data/lib/openhab/core/types/open_closed_type.rb +41 -0
  83. data/lib/openhab/{dsl → core}/types/percent_type.rb +19 -20
  84. data/lib/openhab/core/types/play_pause_type.rb +38 -0
  85. data/lib/openhab/core/types/point_type.rb +117 -0
  86. data/lib/openhab/core/types/quantity_type.rb +325 -0
  87. data/lib/openhab/core/types/raw_type.rb +26 -0
  88. data/lib/openhab/core/types/refresh_type.rb +27 -0
  89. data/lib/openhab/core/types/rewind_fastforward_type.rb +38 -0
  90. data/lib/openhab/core/types/stop_move_type.rb +34 -0
  91. data/lib/openhab/{dsl → core}/types/string_type.rb +17 -28
  92. data/lib/openhab/{dsl → core}/types/type.rb +42 -40
  93. data/lib/openhab/core/types/un_def_type.rb +38 -0
  94. data/lib/openhab/core/types/up_down_type.rb +50 -0
  95. data/lib/openhab/core/types.rb +82 -0
  96. data/lib/openhab/{dsl → core}/uid.rb +4 -23
  97. data/lib/openhab/core/value_cache.rb +188 -0
  98. data/lib/openhab/core.rb +98 -0
  99. data/lib/openhab/core_ext/between.rb +32 -0
  100. data/lib/openhab/core_ext/ephemeris.rb +53 -0
  101. data/lib/openhab/core_ext/java/class.rb +34 -0
  102. data/lib/openhab/core_ext/java/duration.rb +142 -0
  103. data/lib/openhab/core_ext/java/list.rb +436 -0
  104. data/lib/openhab/core_ext/java/local_date.rb +104 -0
  105. data/lib/openhab/core_ext/java/local_time.rb +118 -0
  106. data/lib/openhab/core_ext/java/map.rb +66 -0
  107. data/lib/openhab/core_ext/java/month.rb +71 -0
  108. data/lib/openhab/core_ext/java/month_day.rb +119 -0
  109. data/lib/openhab/core_ext/java/period.rb +103 -0
  110. data/lib/openhab/core_ext/java/temporal_amount.rb +34 -0
  111. data/lib/openhab/core_ext/java/time.rb +62 -0
  112. data/lib/openhab/core_ext/java/unit.rb +15 -0
  113. data/lib/openhab/core_ext/java/zoned_date_time.rb +213 -0
  114. data/lib/openhab/core_ext/ruby/array.rb +21 -0
  115. data/lib/openhab/core_ext/ruby/date.rb +96 -0
  116. data/lib/openhab/core_ext/ruby/date_time.rb +55 -0
  117. data/lib/openhab/core_ext/ruby/module.rb +15 -0
  118. data/lib/openhab/core_ext/ruby/numeric.rb +195 -0
  119. data/lib/openhab/core_ext/ruby/range.rb +70 -0
  120. data/lib/openhab/core_ext/ruby/symbol.rb +7 -0
  121. data/lib/openhab/core_ext/ruby/time.rb +108 -0
  122. data/lib/openhab/core_ext.rb +18 -0
  123. data/lib/openhab/dsl/debouncer.rb +259 -0
  124. data/lib/openhab/dsl/events/watch_event.rb +18 -0
  125. data/lib/openhab/dsl/events.rb +9 -0
  126. data/lib/openhab/dsl/gems.rb +1 -1
  127. data/lib/openhab/dsl/items/builder.rb +578 -0
  128. data/lib/openhab/dsl/items/ensure.rb +73 -82
  129. data/lib/openhab/dsl/items/timed_command.rb +214 -159
  130. data/lib/openhab/dsl/rules/automation_rule.rb +126 -115
  131. data/lib/openhab/dsl/rules/builder.rb +1935 -0
  132. data/lib/openhab/dsl/rules/guard.rb +51 -114
  133. data/lib/openhab/dsl/rules/name_inference.rb +66 -25
  134. data/lib/openhab/dsl/rules/property.rb +48 -75
  135. data/lib/openhab/dsl/rules/rule_triggers.rb +22 -27
  136. data/lib/openhab/dsl/rules/terse.rb +58 -14
  137. data/lib/openhab/dsl/rules/triggers/changed.rb +48 -94
  138. data/lib/openhab/dsl/rules/triggers/channel.rb +9 -40
  139. data/lib/openhab/dsl/rules/triggers/command.rb +14 -63
  140. data/lib/openhab/dsl/rules/triggers/conditions/duration.rb +34 -69
  141. data/lib/openhab/dsl/rules/triggers/conditions/proc.rb +6 -14
  142. data/lib/openhab/dsl/rules/triggers/cron/cron.rb +48 -82
  143. data/lib/openhab/dsl/rules/triggers/cron/cron_handler.rb +30 -47
  144. data/lib/openhab/dsl/rules/triggers/trigger.rb +7 -28
  145. data/lib/openhab/dsl/rules/triggers/updated.rb +21 -45
  146. data/lib/openhab/dsl/rules/triggers/watch/watch_handler.rb +257 -102
  147. data/lib/openhab/dsl/rules/triggers.rb +12 -0
  148. data/lib/openhab/dsl/rules.rb +8 -0
  149. data/lib/openhab/dsl/things/builder.rb +299 -0
  150. data/lib/openhab/{core → dsl}/thread_local.rb +27 -17
  151. data/lib/openhab/dsl/timer_manager.rb +204 -0
  152. data/lib/openhab/dsl/version.rb +9 -0
  153. data/lib/openhab/dsl.rb +979 -0
  154. data/lib/openhab/log.rb +355 -0
  155. data/lib/openhab/osgi.rb +68 -0
  156. data/lib/openhab/rspec/configuration.rb +56 -0
  157. data/lib/openhab/rspec/example_group.rb +132 -0
  158. data/lib/openhab/rspec/helpers.rb +458 -0
  159. data/lib/openhab/rspec/hooks.rb +113 -0
  160. data/lib/openhab/rspec/jruby.rb +46 -0
  161. data/lib/openhab/rspec/karaf.rb +851 -0
  162. data/lib/openhab/rspec/mocks/bundle_install_support.rb +25 -0
  163. data/lib/openhab/rspec/mocks/bundle_resolver.rb +30 -0
  164. data/lib/openhab/rspec/mocks/event_admin.rb +146 -0
  165. data/lib/openhab/rspec/mocks/instance_method_stasher.rb +22 -0
  166. data/lib/openhab/rspec/mocks/persistence_service.rb +155 -0
  167. data/lib/openhab/rspec/mocks/safe_caller.rb +40 -0
  168. data/lib/openhab/rspec/mocks/space.rb +23 -0
  169. data/lib/openhab/rspec/mocks/synchronous_executor.rb +63 -0
  170. data/lib/openhab/rspec/mocks/thing_handler.rb +76 -0
  171. data/lib/openhab/rspec/mocks/timer.rb +134 -0
  172. data/lib/openhab/rspec/openhab/core/actions.rb +38 -0
  173. data/lib/openhab/rspec/openhab/core/items/proxy.rb +15 -0
  174. data/lib/openhab/rspec/openhab/core/things/proxy.rb +27 -0
  175. data/lib/openhab/rspec/shell.rb +31 -0
  176. data/lib/openhab/rspec/suspend_rules.rb +50 -0
  177. data/lib/openhab/rspec.rb +26 -0
  178. data/lib/openhab/yard/base_helper.rb +19 -0
  179. data/lib/openhab/yard/cli/stats.rb +23 -0
  180. data/lib/openhab/yard/code_objects/group_object.rb +23 -0
  181. data/lib/openhab/yard/code_objects/java/base.rb +31 -0
  182. data/lib/openhab/yard/code_objects/java/class_object.rb +11 -0
  183. data/lib/openhab/yard/code_objects/java/field_object.rb +15 -0
  184. data/lib/openhab/yard/code_objects/java/interface_object.rb +15 -0
  185. data/lib/openhab/yard/code_objects/java/package_object.rb +11 -0
  186. data/lib/openhab/yard/code_objects/java/proxy.rb +23 -0
  187. data/lib/openhab/yard/coderay.rb +17 -0
  188. data/lib/openhab/yard/handlers/jruby/base.rb +58 -0
  189. data/lib/openhab/yard/handlers/jruby/class_handler.rb +18 -0
  190. data/lib/openhab/yard/handlers/jruby/constant_handler.rb +18 -0
  191. data/lib/openhab/yard/handlers/jruby/java_import_handler.rb +30 -0
  192. data/lib/openhab/yard/handlers/jruby/mixin_handler.rb +23 -0
  193. data/lib/openhab/yard/html_helper.rb +78 -0
  194. data/lib/openhab/yard/markdown_helper.rb +148 -0
  195. data/lib/openhab/yard/tags/constant_directive.rb +20 -0
  196. data/lib/openhab/yard/tags/group_directive.rb +24 -0
  197. data/lib/openhab/yard/tags/library.rb +3 -0
  198. data/lib/openhab/yard.rb +38 -0
  199. metadata +475 -106
  200. data/lib/openhab/core/item_proxy.rb +0 -29
  201. data/lib/openhab/core/load_path.rb +0 -19
  202. data/lib/openhab/core/openhab_setup.rb +0 -29
  203. data/lib/openhab/core/osgi.rb +0 -58
  204. data/lib/openhab/core/services.rb +0 -24
  205. data/lib/openhab/dsl/actions.rb +0 -114
  206. data/lib/openhab/dsl/between.rb +0 -25
  207. data/lib/openhab/dsl/channel.rb +0 -43
  208. data/lib/openhab/dsl/dsl.rb +0 -59
  209. data/lib/openhab/dsl/group.rb +0 -54
  210. data/lib/openhab/dsl/imports.rb +0 -21
  211. data/lib/openhab/dsl/items/color_item.rb +0 -76
  212. data/lib/openhab/dsl/items/comparable_item.rb +0 -62
  213. data/lib/openhab/dsl/items/contact_item.rb +0 -41
  214. data/lib/openhab/dsl/items/date_time_item.rb +0 -65
  215. data/lib/openhab/dsl/items/dimmer_item.rb +0 -65
  216. data/lib/openhab/dsl/items/generic_item.rb +0 -229
  217. data/lib/openhab/dsl/items/group_item.rb +0 -127
  218. data/lib/openhab/dsl/items/item_equality.rb +0 -59
  219. data/lib/openhab/dsl/items/item_registry.rb +0 -54
  220. data/lib/openhab/dsl/items/items.rb +0 -109
  221. data/lib/openhab/dsl/items/location_item.rb +0 -59
  222. data/lib/openhab/dsl/items/metadata.rb +0 -326
  223. data/lib/openhab/dsl/items/number_item.rb +0 -17
  224. data/lib/openhab/dsl/items/numeric_item.rb +0 -87
  225. data/lib/openhab/dsl/items/persistence.rb +0 -307
  226. data/lib/openhab/dsl/items/player_item.rb +0 -58
  227. data/lib/openhab/dsl/items/rollershutter_item.rb +0 -51
  228. data/lib/openhab/dsl/items/semantics/enumerable.rb +0 -91
  229. data/lib/openhab/dsl/items/semantics.rb +0 -227
  230. data/lib/openhab/dsl/items/string_item.rb +0 -51
  231. data/lib/openhab/dsl/items/switch_item.rb +0 -70
  232. data/lib/openhab/dsl/monkey_patch/actions/actions.rb +0 -4
  233. data/lib/openhab/dsl/monkey_patch/actions/script_thing_actions.rb +0 -39
  234. data/lib/openhab/dsl/monkey_patch/events/events.rb +0 -7
  235. data/lib/openhab/dsl/monkey_patch/events/item_command.rb +0 -85
  236. data/lib/openhab/dsl/monkey_patch/events/item_event.rb +0 -28
  237. data/lib/openhab/dsl/monkey_patch/events/item_state.rb +0 -61
  238. data/lib/openhab/dsl/monkey_patch/events/item_state_changed.rb +0 -60
  239. data/lib/openhab/dsl/monkey_patch/events/thing_status_info.rb +0 -33
  240. data/lib/openhab/dsl/monkey_patch/java/java.rb +0 -4
  241. data/lib/openhab/dsl/monkey_patch/java/local_time.rb +0 -44
  242. data/lib/openhab/dsl/monkey_patch/java/time_extensions.rb +0 -50
  243. data/lib/openhab/dsl/monkey_patch/java/zoned_date_time.rb +0 -45
  244. data/lib/openhab/dsl/monkey_patch/ruby/number.rb +0 -104
  245. data/lib/openhab/dsl/monkey_patch/ruby/ruby.rb +0 -6
  246. data/lib/openhab/dsl/monkey_patch/ruby/string.rb +0 -47
  247. data/lib/openhab/dsl/monkey_patch/ruby/time.rb +0 -61
  248. data/lib/openhab/dsl/openhab.rb +0 -30
  249. data/lib/openhab/dsl/persistence.rb +0 -27
  250. data/lib/openhab/dsl/rules/item_event.rb +0 -19
  251. data/lib/openhab/dsl/rules/rule.rb +0 -160
  252. data/lib/openhab/dsl/rules/rule_config.rb +0 -147
  253. data/lib/openhab/dsl/rules/triggers/generic.rb +0 -31
  254. data/lib/openhab/dsl/rules/triggers/triggers.rb +0 -11
  255. data/lib/openhab/dsl/rules/triggers/watch/watch.rb +0 -81
  256. data/lib/openhab/dsl/states.rb +0 -89
  257. data/lib/openhab/dsl/things.rb +0 -147
  258. data/lib/openhab/dsl/time/month_day.rb +0 -180
  259. data/lib/openhab/dsl/time/time_of_day.rb +0 -235
  260. data/lib/openhab/dsl/timers/manager.rb +0 -119
  261. data/lib/openhab/dsl/timers/reentrant_timer.rb +0 -38
  262. data/lib/openhab/dsl/timers/timer.rb +0 -132
  263. data/lib/openhab/dsl/timers.rb +0 -77
  264. data/lib/openhab/dsl/types/increase_decrease_type.rb +0 -23
  265. data/lib/openhab/dsl/types/next_previous_type.rb +0 -23
  266. data/lib/openhab/dsl/types/on_off_type.rb +0 -28
  267. data/lib/openhab/dsl/types/open_closed_type.rb +0 -29
  268. data/lib/openhab/dsl/types/play_pause_type.rb +0 -27
  269. data/lib/openhab/dsl/types/point_type.rb +0 -180
  270. data/lib/openhab/dsl/types/quantity_type.rb +0 -265
  271. data/lib/openhab/dsl/types/refresh_type.rb +0 -18
  272. data/lib/openhab/dsl/types/rewind_fastforward_type.rb +0 -33
  273. data/lib/openhab/dsl/types/stop_move_type.rb +0 -23
  274. data/lib/openhab/dsl/types/types.rb +0 -83
  275. data/lib/openhab/dsl/types/un_def_type.rb +0 -22
  276. data/lib/openhab/dsl/types/up_down_type.rb +0 -32
  277. data/lib/openhab/dsl/units.rb +0 -45
  278. data/lib/openhab/log/configuration.rb +0 -21
  279. data/lib/openhab/log/logger.rb +0 -282
  280. data/lib/openhab/version.rb +0 -9
  281. data/lib/openhab.rb +0 -38
@@ -0,0 +1,134 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "timecop"
4
+
5
+ module OpenHAB
6
+ module RSpec
7
+ module Mocks
8
+ class Timer < Core::Timer
9
+ # @!visibility private
10
+ module MockedZonedDateTime
11
+ def now
12
+ mocked_time_stack_item = Timecop.top_stack_item
13
+ return super unless mocked_time_stack_item
14
+
15
+ mocked_time_stack_item.time.to_zoned_date_time
16
+ end
17
+ end
18
+ ZonedDateTime.singleton_class.prepend(MockedZonedDateTime)
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
+
53
+ # extend Timecop to support Java time classes
54
+ # @!visibility private
55
+ module TimeCopStackItem
56
+ def parse_time(*args)
57
+ if args.length == 1
58
+ arg = args.first
59
+ if arg.is_a?(Time) ||
60
+ (defined?(DateTime) && arg.is_a?(DateTime)) ||
61
+ (defined?(Date) && arg.is_a?(Date))
62
+ return super
63
+ elsif arg.respond_to?(:to_zoned_date_time)
64
+ return arg.to_zoned_date_time.to_time
65
+ elsif arg.is_a?(java.time.temporal.TemporalAmount)
66
+ return (ZonedDateTime.now + arg).to_time
67
+ end
68
+ end
69
+
70
+ super
71
+ end
72
+ end
73
+ Timecop::TimeStackItem.prepend(TimeCopStackItem)
74
+
75
+ attr_reader :execution_time, :id, :block
76
+
77
+ def initialize(time, id:, thread_locals:, block:) # rubocop:disable Lint/MissingSuper
78
+ @time = time
79
+ @id = id
80
+ @block = block
81
+ @thread_locals = thread_locals
82
+ reschedule!(time)
83
+ end
84
+
85
+ def reschedule!(time = nil)
86
+ Thread.current[:openhab_rescheduled_timer] = true if Thread.current[:openhab_rescheduled_timer] == self
87
+ @execution_time = new_execution_time(time || @time)
88
+ @executed = false
89
+
90
+ DSL::TimerManager.instance.add(self)
91
+
92
+ self
93
+ end
94
+
95
+ def execute
96
+ raise "Timer already cancelled" if cancelled?
97
+ raise "Timer already executed" if terminated?
98
+
99
+ @executed = true
100
+ super
101
+ end
102
+
103
+ def cancel
104
+ return false if terminated? || cancelled?
105
+
106
+ DSL::TimerManager.instance.delete(self)
107
+ cancel!
108
+ true
109
+ end
110
+
111
+ def cancel!
112
+ @execution_time = nil
113
+ true
114
+ end
115
+
116
+ def cancelled?
117
+ @execution_time.nil?
118
+ end
119
+
120
+ def terminated?
121
+ @executed || cancelled?
122
+ end
123
+
124
+ def running?
125
+ false
126
+ end
127
+
128
+ def active?
129
+ !terminated?
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module Core
5
+ module Actions
6
+ # rubocop:disable Lint/UnusedMethodArgument
7
+ # redefine these to do nothing so that rules won't fail
8
+
9
+ module_function
10
+
11
+ def notify(msg, email: nil)
12
+ logger.debug("notify: #{msg}")
13
+ end
14
+
15
+ class Voice
16
+ class << self
17
+ def say(text, voice: nil, sink: nil, volume: nil)
18
+ logger.debug("say: #{text}")
19
+ end
20
+ end
21
+ end
22
+
23
+ class Audio
24
+ class << self
25
+ def play_sound(filename, sink: nil, volume: nil)
26
+ logger.debug("play_sound: #{filename}")
27
+ end
28
+
29
+ def play_stream(url, sink: nil)
30
+ logger.debug("play_stream: #{url}")
31
+ end
32
+ end
33
+ end
34
+
35
+ # rubocop:enable Lint/UnusedMethodArgument
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module Core
5
+ module Items
6
+ class Proxy
7
+ class << self
8
+ def reset_cache
9
+ @proxies.clear
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module Core
5
+ module Things
6
+ class Proxy
7
+ @proxies = {}
8
+
9
+ class << self
10
+ # ensure each item only has a single proxy, so that
11
+ # expect(item).to receive(:method) works
12
+ def new(thing)
13
+ return super unless defined?(::RSpec) && ::RSpec.current_example&.example_group&.consistent_proxies?
14
+
15
+ @proxies.fetch(thing.uid.to_s) do
16
+ @proxies[thing.uid.to_s] = super
17
+ end
18
+ end
19
+
20
+ def reset_cache
21
+ @proxies = {}
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module RSpec
5
+ # based on https://stackoverflow.com/questions/1197224/source-shell-script-into-environment-within-a-ruby-script#19826329
6
+ # @!visibility private
7
+ module Shell
8
+ module_function
9
+
10
+ # Read in the bash environment, after an optional command.
11
+ # Returns Array of key/value pairs.
12
+ def shell_env(cmd = nil)
13
+ cmd = "#{cmd} > /dev/null; " if cmd
14
+ env = `#{cmd}printenv -0`
15
+ env.split("\0").map { |l| l.split("=", 2) }
16
+ end
17
+
18
+ # Source a given file, and compare environment before and after.
19
+ # Returns Hash of any keys that have changed.
20
+ def shell_source(file)
21
+ (shell_env(". #{File.realpath(file)}") - shell_env).to_h
22
+ end
23
+
24
+ # Find variables changed as a result of sourcing the given file,
25
+ # and update in ENV.
26
+ def source_env_from(file)
27
+ shell_source(file).each { |k, v| ENV[k] = v }
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module RSpec
5
+ # @!visibility private
6
+ module SuspendRules
7
+ # I'd prefer to prepend a module, but I can't because of
8
+ # https://github.com/jruby/jruby/issues/6966#issuecomment-1172983776
9
+ class ::OpenHAB::DSL::Rules::AutomationRule # rubocop:disable Style/ClassAndModuleChildren
10
+ def execute(mod = nil, inputs = nil)
11
+ if SuspendRules.suspended?
12
+ logger.trace("Skipping execution of #{uid} because rules are suspended.")
13
+ return
14
+ end
15
+ execute!(mod, inputs)
16
+ end
17
+ end
18
+ # private_constant :AutomationRule
19
+ # DSL::Rules::AutomationRule.prepend(AutomationRule)
20
+
21
+ module DSL
22
+ def after(*, **)
23
+ return if SuspendRules.suspended?
24
+
25
+ super
26
+ end
27
+ end
28
+ private_constant :DSL
29
+ OpenHAB::DSL.prepend(DSL)
30
+
31
+ @suspended = false
32
+
33
+ class << self
34
+ # @!visibility private
35
+ def suspend_rules
36
+ old_suspended = @suspended
37
+ @suspended = true
38
+ yield
39
+ ensure
40
+ @suspended = old_suspended
41
+ end
42
+
43
+ # @!visibility private
44
+ def suspended?
45
+ @suspended
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ unless RUBY_ENGINE == "jruby" &&
4
+ Gem::Version.new(RUBY_ENGINE_VERSION) >= Gem::Version.new("9.3.8.0")
5
+ raise Gem::RubyVersionMismatch, "openhab-scripting requires JRuby 9.3.8.0 or newer"
6
+ end
7
+
8
+ require "jruby"
9
+
10
+ require "diff/lcs"
11
+
12
+ require "openhab/log"
13
+
14
+ require_relative "rspec/configuration"
15
+ require_relative "rspec/helpers"
16
+ require_relative "rspec/karaf"
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
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module YARD
5
+ # @!visibility private
6
+ module BaseHelper
7
+ def link_object(obj, title = nil, *)
8
+ ::YARD::Handlers::JRuby::Base.infer_java_class(obj) if obj.is_a?(String)
9
+ obj = ::YARD::Registry.resolve(object, obj, true, true) if obj.is_a?(String)
10
+ if obj.is_a?(::YARD::CodeObjects::Java::Base) && (see = obj.docstring.tag(:see))
11
+ # link to the first see tag
12
+ return linkify(see.name, title&.to_s || see.text)
13
+ end
14
+
15
+ super
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module YARD
5
+ module CLI
6
+ module Stats
7
+ ::YARD::CLI::Stats.prepend(self)
8
+
9
+ def stats_for_constants
10
+ objs = all_objects.select { |m| m.type == :constant }
11
+ undoc = objs.find_all do |m|
12
+ # allow constants that are simple aliases
13
+ # to not have additional documentation
14
+ m.docstring.blank? && m.target.nil?
15
+ end
16
+ @undoc_list |= undoc if @undoc_list
17
+
18
+ output "Constants", objs.size, undoc.size
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module YARD
5
+ module CodeObjects
6
+ class GroupObject < ::YARD::CodeObjects::Base
7
+ attr_reader :full_name
8
+
9
+ def initialize(namespace, name)
10
+ @full_name = name
11
+ name = name.delete(%(.?"')).tr(" ", "-")
12
+ super
13
+ end
14
+
15
+ def path
16
+ "group#{sep}#{super}"
17
+ end
18
+
19
+ alias_method :to_s, :full_name
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YARD
4
+ module CodeObjects
5
+ module Java
6
+ #
7
+ # Represents a java.lang.Class
8
+ #
9
+ # Which might be a class, an enum, or an interface
10
+ module Base
11
+ module ClassMethods
12
+ def new(name)
13
+ super(:root, name)
14
+ end
15
+ end
16
+
17
+ def self.included(klass)
18
+ klass.singleton_class.include(ClassMethods)
19
+ end
20
+
21
+ def visibility
22
+ :private
23
+ end
24
+
25
+ def simple_name
26
+ name.to_s.split(".").last
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YARD
4
+ module CodeObjects
5
+ module Java
6
+ class ClassObject < CodeObjects::ClassObject
7
+ include Base
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YARD
4
+ module CodeObjects
5
+ module Java
6
+ class FieldObject < CodeObjects::ConstantObject
7
+ include Base
8
+
9
+ def type
10
+ :constant
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YARD
4
+ module CodeObjects
5
+ module Java
6
+ class InterfaceObject < CodeObjects::ModuleObject
7
+ include Base
8
+
9
+ def type
10
+ :module
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YARD
4
+ module CodeObjects
5
+ module Java
6
+ class PackageObject < CodeObjects::ClassObject
7
+ include Base
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YARD
4
+ module CodeObjects
5
+ module Java
6
+ module Proxy
7
+ CodeObjects::Proxy.prepend(self)
8
+
9
+ def initialize(namespace, name, type = nil)
10
+ if name.match?(/^([a-zA-Z_$][a-zA-Z\d_$]*\.)+/)
11
+ @namespace = Registry.root
12
+ @name = name.to_sym
13
+ @obj = nil
14
+ @imethod = nil
15
+ self.type = type
16
+ return
17
+ end
18
+ super
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "coderay"
4
+
5
+ module OpenHAB
6
+ module YARD
7
+ module CodeRay
8
+ module HtmlHelper
9
+ ::CodeRay::Scanners.list.each do |scanner|
10
+ define_method("html_syntax_highlight_#{scanner}") do |source|
11
+ ::CodeRay.scan(source, scanner).html
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YARD
4
+ module Handlers
5
+ module JRuby
6
+ module Base
7
+ class << self
8
+ def infer_java_class(klass, inferred_type = nil, comments = nil, statement = nil)
9
+ components = klass.split(".")
10
+ components.pop if components.last == "freeze"
11
+
12
+ class_first_char = components.last[0]
13
+ is_field = components.last == components.last.upcase
14
+ container_first_char = components[-2]&.[](0)
15
+ is_method = container_first_char &&
16
+ class_first_char != class_first_char.upcase &&
17
+ container_first_char == container_first_char.upcase
18
+ is_package = !is_method && !is_field && class_first_char != class_first_char.upcase
19
+
20
+ # methods aren't supported right now
21
+ return if is_method
22
+
23
+ javadocs = YARD::Config.options.dig(:jruby, "javadocs") || {}
24
+
25
+ href_base = javadocs.find { |package, _href| klass == package || klass.start_with?("#{package}.") }&.last
26
+ return unless href_base
27
+
28
+ inferred_type = CodeObjects::Java::FieldObject if is_field
29
+ inferred_type = CodeObjects::Java::PackageObject if is_package
30
+ if inferred_type.nil?
31
+ docstring = Docstring.parser.parse(comments || statement&.comments).to_docstring
32
+ inferred_type = if docstring.has_tag?(:interface)
33
+ CodeObjects::Java::InterfaceObject
34
+ else
35
+ CodeObjects::Java::ClassObject
36
+ end
37
+ end
38
+
39
+ inferred_type.new(klass) do |o|
40
+ o.source = statement if statement
41
+ suffix = "/package-summary" if is_package
42
+ field = "##{components.pop}" if is_field
43
+ link = "#{href_base}#{components.join("/")}#{suffix}.html#{field}"
44
+ o.docstring.add_tag(Tags::Tag.new(:see, klass, nil, link)) unless o.docstring.has_tag?(:see)
45
+ end
46
+ end
47
+ end
48
+
49
+ def infer_java_class(statement, inferred_type = nil, comments = nil)
50
+ return unless statement.is_a?(Parser::Ruby::AstNode)
51
+ return unless statement.type == :call
52
+
53
+ Base.infer_java_class(statement.source, inferred_type, comments, statement)
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YARD
4
+ module Handlers
5
+ module JRuby
6
+ module ClassHandler
7
+ include Base
8
+
9
+ Ruby::ClassHandler.prepend(self)
10
+
11
+ def parse_superclass(superclass)
12
+ infer_java_class(superclass, CodeObjects::Java::ClassObject)&.then { |k| return k }
13
+ super
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YARD
4
+ module Handlers
5
+ module JRuby
6
+ module ConstantHandler
7
+ include Base
8
+
9
+ Ruby::ConstantHandler.prepend(self)
10
+
11
+ def process_constant(statement)
12
+ infer_java_class(statement[1], nil, statement.comments)
13
+ super
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YARD
4
+ module Handlers
5
+ module JRuby
6
+ class JavaImportHandler < Ruby::Base
7
+ include Base
8
+
9
+ handles method_call(:java_import)
10
+
11
+ process do
12
+ statement.parameters(false).each do |klass|
13
+ # first we auto-create the CodeObject for the class
14
+ obj = infer_java_class(klass)
15
+ next unless obj
16
+
17
+ # don't overwrite an already-extant object with the same name
18
+ next if ::YARD::Registry.at("#{namespace.path}::#{obj.simple_name}")
19
+
20
+ # then we create a new constant in the current namespace
21
+ register CodeObjects::ConstantObject.new(namespace, obj.simple_name) { |o|
22
+ o.source = statement
23
+ o.value = klass.source
24
+ }
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YARD
4
+ module Handlers
5
+ module JRuby
6
+ module MixinHandler
7
+ include Base
8
+
9
+ Ruby::MixinHandler.prepend(self)
10
+
11
+ def process_mixin(mixin)
12
+ if infer_java_class(mixin, CodeObjects::Java::InterfaceObject)
13
+ # make the Ruby::MixinHandler accept that this is a ref
14
+ def mixin.ref?
15
+ true
16
+ end
17
+ end
18
+ super
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end