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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0d253f88db8dde6ae683a6254556a6e2334a5ec16525933a9b9267c214f9876
4
- data.tar.gz: 05d0a09395d4c05b96aa2fab929c277273c8259e3fb6a29000223790f81e5dd0
3
+ metadata.gz: a2826f669c876cc9b59863c2107bc8b1af62327d22c4551ef062f1b7bc97aabb
4
+ data.tar.gz: 61bd119ddc94019361d0150ed8bc1e92b5b42de9f610599f1305fbf04055cb14
5
5
  SHA512:
6
- metadata.gz: 6f6e4741a565c54b2d8d76b5c46ad9069308466b9befa388b89dcd37e1dce54e3dc40a8a7eba019bd750c1073a5202f07ef7750f413de35748f797a628e6575e
7
- data.tar.gz: 4d6e55b63e80d8db94fe6d51b16df1596335701f13f8badc4168893e4b3dd953a217f91ed424559cc7fe1873dc521907054c82e8e73d413b0944c88771d30428
6
+ metadata.gz: 0bf813e7b4aba75c75979c05fc317982dfb1ca94b0eae9de656ed342b1861b293ebb8912ed7935ba709b90506a169be6013b92278281ab4dafdb3205e215f927
7
+ data.tar.gz: 74a35427271bcae3fd179c3ffd1710f145457e8ae1010481b27310aa28bf710c359f784c6893ed630f2737f1f029c43b7c5f925ceed7cb119239c7cfe77a77e7
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module Core
5
+ module Actions
6
+ # @see https://www.openhab.org/docs/configuration/multimedia.html#actions-2 Audio Actions
7
+ class Audio
8
+ class << self
9
+ #
10
+ # Play an audio file via openHAB sound service, Audio.playSound()
11
+ #
12
+ # @param filename [String] The sound file to play
13
+ # @param sink [String] Specify a particular sink to output the speech
14
+ # @param volume [PercentType] Specify the volume for the speech
15
+ #
16
+ # @return [void]
17
+ #
18
+ # @example Play an audio file
19
+ # rule 'Play an audio file' do
20
+ # every :hour
21
+ # run { Audio.play_sound "beep.mp3", volume: 100 }
22
+ # end
23
+ #
24
+ def play_sound(filename, sink: nil, volume: nil)
25
+ volume = PercentType.new(volume) unless volume.is_a?(PercentType) || volume.nil?
26
+ playSound(sink&.to_s, filename.to_s, volume)
27
+ end
28
+
29
+ #
30
+ # Play an audio stream from an URL to the given sink(s). Set url to nil if streaming should be stopped
31
+ #
32
+ # @param [String] url The URL of the audio stream
33
+ # @param [String] sink The audio sink, or nil to use the default audio sink
34
+ #
35
+ # @return [void]
36
+ #
37
+ # @example Play an audio stream
38
+ # Audio.play_stream 'example.com'
39
+ #
40
+ def play_stream(url, sink: nil)
41
+ playStream(sink&.to_s, url)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module Core
5
+ module Actions
6
+ # @see CoreExt::Ephemeris
7
+ class Ephemeris
8
+ class << self
9
+ #
10
+ # Human readable name of the given holiday
11
+ #
12
+ # @param [Symbol, #holiday, nil] holiday
13
+ # @return [String, nil]
14
+ #
15
+ # @example
16
+ # Ephemeris.holiday_name(Date.today) # => "Christmas"
17
+ # Ephemeris.holiday_name(:christmas) # => "Christmas"
18
+ #
19
+ def holiday_name(holiday)
20
+ holiday = holiday.holiday if holiday.respond_to?(:holiday)
21
+ return nil if holiday.nil?
22
+
23
+ ::Ephemeris.get_holiday_description(to_holiday_property_key(holiday))
24
+ end
25
+
26
+ private
27
+
28
+ def to_holiday_property_key(holiday)
29
+ holiday = holiday.to_s
30
+ return holiday.upcase unless holiday.include?(".")
31
+
32
+ religion, holiday = holiday.split(/\.([^.]*)$/)
33
+ :"#{religion}.#{holiday.upcase}"
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module Core
5
+ module Actions
6
+ # @see https://www.openhab.org/docs/configuration/actions.html#exec-actions Exec Actions
7
+ class Exec # rubocop:disable Lint/EmptyClass
8
+ # @!scope class
9
+
10
+ # @!method execute_command_line
11
+ #
12
+ # @return [void]
13
+ #
14
+ # @overload execute_command_line(command_line)
15
+ #
16
+ # Executes a command on the command line without waiting for the
17
+ # command to complete.
18
+ #
19
+ # @param [String] command_line
20
+ # @return [void]
21
+ #
22
+ # @example Execute an external command
23
+ # rule 'Run a command' do
24
+ # every :day
25
+ # run do
26
+ # Exec.execute_command_line('/bin/true')
27
+ # end
28
+ # end
29
+ #
30
+ # @overload execute_command_line(timeout, command_line)
31
+ #
32
+ # Executes a command on the command and waits timeout seconds for
33
+ # the command to complete, returning the output from the command
34
+ # as a String.
35
+ #
36
+ # @param [Duration] timeout
37
+ # @param [String] command_line
38
+ # @return [String]
39
+ #
40
+ # @example Execute an external command and process its results
41
+ # rule 'Run a command' do
42
+ # every :day
43
+ # run do
44
+ # TodaysHoliday_String.update(Exec.execute_command_line(5.seconds, '/home/cody/determine_holiday.rb')
45
+ # end
46
+ # end
47
+ #
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module Core
5
+ module Actions
6
+ # @see https://www.openhab.org/docs/configuration/actions.html#http-actions HTTP Actions
7
+ class HTTP
8
+ class << self
9
+ #
10
+ # Sends an HTTP GET request and returns the result as a String.
11
+ #
12
+ # @param [String] url
13
+ # @param [Hash<String, String>] headers
14
+ # @param [Duration, int, nil] timeout Timeout (in milliseconds, if given as an Integer)
15
+ # @return [String] the response body
16
+ # @return [nil] if an error occurred
17
+ #
18
+ def send_http_get_request(url, headers: {}, timeout: nil)
19
+ timeout ||= 5_000
20
+ timeout = timeout.to_millis if timeout.is_a?(Duration)
21
+
22
+ sendHttpGetRequest(url, headers, timeout)
23
+ end
24
+
25
+ #
26
+ # Sends an HTTP PUT request and returns the result as a String.
27
+ #
28
+ # @param [String] url
29
+ # @param [String] content_type
30
+ # @param [String] content
31
+ # @param [Hash<String, String>] headers
32
+ # @param [Duration, int, nil] timeout Timeout (in milliseconds, if given as an Integer)
33
+ # @return [String] the response body
34
+ # @return [nil] if an error occurred
35
+ #
36
+ def send_http_put_request(url, content_type = nil, content = nil, headers: {}, timeout: nil)
37
+ timeout ||= 1_000
38
+ timeout = timeout.to_millis if timeout.is_a?(Duration)
39
+
40
+ sendHttpPutRequest(url, content_type, content, headers, timeout)
41
+ end
42
+
43
+ #
44
+ # Sends an HTTP POST request and returns the result as a String.
45
+ #
46
+ # @param [String] url
47
+ # @param [String] content_type
48
+ # @param [String] content
49
+ # @param [Hash<String, String>] headers
50
+ # @param [Duration, int, nil] timeout Timeout (in milliseconds, if given as an Integer)
51
+ # @return [String] the response body
52
+ # @return [nil] if an error occurred
53
+ #
54
+ def send_http_post_request(url, content_type = nil, content = nil, headers: {}, timeout: nil)
55
+ timeout ||= 1_000
56
+ timeout = timeout.to_millis if timeout.is_a?(Duration)
57
+
58
+ sendHttpPostRequest(url, content_type, content, headers, timeout)
59
+ end
60
+
61
+ #
62
+ # Sends an HTTP DELETE request and returns the result as a String.
63
+ #
64
+ # @param [String] url
65
+ # @param [Hash<String, String>] headers
66
+ # @param [Duration, int, nil] timeout Timeout (in milliseconds, if given as an Integer)
67
+ # @return [String] the response body
68
+ # @return [nil] if an error occurred
69
+ #
70
+ def send_http_delete_request(url, headers: {}, timeout: nil)
71
+ timeout ||= 1_000
72
+ timeout = timeout.to_millis if timeout.is_a?(Duration)
73
+
74
+ sendHttpDeleteRequest(url, headers, timeout)
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module Core
5
+ module Actions
6
+ # @see org.openhab.core.model.script.actions.Ping
7
+ class Ping
8
+ class << self
9
+ #
10
+ # Checks the vitality of host.
11
+ #
12
+ # If port is `nil`, a regular ping is issued. If other ports are
13
+ # specified we try to open a new Socket with the given timeout.
14
+ #
15
+ # @param [String] host
16
+ # @param [int, nil] port
17
+ # @param [Duration, Integer, nil] timeout Connect timeout (in milliseconds, if given as an Integer)
18
+ # @return [true, false]
19
+ #
20
+ def check_vitality(host, port = nil, timeout = nil)
21
+ port ||= 0
22
+ timeout ||= 0
23
+ timeout = timeout.to_millis if timeout.is_a?(Duration)
24
+ checkVitality(host, port, timeout)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module Core
5
+ module Actions
6
+ # @see org.openhab.core.transform.actions.Transformation
7
+ class Transformation
8
+ class << self
9
+ # @!visibility private
10
+ alias_method :raw_transform, :transform if instance_methods.include?(:transform)
11
+
12
+ #
13
+ # Applies a transformation of a given type with some function to a value.
14
+ #
15
+ # @param [String, Symbol] type The transformation type, e.g. REGEX
16
+ # or MAP
17
+ # @param [String, Symbol] function The function to call. This value depends
18
+ # on the transformation type
19
+ # @param [String] value The value to apply the transformation to
20
+ # @return [String] the transformed value, or the original value if an error occurred
21
+ #
22
+ # @example Run a transformation
23
+ # transform(:map, "myfan.map", 0)
24
+ #
25
+ def transform(type, function, value)
26
+ raw_transform(type.to_s.upcase, function.to_s, value.to_s)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module Core
5
+ module Actions
6
+ # @see https://www.openhab.org/docs/configuration/multimedia.html#actions-3 Voice Actions
7
+ class Voice
8
+ class << self
9
+ # @!visibility private
10
+ alias_method :raw_say, :say if instance_methods.include?(:say)
11
+
12
+ #
13
+ # Say text via openHAB Text-To-Speech service, Voice.say()
14
+ #
15
+ # @param text [String] The text to say
16
+ # @param voice [String] Specify a particular voice to use
17
+ # @param sink [String] Specify a particular sink to output the speech
18
+ # @param volume [PercentType] Specify the volume for the speech
19
+ #
20
+ # @return [void]
21
+ #
22
+ # @example Run the TTS engine and output to the default audio sink.
23
+ # rule 'Say the time every hour' do
24
+ # every :hour
25
+ # run { Voice.say "The time is #{TimeOfDay.now}" }
26
+ # end
27
+ #
28
+ def say(text, voice: nil, sink: nil, volume: nil)
29
+ volume = PercentType.new(volume) unless volume.is_a?(PercentType) || volume.nil?
30
+ raw_say(text.to_s, voice&.to_s, sink&.to_s, volume)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module Core
5
+ #
6
+ # Access to global actions.
7
+ #
8
+ # All openHAB's actions including those provided by add-ons are available, notably:
9
+ # * {Audio}
10
+ # * {CoreExt::Ephemeris Ephemeris}
11
+ # * {Exec}
12
+ # * {HTTP}
13
+ # * {Items::Persistence PersistenceExtensions}
14
+ # * {Ping}
15
+ # * {Items::Semantics Semantics}
16
+ # * {Transformation}
17
+ # * {Voice}
18
+ #
19
+ # From add-ons, e.g.:
20
+ # * NotificationAction (from
21
+ # [openHAB Cloud Connector](https://www.openhab.org/addons/integrations/openhabcloud/);
22
+ # see {notify notify})
23
+ #
24
+ # Thing-specific actions can be accessed from the {Things::Thing Thing} object.
25
+ # See {Things::Thing#actions Thing#actions}.
26
+ #
27
+ module Actions
28
+ OSGi.services("org.openhab.core.model.script.engine.action.ActionService")&.each do |service|
29
+ action_class = service.action_class
30
+ module_name = action_class.simple_name
31
+ action = if action_class.interface?
32
+ impl = OSGi.service(action_class)
33
+ unless impl
34
+ logger.error("Unable to find an implementation object for action service #{action_class}.")
35
+ next
36
+ end
37
+ const_set(module_name, impl)
38
+ else
39
+ (java_import action_class.ruby_class).first
40
+ end
41
+ logger.trace("Loaded ACTION: #{action_class}")
42
+ Object.const_set(module_name, action)
43
+ end
44
+
45
+ # Import common actions
46
+ %w[Exec HTTP Ping Transformation].each do |action|
47
+ klass = (java_import "org.openhab.core.model.script.actions.#{action}").first
48
+ Object.const_set(action, klass)
49
+ end
50
+
51
+ module_function
52
+
53
+ #
54
+ # Send a notification.
55
+ #
56
+ # @param msg [String] The message to send.
57
+ # @param email [String, nil] The email address to send to. If `nil`,
58
+ # the message will be broadcast.
59
+ # @param icon [String, Symbol, nil]
60
+ # @param severity [String, Symbol, nil]
61
+ # @return [void]
62
+ #
63
+ # @example Send a broadcast notification via openHAB Cloud
64
+ # rule 'Send an alert' do
65
+ # changed Alarm_Triggered, to: ON
66
+ # run { notify 'Red Alert!' }
67
+ # end
68
+ #
69
+ def notify(msg, email: nil, icon: nil, severity: nil)
70
+ unless Actions.const_defined?(:NotificationAction)
71
+ raise NotImplementedError, "NotificationAction is not available. Please install the openHAB Cloud addon."
72
+ end
73
+
74
+ if email
75
+ NotificationAction.send_notification(email.to_s, msg.to_s, icon&.to_s, severity&.to_s)
76
+ else
77
+ NotificationAction.send_broadcast_notification(msg.to_s, icon&.to_s, severity&.to_s)
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ if defined?($dependencyListener)
4
+ require "jruby"
5
+
6
+ klass = Class.new(org.jruby.util.collections.StringArraySet) do
7
+ def initialize(other)
8
+ super(JRuby.runtime)
9
+ other.each { |feature| append(feature) }
10
+ end
11
+
12
+ def append(name)
13
+ $dependencyListener.accept(name)
14
+
15
+ super
16
+ end
17
+ end
18
+
19
+ JRuby.runtime.load_service.class.field_accessor :loadedFeatures
20
+ JRuby.runtime.load_service.loadedFeatures = klass.new(JRuby.runtime.load_service.loadedFeatures)
21
+
22
+ loaded_specs = Gem.loaded_specs
23
+ loaded_specs.each_key do |gem|
24
+ $dependencyListener.accept("gem:#{gem}")
25
+ end
26
+
27
+ def loaded_specs.[]=(gem, _spec)
28
+ super
29
+
30
+ $dependencyListener.accept("gem:#{gem}")
31
+ end
32
+ else
33
+ logger.warn("Dependency listener not found; dependency tracking disabled.")
34
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module Core
5
+ module DTO
6
+ java_import org.openhab.core.thing.link.dto.ItemChannelLinkDTO
7
+
8
+ # Adds methods to core openHAB ItemChannelLinkDTO to make it more natural in Ruby
9
+ class ItemChannelLinkDTO
10
+ #
11
+ # @!attribute [r] item_name
12
+ # @return [String] The name of the item that was linked or unlinked.
13
+ #
14
+
15
+ #
16
+ # @!attribute [r] item
17
+ # @return [Item] The item that was linked or unlinked
18
+ #
19
+ def item
20
+ EntityLookup.lookup_item(itemName)
21
+ end
22
+
23
+ #
24
+ # @!attribute [r] channel_uid
25
+ # @return [Things::ChannelUID] The UID of the channel that was linked or unlinked.
26
+ #
27
+ def channel_uid
28
+ Things::ChannelUID.new(channelUID)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module Core
5
+ module DTO
6
+ java_import org.openhab.core.thing.dto.AbstractThingDTO
7
+
8
+ # Adds methods to core openHAB AbstractThingDTO to make it more natural in Ruby
9
+ class AbstractThingDTO
10
+ # @!attribute [r] uid
11
+ # The thing's UID
12
+ # @return [String]
13
+ alias_method :uid, :UID
14
+
15
+ # @!attribute [r] thing_type_uid
16
+ # The thing type's UID
17
+ # @return [String]
18
+ alias_method :thing_type_uid, :thingTypeUID
19
+
20
+ # @!attribute [r] bridge_uid
21
+ # The Bridge's UID
22
+ # @return [String, nil]
23
+ alias_method :bridge_uid, :bridgeUID
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module Core
5
+ # Contains data transfer objects that represent other openHAB objects
6
+ # when they need to be represented with simple classes, such as for JSON
7
+ # responses, or when being attached to events sent over the event bus.
8
+ module DTO
9
+ end
10
+ end
11
+ end