openhab-scripting 2.20.2 → 2.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/openhab/dsl/monkey_patch/events/events.rb +1 -0
- data/lib/openhab/dsl/monkey_patch/events/item_state.rb +23 -0
- data/lib/openhab/dsl/monkey_patch/items/metadata.rb +3 -5
- data/lib/openhab/dsl/monkey_patch/items/persistence.rb +6 -1
- data/lib/openhab/dsl/monkey_patch/ruby/string.rb +1 -1
- data/lib/openhab/dsl/monkey_patch/types/decimal_type.rb +21 -0
- data/lib/openhab/dsl/rules/automation_rule.rb +31 -6
- data/lib/openhab/dsl/rules/triggers/changed.rb +2 -10
- data/lib/openhab/dsl/types/quantity.rb +2 -0
- data/lib/openhab/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b38e635249a2d0e8633e75504eb3e42f79399d1e66b90f5242f3dc8062c711b
|
4
|
+
data.tar.gz: dcb573a627b8f93d5a4f6e1bbb8e9b8033f4765b33e49ab88d07414e055b5e7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6b8e1f865bf8912e0575495c0539e96acd5f7c8dc77582ab355bee6e5def4e45701cf159d77b12fe7975cb8493fafbcc0260706f2bd500fddeecf4a66683e5e
|
7
|
+
data.tar.gz: fb3c37bf6fdd9f9f95feb26e39e44cd336b7da07a4831e1d3b8079bcbac0f57c005c7324e683dbcb5baa67c60124e947e965edb88b3f8a43a51f03e29fa383a9
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'java'
|
4
|
+
|
5
|
+
module OpenHAB
|
6
|
+
module DSL
|
7
|
+
module MonkeyPatch
|
8
|
+
#
|
9
|
+
# Patches OpenHAB events
|
10
|
+
#
|
11
|
+
module Events
|
12
|
+
java_import Java::OrgOpenhabCoreItemsEvents::ItemStateEvent
|
13
|
+
|
14
|
+
#
|
15
|
+
# MonkeyPatch with ruby style accessors
|
16
|
+
#
|
17
|
+
class ItemStateEvent
|
18
|
+
alias state item_state
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -29,7 +29,7 @@ module OpenHAB
|
|
29
29
|
def_delegator :@metadata, :value
|
30
30
|
|
31
31
|
def initialize(metadata: nil, key: nil, value: nil, config: nil)
|
32
|
-
@metadata = metadata || Metadata.new(key || MetadataKey.new('', ''), value, config)
|
32
|
+
@metadata = metadata || Metadata.new(key || MetadataKey.new('', ''), value&.to_s, config)
|
33
33
|
super(@metadata&.configuration)
|
34
34
|
end
|
35
35
|
|
@@ -60,9 +60,7 @@ module OpenHAB
|
|
60
60
|
# @return [Java::Org::openhab::core::items::Metadata] the old metadata
|
61
61
|
#
|
62
62
|
def value=(value)
|
63
|
-
|
64
|
-
|
65
|
-
metadata = Metadata.new(@metadata&.uID, value, @metadata&.configuration)
|
63
|
+
metadata = Metadata.new(@metadata&.uID, value&.to_s, @metadata&.configuration)
|
66
64
|
NamespaceAccessor.registry.update(metadata) if @metadata&.uID
|
67
65
|
end
|
68
66
|
|
@@ -125,7 +123,7 @@ module OpenHAB
|
|
125
123
|
meta_value, configuration = update_from_value(value)
|
126
124
|
|
127
125
|
key = MetadataKey.new(namespace, @item_name)
|
128
|
-
metadata = Metadata.new(key, meta_value, configuration)
|
126
|
+
metadata = Metadata.new(key, meta_value&.to_s, configuration)
|
129
127
|
# registry.get can be omitted, but registry.update will log a warning for nonexistent metadata
|
130
128
|
if NamespaceAccessor.registry.get(key)
|
131
129
|
NamespaceAccessor.registry.update(metadata)
|
@@ -49,7 +49,12 @@ module OpenHAB
|
|
49
49
|
if timestamp.is_a? Java::JavaTimeTemporal::TemporalAmount
|
50
50
|
timestamp = Java::JavaTime::ZonedDateTime.now.minus(timestamp)
|
51
51
|
end
|
52
|
-
PersistenceExtensions.public_send(method, self, timestamp, service&.to_s)
|
52
|
+
result = PersistenceExtensions.public_send(method, self, timestamp, service&.to_s)
|
53
|
+
if result.is_a?(Java::OrgOpenhabCoreLibraryTypes::DecimalType) && respond_to?(:unit) && unit
|
54
|
+
Quantity.new(Java::OrgOpenhabCoreLibraryTypes::QuantityType.new(result.to_big_decimal, unit))
|
55
|
+
else
|
56
|
+
result
|
57
|
+
end
|
53
58
|
end
|
54
59
|
end
|
55
60
|
|
@@ -63,6 +63,27 @@ module OpenHAB
|
|
63
63
|
logger.trace("#{self.class} #{self} == #{other} (#{other.class})")
|
64
64
|
(self <=> other).zero?
|
65
65
|
end
|
66
|
+
|
67
|
+
#
|
68
|
+
# Convert DecimalType to a Quantity
|
69
|
+
#
|
70
|
+
# @param [Object] other String or Unit representing an OpenHAB Unit
|
71
|
+
#
|
72
|
+
# @return [OpenHAB::Core::DSL::Types::Quantity] NumberItem converted to supplied Unit
|
73
|
+
#
|
74
|
+
def |(other)
|
75
|
+
other = SimpleUnitFormat.instance.unitFor(other) if other.is_a? String
|
76
|
+
Quantity.new(QuantityType.new(to_big_decimal, other))
|
77
|
+
end
|
78
|
+
|
79
|
+
#
|
80
|
+
# Provide details about DecimalType object
|
81
|
+
#
|
82
|
+
# @return [String] Representing details about the DecimalType object
|
83
|
+
#
|
84
|
+
def inspect
|
85
|
+
to_string
|
86
|
+
end
|
66
87
|
end
|
67
88
|
end
|
68
89
|
end
|
@@ -100,8 +100,7 @@ module OpenHAB
|
|
100
100
|
# @return [Boolean] True if the rule should execute, false if trigger guard prevents execution
|
101
101
|
#
|
102
102
|
def check_trigger_guards(trigger_delay, inputs)
|
103
|
-
old_state = inputs
|
104
|
-
new_state = inputs['newState']
|
103
|
+
new_state, old_state = retrieve_states(inputs)
|
105
104
|
if check_from(trigger_delay, old_state)
|
106
105
|
return true if check_to(trigger_delay, new_state)
|
107
106
|
|
@@ -113,6 +112,32 @@ module OpenHAB
|
|
113
112
|
end
|
114
113
|
end
|
115
114
|
|
115
|
+
#
|
116
|
+
# Rerieve the newState and oldState, alternatively newStatus and oldStatus
|
117
|
+
# from the input map
|
118
|
+
#
|
119
|
+
# @param [Map] inputs OpenHAB map object describing rule trigger
|
120
|
+
#
|
121
|
+
# @return [Array] An array of the values for [newState, oldState] or [newStatus, oldStatus]
|
122
|
+
#
|
123
|
+
def retrieve_states(inputs)
|
124
|
+
old_state = inputs['oldState'] || thing_status_to_sym(inputs['oldStatus'])
|
125
|
+
new_state = inputs['newState'] || thing_status_to_sym(inputs['newStatus'])
|
126
|
+
|
127
|
+
[new_state, old_state]
|
128
|
+
end
|
129
|
+
|
130
|
+
#
|
131
|
+
# Converts a ThingStatus object to a ruby Symbol
|
132
|
+
#
|
133
|
+
# @param [Java::OrgOpenhabCoreThing::ThingStatus] status A ThingStatus instance
|
134
|
+
#
|
135
|
+
# @return [Symbol] A corresponding symbol, in lower case
|
136
|
+
#
|
137
|
+
def thing_status_to_sym(status)
|
138
|
+
status&.to_s&.downcase&.to_sym
|
139
|
+
end
|
140
|
+
|
116
141
|
#
|
117
142
|
# Check the from state against the trigger delay
|
118
143
|
#
|
@@ -122,7 +147,7 @@ module OpenHAB
|
|
122
147
|
# @return [Boolean] true if no from state is defined or defined state equals supplied state
|
123
148
|
#
|
124
149
|
def check_from(trigger_delay, state)
|
125
|
-
trigger_delay.from.nil? || trigger_delay.from
|
150
|
+
trigger_delay.from.nil? || state == trigger_delay.from
|
126
151
|
end
|
127
152
|
|
128
153
|
#
|
@@ -134,7 +159,7 @@ module OpenHAB
|
|
134
159
|
# @return [Boolean] true if no to state is defined or defined state equals supplied state
|
135
160
|
#
|
136
161
|
def check_to(trigger_delay, state)
|
137
|
-
trigger_delay.to.nil? || trigger_delay.to
|
162
|
+
trigger_delay.to.nil? || state == trigger_delay.to
|
138
163
|
end
|
139
164
|
|
140
165
|
#
|
@@ -174,7 +199,7 @@ module OpenHAB
|
|
174
199
|
queue = create_queue(inputs)
|
175
200
|
process_queue(queue, mod, inputs)
|
176
201
|
end
|
177
|
-
trigger_delay.tracking_to = inputs
|
202
|
+
trigger_delay.tracking_to, = retrieve_states(inputs)
|
178
203
|
end
|
179
204
|
|
180
205
|
#
|
@@ -186,7 +211,7 @@ module OpenHAB
|
|
186
211
|
#
|
187
212
|
#
|
188
213
|
def process_active_timer(inputs, mod, trigger_delay)
|
189
|
-
state = inputs
|
214
|
+
state, = retrieve_states(inputs)
|
190
215
|
if state == trigger_delay.tracking_to
|
191
216
|
logger.trace("Item changed to #{state} for #{trigger_delay}, rescheduling timer.")
|
192
217
|
trigger_delay.timer.reschedule(ZonedDateTime.now.plus(trigger_delay.duration))
|
@@ -58,16 +58,8 @@ module OpenHAB
|
|
58
58
|
# @return [Array] Array of current TriggerDelay objects
|
59
59
|
#
|
60
60
|
def changed_wait(item, duration:, to: nil, from: nil)
|
61
|
-
|
62
|
-
|
63
|
-
config = { 'groupName' => item.group.name }
|
64
|
-
trigger = Trigger::GROUP_STATE_CHANGE
|
65
|
-
else
|
66
|
-
config = { 'itemName' => item.name }
|
67
|
-
trigger = Trigger::ITEM_STATE_CHANGE
|
68
|
-
end
|
69
|
-
logger.trace("Creating Changed Wait Change Trigger for #{config}")
|
70
|
-
trigger = append_trigger(trigger, config)
|
61
|
+
trigger = create_changed_trigger(item, nil, nil)
|
62
|
+
logger.trace("Creating Changed Wait Change Trigger for #{item}")
|
71
63
|
@trigger_delays[trigger.id] = TriggerDelay.new(to: to, from: from, duration: duration)
|
72
64
|
end
|
73
65
|
|
@@ -22,6 +22,7 @@ module OpenHAB
|
|
22
22
|
def_delegator :@quantity, :to_s
|
23
23
|
|
24
24
|
java_import org.openhab.core.library.types.QuantityType
|
25
|
+
java_import org.openhab.core.library.types.DecimalType
|
25
26
|
java_import 'tec.uom.se.format.SimpleUnitFormat'
|
26
27
|
java_import 'tec.uom.se.AbstractUnit'
|
27
28
|
|
@@ -92,6 +93,7 @@ module OpenHAB
|
|
92
93
|
case other
|
93
94
|
when Quantity then [other.quantity, quantity]
|
94
95
|
when QuantityType then [other, quantity]
|
96
|
+
when DecimalType then [Quantity.new(other.to_big_decimal.to_d), quantity]
|
95
97
|
when NumberItem then [other.to_qt.quantity, quantity]
|
96
98
|
when Numeric, String then [Quantity.new(other), self]
|
97
99
|
end
|
data/lib/openhab/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openhab-scripting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.23.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian O'Connell
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- lib/openhab/dsl/monkey_patch/actions/script_thing_actions.rb
|
50
50
|
- lib/openhab/dsl/monkey_patch/events/events.rb
|
51
51
|
- lib/openhab/dsl/monkey_patch/events/item_command.rb
|
52
|
+
- lib/openhab/dsl/monkey_patch/events/item_state.rb
|
52
53
|
- lib/openhab/dsl/monkey_patch/events/item_state_changed.rb
|
53
54
|
- lib/openhab/dsl/monkey_patch/events/thing_status_info.rb
|
54
55
|
- lib/openhab/dsl/monkey_patch/items/contact_item.rb
|