openhab-scripting 5.29.0 → 5.30.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 795ee1035ecfb1a7f38f50243ed0d28af8a578e7d586eedd97c8362d6f4cd03d
4
- data.tar.gz: d1785eb66e599bb3b78a3ab473618a080bffa117a53ddaf13c506e298806d8ad
3
+ metadata.gz: 93b780d352d981919615e78e687910eb11ee024c6c567a6294db4538ddd8712a
4
+ data.tar.gz: dbdcb9b48ee07a0d626bf8aa5ef6da60273d330395c89647dd5a360b28bc3f1c
5
5
  SHA512:
6
- metadata.gz: 3af8371312fdf0dce313b87513db7540545639ef440358c1256f03fe8018768c33636f5aff09bcc1cdceb9a04988492921651fd4ed269f824b18a330feec8088
7
- data.tar.gz: 698841f7a0fd45ca777e1561b915e9c695c309ba9ac802d7a319733f6501539959d55ce2d6ddae8fd9cbee4c35d8d089da74d74fa6011c9b6978b68028449b1c
6
+ metadata.gz: 12c20ab4f52a6fac707f62d004c5eb9268ca6a00a9d9490f96892530091a7da6bc812d5b729b3041a51c1567690269b91dd77e31325a826b15ba3e2d32f5a53a
7
+ data.tar.gz: 718e2af872273b04125d64edce10d248883654388a14ca126c12fdcdaef68ebc25032466fa0bb20963b491fccb753406c668acdb1499ec9ac1567baeb02b10ff
@@ -13,8 +13,8 @@ module OpenHAB
13
13
  # @return [Hash]
14
14
  attr_accessor :inputs
15
15
 
16
- # @return [String]
17
- alias_method :inspect, :to_s
16
+ # @!attribute [r] source
17
+ # @return [String] The component that sent the event.
18
18
 
19
19
  #
20
20
  # Returns the event payload as a Hash.
@@ -26,6 +26,13 @@ module OpenHAB
26
26
  require "json"
27
27
  @payload ||= JSON.parse(get_payload, symbolize_names: true) unless get_payload.empty?
28
28
  end
29
+
30
+ # @return [String]
31
+ def inspect
32
+ s = "#<OpenHAB::Core::Events::#{self.class.simple_name} topic=#{topic} payload=#{payload.inspect}"
33
+ s += " source=#{source.inspect}" if source
34
+ "#{s}>"
35
+ end
29
36
  end
30
37
  end
31
38
  end
@@ -24,6 +24,13 @@ module OpenHAB
24
24
 
25
25
  # @!attribute [r] event
26
26
  # @return [String] The event data
27
+
28
+ # @return [String]
29
+ def inspect
30
+ s = "#<OpenHAB::Core::Events::ChannelTriggeredEvent channel=#{channel} event=#{event.inspect}"
31
+ s += " source=#{source.inspect}" if source
32
+ "#{s}>"
33
+ end
27
34
  end
28
35
  end
29
36
  end
@@ -72,6 +72,13 @@ module OpenHAB
72
72
  # @!method previous?
73
73
  # Check if {#command} is {PREVIOUS}
74
74
  # @return [true, false]
75
+
76
+ # @return [String]
77
+ def inspect
78
+ s = "#<OpenHAB::Core::Events::ItemCommandEvent item=#{itemName} command=#{command.inspect}"
79
+ s += " source=#{source.inspect}" if source
80
+ "#{s}>"
81
+ end
75
82
  end
76
83
  end
77
84
  end
@@ -69,6 +69,14 @@ module OpenHAB
69
69
  def was
70
70
  old_item_state if was?
71
71
  end
72
+
73
+ # @return [String]
74
+ def inspect
75
+ s = "#<OpenHAB::Core::Events::ItemStateChangedEvent item=#{item_name} " \
76
+ "state=#{item_state.inspect} was=#{old_item_state.inspect}"
77
+ s += " source=#{source.inspect}" if source
78
+ "#{s}>"
79
+ end
72
80
  end
73
81
  end
74
82
  end
@@ -68,6 +68,13 @@ module OpenHAB
68
68
  def state
69
69
  item_state if state?
70
70
  end
71
+
72
+ # @return [String]
73
+ def inspect
74
+ s = "#<OpenHAB::Core::Events::#{self.class.simple_name} item=#{item_name} state=#{item_state.inspect}"
75
+ s += " source=#{source.inspect}" if source
76
+ "#{s}>"
77
+ end
71
78
  end
72
79
 
73
80
  # {AbstractEvent} sent when an item's state is updated (regardless of if it changed or not).
@@ -27,6 +27,14 @@ module OpenHAB
27
27
  def thing
28
28
  EntityLookup.lookup_thing(uid)
29
29
  end
30
+
31
+ # @return [String]
32
+ def inspect
33
+ s = "#<OpenHAB::Core::Events::ThingStatusInfoChangedEvent thing=#{uid} " \
34
+ "status=#{status.inspect} was=#{was.inspect}"
35
+ s += " source=#{source.inspect}" if source
36
+ "#{s}>"
37
+ end
30
38
  end
31
39
 
32
40
  # The {AbstractEvent} sent when a {Things::Thing}'s status is set.
@@ -49,6 +57,14 @@ module OpenHAB
49
57
  def thing
50
58
  EntityLookup.lookup_thing(uid)
51
59
  end
60
+
61
+ # @return [String]
62
+ def inspect
63
+ s = "#<OpenHAB::Core::Events::ThingStatusInfoEvent thing=#{uid} " \
64
+ "status=#{status.inspect}"
65
+ s += " source=#{source.inspect}" if source
66
+ "#{s}>"
67
+ end
52
68
  end
53
69
  end
54
70
  end
@@ -5,6 +5,14 @@ module OpenHAB
5
5
  # Contains objects sent to event handlers containing context around the
6
6
  # triggered event.
7
7
  module Events
8
+ class << self
9
+ # @!visibility private
10
+ def publisher
11
+ @publisher ||= OSGi.service("org.openhab.core.events.EventPublisher")
12
+ end
13
+ end
14
+
15
+ java_import org.openhab.core.items.events.ItemEventFactory
8
16
  end
9
17
  end
10
18
  end
@@ -137,6 +137,7 @@ module OpenHAB
137
137
  # @param [Command, #to_s] command command to send to the item.
138
138
  # When given a {Command} argument, it will be passed directly.
139
139
  # Otherwise, the result of `#to_s` will be parsed into a {Command}.
140
+ # @param [String, nil] source Optional string to identify what sent the event.
140
141
  # @return [self, nil] nil when `ensure` is in effect and the item was already in the same state,
141
142
  # otherwise the item.
142
143
  #
@@ -156,10 +157,14 @@ module OpenHAB
156
157
  # @example Sending a string to a dimensioned {NumberItem}
157
158
  # SetTemperature.command("22.5 °C") # The string will be parsed and converted to a QuantityType
158
159
  #
159
- def command(command)
160
+ def command(command, source: nil)
160
161
  command = format_command(command)
161
- logger.trace "Sending Command #{command} to #{name}"
162
- $events.send_command(self, command)
162
+ logger.trace { "Sending Command #{command} to #{name}" }
163
+ if source
164
+ Events.publisher.post(Events::ItemEventFactory.create_command_event(name, command, source.to_s))
165
+ else
166
+ $events.send_command(self, command)
167
+ end
163
168
  Proxy.new(self)
164
169
  end
165
170
  alias_method :command!, :command
@@ -201,7 +206,7 @@ module OpenHAB
201
206
  #
202
207
  def update(state)
203
208
  state = format_update(state)
204
- logger.trace "Sending Update #{state} to #{name}"
209
+ logger.trace { "Sending Update #{state} to #{name}" }
205
210
  $events.post_update(self, state)
206
211
  Proxy.new(self)
207
212
  end
@@ -131,10 +131,10 @@ module OpenHAB
131
131
 
132
132
  # Override because we want to send them to the base item if possible
133
133
  %i[command update].each do |method|
134
- define_method(method) do |command|
135
- return base_item.__send__(method, command) if base_item
134
+ define_method(method) do |command, **kwargs|
135
+ return base_item.__send__(method, command, **kwargs) if base_item
136
136
 
137
- super(command)
137
+ super(command, **kwargs)
138
138
  end
139
139
  end
140
140
 
@@ -103,10 +103,10 @@ module Enumerable
103
103
 
104
104
  # Send a command to every item in the collection, even when {OpenHAB::DSL.ensure_states! ensure_states!} is in effect.
105
105
  # @return [self]
106
- def command!(command)
106
+ def command!(command, **kwargs)
107
107
  # We cannot alias this to #command above, otherwise it will call
108
108
  # DSL::Items::Ensure::Item#command which checks for ensure_states
109
- each { |i| i.command!(command) }
109
+ each { |i| i.command!(command, **kwargs) }
110
110
  self
111
111
  end
112
112
 
@@ -198,7 +198,7 @@ module Enumerable
198
198
  # Send a toggle command to every item in the collection
199
199
  # @return [self]
200
200
  #
201
- def toggle
202
- each(&:toggle)
201
+ def toggle(source: nil)
202
+ each { |i| i.toggle(source: source) }
203
203
  end
204
204
  end
@@ -49,10 +49,10 @@ module OpenHAB
49
49
  #
50
50
  # @return [self]
51
51
  #
52
- def toggle
53
- return on! unless state?
52
+ def toggle(source: nil)
53
+ return on!(source: source) unless state?
54
54
 
55
- command!(!state)
55
+ command!(!state, source: source)
56
56
  end
57
57
 
58
58
  # @!method on?
@@ -35,10 +35,12 @@ module OpenHAB
35
35
  # check if this item is in the command's state before actually
36
36
  # sending the command
37
37
  %i[command update].each do |ensured_method|
38
- # def command(state)
38
+ # rubocop:disable Style/IfUnlessModifier
39
+
40
+ # def command(state, **kwargs)
39
41
  # # immediately send the command if it's a command, but not a state (like REFRESH)
40
- # return super(state) if state.is_a?(Command) && !state.is_a?(State)
41
- # return super(state) unless Thread.current[:openhab_ensure_states]
42
+ # return super(state, **kwargs) if state.is_a?(Command) && !state.is_a?(State)
43
+ # return super(state, **kwargs) unless Thread.current[:openhab_ensure_states]
42
44
  #
43
45
  # formatted_state = format_command(state)
44
46
  # logger.trace do
@@ -46,13 +48,13 @@ module OpenHAB
46
48
  # end
47
49
  # return if raw_state == formatted_state
48
50
  #
49
- # super(formatted_state)
51
+ # super(formatted_state, **kwargs)
50
52
  # end
51
53
  class_eval <<~RUBY, __FILE__, __LINE__ + 1 # rubocop:disable Style/DocumentDynamicEvalDefinition
52
- def #{ensured_method}(state)
54
+ def #{ensured_method}(state, **kwargs)
53
55
  # immediately send the command if it's a command, but not a state (like REFRESH)
54
- #{"return super(state) if state.is_a?(Command) && !state.is_a?(State)" if ensured_method == :command}
55
- return super(state) unless Thread.current[:openhab_ensure_states]
56
+ #{"return super(state, **kwargs) if state.is_a?(Command) && !state.is_a?(State)" if ensured_method == :command}
57
+ return super(state, **kwargs) unless Thread.current[:openhab_ensure_states]
56
58
 
57
59
  formatted_state = format_#{ensured_method}(state)
58
60
  logger.trace do
@@ -60,9 +62,10 @@ module OpenHAB
60
62
  end
61
63
  return if raw_state.as(formatted_state.class) == formatted_state
62
64
 
63
- super(formatted_state)
65
+ super(formatted_state, **kwargs)
64
66
  end
65
67
  RUBY
68
+ # rubocop:enable Style/IfUnlessModifier
66
69
  end
67
70
  end
68
71
 
@@ -149,9 +149,9 @@ module OpenHAB
149
149
  # end
150
150
  # end
151
151
  #
152
- def command(command, for: nil, on_expire: nil, only_when_ensured: false, &block)
152
+ def command(command, for: nil, on_expire: nil, only_when_ensured: false, **kwargs, &block)
153
153
  duration = binding.local_variable_get(:for)
154
- return super(command) unless duration
154
+ return super(command, **kwargs) unless duration
155
155
 
156
156
  on_expire = block if block
157
157
 
@@ -159,10 +159,10 @@ module OpenHAB
159
159
  on_expire ||= default_on_expire(command)
160
160
  if only_when_ensured
161
161
  DSL.ensure_states do
162
- create_timed_command(command, duration: duration, on_expire: on_expire) if super(command)
162
+ create_timed_command(command, duration: duration, on_expire: on_expire) if super(command, **kwargs)
163
163
  end
164
164
  else
165
- super(command)
165
+ super(command, **kwargs)
166
166
  create_timed_command(command, duration: duration, on_expire: on_expire)
167
167
  end
168
168
  end
@@ -180,12 +180,12 @@ module OpenHAB
180
180
  create_ensured_timed_command.call
181
181
  else
182
182
  # timed command still pending; reset it
183
- logger.trace "Outstanding Timed Command #{timed_command_details} encountered - rescheduling"
183
+ logger.trace { "Outstanding Timed Command #{timed_command_details} encountered - rescheduling" }
184
184
  timed_command_details.on_expire = on_expire unless on_expire.nil?
185
185
  timed_command_details.timer.reschedule(duration)
186
186
  # disable the cancel rule while we send the new command
187
187
  DSL.rules[timed_command_details.rule_uid].disable
188
- super(command) # This returns nil when "ensured"
188
+ super(command, **kwargs) # This returns nil when "ensured"
189
189
  DSL.rules[timed_command_details.rule_uid].enable
190
190
  timed_command_details
191
191
  end
@@ -209,7 +209,7 @@ module OpenHAB
209
209
  unmanaged_rule = Core.automation_manager.add_unmanaged_rule(cancel_rule)
210
210
  timed_command_details.rule_uid = unmanaged_rule.uid
211
211
  Core::Rules::Provider.current.add(unmanaged_rule)
212
- logger.trace "Created Timed Command #{timed_command_details}"
212
+ logger.trace { "Created Timed Command #{timed_command_details}" }
213
213
  timed_command_details
214
214
  end
215
215
 
@@ -219,12 +219,14 @@ module OpenHAB
219
219
  def timed_command_timer(timed_command_details, duration)
220
220
  DSL.after(duration) do
221
221
  timed_command_details.mutex.synchronize do
222
- logger.trace "Timed command expired - #{timed_command_details}"
222
+ logger.trace { "Timed command expired - #{timed_command_details}" }
223
223
  DSL.rules[timed_command_details.rule_uid].disable
224
224
  timed_command_details.resolution = :expired
225
225
  case timed_command_details.on_expire
226
226
  when Proc
227
- logger.trace "Invoking block #{timed_command_details.on_expire} after timed command for #{name} expired"
227
+ logger.trace do
228
+ "Invoking block #{timed_command_details.on_expire} after timed command for #{name} expired"
229
+ end
228
230
  timed_command_details.on_expire.call(timed_command_details)
229
231
  when Core::Types::UnDefType
230
232
  update(timed_command_details.on_expire)
@@ -20,7 +20,7 @@ module OpenHAB
20
20
  # @param [Object] thing to combine with channels and iterate over
21
21
  # @return [Enumerable] enumerable channel ids to trigger on
22
22
  def self.channels(channels:, thing:)
23
- logger.trace "Creating Channel/Thing Pairs for channels #{channels.inspect} and things #{thing.inspect}"
23
+ logger.trace { "Creating Channel/Thing Pairs for channels #{channels.inspect} and things #{thing.inspect}" }
24
24
  channels.flatten.product([thing].flatten)
25
25
  .map { |channel_thing| channel_id(*channel_thing) }
26
26
  end
@@ -47,7 +47,7 @@ module OpenHAB
47
47
  def trigger(channel:, trigger:, attach:)
48
48
  config = { "channelUID" => channel }
49
49
  config["event"] = trigger.to_s unless trigger.nil?
50
- logger.trace "Creating Channel Trigger for channels #{channel.inspect} and config #{config.inspect}"
50
+ logger.trace { "Creating Channel Trigger for channels #{channel.inspect} and config #{config.inspect}" }
51
51
  append_trigger(type: CHANNEL_EVENT, config: config, attach: attach)
52
52
  end
53
53
  end
@@ -41,7 +41,7 @@ module OpenHAB
41
41
  def thread_local(**values)
42
42
  old_values = values.to_h { |key, _value| [key, Thread.current[key]] }
43
43
  values.each { |key, value| Thread.current[key] = value }
44
- logger.trace "Executing block with thread local context: #{values} - old context: #{old_values}"
44
+ logger.trace { "Executing block with thread local context: #{values} - old context: #{old_values}" }
45
45
  yield
46
46
  ensure
47
47
  old_values.each { |key, value| Thread.current[key] = value }
@@ -4,6 +4,6 @@ module OpenHAB
4
4
  module DSL
5
5
  # Version of openHAB helper libraries
6
6
  # @return [String]
7
- VERSION = "5.29.0"
7
+ VERSION = "5.30.1"
8
8
  end
9
9
  end
data/lib/openhab/dsl.rb CHANGED
@@ -1087,4 +1087,4 @@ singleton_class.include(OpenHAB::DSL)
1087
1087
  Object.extend(OpenHAB::CoreExt::Ruby::Object::ClassMethods)
1088
1088
  OpenHAB::CoreExt::Ruby::Object.instance_variable_set(:@top_self, self)
1089
1089
 
1090
- logger.debug "openHAB JRuby Scripting Library Version #{OpenHAB::DSL::VERSION} Loaded"
1090
+ logger.debug { "openHAB JRuby Scripting Library Version #{OpenHAB::DSL::VERSION} Loaded" }
data/lib/openhab/osgi.rb CHANGED
@@ -24,7 +24,7 @@ module OpenHAB
24
24
  #
25
25
  def services(name, filter: nil)
26
26
  (bundle_context.get_service_references(name, filter) || []).map do |reference|
27
- logger.trace "OSGi service found for '#{name}' using OSGi Service Reference #{reference}"
27
+ logger.trace { "OSGi service found for '#{name}' using OSGi Service Reference #{reference}" }
28
28
  bundle_context.get_service(reference)
29
29
  end
30
30
  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.29.0
4
+ version: 5.30.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-19 00:00:00.000000000 Z
13
+ date: 2024-10-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -490,7 +490,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
490
490
  - !ruby/object:Gem::Version
491
491
  version: '0'
492
492
  requirements: []
493
- rubygems_version: 3.5.19
493
+ rubygems_version: 3.5.20
494
494
  signing_key:
495
495
  specification_version: 4
496
496
  summary: JRuby Helper Libraries for openHAB Scripting