openhab-scripting 4.47.0 → 5.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (282) hide show
  1. checksums.yaml +4 -4
  2. data/lib/openhab/core/actions/audio.rb +54 -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/item_state_updated_event.rb +22 -0
  23. data/lib/openhab/core/events/thing_status_info_event.rb +55 -0
  24. data/lib/openhab/core/events.rb +10 -0
  25. data/lib/openhab/core/items/accepted_data_types.rb +29 -0
  26. data/lib/openhab/core/items/color_item.rb +52 -0
  27. data/lib/openhab/core/items/contact_item.rb +52 -0
  28. data/lib/openhab/core/items/date_time_item.rb +59 -0
  29. data/lib/openhab/core/items/dimmer_item.rb +148 -0
  30. data/lib/openhab/core/items/generic_item.rb +292 -0
  31. data/lib/openhab/core/items/group_item.rb +176 -0
  32. data/lib/openhab/{dsl → core}/items/image_item.rb +35 -29
  33. data/lib/openhab/core/items/item.rb +273 -0
  34. data/lib/openhab/core/items/location_item.rb +34 -0
  35. data/lib/openhab/core/items/metadata/hash.rb +433 -0
  36. data/lib/openhab/core/items/metadata/namespace_hash.rb +475 -0
  37. data/lib/openhab/core/items/metadata/provider.rb +48 -0
  38. data/lib/openhab/core/items/metadata.rb +11 -0
  39. data/lib/openhab/core/items/number_item.rb +62 -0
  40. data/lib/openhab/core/items/numeric_item.rb +22 -0
  41. data/lib/openhab/core/items/persistence.rb +416 -0
  42. data/lib/openhab/core/items/player_item.rb +66 -0
  43. data/lib/openhab/core/items/provider.rb +44 -0
  44. data/lib/openhab/core/items/proxy.rb +136 -0
  45. data/lib/openhab/core/items/registry.rb +86 -0
  46. data/lib/openhab/core/items/rollershutter_item.rb +68 -0
  47. data/lib/openhab/core/items/semantics/enumerable.rb +177 -0
  48. data/lib/openhab/core/items/semantics.rb +473 -0
  49. data/lib/openhab/core/items/state_storage.rb +53 -0
  50. data/lib/openhab/core/items/string_item.rb +28 -0
  51. data/lib/openhab/core/items/switch_item.rb +78 -0
  52. data/lib/openhab/core/items.rb +108 -0
  53. data/lib/openhab/{dsl → core}/lazy_array.rb +9 -3
  54. data/lib/openhab/core/profile_factory.rb +132 -0
  55. data/lib/openhab/core/provider.rb +230 -0
  56. data/lib/openhab/core/proxy.rb +130 -0
  57. data/lib/openhab/core/registry.rb +40 -0
  58. data/lib/openhab/core/rules/module.rb +26 -0
  59. data/lib/openhab/core/rules/provider.rb +25 -0
  60. data/lib/openhab/core/rules/registry.rb +94 -0
  61. data/lib/openhab/core/rules/rule.rb +174 -0
  62. data/lib/openhab/core/rules.rb +25 -0
  63. data/lib/openhab/core/script_handling.rb +78 -20
  64. data/lib/openhab/core/things/channel.rb +48 -0
  65. data/lib/openhab/core/things/channel_uid.rb +51 -0
  66. data/lib/openhab/core/things/item_channel_link.rb +33 -0
  67. data/lib/openhab/core/things/links/provider.rb +78 -0
  68. data/lib/openhab/core/things/profile_callback.rb +52 -0
  69. data/lib/openhab/core/things/provider.rb +29 -0
  70. data/lib/openhab/core/things/proxy.rb +87 -0
  71. data/lib/openhab/core/things/registry.rb +73 -0
  72. data/lib/openhab/core/things/thing.rb +194 -0
  73. data/lib/openhab/core/things.rb +22 -0
  74. data/lib/openhab/core/timer.rb +148 -0
  75. data/lib/openhab/{dsl → core}/types/comparable_type.rb +5 -3
  76. data/lib/openhab/{dsl → core}/types/date_time_type.rb +55 -127
  77. data/lib/openhab/{dsl → core}/types/decimal_type.rb +50 -48
  78. data/lib/openhab/{dsl → core}/types/hsb_type.rb +35 -83
  79. data/lib/openhab/core/types/increase_decrease_type.rb +34 -0
  80. data/lib/openhab/core/types/next_previous_type.rb +34 -0
  81. data/lib/openhab/{dsl → core}/types/numeric_type.rb +20 -7
  82. data/lib/openhab/core/types/on_off_type.rb +46 -0
  83. data/lib/openhab/core/types/open_closed_type.rb +41 -0
  84. data/lib/openhab/{dsl → core}/types/percent_type.rb +19 -20
  85. data/lib/openhab/core/types/play_pause_type.rb +38 -0
  86. data/lib/openhab/core/types/point_type.rb +117 -0
  87. data/lib/openhab/core/types/quantity_type.rb +325 -0
  88. data/lib/openhab/core/types/raw_type.rb +26 -0
  89. data/lib/openhab/core/types/refresh_type.rb +27 -0
  90. data/lib/openhab/core/types/rewind_fastforward_type.rb +38 -0
  91. data/lib/openhab/core/types/stop_move_type.rb +34 -0
  92. data/lib/openhab/{dsl → core}/types/string_type.rb +17 -28
  93. data/lib/openhab/{dsl → core}/types/type.rb +42 -40
  94. data/lib/openhab/core/types/un_def_type.rb +38 -0
  95. data/lib/openhab/core/types/up_down_type.rb +50 -0
  96. data/lib/openhab/core/types.rb +82 -0
  97. data/lib/openhab/{dsl → core}/uid.rb +4 -23
  98. data/lib/openhab/core/value_cache.rb +188 -0
  99. data/lib/openhab/core.rb +98 -0
  100. data/lib/openhab/core_ext/between.rb +32 -0
  101. data/lib/openhab/core_ext/ephemeris.rb +53 -0
  102. data/lib/openhab/core_ext/java/class.rb +34 -0
  103. data/lib/openhab/core_ext/java/duration.rb +142 -0
  104. data/lib/openhab/core_ext/java/list.rb +436 -0
  105. data/lib/openhab/core_ext/java/local_date.rb +104 -0
  106. data/lib/openhab/core_ext/java/local_time.rb +118 -0
  107. data/lib/openhab/core_ext/java/map.rb +66 -0
  108. data/lib/openhab/core_ext/java/month.rb +71 -0
  109. data/lib/openhab/core_ext/java/month_day.rb +119 -0
  110. data/lib/openhab/core_ext/java/period.rb +103 -0
  111. data/lib/openhab/core_ext/java/temporal_amount.rb +34 -0
  112. data/lib/openhab/core_ext/java/time.rb +62 -0
  113. data/lib/openhab/core_ext/java/unit.rb +15 -0
  114. data/lib/openhab/core_ext/java/zoned_date_time.rb +213 -0
  115. data/lib/openhab/core_ext/ruby/array.rb +21 -0
  116. data/lib/openhab/core_ext/ruby/date.rb +96 -0
  117. data/lib/openhab/core_ext/ruby/date_time.rb +55 -0
  118. data/lib/openhab/core_ext/ruby/module.rb +15 -0
  119. data/lib/openhab/core_ext/ruby/numeric.rb +195 -0
  120. data/lib/openhab/core_ext/ruby/range.rb +70 -0
  121. data/lib/openhab/core_ext/ruby/symbol.rb +7 -0
  122. data/lib/openhab/core_ext/ruby/time.rb +108 -0
  123. data/lib/openhab/core_ext.rb +18 -0
  124. data/lib/openhab/dsl/debouncer.rb +259 -0
  125. data/lib/openhab/dsl/events/watch_event.rb +18 -0
  126. data/lib/openhab/dsl/events.rb +9 -0
  127. data/lib/openhab/dsl/gems.rb +1 -1
  128. data/lib/openhab/dsl/items/builder.rb +578 -0
  129. data/lib/openhab/dsl/items/ensure.rb +73 -82
  130. data/lib/openhab/dsl/items/timed_command.rb +214 -159
  131. data/lib/openhab/dsl/rules/automation_rule.rb +129 -116
  132. data/lib/openhab/dsl/rules/builder.rb +1935 -0
  133. data/lib/openhab/dsl/rules/guard.rb +51 -114
  134. data/lib/openhab/dsl/rules/name_inference.rb +66 -25
  135. data/lib/openhab/dsl/rules/property.rb +48 -75
  136. data/lib/openhab/dsl/rules/rule_triggers.rb +22 -27
  137. data/lib/openhab/dsl/rules/terse.rb +58 -14
  138. data/lib/openhab/dsl/rules/triggers/changed.rb +48 -94
  139. data/lib/openhab/dsl/rules/triggers/channel.rb +9 -40
  140. data/lib/openhab/dsl/rules/triggers/command.rb +14 -63
  141. data/lib/openhab/dsl/rules/triggers/conditions/duration.rb +34 -69
  142. data/lib/openhab/dsl/rules/triggers/conditions/proc.rb +6 -14
  143. data/lib/openhab/dsl/rules/triggers/cron/cron.rb +48 -82
  144. data/lib/openhab/dsl/rules/triggers/cron/cron_handler.rb +30 -47
  145. data/lib/openhab/dsl/rules/triggers/trigger.rb +7 -28
  146. data/lib/openhab/dsl/rules/triggers/updated.rb +21 -45
  147. data/lib/openhab/dsl/rules/triggers/watch/watch_handler.rb +257 -102
  148. data/lib/openhab/dsl/rules/triggers.rb +12 -0
  149. data/lib/openhab/dsl/rules.rb +8 -0
  150. data/lib/openhab/dsl/things/builder.rb +299 -0
  151. data/lib/openhab/{core → dsl}/thread_local.rb +27 -17
  152. data/lib/openhab/dsl/timer_manager.rb +204 -0
  153. data/lib/openhab/dsl/version.rb +9 -0
  154. data/lib/openhab/dsl.rb +979 -0
  155. data/lib/openhab/log.rb +355 -0
  156. data/lib/openhab/osgi.rb +68 -0
  157. data/lib/openhab/rspec/configuration.rb +56 -0
  158. data/lib/openhab/rspec/example_group.rb +132 -0
  159. data/lib/openhab/rspec/helpers.rb +458 -0
  160. data/lib/openhab/rspec/hooks.rb +113 -0
  161. data/lib/openhab/rspec/jruby.rb +46 -0
  162. data/lib/openhab/rspec/karaf.rb +851 -0
  163. data/lib/openhab/rspec/mocks/bundle_install_support.rb +25 -0
  164. data/lib/openhab/rspec/mocks/bundle_resolver.rb +30 -0
  165. data/lib/openhab/rspec/mocks/event_admin.rb +146 -0
  166. data/lib/openhab/rspec/mocks/instance_method_stasher.rb +22 -0
  167. data/lib/openhab/rspec/mocks/persistence_service.rb +155 -0
  168. data/lib/openhab/rspec/mocks/safe_caller.rb +40 -0
  169. data/lib/openhab/rspec/mocks/space.rb +23 -0
  170. data/lib/openhab/rspec/mocks/synchronous_executor.rb +63 -0
  171. data/lib/openhab/rspec/mocks/thing_handler.rb +76 -0
  172. data/lib/openhab/rspec/mocks/timer.rb +134 -0
  173. data/lib/openhab/rspec/openhab/core/actions.rb +38 -0
  174. data/lib/openhab/rspec/openhab/core/items/proxy.rb +15 -0
  175. data/lib/openhab/rspec/openhab/core/things/proxy.rb +27 -0
  176. data/lib/openhab/rspec/shell.rb +31 -0
  177. data/lib/openhab/rspec/suspend_rules.rb +50 -0
  178. data/lib/openhab/rspec.rb +26 -0
  179. data/lib/openhab/yard/base_helper.rb +19 -0
  180. data/lib/openhab/yard/cli/stats.rb +23 -0
  181. data/lib/openhab/yard/code_objects/group_object.rb +23 -0
  182. data/lib/openhab/yard/code_objects/java/base.rb +31 -0
  183. data/lib/openhab/yard/code_objects/java/class_object.rb +11 -0
  184. data/lib/openhab/yard/code_objects/java/field_object.rb +15 -0
  185. data/lib/openhab/yard/code_objects/java/interface_object.rb +15 -0
  186. data/lib/openhab/yard/code_objects/java/package_object.rb +11 -0
  187. data/lib/openhab/yard/code_objects/java/proxy.rb +23 -0
  188. data/lib/openhab/yard/coderay.rb +17 -0
  189. data/lib/openhab/yard/handlers/jruby/base.rb +58 -0
  190. data/lib/openhab/yard/handlers/jruby/class_handler.rb +18 -0
  191. data/lib/openhab/yard/handlers/jruby/constant_handler.rb +18 -0
  192. data/lib/openhab/yard/handlers/jruby/java_import_handler.rb +30 -0
  193. data/lib/openhab/yard/handlers/jruby/mixin_handler.rb +23 -0
  194. data/lib/openhab/yard/html_helper.rb +78 -0
  195. data/lib/openhab/yard/markdown_helper.rb +148 -0
  196. data/lib/openhab/yard/tags/constant_directive.rb +20 -0
  197. data/lib/openhab/yard/tags/group_directive.rb +24 -0
  198. data/lib/openhab/yard/tags/library.rb +3 -0
  199. data/lib/openhab/yard.rb +38 -0
  200. metadata +476 -106
  201. data/lib/openhab/core/item_proxy.rb +0 -29
  202. data/lib/openhab/core/load_path.rb +0 -19
  203. data/lib/openhab/core/openhab_setup.rb +0 -29
  204. data/lib/openhab/core/osgi.rb +0 -58
  205. data/lib/openhab/core/services.rb +0 -24
  206. data/lib/openhab/dsl/actions.rb +0 -114
  207. data/lib/openhab/dsl/between.rb +0 -25
  208. data/lib/openhab/dsl/channel.rb +0 -43
  209. data/lib/openhab/dsl/dsl.rb +0 -59
  210. data/lib/openhab/dsl/group.rb +0 -54
  211. data/lib/openhab/dsl/imports.rb +0 -21
  212. data/lib/openhab/dsl/items/color_item.rb +0 -76
  213. data/lib/openhab/dsl/items/comparable_item.rb +0 -62
  214. data/lib/openhab/dsl/items/contact_item.rb +0 -41
  215. data/lib/openhab/dsl/items/date_time_item.rb +0 -65
  216. data/lib/openhab/dsl/items/dimmer_item.rb +0 -65
  217. data/lib/openhab/dsl/items/generic_item.rb +0 -229
  218. data/lib/openhab/dsl/items/group_item.rb +0 -127
  219. data/lib/openhab/dsl/items/item_equality.rb +0 -59
  220. data/lib/openhab/dsl/items/item_registry.rb +0 -54
  221. data/lib/openhab/dsl/items/items.rb +0 -109
  222. data/lib/openhab/dsl/items/location_item.rb +0 -59
  223. data/lib/openhab/dsl/items/metadata.rb +0 -326
  224. data/lib/openhab/dsl/items/number_item.rb +0 -17
  225. data/lib/openhab/dsl/items/numeric_item.rb +0 -87
  226. data/lib/openhab/dsl/items/persistence.rb +0 -307
  227. data/lib/openhab/dsl/items/player_item.rb +0 -58
  228. data/lib/openhab/dsl/items/rollershutter_item.rb +0 -51
  229. data/lib/openhab/dsl/items/semantics/enumerable.rb +0 -91
  230. data/lib/openhab/dsl/items/semantics.rb +0 -227
  231. data/lib/openhab/dsl/items/string_item.rb +0 -51
  232. data/lib/openhab/dsl/items/switch_item.rb +0 -70
  233. data/lib/openhab/dsl/monkey_patch/actions/actions.rb +0 -4
  234. data/lib/openhab/dsl/monkey_patch/actions/script_thing_actions.rb +0 -39
  235. data/lib/openhab/dsl/monkey_patch/events/events.rb +0 -7
  236. data/lib/openhab/dsl/monkey_patch/events/item_command.rb +0 -85
  237. data/lib/openhab/dsl/monkey_patch/events/item_event.rb +0 -28
  238. data/lib/openhab/dsl/monkey_patch/events/item_state.rb +0 -61
  239. data/lib/openhab/dsl/monkey_patch/events/item_state_changed.rb +0 -60
  240. data/lib/openhab/dsl/monkey_patch/events/thing_status_info.rb +0 -33
  241. data/lib/openhab/dsl/monkey_patch/java/java.rb +0 -4
  242. data/lib/openhab/dsl/monkey_patch/java/local_time.rb +0 -44
  243. data/lib/openhab/dsl/monkey_patch/java/time_extensions.rb +0 -50
  244. data/lib/openhab/dsl/monkey_patch/java/zoned_date_time.rb +0 -45
  245. data/lib/openhab/dsl/monkey_patch/ruby/number.rb +0 -104
  246. data/lib/openhab/dsl/monkey_patch/ruby/ruby.rb +0 -6
  247. data/lib/openhab/dsl/monkey_patch/ruby/string.rb +0 -47
  248. data/lib/openhab/dsl/monkey_patch/ruby/time.rb +0 -61
  249. data/lib/openhab/dsl/openhab.rb +0 -30
  250. data/lib/openhab/dsl/persistence.rb +0 -27
  251. data/lib/openhab/dsl/rules/item_event.rb +0 -19
  252. data/lib/openhab/dsl/rules/rule.rb +0 -160
  253. data/lib/openhab/dsl/rules/rule_config.rb +0 -147
  254. data/lib/openhab/dsl/rules/triggers/generic.rb +0 -31
  255. data/lib/openhab/dsl/rules/triggers/triggers.rb +0 -11
  256. data/lib/openhab/dsl/rules/triggers/watch/watch.rb +0 -81
  257. data/lib/openhab/dsl/states.rb +0 -89
  258. data/lib/openhab/dsl/things.rb +0 -147
  259. data/lib/openhab/dsl/time/month_day.rb +0 -180
  260. data/lib/openhab/dsl/time/time_of_day.rb +0 -235
  261. data/lib/openhab/dsl/timers/manager.rb +0 -119
  262. data/lib/openhab/dsl/timers/reentrant_timer.rb +0 -38
  263. data/lib/openhab/dsl/timers/timer.rb +0 -132
  264. data/lib/openhab/dsl/timers.rb +0 -77
  265. data/lib/openhab/dsl/types/increase_decrease_type.rb +0 -23
  266. data/lib/openhab/dsl/types/next_previous_type.rb +0 -23
  267. data/lib/openhab/dsl/types/on_off_type.rb +0 -28
  268. data/lib/openhab/dsl/types/open_closed_type.rb +0 -29
  269. data/lib/openhab/dsl/types/play_pause_type.rb +0 -27
  270. data/lib/openhab/dsl/types/point_type.rb +0 -180
  271. data/lib/openhab/dsl/types/quantity_type.rb +0 -265
  272. data/lib/openhab/dsl/types/refresh_type.rb +0 -18
  273. data/lib/openhab/dsl/types/rewind_fastforward_type.rb +0 -33
  274. data/lib/openhab/dsl/types/stop_move_type.rb +0 -23
  275. data/lib/openhab/dsl/types/types.rb +0 -83
  276. data/lib/openhab/dsl/types/un_def_type.rb +0 -22
  277. data/lib/openhab/dsl/types/up_down_type.rb +0 -32
  278. data/lib/openhab/dsl/units.rb +0 -45
  279. data/lib/openhab/log/configuration.rb +0 -21
  280. data/lib/openhab/log/logger.rb +0 -282
  281. data/lib/openhab/version.rb +0 -9
  282. data/lib/openhab.rb +0 -38
@@ -1,23 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'java'
4
- require_relative 'percent_type'
3
+ require_relative "percent_type"
4
+
5
+ require_relative "type"
5
6
 
6
7
  module OpenHAB
7
- module DSL
8
+ module Core
8
9
  module Types
9
10
  HSBType = org.openhab.core.library.types.HSBType
10
11
 
11
- # global alias - required for jrubyscripting addon <= OH3.2.0
12
- ::HSBType = HSBType if ::HSBType.is_a?(java.lang.Class)
13
-
14
- # Adds methods to core OpenHAB HSBType to make it more natural in Ruby
12
+ # {HSBType} is a complex type with constituents for hue, saturation and
13
+ # brightness and can be used for color items.
15
14
  class HSBType < PercentType
16
- # @!parse BLACK = BLACK # @return [HSBType]
17
- # @!parse WHITE = WHITE # @return [HSBType]
18
- # @!parse RED = RED # @return [HSBType]
19
- # @!parse GREEN = GREEN # @return [HSBType]
20
- # @!parse BLUE = BLUE # @return [HSBType]
15
+ # @!constant BLACK
16
+ # @return [HSBType]
17
+ # @!constant WHITE
18
+ # @return [HSBType]
19
+ # @!constant RED
20
+ # @return [HSBType]
21
+ # @!constant GREEN
22
+ # @return [HSBType]
23
+ # @!constant BLUE
24
+ # @return [HSBType]
21
25
 
22
26
  # conversion to QuantityType doesn't make sense on HSBType
23
27
  undef_method :|
@@ -53,11 +57,11 @@ module OpenHAB
53
57
 
54
58
  # add additional "overloads" to the constructor
55
59
  # @!visibility private
56
- def new(*args) # rubocop:disable Metrics
60
+ def new(*args)
57
61
  if args.length == 1 && args.first.respond_to?(:to_str)
58
62
  value = args.first.to_str
59
63
 
60
- # parse some formats OpenHAB doesn't understand
64
+ # parse some formats openHAB doesn't understand
61
65
  # in this case, HTML hex format for rgb
62
66
  if (match = value.match(/^#(\h{2})(\h{2})(\h{2})$/))
63
67
  rgb = match.to_a[1..3].map { |v| v.to_i(16) }
@@ -73,12 +77,12 @@ module OpenHAB
73
77
  return super unless args.length == 3
74
78
 
75
79
  # convert from several numeric-like types to the exact types
76
- # OpenHAB needs
80
+ # openHAB needs
77
81
  hue = args[0]
78
82
  args[0] = if hue.is_a?(DecimalType)
79
83
  hue
80
84
  elsif hue.is_a?(QuantityType)
81
- DecimalType.new(hue.to_unit(org.openhab.core.library.unit.Units::DEGREE_ANGLE).to_big_decimal)
85
+ DecimalType.new(hue.to_unit(Units::DEGREE_ANGLE).to_big_decimal)
82
86
  elsif hue.respond_to?(:to_d)
83
87
  DecimalType.new(hue)
84
88
  end
@@ -97,49 +101,18 @@ module OpenHAB
97
101
  #
98
102
  # Comparison
99
103
  #
100
- # @param [NumericType, Items::NumericItem, Items::ColorItem, Numeric, String]
104
+ # @param [NumericType, Numeric]
101
105
  # other object to compare to
102
106
  #
103
- # @return [Integer, nil] -1, 0, +1 depending on whether +other+ is
107
+ # @return [Integer, nil] -1, 0, +1 depending on whether `other` is
104
108
  # less than, equal to, or greater than self
105
109
  #
106
- # nil is returned if the two values are incomparable
110
+ # `nil` is returned if the two values are incomparable.
107
111
  #
108
- def <=>(other) # rubocop:disable Metrics
112
+ def <=>(other)
109
113
  logger.trace("(#{self.class}) #{self} <=> #{other} (#{other.class})")
110
- if other.is_a?(Items::ColorItem) ||
111
- (other.is_a?(Items::GroupItem) && other.base_item.is_a?(ColorItem))
112
- return nil unless other.state?
113
-
114
- self <=> other.state
115
- elsif other.is_a?(HSBType)
116
- to_a <=> other.to_a
117
- elsif other.respond_to?(:to_str)
118
- self <=> HSBType.new(other)
119
- else
120
- super
121
- end
122
- end
123
-
124
- #
125
- # Type Coercion
126
- #
127
- # Coerce object to a HSBType
128
- #
129
- # @param [NumericType, Items::NumericItem, Items::ColorItem, Numeric, String]
130
- # other object to coerce to a HSBType
131
- #
132
- # @return [[HSBType, HSBType]]
133
- #
134
- def coerce(other)
135
- logger.trace("Coercing #{self} as a request from #{other.class}")
136
- if other.is_a?(Items::NumericItem) ||
137
- (other.is_a?(Items::GroupItem) && other.base_item.is_a?(Items::NumericItem))
138
- return unless other.state?
139
-
140
- [other.state, self]
141
- elsif other.respond_to?(:to_str)
142
- [HSBType.new(other.to_str), self]
114
+ if other.is_a?(HSBType)
115
+ [brightness, hue, saturation] <=> [other.brightness, other.hue, other.saturation]
143
116
  else
144
117
  super
145
118
  end
@@ -147,12 +120,12 @@ module OpenHAB
147
120
 
148
121
  # rename raw methods so we can overwrite them
149
122
  # @!visibility private
150
- alias raw_hue hue
123
+ alias_method :raw_hue, :hue
151
124
 
152
125
  # @!attribute [r] hue
153
- # @return [QuantityType]
126
+ # @return [QuantityType] The color's hue component as a {QuantityType} of unit DEGREE_ANGLE.
154
127
  def hue
155
- QuantityType.new(raw_hue.to_big_decimal, org.openhab.core.library.unit.Units::DEGREE_ANGLE)
128
+ QuantityType.new(raw_hue.to_big_decimal, Units::DEGREE_ANGLE)
156
129
  end
157
130
 
158
131
  # Convert to a packed 32-bit RGB value representing the color in the default sRGB color model.
@@ -160,7 +133,7 @@ module OpenHAB
160
133
  # The alpha component is always 100%.
161
134
  #
162
135
  # @return [Integer]
163
- alias argb rgb
136
+ alias_method :argb, :rgb
164
137
 
165
138
  # Convert to a packed 24-bit RGB value representing the color in the default sRGB color model.
166
139
  # @return [Integer]
@@ -169,9 +142,9 @@ module OpenHAB
169
142
  end
170
143
 
171
144
  # Convert to an HTML-style string of 6 hex characters in the default sRGB color model.
172
- # @return [String] +'#xxxxxx'+
145
+ # @return [String] `"#xxxxxx"`
173
146
  def to_hex
174
- Kernel.format('#%06x', rgb)
147
+ Kernel.format("#%06x", rgb)
175
148
  end
176
149
 
177
150
  # include units
@@ -180,29 +153,6 @@ module OpenHAB
180
153
  "#{hue},#{saturation},#{brightness}"
181
154
  end
182
155
 
183
- #
184
- # Convert the ColorItem to a hash
185
- # @param [:hsb, :rgb] format for hash
186
- # @return [Hash] in requested format
187
- def to_h(format = :hsb)
188
- values = to_a(format)
189
- keys = (format == :hsb ? %i[hue saturation brightness] : %i[red green blue])
190
- keys.zip(values).to_h
191
- end
192
-
193
- #
194
- # Convert the ColorItem to an array of values
195
- # @param [:hsb, :rgb] format for elements in the array
196
- # @return [Array] of ColorItem components in requested format
197
- def to_a(format = :hsb)
198
- case format
199
- when :hsb then [hue, saturation, brightness]
200
- when :rgb then [red, green, blue].map(&:to_byte)
201
- else
202
- raise ArgumentError, "Unsupported format #{format}"
203
- end
204
- end
205
-
206
156
  # @!attribute [r] saturation
207
157
  # @return [PercentType]
208
158
 
@@ -224,8 +174,10 @@ module OpenHAB
224
174
 
225
175
  # @!method to_xy
226
176
  # Convert to the xyY values representing this object's color in CIE XY color model
227
- # @return [[PercentType, PercentType]]
177
+ # @return [[PercentType, PercentType, PercentType]]
228
178
  end
229
179
  end
230
180
  end
231
181
  end
182
+
183
+ # @!parse HSBType = OpenHAB::Core::Types::HSBType
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "type"
4
+
5
+ module OpenHAB
6
+ module Core
7
+ module Types
8
+ IncreaseDecreaseType = org.openhab.core.library.types.IncreaseDecreaseType
9
+
10
+ # Represents {INCREASE} and {DECREASE} commands.
11
+ class IncreaseDecreaseType # rubocop:disable Lint/EmptyClass
12
+ # @!parse include Command
13
+
14
+ # @!constant INCREASE
15
+ # Increase Command
16
+ # @!constant DECREASE
17
+ # Decrease Command
18
+
19
+ # @!method increase?
20
+ # Check if `self == INCREASE`
21
+ # @return [true,false]
22
+
23
+ # @!method decrease?
24
+ # Check if `self == DECREASE`
25
+ # @return [true,false]
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ # @!parse
32
+ # IncreaseDecreaseType = OpenHAB::Core::Types::IncreaseDecreaseType
33
+ # INCREASE = OpenHAB::Core::Types::IncreaseDecreaseType::INCREASE
34
+ # DECREASE = OpenHAB::Core::Types::IncreaseDecreaseType::DECREASE
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "type"
4
+
5
+ module OpenHAB
6
+ module Core
7
+ module Types
8
+ NextPreviousType = org.openhab.core.library.types.NextPreviousType
9
+
10
+ # Implements {NEXT} and {PREVIOUS} commands.
11
+ class NextPreviousType # rubocop:disable Lint/EmptyClass
12
+ # @!parse include Command
13
+
14
+ # @!constant NEXT
15
+ # Next Command
16
+ # @!constant PREVIOUS
17
+ # Previous Command
18
+
19
+ # @!method next?
20
+ # Check if `self == NEXT`
21
+ # @return [true,false]
22
+
23
+ # @!method previous?
24
+ # Check if `self == PREVIOUS`
25
+ # @return [true,false]
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ # @!parse
32
+ # NextPreviousType = OpenHAB::Core::Types::NextPreviousType
33
+ # NEXT = OpenHAB::Core::Types::NextPreviousType::NEXT
34
+ # PREVIOUS = OpenHAB::Core::Types::NextPreviousType::PREVIOUS
@@ -1,19 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bigdecimal'
4
- require 'forwardable'
3
+ require "bigdecimal"
4
+ require "bigdecimal/util"
5
+ require "forwardable"
6
+
7
+ require_relative "type"
5
8
 
6
9
  module OpenHAB
7
- module DSL
10
+ module Core
8
11
  module Types
9
- # Mixin for methods common to DecimalType and QuantityType
12
+ # Mixin for methods common to DecimalType and QuantityType.
10
13
  module NumericType
11
- # apply meta-programming to including class
14
+ # @!visibility private
12
15
  def self.included(klass)
13
16
  klass.extend Forwardable
14
17
 
15
18
  klass.delegate %i[to_d zero?] => :to_big_decimal
16
19
  klass.delegate %i[positive? negative? to_f to_i to_int hash] => :to_d
20
+
17
21
  # remove the JRuby default == so that we can inherit the Ruby method
18
22
  klass.remove_method :==
19
23
  end
@@ -21,7 +25,7 @@ module OpenHAB
21
25
  #
22
26
  # Check equality without type conversion
23
27
  #
24
- # @return [Boolean] if the same value is represented, without type
28
+ # @return [true,false] if the same value is represented, without type
25
29
  # conversion
26
30
  def eql?(other)
27
31
  return false unless other.instance_of?(self.class)
@@ -29,10 +33,19 @@ module OpenHAB
29
33
  compare_to(other).zero?
30
34
  end
31
35
 
32
- # Unary plus
36
+ # @return [self]
33
37
  def +@
34
38
  self
35
39
  end
40
+
41
+ # @!method to_d
42
+ # @return [BigDecimal]
43
+
44
+ # @!method to_i
45
+ # @return [Integer]
46
+
47
+ # @!method to_f
48
+ # @return [Float]
36
49
  end
37
50
  end
38
51
  end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "type"
4
+
5
+ module OpenHAB
6
+ module Core
7
+ module Types
8
+ OnOffType = org.openhab.core.library.types.OnOffType
9
+
10
+ #
11
+ # Implements {ON} and {OFF} commands and states.
12
+ #
13
+ # Also, {PercentType} can be converted to {OnOffType}
14
+ # for more semantic comparisons. `0` is {OFF}, anything
15
+ # else if {ON}.
16
+ #
17
+ class OnOffType
18
+ # @!parse include Command, State
19
+
20
+ # @!constant ON
21
+ # On Command/State
22
+ # @!constant OFF
23
+ # Off Command/State
24
+
25
+ # @!method on?
26
+ # Check if `self == ON`
27
+ # @return [true,false]
28
+
29
+ # @!method off?
30
+ # Check if `self == OFF`
31
+ # @return [true,false]
32
+
33
+ # Invert the type
34
+ # @return [OnOffType] {OFF} if {on?}, {ON} if {off?}
35
+ def !
36
+ on? ? OFF : ON
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ # @!parse
44
+ # OnOffType = OpenHAB::Core::Types::OnOffType
45
+ # ON = OpenHAB::Core::Types::OnOffType::ON
46
+ # OFF = OpenHAB::Core::Types::OnOffType::OFF
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "type"
4
+
5
+ module OpenHAB
6
+ module Core
7
+ module Types
8
+ OpenClosedType = org.openhab.core.library.types.OpenClosedType
9
+
10
+ # Implements {OPEN} and {CLOSED} states.
11
+ class OpenClosedType
12
+ # @!parse include State
13
+
14
+ # @!constant OPEN
15
+ # Open State
16
+ # @!constant CLOSED
17
+ # Closed State
18
+
19
+ # @!method open?
20
+ # Check if `self == OPEN`
21
+ # @return [true,false]
22
+
23
+ # @!method closed?
24
+ # Check if `self == CLOSED`
25
+ # @return [true,false]
26
+
27
+ # Invert the type
28
+ # @return [OpenClosedType] {OPEN} if {closed?}, {CLOSED} if {open?}
29
+ def !
30
+ return CLOSED if open?
31
+ return OPEN if closed?
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ # @!parse
39
+ # OpenClosedType = OpenHAB::Core::Types::OpenClosedType
40
+ # OPEN = OpenHAB::Core::Types::OpenClosedType::OPEN
41
+ # CLOSED = OpenHAB::Core::Types::OpenClosedType::CLOSED
@@ -1,59 +1,56 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'decimal_type'
3
+ require_relative "decimal_type"
4
4
 
5
5
  module OpenHAB
6
- module DSL
6
+ module Core
7
7
  module Types
8
8
  PercentType = org.openhab.core.library.types.PercentType
9
9
 
10
- # global alias - required for jrubyscripting addon <= OH3.2.0
11
- ::PercentType = PercentType if ::PercentType.is_a?(java.lang.Class)
12
-
13
- # Adds methods to core OpenHAB PercentType to make it more natural in Ruby
10
+ # {PercentType} extends {DecimalType} by putting constraints for its value on top (0-100).
14
11
  class PercentType < DecimalType
15
12
  # remove the JRuby default == so that we can inherit the Ruby method
16
13
  remove_method :==
17
14
 
18
15
  #
19
- # Check if +ON+
16
+ # Check if {ON}
20
17
  #
21
- # Note that +ON+ is defined as any value besides 0%.
18
+ # Note that {ON} is defined as any value besides 0%.
22
19
  #
23
- # @return [Boolean]
20
+ # @return [true,false]
24
21
  #
25
22
  def on?
26
23
  as(OnOffType).on?
27
24
  end
28
25
 
29
26
  #
30
- # Check if +OFF+
27
+ # Check if {OFF}
31
28
  #
32
- # Note that +OFF+ is defined as 0% exactly.
29
+ # Note that {OFF} is defined as 0% exactly.
33
30
  #
34
- # @return [Boolean]
31
+ # @return [true,false]
35
32
  #
36
33
  def off?
37
34
  as(OnOffType).off?
38
35
  end
39
36
 
40
37
  #
41
- # Check if +UP+
38
+ # Check if {UP}
42
39
  #
43
- # Note that +UP+ is defined as 0% exactly.
40
+ # Note that {UP} is defined as 0% exactly.
44
41
  #
45
- # @return [Boolean]
42
+ # @return [true,false]
46
43
  #
47
44
  def up?
48
45
  !!as(UpDownType)&.up?
49
46
  end
50
47
 
51
48
  #
52
- # Check if +DOWN+
49
+ # Check if {DOWN}
53
50
  #
54
- # Note that +DOWN+ is defined as 100% exactly.
51
+ # Note that {DOWN} is defined as 100% exactly.
55
52
  #
56
- # @return [Boolean]
53
+ # @return [true,false]
57
54
  #
58
55
  def down?
59
56
  !!as(UpDownType)&.down?
@@ -71,9 +68,9 @@ module OpenHAB
71
68
  # @param range [Range] the range as a numeric
72
69
  # @return [Numeric] the value as a percentage of the range
73
70
  #
74
- def scale(range) # rubocop:disable Metrics/AbcSize
71
+ def scale(range)
75
72
  unless range.is_a?(Range) && range.min.is_a?(Numeric) && range.max.is_a?(Numeric)
76
- raise ArgumentError, 'range must be a Range of Numerics'
73
+ raise ArgumentError, "range must be a Range of Numerics"
77
74
  end
78
75
 
79
76
  result = (to_d * (range.max - range.min) / 100) + range.min
@@ -94,3 +91,5 @@ module OpenHAB
94
91
  end
95
92
  end
96
93
  end
94
+
95
+ # @!parse PercentType = OpenHAB::Core::Types::PercentType
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "type"
4
+
5
+ module OpenHAB
6
+ module Core
7
+ module Types
8
+ PlayPauseType = org.openhab.core.library.types.PlayPauseType
9
+
10
+ # Implements {PLAY} and {PAUSE} commands and states.
11
+ class PlayPauseType # rubocop:disable Lint/EmptyClass
12
+ # @!parse include Command, State
13
+
14
+ # @!constant PLAY
15
+ # Play Command/Playing State
16
+ # @!constant PAUSE
17
+ # Pause Command/Paused State
18
+
19
+ # @!method playing?
20
+ # Check if `self == PLAY`
21
+ # @return [true,false]
22
+
23
+ # @!parse alias play? playing?
24
+
25
+ # @!method paused?
26
+ # Check if `self == PAUSE`
27
+ # @return [true,false]
28
+
29
+ # @!parse alias pause? paused?
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ # @!parse
36
+ # PlayPauseType = OpenHAB::Core::Types::PlayPauseType
37
+ # PLAY = OpenHAB::Core::Types::PlayPauseType::PLAY
38
+ # PAUSE = OpenHAB::Core::Types::PlayPauseType::PAUSE
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "type"
4
+
5
+ module OpenHAB
6
+ module Core
7
+ module Types
8
+ PointType = org.openhab.core.library.types.PointType
9
+
10
+ # {PointType} can be used for items that are dealing with GPS or location awareness functionality.
11
+ class PointType
12
+ # @!parse include Command, State
13
+
14
+ # @overload initialize(latitude, longitude, altitude)
15
+ # @param [DecimalType, QuantityType, StringType, Numeric] latitude
16
+ # @param [DecimalType, QuantityType, StringType, Numeric] longitude
17
+ # @param [DecimalType, QuantityType, StringType, Numeric] altitude
18
+ def initialize(*args)
19
+ if (2..3).cover?(args.length)
20
+ args = args.each_with_index.map do |value, index|
21
+ if value.is_a?(DecimalType) || value.is_a?(StringType)
22
+ value
23
+ elsif value.is_a?(QuantityType)
24
+ unit = (index == 2) ? DSL.unit(SIUnits::METRE.dimension) || SIUnits::METRE : Units::DEGREE_ANGLE
25
+ DecimalType.new(value.to_unit(unit).to_big_decimal)
26
+ elsif value.respond_to?(:to_str)
27
+ StringType.new(value.to_str)
28
+ elsif value.respond_to?(:to_d)
29
+ DecimalType.new(value)
30
+ end
31
+ end
32
+ end
33
+
34
+ super(*args)
35
+ end
36
+
37
+ #
38
+ # Check equality without type conversion
39
+ #
40
+ # @return [true,false] if the same value is represented, without type
41
+ # conversion
42
+ def eql?(other)
43
+ return false unless other.instance_of?(self.class)
44
+
45
+ equals(other)
46
+ end
47
+
48
+ #
49
+ # Check equality with type conversion
50
+ #
51
+ # @param [PointType, String]
52
+ # other object to compare to
53
+ #
54
+ # @return [true,false]
55
+ #
56
+ def ==(other)
57
+ logger.trace { "(#{self.class}) #{self} == #{other} (#{other.class})" }
58
+ if other.instance_of?(self.class)
59
+ equals(other)
60
+ elsif other.respond_to?(:coerce)
61
+ return false unless (lhs, rhs = other.coerce(self))
62
+
63
+ lhs == rhs
64
+ end
65
+ end
66
+
67
+ # rename raw methods so we can overwrite them
68
+ # @!visibility private
69
+ alias_method :raw_latitude, :latitude
70
+ # .
71
+ # @!visibility private
72
+ alias_method :raw_longitude, :longitude
73
+ # .
74
+ # @!visibility private
75
+ alias_method :raw_altitude, :altitude
76
+ # .
77
+ # @!visibility private
78
+ alias_method :raw_distance_from, :distance_from
79
+
80
+ # @!attribute [r] latitude
81
+ # @return [QuantityType]
82
+ def latitude
83
+ QuantityType.new(raw_latitude.to_big_decimal, SIUnits::DEGREE_ANGLE)
84
+ end
85
+
86
+ # @!attribute [r] longitude
87
+ # @return [QuantityType]
88
+ def longitude
89
+ QuantityType.new(raw_longitude.to_big_decimal, SIUnits::DEGREE_ANGLE)
90
+ end
91
+
92
+ # @!attribute [r] altitude
93
+ # @return [QuantityType]
94
+ def altitude
95
+ QuantityType.new(raw_altitude.to_big_decimal, Units::METRE)
96
+ end
97
+
98
+ #
99
+ # Calculate the distance in meters from other, ignoring altitude.
100
+ #
101
+ # This algorithm also ignores the oblate spheroid shape of Earth and
102
+ # assumes a perfect sphere, so results are inexact.
103
+ #
104
+ # @return [QuantityType]
105
+ def distance_from(other)
106
+ logger.trace("(#{self}).distance_from(#{other} (#{other.class})")
107
+ raise TypeError, "#{other.class} can't be coerced into #{self.class}" unless other.is_a?(PointType)
108
+
109
+ QuantityType.new(raw_distance_from(other), SIUnits::METRE)
110
+ end
111
+ alias_method :-, :distance_from
112
+ end
113
+ end
114
+ end
115
+ end
116
+
117
+ # @!parse PointType = OpenHAB::Core::Types::PointType