openhab-scripting 4.11.1 → 4.13.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f8fbc8b811541d42b4409776ee2debc6681bfbf17d725e68b3090a31b7ab3ae
|
4
|
+
data.tar.gz: 621ae3605cd46036106b12cf64dc6eb200d7bdcd6cbd5e10cd512bc52f98f5b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c73ffba5f0d95ba2cf622659b9f2bb52e1e3a033c7ef4f52f04beff29abfdea86f79f4b1f9aa08dd6bc2c9478f0adad3942866c0cb556df6fd6164d18f19f389
|
7
|
+
data.tar.gz: f4f04af30d25bd46fe5625240d218f9fa610172a03d1e26d0ac0feda4efc54a8b17a403ed0b533bf2bfef79b0eaace7eb2fac7ca9ae48c88741f4a54cce39f66
|
@@ -29,7 +29,7 @@ module OpenHAB
|
|
29
29
|
|
30
30
|
def initialize(metadata: nil, key: nil, value: nil, config: nil)
|
31
31
|
@metadata = metadata || Metadata.new(key || MetadataKey.new('', ''), value&.to_s, config)
|
32
|
-
super(to_ruby(@metadata&.configuration))
|
32
|
+
super(MetadataItem.to_ruby(@metadata&.configuration))
|
33
33
|
end
|
34
34
|
|
35
35
|
#
|
@@ -86,8 +86,6 @@ module OpenHAB
|
|
86
86
|
[@metadata&.value, @metadata&.configuration || {}]
|
87
87
|
end
|
88
88
|
|
89
|
-
private
|
90
|
-
|
91
89
|
#
|
92
90
|
# Recursively convert the supplied Hash object into a Ruby Hash and recreate the keys and values
|
93
91
|
#
|
@@ -95,7 +93,7 @@ module OpenHAB
|
|
95
93
|
#
|
96
94
|
# @return [Hash] The converted hash
|
97
95
|
#
|
98
|
-
def to_ruby_hash(hash)
|
96
|
+
def self.to_ruby_hash(hash)
|
99
97
|
return unless hash.respond_to? :each_with_object
|
100
98
|
|
101
99
|
hash.each_with_object({}) { |(key, value), ruby_hash| ruby_hash[to_ruby(key)] = to_ruby(value) }
|
@@ -108,14 +106,14 @@ module OpenHAB
|
|
108
106
|
#
|
109
107
|
# @return [Array] The converted array
|
110
108
|
#
|
111
|
-
def to_ruby_array(array)
|
109
|
+
def self.to_ruby_array(array)
|
112
110
|
return unless array.respond_to? :each_with_object
|
113
111
|
|
114
112
|
array.each_with_object([]) { |value, ruby_array| ruby_array << to_ruby(value) }
|
115
113
|
end
|
116
114
|
|
117
115
|
# Convert the given object to Ruby equivalent
|
118
|
-
def to_ruby(value)
|
116
|
+
def self.to_ruby(value)
|
119
117
|
case value
|
120
118
|
when Hash, Java::JavaUtil::Map then to_ruby_hash(value)
|
121
119
|
when Array, Java::JavaUtil::List then to_ruby_array(value)
|
@@ -188,7 +186,9 @@ module OpenHAB
|
|
188
186
|
return unless block_given?
|
189
187
|
|
190
188
|
NamespaceAccessor.registry.getAll.each do |meta|
|
191
|
-
|
189
|
+
if meta.uID.itemName == @item_name
|
190
|
+
yield meta.uID.namespace, MetadataItem.to_ruby(meta.value), MetadataItem.to_ruby(meta.configuration)
|
191
|
+
end
|
192
192
|
end
|
193
193
|
end
|
194
194
|
|
@@ -64,6 +64,32 @@ module OpenHAB
|
|
64
64
|
def to_s
|
65
65
|
"#{to_string}%"
|
66
66
|
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# Scale the value to a particular range
|
70
|
+
#
|
71
|
+
# @param range [Range] the range as a numeric
|
72
|
+
# @return [Numeric] the value as a percentage of the range
|
73
|
+
#
|
74
|
+
def scale(range) # rubocop:disable Metrics/AbcSize
|
75
|
+
unless range.is_a?(Range) && range.min.is_a?(Numeric) && range.max.is_a?(Numeric)
|
76
|
+
raise ArgumentError, 'range must be a Range of Numerics'
|
77
|
+
end
|
78
|
+
|
79
|
+
result = (to_d * (range.max - range.min) / 100) + range.min
|
80
|
+
case range.max
|
81
|
+
when Integer then result.round
|
82
|
+
when Float then result.to_f
|
83
|
+
else result
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# scale the value to fit in a single byte
|
88
|
+
#
|
89
|
+
# @return [Integer] an integer in the range 0-255
|
90
|
+
def to_byte
|
91
|
+
scale(0..255)
|
92
|
+
end
|
67
93
|
end
|
68
94
|
end
|
69
95
|
end
|
@@ -50,6 +50,9 @@ module OpenHAB
|
|
50
50
|
def <=>(other) # rubocop:disable Metrics
|
51
51
|
logger.trace("(#{self.class}) #{self} <=> #{other} (#{other.class})")
|
52
52
|
if other.is_a?(self.class)
|
53
|
+
return unitize(other.unit).compare_to(other) if unit == ONE
|
54
|
+
return compare_to(other.unitize(unit)) if other.unit == ONE
|
55
|
+
|
53
56
|
compare_to(other)
|
54
57
|
elsif other.is_a?(Items::NumericItem) ||
|
55
58
|
(other.is_a?(Items::GroupItem) && other.base_item.is_a?(NumericItem))
|
data/lib/openhab/version.rb
CHANGED
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: 4.
|
4
|
+
version: 4.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian O'Connell
|
@@ -152,15 +152,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
152
152
|
requirements:
|
153
153
|
- - ">="
|
154
154
|
- !ruby/object:Gem::Version
|
155
|
-
version: 2.
|
155
|
+
version: 2.6.0
|
156
156
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
157
|
requirements:
|
158
158
|
- - ">="
|
159
159
|
- !ruby/object:Gem::Version
|
160
160
|
version: '0'
|
161
161
|
requirements: []
|
162
|
-
|
163
|
-
rubygems_version: 2.7.6.3
|
162
|
+
rubygems_version: 3.0.3.1
|
164
163
|
signing_key:
|
165
164
|
specification_version: 4
|
166
165
|
summary: JRuby Helper Libraries for OpenHAB Scripting
|