openhab-scripting 5.19.0 → 5.20.0

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: 806939292f4f749b0fd1db95f1b99a35365f8de972e96b90bb824a217f151743
4
- data.tar.gz: 783bd04b6bcb2d6fedef08d69aecb150f3578a9a6a011015b968cb4614949263
3
+ metadata.gz: 04fb1ca1c7f49ca0f821111edd4c1d178066d6d0c55ce0d574efc7bf1307aa36
4
+ data.tar.gz: aa5005277edc1667540d6c87aee158e5dcd02095ce6633303eacaa5343ecc1b1
5
5
  SHA512:
6
- metadata.gz: 11e236b0c0c642d154e0340ce1330311fcaec8f60c180af58ec4bfc2fd013a2de64d54ae327316b90bf565f5255c76c1f3d810595225d9c8b22ff40c8fb12e7b
7
- data.tar.gz: 47d995352bb04ced923551adcf16f7022823b2cf4e2aed9d758be688fa9a75cc40b0778700e2e0e04f15e8092453ae2c0323565de9dc73047faaeff37d0bd397
6
+ metadata.gz: e3c2c463868f6c9ec8f452bc8d1e0c0a5dc4c0f34243eceb4ad6661d9e52deafc04cddad3a4332c51fe039f246d0133b245f1c885b9e892f79e913f38f6c6619
7
+ data.tar.gz: b6e03f118796c8af22d2a6922fba92368954ba3fd15c13029b6d627c5dc9cd5f1f27507f77990545176f8bd67af588e987b780393e76090f3c49b4a663351168
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "generic_item"
4
+
5
+ module OpenHAB
6
+ module Core
7
+ module Items
8
+ java_import org.openhab.core.library.items.CallItem
9
+
10
+ #
11
+ # A {CallItem} identifies a telephone call by its origin and destination.
12
+ #
13
+ # @!attribute [r] state
14
+ # @return [StringListType, nil]
15
+ #
16
+ class CallItem < GenericItem
17
+ # @!visibility private
18
+ def format_type(command)
19
+ return command if command.is_a?(Types::StringListType)
20
+ return Types::StringListType.new(command.to_ary.map(&:to_s)) if command.respond_to?(:to_ary)
21
+
22
+ super
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ # @!parse CallItem = OpenHAB::Core::Items::CallItem
@@ -134,7 +134,9 @@ module OpenHAB
134
134
  #
135
135
  # The similar method `command!`, however, will always send the command regardless of the item's state.
136
136
  #
137
- # @param [Command] command command to send to the item
137
+ # @param [Command, #to_s] command command to send to the item.
138
+ # When given a {Command} argument, it will be passed directly.
139
+ # Otherwise, the result of `#to_s` will be parsed into a {Command}.
138
140
  # @return [self, nil] nil when `ensure` is in effect and the item was already in the same state,
139
141
  # otherwise the item.
140
142
  #
@@ -143,6 +145,17 @@ module OpenHAB
143
145
  # @see OpenHAB::DSL.ensure_states! ensure_states!
144
146
  # @see DSL::Items::Ensure::Ensurable#ensure ensure
145
147
  #
148
+ # @example Sending a {Command} to an item
149
+ # MySwitch.command(ON) # The preferred method is `MySwitch.on`
150
+ # Garage_Door.command(DOWN) # The preferred method is `Garage_Door.down`
151
+ # SetTemperature.command 20 | "°C"
152
+ #
153
+ # @example Sending a plain number to a {NumberItem}
154
+ # SetTemperature.command(22.5) # if it accepts a DecimalType
155
+ #
156
+ # @example Sending a string to a dimensioned {NumberItem}
157
+ # SetTemperature.command("22.5 °C") # The string will be parsed and converted to a QuantityType
158
+ #
146
159
  def command(command)
147
160
  command = format_command(command)
148
161
  logger.trace "Sending Command #{command} to #{name}"
@@ -165,10 +178,27 @@ module OpenHAB
165
178
  #
166
179
  # Send an update to this item
167
180
  #
168
- # @param [State] state
181
+ # @param [State, #to_s, nil] state the state to update the item.
182
+ # When given a {State} argument, it will be passed directly.
183
+ # Otherwise, the result of `#to_s` will be parsed into a {State} first.
184
+ # If `nil` is passed, the item will be updated to {NULL}.
169
185
  # @return [self, nil] nil when `ensure` is in effect and the item was already in the same state,
170
186
  # otherwise the item.
171
187
  #
188
+ # @example Updating to a {State}
189
+ # DoorStatus.update(OPEN)
190
+ # InsideTemperature.update 20 | "°C"
191
+ #
192
+ # @example Updating to {NULL}, the two following are equivalent:
193
+ # DoorStatus.update(nil)
194
+ # DoorStatus.update(NULL)
195
+ #
196
+ # @example Updating with a plain number
197
+ # PeopleCount.update(5) # A plain NumberItem
198
+ #
199
+ # @example Updating with a string to a dimensioned {NumberItem}
200
+ # InsideTemperature.update("22.5 °C") # The string will be parsed and converted to a QuantityType
201
+ #
172
202
  def update(state)
173
203
  state = format_update(state)
174
204
  logger.trace "Sending Update #{state} to #{name}"
@@ -427,6 +427,7 @@ module OpenHAB
427
427
  end
428
428
  end
429
429
 
430
+ def_type_predicate(:call)
430
431
  def_type_predicate(:color)
431
432
  def_type_predicate(:contact)
432
433
  def_type_predicate(:date_time)
@@ -27,8 +27,7 @@ module OpenHAB
27
27
  #
28
28
  # @example Comparison using Quantity
29
29
  # # Because Power_Usage has a unit, the return value
30
- # # from average_since is a QuantityType which can be
31
- # # compared against a string with quantity
30
+ # # from average_since is a QuantityType
32
31
  # if Power_Usage.average_since(15.minutes.ago) > 5 | "kW"
33
32
  # logger.info("The power usage exceeded its 15 min average)
34
33
  # end
@@ -429,7 +428,7 @@ module OpenHAB
429
428
  # @overload persist(timestamp, state, service = nil)
430
429
  # Persists a state at a given timestamp
431
430
  # @param [#to_zoned_date_time] timestamp The timestamp for the given state to be stored
432
- # @param [Types::State] state The state to be stored
431
+ # @param [Types::State, #to_s] state The state to be stored
433
432
  # @param [Symbol, String] service An optional persistence id instead of the default persistence service.
434
433
  # @return [void]
435
434
  # @since openHAB 4.2
@@ -508,7 +507,20 @@ module OpenHAB
508
507
  # @see last_update
509
508
  # @since openHAB 4.2
510
509
 
511
- %i[last_update next_update].each do |method|
510
+ # @!method last_change(service = nil)
511
+ # Returns the time the item was last changed.
512
+ # @param [Symbol, String] service An optional persistence id instead of the default persistence service.
513
+ # @return [ZonedDateTime, nil] The timestamp of the last update
514
+ # @since openHAB 4.2
515
+
516
+ # @!method next_change(service = nil)
517
+ # Returns the first future change time of the item.
518
+ # @param [Symbol, String] service An optional persistence id instead of the default persistence service.
519
+ # @return [ZonedDateTime, nil] The timestamp of the next update
520
+ # @see last_update
521
+ # @since openHAB 4.2
522
+
523
+ %i[last_update next_update last_change next_change].each do |method|
512
524
  # @deprecated OH 4.1 remove this guard when dropping OH 4.1
513
525
  next unless Actions::PersistenceExtensions.respond_to?(method)
514
526
 
@@ -123,7 +123,7 @@ module OpenHAB
123
123
  #
124
124
  # Links the channel to an item.
125
125
  #
126
- # @param [String, Items::Item] channel The channel to link to.
126
+ # @param [String, Items::Item] item The item to link to.
127
127
  # @param [Hash] config The configuration for the link.
128
128
  #
129
129
  # @return [Things::ItemChannelLink] The created link.
@@ -80,7 +80,10 @@ module OpenHAB
80
80
  # @param value [#to_zoned_date_time, #to_time, #to_str, #to_d, nil]
81
81
  #
82
82
  def initialize(value = nil)
83
- if value.respond_to?(:to_zoned_date_time)
83
+ if value.nil?
84
+ super()
85
+ return
86
+ elsif value.respond_to?(:to_zoned_date_time)
84
87
  super(value.to_zoned_date_time)
85
88
  return
86
89
  elsif value.respond_to?(:to_time)
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "forwardable"
4
+
5
+ require_relative "type"
6
+
7
+ module OpenHAB
8
+ module Core
9
+ module Types
10
+ StringListType = org.openhab.core.library.types.StringListType
11
+
12
+ # {StringListType} can be used for items that are dealing with telephony functionality.
13
+ #
14
+ # The entries can be accessed like an array.
15
+ #
16
+ # @example
17
+ # string_list = StringListType.new("a", "b", "c")
18
+ # logger.info "first entry: #{string_list.first}" # => "a"
19
+ # logger.info "second entry: #{string_list[1]}" # => "b"
20
+ # logger.info "last entry: #{string_list.last}" # => "c"
21
+ # logger.info "length: #{string_list.size}" # => 3
22
+ #
23
+ class StringListType
24
+ extend Forwardable
25
+
26
+ field_reader :typeDetails
27
+
28
+ # @!parse include Command, State
29
+
30
+ # @!visibility private
31
+ def inspect
32
+ "#<OpenHAB::Core::Types::StringListType #{to_a.inspect}>"
33
+ end
34
+
35
+ # @return [Array<String>] the values as an array
36
+ def to_a
37
+ typeDetails.to_a
38
+ end
39
+
40
+ # @!visibility private
41
+ def ==(other)
42
+ return super if other.is_a?(StringListType)
43
+ return to_a == other.to_a if other.respond_to?(:to_a)
44
+
45
+ super
46
+ end
47
+
48
+ # any method that exists on Array gets forwarded to states
49
+ delegate (Array.instance_methods - instance_methods) => :to_a
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ # @!parse StringListType = OpenHAB::Core::Types::StringListType
@@ -18,7 +18,7 @@ module OpenHAB
18
18
  # @since openHAB 4.1
19
19
  #
20
20
  # @example
21
- # time_series = TimeSeries.new # defaults to :add policy
21
+ # time_series = TimeSeries.new # defaults to :replace policy
22
22
  # .add(Time.at(2), DecimalType.new(2))
23
23
  # .add(Time.at(1), DecimalType.new(1))
24
24
  # .add(Time.at(3), DecimalType.new(3))
@@ -55,6 +55,8 @@ module OpenHAB
55
55
  end
56
56
  end
57
57
 
58
+ # @return [CallItem]
59
+ def_item_method(:call)
58
60
  # @return [ColorItem]
59
61
  def_item_method(:color)
60
62
  # @return [ContactItem]
@@ -1283,6 +1283,8 @@ module OpenHAB
1283
1283
  # @param [Object] attach Object to be attached to the trigger
1284
1284
  # @return [void]
1285
1285
  #
1286
+ # @see at
1287
+ #
1286
1288
  # @example
1287
1289
  # rule "Daily" do
1288
1290
  # every :day, at: '5:15'
@@ -1297,7 +1299,13 @@ module OpenHAB
1297
1299
  # run { Light.on }
1298
1300
  # end
1299
1301
  #
1300
- # @example
1302
+ # @example Trigger at the time portion of a DateTime Item
1303
+ # rule "Every day at sunset" do
1304
+ # every :day, at: Sunset_Time
1305
+ # run { logger.info "It's getting dark" }
1306
+ # end
1307
+ #
1308
+ # @example Specific day of the week
1301
1309
  # rule "Weekly" do
1302
1310
  # every :monday, at: '5:15'
1303
1311
  # run do
@@ -1305,7 +1313,7 @@ module OpenHAB
1305
1313
  # end
1306
1314
  # end
1307
1315
  #
1308
- # @example
1316
+ # @example Symbolic interval
1309
1317
  # rule "Often" do
1310
1318
  # every :minute
1311
1319
  # run do
@@ -1321,7 +1329,7 @@ module OpenHAB
1321
1329
  # end
1322
1330
  # end
1323
1331
  #
1324
- # @example
1332
+ # @example Duration interval
1325
1333
  # rule "Often" do
1326
1334
  # every 5.minutes
1327
1335
  # run do
@@ -1329,18 +1337,12 @@ module OpenHAB
1329
1337
  # end
1330
1338
  # end
1331
1339
  #
1332
- # @example
1340
+ # @example MonthDay
1333
1341
  # rule 'Every 14th of Feb at 2pm' do
1334
1342
  # every '02-14', at: '2pm'
1335
1343
  # run { logger.info "Happy Valentine's Day!" }
1336
1344
  # end
1337
1345
  #
1338
- # @example
1339
- # rule "Every day at sunset" do
1340
- # every :day, at: Sunset_Time
1341
- # run { logger.info "It's getting dark" }
1342
- # end
1343
- #
1344
1346
  def every(value, at: nil, attach: nil)
1345
1347
  return every(java.time.MonthDay.parse(value), at: at, attach: attach) if value.is_a?(String)
1346
1348
 
@@ -1735,6 +1737,8 @@ module OpenHAB
1735
1737
  # @param [Item, String, Symbol] item The item (or its name)
1736
1738
  # @return [void]
1737
1739
  #
1740
+ # @see every
1741
+ #
1738
1742
  # @example
1739
1743
  # rule "say hello when the kids get home from school" do
1740
1744
  # at HomeFromSchool_Time
@@ -288,7 +288,8 @@ module OpenHAB
288
288
  # If an array is given:
289
289
  # - Scalar elements define the command, and the label is the same as the command.
290
290
  # - Array elements contain the command, label, and optional third element for the icon.
291
- # - Hash elements contain the command, label, and optional icon defined by the corresponding keys.
291
+ # - Hash elements contain the `command`, `release` (optional), `label`, and `icon` (optional)
292
+ # defined by the corresponding keys.
292
293
  #
293
294
  # @since openHAB 4.1 added support for icons
294
295
  #
@@ -314,6 +315,12 @@ module OpenHAB
314
315
  # {command: "auto", label: "Auto"} # no icon
315
316
  # ]
316
317
  #
318
+ # @example Since openHAB 4.2, `release` is also supported in the array of hashes
319
+ # # when `release` is specified, `command` will be sent on press and `release` on release
320
+ # switch mappings: [
321
+ # {label: "On", command: ON, release: OFF, icon: "f7:power"}
322
+ # ]
323
+ #
317
324
  # @return [Hash, Array, nil]
318
325
  # @see LinkableWidgetBuilder#switch
319
326
  # @see https://www.openhab.org/docs/ui/sitemaps.html#mappings
@@ -334,8 +341,9 @@ module OpenHAB
334
341
  widget = super
335
342
  mappings&.each do |cmd, label, icon|
336
343
  mapping = SitemapBuilder.factory.create_mapping
337
- cmd, label, icon = cmd.values_at(:command, :label, :icon) if cmd.is_a?(Hash)
344
+ cmd, release_cmd, label, icon = cmd.values_at(:command, :release, :label, :icon) if cmd.is_a?(Hash)
338
345
  mapping.cmd = cmd.to_s
346
+ mapping.release_cmd = release_cmd.to_s unless release_cmd.nil?
339
347
  mapping.label = label&.to_s || cmd.to_s
340
348
  # @deprecated OH 4.1 the if check is not needed in OH4.1+
341
349
  mapping.icon = icon if icon
@@ -395,32 +403,44 @@ module OpenHAB
395
403
  # @return [true, false, nil]
396
404
  # @note This parameter only works on Android
397
405
  attr_writer :switch
406
+ # Only send the command when the slider is released
407
+ # @return [true, false, nil]
408
+ attr_writer :release_only
398
409
 
399
410
  # (see SetpointBuilder#initialize)
400
- # @!method initialize(item: nil, label: nil, icon: nil, static_icon: nil, range: nil, step: nil, switch: nil, frequency: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
411
+ # @!method initialize(item: nil, label: nil, icon: nil, static_icon: nil, range: nil, step: nil, switch: nil, frequency: nil, release_only: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil)
401
412
  # @param switch [true, false, nil]
402
413
  # A short press on the item toggles the item on or off (see {SliderBuilder#switch=})
403
414
  # @param frequency [Numeric, nil]
404
415
  # How often to send requests (in seconds) (see {SliderBuilder#frequency})
416
+ # @param release_only [true, false, nil]
417
+ # Only send the command when the slider is released (see {SliderBuilder#release_only=})
405
418
  # @!visibility private
406
- def initialize(type, builder_proxy, switch: nil, frequency: nil, **kwargs, &block)
419
+ def initialize(type, builder_proxy, switch: nil, frequency: nil, release_only: nil, **kwargs, &block)
407
420
  super(type, builder_proxy, **kwargs, &block)
408
421
 
409
422
  @switch = switch
410
423
  @frequency = frequency
411
- @switch_enabled = nil
424
+ @release_only = release_only
412
425
  end
413
426
 
414
427
  # (see #switch=)
415
428
  def switch?
416
- @switch_enabled
429
+ @switch
430
+ end
431
+
432
+ # (see #release_only=)
433
+ def release_only?
434
+ @release_only
417
435
  end
418
436
 
419
437
  # @!visibility private
420
438
  def build
421
439
  widget = super
422
- widget.switch_enabled = switch?
440
+ widget.switch_enabled = switch? unless @switch.nil?
423
441
  widget.send_frequency = (frequency * 1000).to_i if frequency
442
+ # @deprecated OH 4.1 remove the version check when dropping OH 4.1 support
443
+ widget.release_only = release_only? if OpenHAB::Core.version >= OpenHAB::Core::V4_2 && !@release_only.nil?
424
444
  widget
425
445
  end
426
446
  end
@@ -737,7 +757,12 @@ module OpenHAB
737
757
  def build
738
758
  widget = super
739
759
  buttons.each do |button|
740
- button_object = SitemapBuilder.factory.create_button
760
+ button_object = if SitemapBuilder.factory.respond_to?(:create_button_definition)
761
+ SitemapBuilder.factory.create_button_definition
762
+ else
763
+ # @deprecated OH 4.1 in OH 4.2 this clause is not needed
764
+ SitemapBuilder.factory.create_button
765
+ end
741
766
  button_object.row = button[0]
742
767
  button_object.column = button[1]
743
768
  button_object.cmd = button[2]
@@ -931,6 +956,7 @@ module OpenHAB
931
956
  # step: nil,
932
957
  # switch: nil,
933
958
  # frequency: nil,
959
+ # release_only: nil,
934
960
  # label_color: nil,
935
961
  # value_color: nil,
936
962
  # icon_color: nil,
@@ -4,6 +4,6 @@ module OpenHAB
4
4
  module DSL
5
5
  # Version of openHAB helper libraries
6
6
  # @return [String]
7
- VERSION = "5.19.0"
7
+ VERSION = "5.20.0"
8
8
  end
9
9
  end
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.19.0
4
+ version: 5.20.0
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-05-16 00:00:00.000000000 Z
13
+ date: 2024-06-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -263,6 +263,7 @@ files:
263
263
  - lib/openhab/core/events/timer_event.rb
264
264
  - lib/openhab/core/items.rb
265
265
  - lib/openhab/core/items/accepted_data_types.rb
266
+ - lib/openhab/core/items/call_item.rb
266
267
  - lib/openhab/core/items/color_item.rb
267
268
  - lib/openhab/core/items/contact_item.rb
268
269
  - lib/openhab/core/items/date_time_item.rb
@@ -348,6 +349,7 @@ files:
348
349
  - lib/openhab/core/types/refresh_type.rb
349
350
  - lib/openhab/core/types/rewind_fastforward_type.rb
350
351
  - lib/openhab/core/types/stop_move_type.rb
352
+ - lib/openhab/core/types/string_list_type.rb
351
353
  - lib/openhab/core/types/string_type.rb
352
354
  - lib/openhab/core/types/time_series.rb
353
355
  - lib/openhab/core/types/type.rb
@@ -485,7 +487,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
485
487
  - !ruby/object:Gem::Version
486
488
  version: '0'
487
489
  requirements: []
488
- rubygems_version: 3.5.10
490
+ rubygems_version: 3.5.14
489
491
  signing_key:
490
492
  specification_version: 4
491
493
  summary: JRuby Helper Libraries for openHAB Scripting