openhab-scripting 3.6.0 → 3.7.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/dsl/items/item_delegate.rb +2 -0
- data/lib/openhab/dsl/items/number_item.rb +4 -4
- data/lib/openhab/dsl/monkey_patch/items/items.rb +2 -1
- data/lib/openhab/dsl/monkey_patch/types/decimal_type.rb +2 -1
- data/lib/openhab/dsl/types/quantity.rb +16 -10
- data/lib/openhab/dsl/units.rb +2 -3
- data/lib/openhab/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89ffddc84813de3f052d94698ecefc53749209ab11ed9ab0cb3c4d49147160e1
|
4
|
+
data.tar.gz: 7cda484eeb62e12d4bff2428c92ec3e50290355ee73cb7e9b5c3e31df211f7c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07b69684db4ca8a2ea2ca55b6ce4b322178ba91231a7ca2406f03bf2f93daa25987e8376307685799aa4c59a0570cd4cd7e9021b57d712c3ee1f28f8b524aa82
|
7
|
+
data.tar.gz: 5bf3600892d7af2e93f7102e12d4a972d57393d3e549d1275adb0d245a0dbb64be4ebb1d739d38eef65242526116829eae07643300665d17cc12155d8b3687c7
|
@@ -23,8 +23,8 @@ module OpenHAB
|
|
23
23
|
|
24
24
|
java_import org.openhab.core.library.types.DecimalType
|
25
25
|
java_import org.openhab.core.library.types.QuantityType
|
26
|
-
java_import
|
27
|
-
java_import
|
26
|
+
java_import org.openhab.core.types.util.UnitUtils
|
27
|
+
java_import org.openhab.core.library.unit.Units
|
28
28
|
|
29
29
|
item_type Java::OrgOpenhabCoreLibraryItems::NumberItem
|
30
30
|
|
@@ -93,7 +93,7 @@ module OpenHAB
|
|
93
93
|
# @return [OpenHAB::DSL::Types::Quantity] NumberItem converted to supplied Unit
|
94
94
|
#
|
95
95
|
def |(other)
|
96
|
-
other =
|
96
|
+
other = UnitUtils.parse_unit(other) if other.is_a? String
|
97
97
|
|
98
98
|
if dimension
|
99
99
|
to_qt | other
|
@@ -111,7 +111,7 @@ module OpenHAB
|
|
111
111
|
if dimension
|
112
112
|
Quantity.new(@number_item.get_state_as(QuantityType))
|
113
113
|
else
|
114
|
-
Quantity.new(QuantityType.new(to_d.to_java,
|
114
|
+
Quantity.new(QuantityType.new(to_d.to_java, Units::ONE))
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
@@ -33,7 +33,7 @@ module OpenHAB
|
|
33
33
|
#
|
34
34
|
#
|
35
35
|
def command(command)
|
36
|
-
command = command.to_java.strip_trailing_zeros if command.is_a? BigDecimal
|
36
|
+
command = command.to_java.strip_trailing_zeros.to_plain_string if command.is_a? BigDecimal
|
37
37
|
logger.trace "Sending Command #{command} to #{id}"
|
38
38
|
BusEvent.sendCommand(self, command.to_s)
|
39
39
|
end
|
@@ -47,6 +47,7 @@ module OpenHAB
|
|
47
47
|
#
|
48
48
|
#
|
49
49
|
def update(update)
|
50
|
+
update = update.to_java.strip_trailing_zeros.to_plain_string if update.is_a? BigDecimal
|
50
51
|
logger.trace "Sending Update #{update} to #{id}"
|
51
52
|
BusEvent.postUpdate(self, update.to_s)
|
52
53
|
end
|
@@ -10,6 +10,7 @@ module OpenHAB
|
|
10
10
|
#
|
11
11
|
module Types
|
12
12
|
java_import Java::OrgOpenhabCoreLibraryTypes::DecimalType
|
13
|
+
java_import org.openhab.core.types.util.UnitUtils
|
13
14
|
|
14
15
|
#
|
15
16
|
# MonkeyPatching Decimal Type
|
@@ -72,7 +73,7 @@ module OpenHAB
|
|
72
73
|
# @return [OpenHAB::Core::DSL::Types::Quantity] NumberItem converted to supplied Unit
|
73
74
|
#
|
74
75
|
def |(other)
|
75
|
-
other =
|
76
|
+
other = UnitUtils.parse_unit(other) if other.is_a? String
|
76
77
|
Quantity.new(QuantityType.new(to_big_decimal, other))
|
77
78
|
end
|
78
79
|
|
@@ -20,11 +20,12 @@ module OpenHAB
|
|
20
20
|
include OpenHAB::Log
|
21
21
|
|
22
22
|
def_delegator :@quantity, :to_s
|
23
|
+
def_delegators '@quantity.double_value', :positive?, :negative?, :zero?
|
23
24
|
|
24
25
|
java_import org.openhab.core.library.types.QuantityType
|
25
26
|
java_import org.openhab.core.library.types.DecimalType
|
26
|
-
java_import
|
27
|
-
java_import
|
27
|
+
java_import org.openhab.core.types.util.UnitUtils
|
28
|
+
java_import org.openhab.core.library.unit.Units
|
28
29
|
|
29
30
|
# @return [Hash] Mapping of operation symbols to BigDecimal methods
|
30
31
|
OPERATIONS = {
|
@@ -48,7 +49,7 @@ module OpenHAB
|
|
48
49
|
@quantity = case quantity
|
49
50
|
when String then QuantityType.new(quantity)
|
50
51
|
when QuantityType then quantity
|
51
|
-
when NumberItem, Numeric then QuantityType.new(quantity.to_d.to_java,
|
52
|
+
when NumberItem, Numeric then QuantityType.new(quantity.to_d.to_java, Units::ONE)
|
52
53
|
else raise ArgumentError, "Unexpected type #{quantity.class} provided to Quantity initializer"
|
53
54
|
end
|
54
55
|
super()
|
@@ -62,7 +63,7 @@ module OpenHAB
|
|
62
63
|
# @return [Quantity] This quantity converted to another unit
|
63
64
|
#
|
64
65
|
def |(other)
|
65
|
-
other =
|
66
|
+
other = UnitUtils.parse_unit(other) if other.is_a? String
|
66
67
|
|
67
68
|
Quantity.new(quantity.to_unit(other))
|
68
69
|
end
|
@@ -164,7 +165,7 @@ module OpenHAB
|
|
164
165
|
# @return [String] Representing details about the quantity object
|
165
166
|
#
|
166
167
|
def inspect
|
167
|
-
if @quantity.unit ==
|
168
|
+
if @quantity.unit == Units::ONE
|
168
169
|
"unit=#{@quantity.unit}, value=#{@quantity.to_string}"
|
169
170
|
else
|
170
171
|
@quantity.to_string
|
@@ -185,8 +186,8 @@ module OpenHAB
|
|
185
186
|
#
|
186
187
|
# @return [Array] Array of QuantityType objects
|
187
188
|
#
|
188
|
-
def to_qt(*
|
189
|
-
[
|
189
|
+
def to_qt(*quantities)
|
190
|
+
[quantities].flatten.compact.map { |item| item.is_a?(Quantity) ? item.quantity : item }
|
190
191
|
end
|
191
192
|
|
192
193
|
#
|
@@ -198,7 +199,7 @@ module OpenHAB
|
|
198
199
|
# @return [Boolean] True if the quantity should be unitzed based on the unit and operation, false otherwise
|
199
200
|
#
|
200
201
|
def unitize?(quantity, operation)
|
201
|
-
!(quantity.unit ==
|
202
|
+
!(quantity.unit == Units::ONE && DIMENSIONLESS_NON_UNITIZED_OPERATIONS.include?(operation))
|
202
203
|
end
|
203
204
|
|
204
205
|
#
|
@@ -214,7 +215,7 @@ module OpenHAB
|
|
214
215
|
case quantity.unit
|
215
216
|
when unit
|
216
217
|
quantity
|
217
|
-
when
|
218
|
+
when Units::ONE
|
218
219
|
convert_unit_from_dimensionless(quantity, unit)
|
219
220
|
else
|
220
221
|
convert_unit_from_dimensioned(quantity, unit)
|
@@ -263,7 +264,12 @@ module OpenHAB
|
|
263
264
|
def unitize(quantity_a, quantity_b, operation = nil)
|
264
265
|
logger.trace("Unitizing (#{quantity_a}) and (#{quantity_b})")
|
265
266
|
quantity_a, quantity_b = [quantity_a, quantity_b].map do |qt|
|
266
|
-
unitize?(qt, operation) ? convert_unit(qt) : qt
|
267
|
+
unitize?(qt, operation) ? convert_unit(qt) : qt.to_big_decimal
|
268
|
+
end
|
269
|
+
|
270
|
+
# Make sure the operation is called on the QuantityType
|
271
|
+
if quantity_a.is_a?(Java::JavaMath::BigDecimal) && quantity_b.is_a?(QuantityType) && operation == '*'
|
272
|
+
quantity_a, quantity_b = [quantity_b, quantity_a]
|
267
273
|
end
|
268
274
|
return yield quantity_a, quantity_b if block_given?
|
269
275
|
|
data/lib/openhab/dsl/units.rb
CHANGED
@@ -10,6 +10,7 @@ end
|
|
10
10
|
|
11
11
|
Object.send(:remove_const, :QuantityType)
|
12
12
|
java_import org.openhab.core.library.types.QuantityType
|
13
|
+
java_import org.openhab.core.types.util.UnitUtils
|
13
14
|
|
14
15
|
module OpenHAB
|
15
16
|
module DSL
|
@@ -17,8 +18,6 @@ module OpenHAB
|
|
17
18
|
# Provides support for interacting with OpenHAB Units of Measurement
|
18
19
|
#
|
19
20
|
module Units
|
20
|
-
java_import 'tec.uom.se.format.SimpleUnitFormat'
|
21
|
-
|
22
21
|
#
|
23
22
|
# Sets a thread local variable to the supplied unit such that classes operating inside the block
|
24
23
|
# can perform automatic conversions to the supplied unit for NumberItems
|
@@ -28,7 +27,7 @@ module OpenHAB
|
|
28
27
|
#
|
29
28
|
#
|
30
29
|
def unit(unit)
|
31
|
-
unit =
|
30
|
+
unit = UnitUtils.parse_unit(unit) if unit.is_a? String
|
32
31
|
Thread.current.thread_variable_set(:unit, unit)
|
33
32
|
yield
|
34
33
|
ensure
|
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: 3.
|
4
|
+
version: 3.7.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-06-
|
11
|
+
date: 2021-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|