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 +4 -4
- data/lib/openhab/core/items/item.rb +23 -2
- data/lib/openhab/dsl/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6b42fbceb3c29151aaef433d5992fa21dd38662e25e3644cdbdc0a81cfa392d5
|
|
4
|
+
data.tar.gz: 7ce847854bad3ccc7b2734cbd788b5a1a3fe21e82ec966240554a645a19b3518
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
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
|
data/lib/openhab/dsl/version.rb
CHANGED