openhab-scripting 5.27.0 → 5.27.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59deb6289921c0c6d35579783efbb35f75ceac9ff24922e0f74d6652ef575b59
4
- data.tar.gz: 260ee0993a3ab89775d9b5a2e8f3e40f295dd16ad8f0adf3b003b521cb08a12e
3
+ metadata.gz: 5e0abb8ef69de3f3ee26fa45213d2d9afa55f4b4816cde92ab6dd68ea9f95ad5
4
+ data.tar.gz: bcb8c93446e87d55b2d07cfa24762b684e313f2f546c77bfa1b946c227061a00
5
5
  SHA512:
6
- metadata.gz: 127b6e33961395b973b8aa543940502530101f30e15526aa598b574e8d3a05ec82c65d79fd0d0d6176a2aa57aed8f244fbd480c76457e3440f94503f92028530
7
- data.tar.gz: 4949521fcc45fdb1dba17a09c960d4a5e7afd2c964328a9fd8b66b11ac2c773c7e413e6ec2d797f9e6d9f8e9130297c9700af4d46bf968ec064b0dfa2ea6eb32
6
+ metadata.gz: ec47bcf9491772968a8f6ca7ac5853ed403986d75eb1ae69f92f43ada70af126552abec30af4a7d02bd5cf63daaf4ce5d7b9b86433899f1161e72e5807f6c06e
7
+ data.tar.gz: ad58da972b4b1bbf34e4a9e0af7bc56f8debec4126ce64e1c8133b6d1dd10d584c3c7344bb9740be56977f5c948a6ccb6db055a0179fd4fb84d77d53e88e36e1
@@ -213,8 +213,18 @@ module OpenHAB
213
213
  old
214
214
  end
215
215
 
216
+ # @!visibility private
217
+ def clear
218
+ elements = @elements
219
+ @elements = java.util.concurrent.ConcurrentHashMap.new
220
+ elements.each_value do |v|
221
+ notify_listeners_about_removed_element(v)
222
+ end
223
+ end
224
+
216
225
  # @!visibility private
217
226
  def unregister
227
+ clear
218
228
  # @deprecated OH3.4 safe navigation only required for missing Semantics registry
219
229
  self.class.registry&.remove_provider(self)
220
230
  end
@@ -47,6 +47,7 @@ module OpenHAB
47
47
  # rubocop:enable Naming/MethodName
48
48
 
49
49
  # @!visibility private
50
+ # Override this because we don't have a registry
50
51
  def unregister
51
52
  clear
52
53
  @registration.unregister
@@ -140,16 +141,6 @@ module OpenHAB
140
141
  end
141
142
  end
142
143
 
143
- # For use in specs
144
- # @!visibility private
145
- def clear
146
- elements = @elements
147
- @elements = java.util.concurrent.ConcurrentHashMap.new
148
- elements.each_value do |v|
149
- notify_listeners_about_removed_element(v)
150
- end
151
- end
152
-
153
144
  #
154
145
  # Notify listeners about updated sitemap
155
146
  #
@@ -26,36 +26,20 @@ module OpenHAB
26
26
  include Comparable
27
27
  end
28
28
 
29
- #
30
- # Regex expression to identify strings defining a time in hours, minutes and optionally seconds
31
- #
32
- TIME_ONLY_REGEX = /\A(?<hours>\d\d):(?<minutes>\d\d)(?<seconds>:\d\d)?\Z/.freeze
33
-
34
- #
35
- # Regex expression to identify strings defining a time in year, month, and day
36
- #
37
- DATE_ONLY_REGEX = /\A\d{4}-\d\d-\d\d\Z/.freeze
38
- private_constant :TIME_ONLY_REGEX, :DATE_ONLY_REGEX
39
-
40
29
  class << self
41
30
  #
42
- # Parses a String representing a time into a {DateTimeType}. First tries to parse it
43
- # using Java's parser, then falls back to the Ruby `Time.parse`.
31
+ # Parse a time string into a {DateTimeType}.
44
32
  #
45
- # @param [String] time_string
33
+ # @note openHAB's DateTimeType.new(String) constructor will parse time-only strings and fill in `1970-01-01`
34
+ # as the date, whereas this method will use the current date.
46
35
  #
36
+ # @param (see DSL#try_parse_time_like)
47
37
  # @return [DateTimeType]
48
38
  #
49
39
  def parse(time_string)
50
- time_string = "#{time_string}Z" if TIME_ONLY_REGEX.match?(time_string)
51
- DateTimeType.new(time_string)
52
- rescue java.lang.StringIndexOutOfBoundsException, java.lang.IllegalArgumentException => e
53
- # Try Ruby's Time.parse if DateTimeType parser fails
54
- begin
55
- DateTimeType.new(::Time.parse(time_string).to_zoned_date_time)
56
- rescue ArgumentError
57
- raise ArgumentError, e.message
58
- end
40
+ DateTimeType.new(DSL.try_parse_time_like(time_string).to_zoned_date_time)
41
+ rescue ArgumentError
42
+ raise ArgumentError, e.message
59
43
  end
60
44
  end
61
45
 
@@ -4,6 +4,6 @@ module OpenHAB
4
4
  module DSL
5
5
  # Version of openHAB helper libraries
6
6
  # @return [String]
7
- VERSION = "5.27.0"
7
+ VERSION = "5.27.1"
8
8
  end
9
9
  end
data/lib/openhab/dsl.rb CHANGED
@@ -1072,6 +1072,16 @@ module OpenHAB
1072
1072
  Thread.current[:openhab_holiday_file] = file
1073
1073
  end
1074
1074
 
1075
+ #
1076
+ # @param [String] string Date/time string to parse.
1077
+ # The string can be in any format recognized by:
1078
+ # - {OpenHAB::CoreExt::Java::LocalTime.parse LocalTime.parse}
1079
+ # - {OpenHAB::CoreExt::Java::LocalDate.parse LocalDate.parse}
1080
+ # - {OpenHAB::CoreExt::Java::MonthDay.parse MonthDay.parse}, e.g. "12-25"
1081
+ # - {OpenHAB::CoreExt::Java::ZonedDateTime.parse ZonedDateTime.parse}
1082
+ # - [Time.parse](https://rubyapi.org/o/time#method-c-parse), e.g. "2021-01-01 12:00:", or "3:30pm"
1083
+ # @return [LocalTime, LocalDate, MonthDay, ZonedDateTime, Time] the parsed date/time
1084
+ #
1075
1085
  # @!visibility private
1076
1086
  def try_parse_time_like(string)
1077
1087
  return string unless string.is_a?(String)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openhab-scripting
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.27.0
4
+ version: 5.27.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian O'Connell
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-09-08 00:00:00.000000000 Z
13
+ date: 2024-09-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler