openhab-scripting 5.42.1 → 5.43.0

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: 73d44fb2a401e3ffc950a2d19ca59000005bf77cbb891e9e94287b8f0909adb1
4
- data.tar.gz: a7c690eb7003d86678ad9a3a5310eb3566a6f77d11fd984049f825959f5c4346
3
+ metadata.gz: 6b42fbceb3c29151aaef433d5992fa21dd38662e25e3644cdbdc0a81cfa392d5
4
+ data.tar.gz: 7ce847854bad3ccc7b2734cbd788b5a1a3fe21e82ec966240554a645a19b3518
5
5
  SHA512:
6
- metadata.gz: 1517830917a483f391f14fc45ad281e2f04165797a1f13a65b543d6cd89d1196f5312b605312e41733de73012282bf474c77bd261574ba226b6bd6df62055a5e
7
- data.tar.gz: d0c83fdf5d653c0e548a7de8d0035e0b2beefa3963d963ef20d51b3ed01ffc585b9085124b0dc2dfb0eef6ae2e3848c44958cb6a7dc7d346dd45f94f568a96eb
6
+ metadata.gz: 8f0940e4520b47a7f35dada758fea1e079d8fca10e9e484e4d54f2cea738b7ca6d06dd81eed936c1525b5f9ef9fb884d4fb36fd4e714adc47c8d87544a824368
7
+ data.tar.gz: edba4793deda5989f59b0b8c106273d3ffb3963575c8dbcbeb45d75e316141cba86528c8e6126c4e53629043be86d21a6b321c174a2ec90803eec22217853634
@@ -10,6 +10,9 @@ module OpenHAB
10
10
  # The core features of an openHAB item.
11
11
  #
12
12
  module Item
13
+ EVENT_SOURCE = "org.openhab.automation.jrubyscripting"
14
+ private_constant :EVENT_SOURCE
15
+
13
16
  class << self
14
17
  # @!visibility private
15
18
  #
@@ -152,6 +155,7 @@ module OpenHAB
152
155
  def command(command, source: nil)
153
156
  command = format_command(command)
154
157
  logger.trace { "Sending Command #{command} to #{name}" }
158
+ source ||= infer_source if VERSION >= V5_1
155
159
  if source
156
160
  Events.publisher.post(Events::ItemEventFactory.create_command_event(name, command, source.to_s))
157
161
  else
@@ -179,6 +183,7 @@ module OpenHAB
179
183
  # When given a {State} argument, it will be passed directly.
180
184
  # Otherwise, the result of `#to_s` will be parsed into a {State} first.
181
185
  # If `nil` is passed, the item will be updated to {NULL}.
186
+ # @param [String, nil] source Optional string to identify what sent the event.
182
187
  # @return [self, nil] nil when `ensure` is in effect and the item was already in the same state,
183
188
  # otherwise the item.
184
189
  #
@@ -196,10 +201,15 @@ module OpenHAB
196
201
  # @example Updating with a string to a dimensioned {NumberItem}
197
202
  # InsideTemperature.update("22.5 °C") # The string will be parsed and converted to a QuantityType
198
203
  #
199
- def update(state)
204
+ def update(state, source: nil)
200
205
  state = format_update(state)
201
206
  logger.trace { "Sending Update #{state} to #{name}" }
202
- $events.post_update(self, state)
207
+ source ||= infer_source if VERSION >= V5_1
208
+ if source
209
+ Events.publisher.post(Events::ItemEventFactory.create_state_event(name, state, source.to_s))
210
+ else
211
+ $events.post_update(self, state)
212
+ end
203
213
  Proxy.new(self)
204
214
  end
205
215
  alias_method :update!, :update
@@ -630,6 +640,17 @@ module OpenHAB
630
640
  # Allows sub-classes to append additional details to the type in an inspect string
631
641
  # @return [String]
632
642
  def type_details; end
643
+
644
+ def infer_source
645
+ actor = if $ctx&.key?("ruleUID")
646
+ "rule:#{$ctx["ruleUID"]}"
647
+ elsif (rule_uid = Thread.current[:openhab_rule_uid])
648
+ "#{Thread.current[:openhab_rule_type]}:#{rule_uid}"
649
+ else
650
+ Log.top_level_file
651
+ end
652
+ org.openhab.core.events.AbstractEvent.build_source(EVENT_SOURCE, actor)
653
+ end
633
654
  end
634
655
  end
635
656
  end
@@ -4,6 +4,6 @@ module OpenHAB
4
4
  module DSL
5
5
  # Version of openHAB helper libraries
6
6
  # @return [String]
7
- VERSION = "5.42.1"
7
+ VERSION = "5.43.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.42.1
4
+ version: 5.43.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian O'Connell