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
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OpenHAB
4
- module DSL
5
- module Types
6
- OpenClosedType = org.openhab.core.library.types.OpenClosedType
7
-
8
- # Adds methods to core OpenHAB OpenClosedType to make it more natural in Ruby
9
- class OpenClosedType
10
- # @!parse include Type
11
-
12
- # @!method open?
13
- # Check if == +OPEN+
14
- # @return [Boolean]
15
-
16
- # @!method closed?
17
- # Check if == +CLOSED+
18
- # @return [Boolean]
19
-
20
- # Invert the type
21
- # @return [OpenClosedType] +OPEN+ if +CLOSED+, +CLOSED+ if +OPEN+
22
- def !
23
- return CLOSED if open?
24
- return OPEN if closed?
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OpenHAB
4
- module DSL
5
- module Types
6
- PlayPauseType = org.openhab.core.library.types.PlayPauseType
7
-
8
- # Adds methods to core OpenHAB PlayPauseType to make it more
9
- # natural in Ruby
10
- class PlayPauseType # rubocop:disable Lint/EmptyClass
11
- # @!parse include Type
12
-
13
- # @!method playing?
14
- # Check if == +PLAY+
15
- # @return [Boolean]
16
-
17
- # @!parse alias play? playing?
18
-
19
- # @!method paused?
20
- # Check if == +PAUSE+
21
- # @return [Boolean]
22
-
23
- # @!parse alias pause? paused?
24
- end
25
- end
26
- end
27
- end
@@ -1,180 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OpenHAB
4
- module DSL
5
- module Types
6
- PointType = org.openhab.core.library.types.PointType
7
-
8
- # global scope - required for jrubyscripting addon <= OH3.2.0
9
- # @!visibility private
10
- ::PointType = PointType if ::PointType.is_a?(java.lang.Class)
11
-
12
- # Adds methods to core OpenHAB PointType to make it more natural in Ruby
13
- class PointType
14
- # @!parse include PrimitiveType
15
-
16
- # @overload initialize(latitude, longitude, altitude)
17
- # @param [DecimalType, QuantityType, StringType, Numeric] latitude
18
- # @param [DecimalType, QuantityType, StringType, Numeric] longitude
19
- # @param [DecimalType, QuantityType, StringType, Numeric] altitude
20
- def initialize(*args) # rubocop:disable Metrics
21
- args = from_hash(args.first.to_hash) if args.first.respond_to? :to_hash
22
- if (2..3).cover?(args.length)
23
- args = args.each_with_index.map do |value, index|
24
- if value.is_a?(DecimalType) || value.is_a?(StringType)
25
- value
26
- elsif value.is_a?(QuantityType)
27
- unit = index == 2 ? Units.unit || SIUnits::METRE : Units::DEGREE_ANGLE
28
- DecimalType.new(value.to_unit(unit).to_big_decimal)
29
- elsif value.respond_to?(:to_str)
30
- StringType.new(value.to_str)
31
- elsif value.respond_to?(:to_d)
32
- DecimalType.new(value)
33
- end
34
- end
35
- end
36
-
37
- super(*args)
38
- end
39
-
40
- #
41
- # Check equality without type conversion
42
- #
43
- # @return [Boolean] if the same value is represented, without type
44
- # conversion
45
- def eql?(other)
46
- return false unless other.instance_of?(self.class)
47
-
48
- equals(other.to_s).zero?
49
- end
50
-
51
- #
52
- # Check equality with type conversion
53
- #
54
- # @param [PointType, Items::LocationItem, String]
55
- # other object to compare to
56
- #
57
- # @return [Boolean]
58
- #
59
- def ==(other) # rubocop:disable Metrics
60
- logger.trace { "(#{self.class}) #{self} == #{other} (#{other.class})" }
61
- if other.is_a?(Items::LocationItem) ||
62
- (other.is_a?(Items::GroupItem) && other.base_item.is_a?(LocationItem))
63
- return false unless other.state?
64
-
65
- self == other.state
66
- elsif other.respond_to?(:to_str)
67
- self == PointType.new(other)
68
- elsif other.respond_to?(:coerce)
69
- return false unless (lhs, rhs = other.coerce(self))
70
-
71
- lhs == rhs
72
- end
73
- end
74
-
75
- #
76
- # Type Coercion
77
- #
78
- # Coerce object to a PointType
79
- #
80
- # @param [Items::LocationItem, String] other object to coerce to a
81
- # PointType
82
- #
83
- # @return [[PointType, PointType]]
84
- #
85
- def coerce(other)
86
- lhs = coerce_single(other)
87
- return unless lhs
88
-
89
- [lhs, self]
90
- end
91
-
92
- # rename raw methods so we can overwrite them
93
- # @!visibility private
94
- alias raw_latitude latitude
95
- # .
96
- # @!visibility private
97
- alias raw_longitude longitude
98
- # .
99
- # @!visibility private
100
- alias raw_altitude altitude
101
- # .
102
- # @!visibility private
103
- alias raw_distance_from distance_from
104
-
105
- # @!attribute [r] latitude
106
- # @return [QuantityType]
107
- def latitude
108
- QuantityType.new(raw_latitude.to_big_decimal, SIUnits::DEGREE_ANGLE)
109
- end
110
-
111
- # @!attribute [r] longitude
112
- # @return [QuantityType]
113
- def longitude
114
- QuantityType.new(raw_longitude.to_big_decimal, SIUnits::DEGREE_ANGLE)
115
- end
116
-
117
- # @!attribute [r] altitude
118
- # @return [QuantityType]
119
- def altitude
120
- QuantityType.new(raw_altitude.to_big_decimal, Units::METRE)
121
- end
122
-
123
- #
124
- # Convert the PointType to a hash
125
- # @return [Hash] with keys latitude/longitude/altitude
126
- def to_h
127
- { latitude: latitude, longitude: longitude, altitude: altitude }
128
- end
129
-
130
- #
131
- # Calculate the distance in meters from other, ignoring altitude.
132
- #
133
- # This algorithm also ignores the oblate spheroid shape of Earth and
134
- # assumes a perfect sphere, so results are inexact.
135
- #
136
- # @return [QuantityType]
137
- def distance_from(other)
138
- logger.trace("(#{self}).distance_from(#{other} (#{other.class})")
139
- other = coerce_single(other)
140
- raise TypeError, "#{other.class} can't be coerced into #{self.class}" unless other
141
-
142
- QuantityType.new(raw_distance_from(other), SIUnits::METRE)
143
- end
144
- alias - distance_from
145
-
146
- private
147
-
148
- # coerce an object to a PointType
149
- # @return [PointType]
150
- def coerce_single(other) # rubocop:disable Metrics
151
- logger.trace("Coercing #{self} as a request from #{other.class}")
152
- if other.is_a?(PointType)
153
- other
154
- elsif other.is_a?(Items::LocationItem)
155
- return unless other.state?
156
-
157
- other.state
158
- elsif other.respond_to?(:to_str)
159
- PointType.new(other.to_str)
160
- elsif other.respond_to?(:to_hash)
161
- PointType.new(other.to_hash)
162
- end
163
- end
164
-
165
- #
166
- # Convert hash into ordered arguments for constructor
167
- #
168
- def from_hash(hash)
169
- keys = [%i[lat long alt], %i[latitude longitude altitude]]
170
- keys.each do |key_set|
171
- values = hash.transform_keys(&:to_sym).values_at(*key_set)
172
-
173
- return *values.compact if values[0..1].all?
174
- end
175
- raise ArgumentError, "Supplied arguments (#{hash}) must contain one of the following sets #{keys}"
176
- end
177
- end
178
- end
179
- end
180
- end
@@ -1,265 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'numeric_type'
4
-
5
- module OpenHAB
6
- module DSL
7
- module Types
8
- QuantityType = org.openhab.core.library.types.QuantityType
9
-
10
- # global alias - required for jrubyscripting addon <= OH3.2.0
11
- ::QuantityType = QuantityType if ::QuantityType.is_a?(java.lang.Class)
12
-
13
- # @deprecated
14
- # Backwards-compatible alias
15
- Quantity = QuantityType
16
-
17
- # Adds methods to core OpenHAB QuantityType to make it more natural in Ruby
18
- class QuantityType # rubocop:disable Metrics/ClassLength
19
- # @!parse include Type
20
- include NumericType
21
-
22
- # private alias
23
- ONE_UNIT = org.openhab.core.library.unit.Units::ONE
24
- private_constant :ONE_UNIT
25
-
26
- #
27
- # Convert this quantity into a another unit
28
- #
29
- alias | to_unit
30
-
31
- #
32
- # Comparison
33
- #
34
- # @param [NumericType, Items::NumericItem, Numeric, String]
35
- # other object to compare to
36
- #
37
- # @return [Integer, nil] -1, 0, +1 depending on whether +other+ is
38
- # less than, equal to, or greater than self
39
- #
40
- # nil is returned if the two values are incomparable
41
- #
42
- def <=>(other) # rubocop:disable Metrics
43
- logger.trace("(#{self.class}) #{self} <=> #{other} (#{other.class})")
44
- if other.is_a?(self.class)
45
- return unitize(other.unit).compare_to(other) if unit == ONE_UNIT
46
- return compare_to(other.unitize(unit)) if other.unit == ONE_UNIT
47
-
48
- compare_to(other)
49
- elsif other.is_a?(Items::NumericItem) ||
50
- (other.is_a?(Items::GroupItem) && other.base_item.is_a?(NumericItem))
51
- return nil unless other.state?
52
-
53
- self <=> other.state
54
- elsif other.respond_to?(:to_str)
55
- compare_to(QuantityType.new(other.to_str))
56
- elsif other.respond_to?(:to_d)
57
- compare_to(QuantityType.new(other.to_d.to_java, Units.unit || unit))
58
- elsif other.respond_to?(:coerce)
59
- return nil unless (lhs, rhs = other.coerce(self))
60
-
61
- lhs <=> rhs
62
- end
63
- end
64
-
65
- #
66
- # Type Coercion
67
- #
68
- # Coerce object to a QuantityType
69
- #
70
- # @param [Items::NumericItem, Numeric, Type, String] other object to
71
- # coerce to a {QuantityType}
72
- #
73
- # if +other+ is a {Type}, +self+ will instead be coerced
74
- # to that type to accomodate comparison with things such as {OnOffType}
75
- #
76
- # @return [[QuantityType, QuantityType]]
77
- def coerce(other) # rubocop:disable Metrics
78
- logger.trace("Coercing #{self} as a request from #{other.class}")
79
- if other.is_a?(Items::NumericItem) ||
80
- (other.is_a?(Items::GroupItem) && other.base_item.is_a?(Items::NumericItem))
81
- return unless other.state?
82
-
83
- [other.state, self]
84
- elsif other.is_a?(Type)
85
- [other, as(other.class)]
86
- elsif other.respond_to?(:to_d)
87
- [QuantityType.new(other.to_d.to_java, ONE_UNIT), self]
88
- elsif other.is_a?(String)
89
- [QuantityType.new(other), self]
90
- end
91
- end
92
-
93
- # arithmetic operators
94
- alias -@ negate
95
-
96
- {
97
- :add => :+,
98
- :subtract => :-
99
- }.each do |java_op, ruby_op|
100
- convert = 'self.class.new(other, Units.unit || unit)'
101
-
102
- class_eval( # rubocop:disable Style/DocumentDynamicEvalDefinition https://github.com/rubocop/rubocop/issues/10179
103
- # def +(other)
104
- # logger.trace("#{self} + #{other} (#{other.class})")
105
- # if other.is_a?(Items::NumericItem) ||
106
- # (other.is_a?(Items::GroupItem) && other.base_item.is_a?(Items::NumericItem))
107
- # self + other.state
108
- # elsif other.is_a?(QuantityType)
109
- # add_quantity(other)
110
- # elsif other.is_a?(DecimalType)
111
- # other = other.to_big_decimal
112
- # add_quantity(self.class.new(other, Units.unit || unit))
113
- # elsif other.is_a?(java.math.BigDecimal)
114
- # add_quantity(self.class.new(other, Units.unit || unit))
115
- # elsif other.respond_to?(:to_str)
116
- # self + self.class.new(other)
117
- # elsif other.respond_to?(:to_d)
118
- # other = other.to_d.to_java
119
- # add_quantity(self.class.new(other, Units.unit || unit))
120
- # elsif other.respond_to?(:coerce) && (lhs, rhs = other.coerce(to_d))
121
- # lhs + rhs
122
- # else
123
- # raise TypeError, "#{other.class} can't be coerced into #{self.class}"
124
- # end
125
- # end
126
- <<~RUBY, __FILE__, __LINE__ + 1
127
- def #{ruby_op}(other)
128
- logger.trace("\#{self} #{ruby_op} \#{other} (\#{other.class})")
129
- if other.is_a?(Items::NumericItem) ||
130
- (other.is_a?(Items::GroupItem) && other.base_item.is_a?(Items::NumericItem))
131
- self #{ruby_op} other.state
132
- elsif other.is_a?(QuantityType)
133
- #{java_op}_quantity(other)
134
- elsif other.is_a?(DecimalType)
135
- other = other.to_big_decimal
136
- #{java_op}_quantity(#{convert})
137
- elsif other.is_a?(java.math.BigDecimal)
138
- #{java_op}_quantity(#{convert})
139
- elsif other.respond_to?(:to_str)
140
- self #{ruby_op} self.class.new(other)
141
- elsif other.respond_to?(:to_d)
142
- other = other.to_d.to_java
143
- #{java_op}_quantity(#{convert})
144
- elsif other.respond_to?(:coerce) && (lhs, rhs = other.coerce(to_d))
145
- lhs #{ruby_op} rhs
146
- else
147
- raise TypeError, "\#{other.class} can't be coerced into \#{self.class}"
148
- end
149
- end
150
- RUBY
151
- )
152
- end
153
-
154
- {
155
- :multiply => :*,
156
- :divide => :/
157
- }.each do |java_op, ruby_op|
158
- class_eval( # rubocop:disable Style/DocumentDynamicEvalDefinition https://github.com/rubocop/rubocop/issues/10179
159
- # def *(other)
160
- # logger.trace("#{self} * #{other} (#{other.class})")
161
- # if other.is_a?(Items::NumericItem) ||
162
- # (other.is_a?(Items::GroupItem) && other.base_item.is_a?(Items::NumericItem))
163
- # self * other.state
164
- # elsif other.is_a?(QuantityType)
165
- # multiply_quantity(other)
166
- # elsif other.is_a?(DecimalType)
167
- # multiply(other.to_big_decimal)
168
- # elsif other.is_a?(java.math.BigDecimal)
169
- # multiply(other)
170
- # elsif other.respond_to?(:to_str)
171
- # self * self.class.new(other)
172
- # elsif other.respond_to?(:to_d)
173
- # multiply(other.to_d.to_java)
174
- # elsif other.respond_to?(:coerce) && (lhs, rhs = other.coerce(to_d))
175
- # lhs * rhs
176
- # else
177
- # raise TypeError, "#{other.class} can't be coerced into #{self.class}"
178
- # end
179
- # end
180
- <<~RUBY, __FILE__, __LINE__ + 1
181
- def #{ruby_op}(other)
182
- logger.trace("\#{self} #{ruby_op} \#{other} (\#{other.class})")
183
- if other.is_a?(Items::NumericItem) ||
184
- (other.is_a?(Items::GroupItem) && other.base_item.is_a?(Items::NumericItem))
185
- self #{ruby_op} other.state
186
- elsif other.is_a?(QuantityType)
187
- #{java_op}_quantity(other)
188
- elsif other.is_a?(DecimalType)
189
- #{java_op}(other.to_big_decimal)
190
- elsif other.is_a?(java.math.BigDecimal)
191
- #{java_op}(other)
192
- elsif other.respond_to?(:to_str)
193
- self #{ruby_op} self.class.new(other)
194
- elsif other.respond_to?(:to_d)
195
- #{java_op}(other.to_d.to_java)
196
- elsif other.respond_to?(:coerce) && (lhs, rhs = other.coerce(to_d))
197
- lhs #{ruby_op} rhs
198
- else
199
- raise TypeError, "\#{other.class} can't be coerced into \#{self.class}"
200
- end
201
- end
202
- RUBY
203
- )
204
- end
205
-
206
- # if it's a dimensionless quantity, change the unit to match other_unit
207
- # @!visibility private
208
- def unitize(other_unit = unit)
209
- # prefer converting to the thread-specified unit if there is one
210
- other_unit = Units.unit || other_unit
211
- logger.trace("Converting #{self} to #{other_unit}")
212
-
213
- case unit
214
- when ONE_UNIT
215
- QuantityType.new(to_big_decimal, other_unit)
216
- when other_unit
217
- self
218
- else
219
- to_unit(other_unit)
220
- end
221
- end
222
-
223
- # if unit is +ONE_UNIT+, return a plain Java BigDecimal
224
- # @!visibility private
225
- def deunitize
226
- return to_big_decimal if unit == ONE_UNIT
227
-
228
- self
229
- end
230
-
231
- private
232
-
233
- # do addition directly against a QuantityType while ensuring we unitize
234
- # both sides
235
- def add_quantity(other)
236
- unitize(other.unit).add(other.unitize(unit))
237
- end
238
-
239
- # do subtraction directly against a QuantityType while ensuring we
240
- # unitize both sides
241
- def subtract_quantity(other)
242
- unitize(other.unit).subtract(other.unitize(unit))
243
- end
244
-
245
- # do multiplication directly against a QuantityType while ensuring
246
- # we deunitize both sides, and also invert the operation if one side
247
- # isn't actually a unit
248
- def multiply_quantity(other)
249
- lhs = deunitize
250
- rhs = other.deunitize
251
- # reverse the arguments if it's multiplication and the LHS isn't a QuantityType
252
- lhs, rhs = rhs, lhs if lhs.is_a?(java.math.BigDecimal)
253
- # what a waste... using a QuantityType to multiply two dimensionless quantities
254
- # have to make sure lhs is still a QuantityType in order to return a new
255
- # QuantityType that's still dimensionless
256
- lhs = other if lhs.is_a?(java.math.BigDecimal)
257
-
258
- lhs.multiply(rhs)
259
- end
260
-
261
- alias divide_quantity divide
262
- end
263
- end
264
- end
265
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OpenHAB
4
- module DSL
5
- module Types
6
- RefreshType = org.openhab.core.types.RefreshType
7
-
8
- # Adds methods to core OpenHAB RefreshType to make it more natural in Ruby
9
- class RefreshType # rubocop:disable Lint/EmptyClass
10
- # @!parse include Type
11
-
12
- # @!method refresh?
13
- # Check if == +REFRESH+
14
- # @return [Boolean]
15
- end
16
- end
17
- end
18
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OpenHAB
4
- module DSL
5
- module Types
6
- RewindFastforwardType = org.openhab.core.library.types.RewindFastforwardType
7
-
8
- # Adds methods to core OpenHAB RewindFastforwardType to make it more
9
- # natural in Ruby
10
- class RewindFastforwardType # rubocop:disable Lint/EmptyClass
11
- # @!parse include Type
12
-
13
- # @!method rewinding?
14
- # Check if == +REWIND+
15
- # @return [Boolean]
16
-
17
- # @!parse alias rewind? rewinding?
18
-
19
- # @!method fast_forwarding?
20
- # Check if == +FASTFORWARD+
21
- # @return [Boolean]
22
-
23
- # @!parse alias fast_forward? fast_forwarding?
24
-
25
- # @deprecated
26
- # @!parse alias fastforward? fast_forwarding?
27
-
28
- # @deprecated
29
- # @!parse alias fastforwarding? fast_forwarding?
30
- end
31
- end
32
- end
33
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OpenHAB
4
- module DSL
5
- module Types
6
- StopMoveType = org.openhab.core.library.types.StopMoveType
7
-
8
- # Adds methods to core OpenHAB StopMoveType to make it more
9
- # natural in Ruby
10
- class StopMoveType # rubocop:disable Lint/EmptyClass
11
- # @!parse include Type
12
-
13
- # @!method stop?
14
- # Check if == +STOP+
15
- # @return [Boolean]
16
-
17
- # @!method move?
18
- # Check if == +MOVE+
19
- # @return [Boolean]
20
- end
21
- end
22
- end
23
- end
@@ -1,83 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'openhab/log/logger'
4
-
5
- require_relative 'type'
6
-
7
- require_relative 'date_time_type'
8
- require_relative 'decimal_type'
9
- require_relative 'hsb_type'
10
- require_relative 'increase_decrease_type'
11
- require_relative 'next_previous_type'
12
- require_relative 'open_closed_type'
13
- require_relative 'on_off_type'
14
- require_relative 'percent_type'
15
- require_relative 'play_pause_type'
16
- require_relative 'point_type'
17
- require_relative 'quantity_type'
18
- require_relative 'refresh_type'
19
- require_relative 'rewind_fastforward_type'
20
- require_relative 'stop_move_type'
21
- require_relative 'string_type'
22
- require_relative 'up_down_type'
23
- require_relative 'un_def_type'
24
-
25
- module OpenHAB
26
- module DSL
27
- # Hash taking a Enum value, and returning two symbols of
28
- # predicates to be defined for it. the first is the "command" form,
29
- # which should be defined on ItemCommandEvent, and on the Type itself.
30
- # the second is "state" form, which should be defined on the applicable
31
- # Item, and on the Type itself.
32
- # @!visibility private
33
- PREDICATE_ALIASES = Hash.new { |_h, k| [:"#{k.downcase}?"] * 2 }
34
- .merge({
35
- 'PLAY' => %i[play? playing?],
36
- 'PAUSE' => %i[pause? paused?],
37
- 'REWIND' => %i[rewind? rewinding?],
38
- 'FASTFORWARD' => %i[fast_forward? fast_forwarding?]
39
- }).freeze
40
-
41
- # Hash taking a Enum value, and returning an array of symbols
42
- # of the command to define for it
43
- # @!visibility private
44
- COMMAND_ALIASES = Hash.new { |_h, k| k.downcase.to_sym }
45
- .merge({
46
- 'FASTFORWARD' => :fast_forward
47
- }).freeze
48
-
49
- #
50
- # Contains all OpenHAB *Type classes, as well as associated support
51
- # modules
52
- #
53
- module Types
54
- include OpenHAB::Log
55
-
56
- constants.map { |c| const_get(c) }
57
- .grep(Module)
58
- .select { |k| k < java.lang.Enum }
59
- .each do |klass|
60
- # make sure == from Type is inherited
61
- klass.remove_method(:==)
62
-
63
- # dynamically define predicate methods
64
- klass.values.each do |value| # rubocop:disable Style/HashEachMethods this isn't a Ruby hash
65
- # include all the aliases that we define for items both command and
66
- # state aliases (since types can be interrogated as an incoming
67
- # command, or as the state of an item)
68
- command = :"#{OpenHAB::DSL::COMMAND_ALIASES[value.to_s]}?"
69
- states = OpenHAB::DSL::PREDICATE_ALIASES[value.to_s]
70
-
71
- ([command] | states).each do |method|
72
- logger.trace("Defining #{klass}##{method} for #{value}")
73
- klass.class_eval <<~RUBY, __FILE__, __LINE__ + 1
74
- def #{method} # def on?
75
- self == #{value} # self == ON
76
- end # end
77
- RUBY
78
- end
79
- end
80
- end
81
- end
82
- end
83
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OpenHAB
4
- module DSL
5
- module Types
6
- UnDefType = org.openhab.core.types.UnDefType
7
-
8
- # Adds methods to core OpenHAB UnDefType to make it more natural in Ruby
9
- class UnDefType # rubocop:disable Lint/EmptyClass
10
- # @!parse include Type
11
-
12
- # @!method null?
13
- # Check if == +NULL+
14
- # @return [Boolean]
15
-
16
- # @!method undef?
17
- # Check if == +UNDEF+
18
- # @return [Boolean]
19
- end
20
- end
21
- end
22
- end