openhab-jrubyscripting 5.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. checksums.yaml +7 -0
  2. data/lib/openhab/core/actions.rb +163 -0
  3. data/lib/openhab/core/entity_lookup.rb +144 -0
  4. data/lib/openhab/core/events/abstract_event.rb +17 -0
  5. data/lib/openhab/core/events/item_channel_link.rb +36 -0
  6. data/lib/openhab/core/events/item_command_event.rb +78 -0
  7. data/lib/openhab/core/events/item_event.rb +22 -0
  8. data/lib/openhab/core/events/item_state_changed_event.rb +52 -0
  9. data/lib/openhab/core/events/item_state_event.rb +51 -0
  10. data/lib/openhab/core/events/thing.rb +29 -0
  11. data/lib/openhab/core/events/thing_status_info_event.rb +53 -0
  12. data/lib/openhab/core/events.rb +10 -0
  13. data/lib/openhab/core/items/accepted_data_types.rb +29 -0
  14. data/lib/openhab/core/items/color_item.rb +52 -0
  15. data/lib/openhab/core/items/contact_item.rb +52 -0
  16. data/lib/openhab/core/items/date_time_item.rb +58 -0
  17. data/lib/openhab/core/items/dimmer_item.rb +148 -0
  18. data/lib/openhab/core/items/generic_item.rb +344 -0
  19. data/lib/openhab/core/items/group_item.rb +174 -0
  20. data/lib/openhab/core/items/image_item.rb +109 -0
  21. data/lib/openhab/core/items/location_item.rb +34 -0
  22. data/lib/openhab/core/items/metadata/hash.rb +390 -0
  23. data/lib/openhab/core/items/metadata/namespace_hash.rb +469 -0
  24. data/lib/openhab/core/items/metadata.rb +11 -0
  25. data/lib/openhab/core/items/number_item.rb +62 -0
  26. data/lib/openhab/core/items/numeric_item.rb +22 -0
  27. data/lib/openhab/core/items/persistence.rb +327 -0
  28. data/lib/openhab/core/items/player_item.rb +66 -0
  29. data/lib/openhab/core/items/proxy.rb +59 -0
  30. data/lib/openhab/core/items/registry.rb +66 -0
  31. data/lib/openhab/core/items/rollershutter_item.rb +68 -0
  32. data/lib/openhab/core/items/semantics/enumerable.rb +152 -0
  33. data/lib/openhab/core/items/semantics.rb +476 -0
  34. data/lib/openhab/core/items/state_storage.rb +53 -0
  35. data/lib/openhab/core/items/string_item.rb +28 -0
  36. data/lib/openhab/core/items/switch_item.rb +78 -0
  37. data/lib/openhab/core/items.rb +114 -0
  38. data/lib/openhab/core/lazy_array.rb +52 -0
  39. data/lib/openhab/core/profile_factory.rb +118 -0
  40. data/lib/openhab/core/script_handling.rb +55 -0
  41. data/lib/openhab/core/things/channel.rb +48 -0
  42. data/lib/openhab/core/things/channel_uid.rb +51 -0
  43. data/lib/openhab/core/things/item_channel_link.rb +33 -0
  44. data/lib/openhab/core/things/profile_callback.rb +52 -0
  45. data/lib/openhab/core/things/proxy.rb +69 -0
  46. data/lib/openhab/core/things/registry.rb +46 -0
  47. data/lib/openhab/core/things/thing.rb +194 -0
  48. data/lib/openhab/core/things.rb +22 -0
  49. data/lib/openhab/core/timer.rb +128 -0
  50. data/lib/openhab/core/types/comparable_type.rb +23 -0
  51. data/lib/openhab/core/types/date_time_type.rb +259 -0
  52. data/lib/openhab/core/types/decimal_type.rb +192 -0
  53. data/lib/openhab/core/types/hsb_type.rb +183 -0
  54. data/lib/openhab/core/types/increase_decrease_type.rb +34 -0
  55. data/lib/openhab/core/types/next_previous_type.rb +34 -0
  56. data/lib/openhab/core/types/numeric_type.rb +52 -0
  57. data/lib/openhab/core/types/on_off_type.rb +46 -0
  58. data/lib/openhab/core/types/open_closed_type.rb +41 -0
  59. data/lib/openhab/core/types/percent_type.rb +95 -0
  60. data/lib/openhab/core/types/play_pause_type.rb +38 -0
  61. data/lib/openhab/core/types/point_type.rb +117 -0
  62. data/lib/openhab/core/types/quantity_type.rb +327 -0
  63. data/lib/openhab/core/types/raw_type.rb +26 -0
  64. data/lib/openhab/core/types/refresh_type.rb +27 -0
  65. data/lib/openhab/core/types/rewind_fastforward_type.rb +38 -0
  66. data/lib/openhab/core/types/stop_move_type.rb +34 -0
  67. data/lib/openhab/core/types/string_type.rb +76 -0
  68. data/lib/openhab/core/types/type.rb +117 -0
  69. data/lib/openhab/core/types/un_def_type.rb +38 -0
  70. data/lib/openhab/core/types/up_down_type.rb +50 -0
  71. data/lib/openhab/core/types.rb +69 -0
  72. data/lib/openhab/core/uid.rb +36 -0
  73. data/lib/openhab/core.rb +85 -0
  74. data/lib/openhab/core_ext/java/duration.rb +115 -0
  75. data/lib/openhab/core_ext/java/local_date.rb +93 -0
  76. data/lib/openhab/core_ext/java/local_time.rb +106 -0
  77. data/lib/openhab/core_ext/java/month.rb +59 -0
  78. data/lib/openhab/core_ext/java/month_day.rb +105 -0
  79. data/lib/openhab/core_ext/java/period.rb +103 -0
  80. data/lib/openhab/core_ext/java/temporal_amount.rb +34 -0
  81. data/lib/openhab/core_ext/java/time.rb +58 -0
  82. data/lib/openhab/core_ext/java/unit.rb +15 -0
  83. data/lib/openhab/core_ext/java/zoned_date_time.rb +116 -0
  84. data/lib/openhab/core_ext/ruby/array.rb +21 -0
  85. data/lib/openhab/core_ext/ruby/class.rb +15 -0
  86. data/lib/openhab/core_ext/ruby/date.rb +89 -0
  87. data/lib/openhab/core_ext/ruby/numeric.rb +190 -0
  88. data/lib/openhab/core_ext/ruby/range.rb +70 -0
  89. data/lib/openhab/core_ext/ruby/time.rb +104 -0
  90. data/lib/openhab/core_ext.rb +18 -0
  91. data/lib/openhab/dsl/events/watch_event.rb +18 -0
  92. data/lib/openhab/dsl/events.rb +9 -0
  93. data/lib/openhab/dsl/gems.rb +3 -0
  94. data/lib/openhab/dsl/items/builder.rb +618 -0
  95. data/lib/openhab/dsl/items/ensure.rb +93 -0
  96. data/lib/openhab/dsl/items/timed_command.rb +236 -0
  97. data/lib/openhab/dsl/rules/automation_rule.rb +308 -0
  98. data/lib/openhab/dsl/rules/builder.rb +1373 -0
  99. data/lib/openhab/dsl/rules/guard.rb +115 -0
  100. data/lib/openhab/dsl/rules/name_inference.rb +160 -0
  101. data/lib/openhab/dsl/rules/property.rb +76 -0
  102. data/lib/openhab/dsl/rules/rule_triggers.rb +96 -0
  103. data/lib/openhab/dsl/rules/terse.rb +63 -0
  104. data/lib/openhab/dsl/rules/triggers/changed.rb +169 -0
  105. data/lib/openhab/dsl/rules/triggers/channel.rb +57 -0
  106. data/lib/openhab/dsl/rules/triggers/command.rb +107 -0
  107. data/lib/openhab/dsl/rules/triggers/conditions/duration.rb +161 -0
  108. data/lib/openhab/dsl/rules/triggers/conditions/proc.rb +164 -0
  109. data/lib/openhab/dsl/rules/triggers/cron/cron.rb +195 -0
  110. data/lib/openhab/dsl/rules/triggers/cron/cron_handler.rb +127 -0
  111. data/lib/openhab/dsl/rules/triggers/trigger.rb +56 -0
  112. data/lib/openhab/dsl/rules/triggers/updated.rb +130 -0
  113. data/lib/openhab/dsl/rules/triggers/watch/watch.rb +55 -0
  114. data/lib/openhab/dsl/rules/triggers/watch/watch_handler.rb +155 -0
  115. data/lib/openhab/dsl/rules/triggers.rb +12 -0
  116. data/lib/openhab/dsl/rules.rb +29 -0
  117. data/lib/openhab/dsl/script_handling.rb +55 -0
  118. data/lib/openhab/dsl/things/builder.rb +263 -0
  119. data/lib/openhab/dsl/thread_local.rb +48 -0
  120. data/lib/openhab/dsl/timer_manager.rb +191 -0
  121. data/lib/openhab/dsl/version.rb +9 -0
  122. data/lib/openhab/dsl.rb +686 -0
  123. data/lib/openhab/log.rb +348 -0
  124. data/lib/openhab/osgi.rb +70 -0
  125. data/lib/openhab/rspec/configuration.rb +56 -0
  126. data/lib/openhab/rspec/example_group.rb +90 -0
  127. data/lib/openhab/rspec/helpers.rb +439 -0
  128. data/lib/openhab/rspec/hooks.rb +93 -0
  129. data/lib/openhab/rspec/jruby.rb +46 -0
  130. data/lib/openhab/rspec/karaf.rb +811 -0
  131. data/lib/openhab/rspec/mocks/bundle_install_support.rb +25 -0
  132. data/lib/openhab/rspec/mocks/bundle_resolver.rb +30 -0
  133. data/lib/openhab/rspec/mocks/event_admin.rb +146 -0
  134. data/lib/openhab/rspec/mocks/metadata_provider.rb +75 -0
  135. data/lib/openhab/rspec/mocks/persistence_service.rb +140 -0
  136. data/lib/openhab/rspec/mocks/safe_caller.rb +40 -0
  137. data/lib/openhab/rspec/mocks/synchronous_executor.rb +56 -0
  138. data/lib/openhab/rspec/mocks/thing_handler.rb +76 -0
  139. data/lib/openhab/rspec/mocks/timer.rb +95 -0
  140. data/lib/openhab/rspec/openhab/core/actions.rb +26 -0
  141. data/lib/openhab/rspec/openhab/core/items/proxy.rb +27 -0
  142. data/lib/openhab/rspec/openhab/core/things/proxy.rb +27 -0
  143. data/lib/openhab/rspec/shell.rb +31 -0
  144. data/lib/openhab/rspec/suspend_rules.rb +60 -0
  145. data/lib/openhab/rspec.rb +17 -0
  146. data/lib/openhab/yard/cli/stats.rb +23 -0
  147. data/lib/openhab/yard/code_objects/group_object.rb +17 -0
  148. data/lib/openhab/yard/code_objects/java/base.rb +31 -0
  149. data/lib/openhab/yard/code_objects/java/class_object.rb +11 -0
  150. data/lib/openhab/yard/code_objects/java/field_object.rb +15 -0
  151. data/lib/openhab/yard/code_objects/java/interface_object.rb +15 -0
  152. data/lib/openhab/yard/code_objects/java/package_object.rb +11 -0
  153. data/lib/openhab/yard/code_objects/java/proxy.rb +23 -0
  154. data/lib/openhab/yard/handlers/jruby/base.rb +49 -0
  155. data/lib/openhab/yard/handlers/jruby/class_handler.rb +18 -0
  156. data/lib/openhab/yard/handlers/jruby/constant_handler.rb +18 -0
  157. data/lib/openhab/yard/handlers/jruby/java_import_handler.rb +27 -0
  158. data/lib/openhab/yard/handlers/jruby/mixin_handler.rb +23 -0
  159. data/lib/openhab/yard/html_helper.rb +44 -0
  160. data/lib/openhab/yard/tags/constant_directive.rb +20 -0
  161. data/lib/openhab/yard/tags/group_directive.rb +24 -0
  162. data/lib/openhab/yard/tags/library.rb +3 -0
  163. data/lib/openhab/yard.rb +32 -0
  164. metadata +504 -0
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Extensions to Date
4
+ class Date
5
+ #
6
+ # Extends {#+} to allow adding a {java.time.temporal.TemporalAmount TemporalAmount}
7
+ #
8
+ # @param [java.time.temporal.TemporalAmount] other
9
+ # @return [LocalDate] If other is a {java.time.temporal.TemporalAmount TemporalAmount}
10
+ #
11
+ def plus_with_temporal(other)
12
+ return to_local_date + other if other.is_a?(java.time.temporal.TemporalAmount)
13
+
14
+ plus_without_temporal(other)
15
+ end
16
+ alias_method :plus_without_temporal, :+
17
+ alias_method :+, :plus_with_temporal
18
+
19
+ #
20
+ # Extends {#-} to allow subtracting a {java.time.temporal.TemporalAmount TemporalAmount}
21
+ #
22
+ # @param [java.time.temporal.TemporalAmount] other
23
+ # @return [LocalDate] If other is a {java.time.temporal.TemporalAmount TemporalAmount}
24
+ #
25
+ def minus_with_temporal(other)
26
+ case other
27
+ when java.time.temporal.TemporalAmount, java.time.LocalDate
28
+ to_local_date - other
29
+ else
30
+ minus_without_temporal(other)
31
+ end
32
+ end
33
+ alias_method :minus_without_temporal, :-
34
+ alias_method :-, :minus_with_temporal
35
+
36
+ # @return [LocalDate]
37
+ def to_local_date(_context = nil)
38
+ java.time.LocalDate.of(year, month, day)
39
+ end
40
+
41
+ # @return [Month]
42
+ def to_month
43
+ java.time.Month.of(month)
44
+ end
45
+
46
+ # @return [MonthDay]
47
+ def to_month_day
48
+ java.time.MonthDay.of(month, day)
49
+ end
50
+
51
+ # @param [ZonedDateTime, nil] context
52
+ # A {ZonedDateTime} used to fill in missing fields during conversion.
53
+ # {OpenHAB::CoreExt::Java::ZonedDateTime.now ZonedDateTime.now} is assumed
54
+ # if not given.
55
+ # @return [ZonedDateTime]
56
+ def to_zoned_date_time(context = nil)
57
+ to_local_date.to_zoned_date_time(context)
58
+ end
59
+
60
+ # @return [Integer, nil]
61
+ def compare_with_coercion(other)
62
+ return compare_without_coercion(other) if other.is_a?(self.class)
63
+
64
+ return self <=> other.to_date(self) if other.is_a?(java.time.MonthDay)
65
+
66
+ if other.respond_to?(:coerce) && (lhs, rhs = coerce(self))
67
+ return lhs <=> rhs
68
+ end
69
+
70
+ compare_without_coercion(other)
71
+ end
72
+ alias_method :compare_without_coercion, :<=>
73
+ alias_method :<=>, :compare_with_coercion
74
+
75
+ #
76
+ # Convert `other` to Date, if possible.
77
+ #
78
+ # @param [#to_date] other
79
+ # @return [Array, nil]
80
+ #
81
+ def coerce(other)
82
+ return nil unless other.respond_to?(:to_date)
83
+ return [other.to_date(self), self] if other.method(:to_date).arity == 1
84
+
85
+ [other.to_date, self]
86
+ end
87
+
88
+ alias_method :inspect, :to_s
89
+ end
@@ -0,0 +1,190 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Extensions to Integer
4
+ class Integer
5
+ class << self
6
+ #
7
+ # @!macro def_duration_method
8
+ # @!method $1
9
+ #
10
+ # Create {Duration} of `self` $1
11
+ #
12
+ # @return [Duration]
13
+ #
14
+ # @!visibility private
15
+ def def_duration_method(unit)
16
+ class_eval <<~RUBY, __FILE__, __LINE__ + 1
17
+ def #{unit} # def seconds
18
+ java.time.Duration.of_#{unit}(self) # java.time.Duration.of_seconds(self)
19
+ end # end
20
+ RUBY
21
+ end
22
+
23
+ #
24
+ # @!macro def_period_method
25
+ # @!method $1
26
+ #
27
+ # Create {Period} of `self` $1
28
+ #
29
+ # @return [Period]
30
+ #
31
+ # @!visibility private
32
+ def def_period_method(unit)
33
+ class_eval <<~RUBY, __FILE__, __LINE__ + 1
34
+ def #{unit} # def days
35
+ java.time.Period.of_#{unit}(self) # java.time.Period.of_days(self)
36
+ end # end
37
+ RUBY
38
+ end
39
+ end
40
+
41
+ #
42
+ # Create {Duration} of `self` milliseconds
43
+ #
44
+ # @return [Duration]
45
+ #
46
+ def milliseconds
47
+ Duration.of_millis(self)
48
+ end
49
+ alias_method :millisecond, :milliseconds
50
+ alias_method :ms, :milliseconds
51
+ def_duration_method(:seconds)
52
+ alias_method :second, :seconds
53
+ def_duration_method(:minutes)
54
+ alias_method :minute, :minutes
55
+ def_duration_method(:hours)
56
+ alias_method :hour, :hours
57
+ def_period_method(:days)
58
+ alias_method :day, :days
59
+ def_period_method(:months)
60
+ alias_method :month, :months
61
+ def_period_method(:years)
62
+ alias_method :year, :years
63
+ end
64
+
65
+ # Extensions to Float
66
+ class Float
67
+ #
68
+ # Create {Duration} of `self` milliseconds
69
+ #
70
+ # @return [Duration]
71
+ #
72
+ def milliseconds
73
+ java.time.Duration.of_nanos((self * 1_000_000).to_i)
74
+ end
75
+ alias_method :millisecond, :milliseconds
76
+ alias_method :ms, :milliseconds
77
+
78
+ #
79
+ # Create {Duration} of `self` seconds
80
+ #
81
+ # @return [Duration]
82
+ #
83
+ def seconds
84
+ (self * 1000).milliseconds
85
+ end
86
+ alias_method :second, :seconds
87
+
88
+ #
89
+ # Create {Duration} of `self` minutes
90
+ #
91
+ # @return [Duration]
92
+ #
93
+ def minutes
94
+ (self * 60).seconds
95
+ end
96
+ alias_method :minute, :minutes
97
+
98
+ #
99
+ # Create {Duration} of `self` hours
100
+ #
101
+ # @return [Duration]
102
+ #
103
+ def hours
104
+ (self * 60).minutes
105
+ end
106
+ alias_method :hour, :hours
107
+
108
+ #
109
+ # Create {Duration} of `self` days
110
+ #
111
+ # @return [Duration]
112
+ #
113
+ def days
114
+ (self * 24).hours
115
+ end
116
+ alias_method :day, :days
117
+
118
+ #
119
+ # Create {Duration} of `self` months
120
+ #
121
+ # @return [Duration]
122
+ #
123
+ def months
124
+ (self * java.time.temporal.ChronoUnit::MONTHS.duration.to_i).seconds
125
+ end
126
+ alias_method :month, :months
127
+
128
+ #
129
+ # Create {Duration} of `self` years
130
+ #
131
+ # @return [Duration]
132
+ #
133
+ def years
134
+ (self * java.time.temporal.ChronoUnit::YEARS.duration.to_i).seconds
135
+ end
136
+ alias_method :year, :years
137
+ end
138
+
139
+ module OpenHAB
140
+ module CoreExt
141
+ module Ruby
142
+ #
143
+ # Extend Numeric to create quantity object
144
+ #
145
+ module QuantityTypeConversion
146
+ #
147
+ # Convert Numeric to a QuantityType
148
+ #
149
+ # @param [String, javax.measure.Unit] unit
150
+ #
151
+ # @return [QuantityType] `self` as a {QuantityType} of the supplied Unit
152
+ #
153
+ def |(unit) # rubocop:disable Naming/BinaryOperatorParameterName
154
+ unit = org.openhab.core.types.util.UnitUtils.parse_unit(unit.to_str) if unit.respond_to?(:to_str)
155
+
156
+ return super unless unit.is_a?(javax.measure.Unit)
157
+
158
+ Core::Types::QuantityType.new(to_d.to_java, unit)
159
+ end
160
+ end
161
+
162
+ # Extensions to Numeric
163
+ module Numeric
164
+ include QuantityTypeConversion
165
+ # non-Integer/Float (i.e. BigDecimal) can still be converted to Duration, via converting to float first
166
+ extend Forwardable
167
+ def_delegators :to_f,
168
+ :milliseconds,
169
+ :millisecond,
170
+ :ms,
171
+ :seconds,
172
+ :second,
173
+ :minutes,
174
+ :minute,
175
+ :hours,
176
+ :hour,
177
+ :day,
178
+ :days,
179
+ :month,
180
+ :months,
181
+ :year,
182
+ :years
183
+ end
184
+
185
+ # Integer already has #|, so we have to prepend it here
186
+ ::Integer.prepend(QuantityTypeConversion)
187
+ ::Numeric.include(Numeric)
188
+ end
189
+ end
190
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module CoreExt
5
+ module Ruby
6
+ # Extensions to Range
7
+ module Range
8
+ def cover?(object)
9
+ # inverted circular range
10
+ if circular?
11
+ return object >= self.begin || object < self.end if exclude_end?
12
+
13
+ return object >= self.begin || object <= self.end
14
+ end
15
+ super
16
+ end
17
+
18
+ # Delegates to {#cover?} if {#circular?}
19
+ # @!visibility private
20
+ def ===(object)
21
+ return cover?(object) if circular?
22
+
23
+ super
24
+ end
25
+
26
+ # normal Range#each will not yield at all if begin > end
27
+ def each
28
+ return super unless circular?
29
+ return to_enum(:each) unless block_given?
30
+
31
+ val = self.begin
32
+ loop do
33
+ is_end = val == self.end
34
+ break if is_end && exclude_end?
35
+
36
+ yield val
37
+ break if is_end
38
+
39
+ val = val.succ
40
+ end
41
+ end
42
+
43
+ #
44
+ # Checks if this range is circular
45
+ #
46
+ # A circular range is one whose data type will repeat if keep you keep
47
+ # calling #succ on it, and whose beginning is after its end.
48
+ #
49
+ # Used by {#cover?} to check if the value is between `end` and `begin`,
50
+ # instead of `begin` and `end`.
51
+ #
52
+ # @return [true, false]
53
+ #
54
+ def circular?
55
+ return false if self.begin.nil? || self.end.nil?
56
+ return false if self.begin <= self.end
57
+
58
+ case self.begin || self.end
59
+ when java.time.LocalTime, java.time.MonthDay, java.time.Month
60
+ true
61
+ else
62
+ false
63
+ end
64
+ end
65
+
66
+ ::Range.prepend(self)
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "forwardable"
4
+
5
+ module OpenHAB
6
+ module CoreExt
7
+ module Ruby
8
+ # Extensions to Time and DateTime
9
+ module TimeExtensions
10
+ extend Forwardable
11
+
12
+ # @!visibility private
13
+ def self.included(base)
14
+ base.send :alias_method, :plus_without_temporal, :+
15
+ base.send :alias_method, :+, :plus_with_temporal
16
+ base.send :alias_method, :minus_without_temporal, :-
17
+ base.send :alias_method, :-, :minus_with_temporal
18
+ end
19
+
20
+ #
21
+ # @!method +(other)
22
+ #
23
+ # Extends {#+} to allow adding a {java.time.temporal.TemporalAmount TemporalAmount}
24
+ #
25
+ # @param [java.time.temporal.TemporalAmount] other
26
+ # @return [ZonedDateTime] If other is a {java.time.temporal.TemporalAmount TemporalAmount}
27
+ # @return [Time] If other is a Numeric
28
+ #
29
+ def plus_with_temporal(other)
30
+ return to_zoned_date_time + other if other.is_a?(java.time.temporal.TemporalAmount)
31
+
32
+ plus_without_temporal(other)
33
+ end
34
+
35
+ #
36
+ # @!method -(other)
37
+ #
38
+ # Extends {#-} to allow subtracting a {java.time.temporal.TemporalAmount TemporalAmount}
39
+ #
40
+ # @param [java.time.temporal.TemporalAmount] other
41
+ # @return [ZonedDateTime] If other is a {java.time.temporal.TemporalAmount TemporalAmount}
42
+ # @return [Time] If other is a Numeric
43
+ #
44
+ def minus_with_temporal(other)
45
+ return to_zoned_date_time - other if other.is_a?(java.time.temporal.TemporalAmount)
46
+
47
+ minus_without_temporal(other)
48
+ end
49
+
50
+ # @return [LocalDate]
51
+ def to_local_date(_context = nil)
52
+ java.time.LocalDate.of(year, month, day)
53
+ end
54
+
55
+ # @!method to_local_time
56
+ # @return [LocalTime]
57
+ def_delegator :to_zoned_date_time, :to_local_time
58
+
59
+ # @return [Month]
60
+ def to_month
61
+ java.time.Month.of(month)
62
+ end
63
+
64
+ # @return [MonthDay]
65
+ def to_month_day
66
+ java.time.MonthDay.of(month, day)
67
+ end
68
+
69
+ # @param [ZonedDateTime, nil] context
70
+ # A {ZonedDateTime} used to fill in missing fields
71
+ # during conversion. Not used in this class.
72
+ # @return [ZonedDateTime]
73
+ def to_zoned_date_time(context = nil) # rubocop:disable Lint/UnusedMethodArgument
74
+ to_java(ZonedDateTime)
75
+ end
76
+
77
+ #
78
+ # Converts to a {ZonedDateTime} if `other`
79
+ # is also convertible to a ZonedDateTime.
80
+ #
81
+ # @param [#to_zoned_date_time] other
82
+ # @return [Array, nil]
83
+ #
84
+ def coerce(other)
85
+ [other.to_zoned_date_time(to_zoned_date_time), self] if other.respond_to?(:to_zoned_date_time)
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+
92
+ #
93
+ # Extensions to Ruby Time
94
+ #
95
+ class Time
96
+ include(OpenHAB::CoreExt::Ruby::TimeExtensions)
97
+ end
98
+
99
+ #
100
+ # Extensions to Ruby DateTime
101
+ #
102
+ class DateTime
103
+ include(OpenHAB::CoreExt::Ruby::TimeExtensions)
104
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ Dir[File.expand_path("core_ext/**/*.rb", __dir__)].sort.each do |f|
4
+ require f
5
+ end
6
+
7
+ module OpenHAB
8
+ # Extensions to core classes
9
+ module CoreExt
10
+ # Extensions to core Java classes
11
+ module Java
12
+ end
13
+
14
+ # Extensions to core Ruby classes
15
+ module Ruby
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module DSL
5
+ module Events
6
+ #
7
+ # Event object passed by a {Rules::Builder#watch} trigger.
8
+ #
9
+ # @!attribute [r] path
10
+ # @return [Pathname] The path that had an event
11
+ # @!attribute [r] type
12
+ # @return [:created, :modified, :deleted] Type of change
13
+ # @!attribute [r] attachment
14
+ # @return [Object] The trigger's attachment
15
+ WatchEvent = Struct.new(:type, :path, :attachment)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module DSL
5
+ # Contains event classes for events defined by the DSL.
6
+ module Events
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/inline"