openhab-scripting 4.10.0 → 4.10.1
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/items/color_item.rb +0 -2
- data/lib/openhab/dsl/items/date_time_item.rb +0 -2
- data/lib/openhab/dsl/items/location_item.rb +0 -2
- data/lib/openhab/dsl/items/numeric_item.rb +0 -2
- data/lib/openhab/dsl/types/date_time_type.rb +5 -8
- data/lib/openhab/dsl/types/decimal_type.rb +5 -8
- data/lib/openhab/dsl/types/hsb_type.rb +1 -1
- data/lib/openhab/dsl/types/point_type.rb +12 -7
- data/lib/openhab/dsl/types/quantity_type.rb +8 -13
- data/lib/openhab/dsl/types/string_type.rb +3 -4
- data/lib/openhab/dsl/types/type.rb +13 -4
- data/lib/openhab/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: d06a02d7b0f2d02ed4e0ac6fdb06b61ef109b2eacb68cbc4c84c4ca766b94b9b
|
4
|
+
data.tar.gz: 69863d7d2d8a7c1f578a5eceeb949aa19ff09d23e1e7910aafad54f69eab3661
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bb723993916a3382b1795526c9b2373cc7017f8983e04e388c8fc655a427607eeb2564cf973769d0852306207c52b7540c4298034482b23cc6d9cfd588c7b8d
|
7
|
+
data.tar.gz: 234f9e2fc4752707ec7e4290745cca0eececfcbd0bb868feff6cb44850ff97df5eca6f0c2d755a350063aa7e8475db698d6efe9fd617d76f6971f33b77474ce7
|
@@ -39,8 +39,6 @@ module OpenHAB
|
|
39
39
|
logger.trace("Coercing #{self} as a request from #{other.class}")
|
40
40
|
return [other, nil] unless state?
|
41
41
|
return [other, state] if other.is_a?(Types::HSBType) || other.respond_to?(:to_str)
|
42
|
-
|
43
|
-
raise TypeError, "can't convert #{other.class} into #{self.class}"
|
44
42
|
end
|
45
43
|
|
46
44
|
# any method that exists on {Types::HSBType} gets forwarded to +state+
|
@@ -40,8 +40,6 @@ module OpenHAB
|
|
40
40
|
logger.trace("Coercing #{self} as a request from #{other.class}")
|
41
41
|
return [other, nil] unless state?
|
42
42
|
return [other, state] if other.is_a?(Types::DateTimeType) || other.respond_to?(:to_time)
|
43
|
-
|
44
|
-
raise TypeError, "can't convert #{other.class} into #{self.class}"
|
45
43
|
end
|
46
44
|
|
47
45
|
# any method that exists on DateTimeType, Java's ZonedDateTime, or
|
@@ -39,8 +39,6 @@ module OpenHAB
|
|
39
39
|
logger.trace("Coercing #{self} as a request from #{other.class}")
|
40
40
|
return [other, nil] unless state?
|
41
41
|
return [other, state] if other.is_a?(Types::PointType) || other.respond_to?(:to_str)
|
42
|
-
|
43
|
-
raise TypeError, "can't convert #{other.class} into #{self.class}"
|
44
42
|
end
|
45
43
|
|
46
44
|
# OpenHAB has this method, but it _only_ accepts PointType, so remove it and delegate
|
@@ -47,8 +47,6 @@ module OpenHAB
|
|
47
47
|
logger.trace("Coercing #{self} as a request from #{other.class}")
|
48
48
|
return [other, nil] unless state?
|
49
49
|
return [other, state] if other.is_a?(Types::NumericType) || other.respond_to?(:to_d)
|
50
|
-
|
51
|
-
raise TypeError, "can't convert #{other.class} into #{self.class}"
|
52
50
|
end
|
53
51
|
|
54
52
|
# strip trailing zeros from commands
|
@@ -161,7 +161,8 @@ module OpenHAB
|
|
161
161
|
time_string = "#{time_string}T00:00:00#{zone}" if DATE_ONLY_REGEX.match?(time_string)
|
162
162
|
self <=> DateTimeType.parse(time_string)
|
163
163
|
elsif other.respond_to?(:coerce)
|
164
|
-
lhs, rhs = other.coerce(self)
|
164
|
+
return nil unless (lhs, rhs = other.coerce(self))
|
165
|
+
|
165
166
|
lhs <=> rhs
|
166
167
|
end
|
167
168
|
end
|
@@ -179,13 +180,11 @@ module OpenHAB
|
|
179
180
|
def coerce(other)
|
180
181
|
logger.trace("Coercing #{self} as a request from #{other.class}")
|
181
182
|
if other.is_a?(Items::DateTimeItem)
|
182
|
-
|
183
|
+
return unless other.state?
|
183
184
|
|
184
185
|
[other.state, self]
|
185
186
|
elsif other.respond_to?(:to_time)
|
186
187
|
[DateTimeType.new(other), self]
|
187
|
-
else
|
188
|
-
raise TypeError, "can't convert #{other.class} into #{self.class}"
|
189
188
|
end
|
190
189
|
end
|
191
190
|
|
@@ -286,8 +285,7 @@ module OpenHAB
|
|
286
285
|
self + other
|
287
286
|
elsif other.respond_to?(:to_d)
|
288
287
|
DateTimeType.new(zoned_date_time.plusNanos((other.to_d * 1_000_000_000).to_i))
|
289
|
-
elsif other.respond_to?(:coerce)
|
290
|
-
lhs, rhs = other.coerce(to_d)
|
288
|
+
elsif other.respond_to?(:coerce) && (lhs, rhs = other.coerce(to_d))
|
291
289
|
lhs + rhs
|
292
290
|
else
|
293
291
|
raise TypeError, "\#{other.class} can't be coerced into \#{self.class}"
|
@@ -320,8 +318,7 @@ module OpenHAB
|
|
320
318
|
self - other
|
321
319
|
elsif other.respond_to?(:to_d)
|
322
320
|
DateTimeType.new(zoned_date_time.minusNanos((other.to_d * 1_000_000_000).to_i))
|
323
|
-
elsif other.respond_to?(:coerce)
|
324
|
-
lhs, rhs = other.coerce(to_d)
|
321
|
+
elsif other.respond_to?(:coerce) && (lhs, rhs = other.coerce(to_d))
|
325
322
|
lhs - rhs
|
326
323
|
else
|
327
324
|
raise TypeError, "\#{other.class} can't be coerced into \#{self.class}"
|
@@ -87,7 +87,8 @@ module OpenHAB
|
|
87
87
|
elsif other.respond_to?(:to_d)
|
88
88
|
to_d <=> other.to_d
|
89
89
|
elsif other.respond_to?(:coerce)
|
90
|
-
lhs, rhs = other.coerce(self)
|
90
|
+
return nil unless (lhs, rhs = other.coerce(self))
|
91
|
+
|
91
92
|
lhs <=> rhs
|
92
93
|
end
|
93
94
|
end
|
@@ -109,15 +110,13 @@ module OpenHAB
|
|
109
110
|
logger.trace("Coercing #{self} as a request from #{other.class}")
|
110
111
|
if other.is_a?(Items::NumericItem) ||
|
111
112
|
(other.is_a?(Items::GroupItem) && other.base_item.is_a?(Items::NumericItem))
|
112
|
-
|
113
|
+
return unless other.state?
|
113
114
|
|
114
115
|
[other.state, self]
|
115
116
|
elsif other.is_a?(Type)
|
116
117
|
[other, as(other.class)]
|
117
118
|
elsif other.respond_to?(:to_d)
|
118
119
|
[self.class.new(other.to_d), self]
|
119
|
-
else
|
120
|
-
raise TypeError, "can't convert #{other.class} into #{self.class}"
|
121
120
|
end
|
122
121
|
end
|
123
122
|
|
@@ -150,8 +149,7 @@ module OpenHAB
|
|
150
149
|
# # result could already be a QuantityType
|
151
150
|
# result = self.class.new(result) unless result.is_a?(NumericType)
|
152
151
|
# result
|
153
|
-
# elsif other.respond_to?(:coerce)
|
154
|
-
# lhs, rhs = other.coerce(to_d)
|
152
|
+
# elsif other.respond_to?(:coerce) && (lhs, rhs = other.coerce(to_d))
|
155
153
|
# lhs + rhs
|
156
154
|
# else
|
157
155
|
# raise TypeError, "#{other.class} can't be coerced into #{self.class}"
|
@@ -168,8 +166,7 @@ module OpenHAB
|
|
168
166
|
# result could already be a QuantityType
|
169
167
|
result = self.class.new(result) unless result.is_a?(NumericType)
|
170
168
|
result
|
171
|
-
elsif other.respond_to?(:coerce)
|
172
|
-
lhs, rhs = other.coerce(to_d)
|
169
|
+
elsif other.respond_to?(:coerce) && (lhs, rhs = other.coerce(to_d))
|
173
170
|
lhs #{ruby_op} rhs
|
174
171
|
else
|
175
172
|
raise TypeError, "\#{other.class} can't be coerced into \#{self.class}"
|
@@ -133,7 +133,7 @@ module OpenHAB
|
|
133
133
|
logger.trace("Coercing #{self} as a request from #{other.class}")
|
134
134
|
if other.is_a?(Items::NumericItem) ||
|
135
135
|
(other.is_a?(Items::GroupItem) && other.base_item.is_a?(Items::NumericItem))
|
136
|
-
|
136
|
+
return unless other.state?
|
137
137
|
|
138
138
|
[other.state, self]
|
139
139
|
elsif other.respond_to?(:to_str)
|
@@ -64,7 +64,8 @@ module OpenHAB
|
|
64
64
|
elsif other.respond_to?(:to_str)
|
65
65
|
self == PointType.new(other)
|
66
66
|
elsif other.respond_to?(:coerce)
|
67
|
-
lhs, rhs = other.coerce(self)
|
67
|
+
return false unless (lhs, rhs = other.coerce(self))
|
68
|
+
|
68
69
|
lhs == rhs
|
69
70
|
end
|
70
71
|
end
|
@@ -80,7 +81,10 @@ module OpenHAB
|
|
80
81
|
# @return [[PointType, PointType]]
|
81
82
|
#
|
82
83
|
def coerce(other)
|
83
|
-
|
84
|
+
lhs = coerce_single(other)
|
85
|
+
return unless lhs
|
86
|
+
|
87
|
+
[lhs, self]
|
84
88
|
end
|
85
89
|
|
86
90
|
# rename raw methods so we can overwrite them
|
@@ -123,7 +127,10 @@ module OpenHAB
|
|
123
127
|
# @return [QuantityType]
|
124
128
|
def distance_from(other)
|
125
129
|
logger.trace("(#{self}).distance_from(#{other} (#{other.class})")
|
126
|
-
|
130
|
+
other = coerce_single(other)
|
131
|
+
raise TypeError, "#{other.class} can't be coerced into #{self.class}" unless other
|
132
|
+
|
133
|
+
QuantityType.new(raw_distance_from(other), SIUnits::METRE)
|
127
134
|
end
|
128
135
|
alias - distance_from
|
129
136
|
|
@@ -131,18 +138,16 @@ module OpenHAB
|
|
131
138
|
|
132
139
|
# coerce an object to a PointType
|
133
140
|
# @return [PointType]
|
134
|
-
def coerce_single(other)
|
141
|
+
def coerce_single(other)
|
135
142
|
logger.trace("Coercing #{self} as a request from #{other.class}")
|
136
143
|
if other.is_a?(PointType)
|
137
144
|
other
|
138
145
|
elsif other.is_a?(Items::LocationItem)
|
139
|
-
|
146
|
+
return unless other.state?
|
140
147
|
|
141
148
|
other.state
|
142
149
|
elsif other.respond_to?(:to_str)
|
143
150
|
PointType.new(other.to_str)
|
144
|
-
else
|
145
|
-
raise TypeError, "can't convert #{other.class} into #{self.class}"
|
146
151
|
end
|
147
152
|
end
|
148
153
|
end
|
@@ -61,7 +61,8 @@ module OpenHAB
|
|
61
61
|
elsif other.respond_to?(:to_d)
|
62
62
|
compare_to(QuantityType.new(other.to_d.to_java, Units.unit || unit))
|
63
63
|
elsif other.respond_to?(:coerce)
|
64
|
-
lhs, rhs = other.coerce(self)
|
64
|
+
return nil unless (lhs, rhs = other.coerce(self))
|
65
|
+
|
65
66
|
lhs <=> rhs
|
66
67
|
end
|
67
68
|
end
|
@@ -82,7 +83,7 @@ module OpenHAB
|
|
82
83
|
logger.trace("Coercing #{self} as a request from #{other.class}")
|
83
84
|
if other.is_a?(Items::NumericItem) ||
|
84
85
|
(other.is_a?(Items::GroupItem) && other.base_item.is_a?(Items::NumericItem))
|
85
|
-
|
86
|
+
return unless other.state?
|
86
87
|
|
87
88
|
[other.state, self]
|
88
89
|
elsif other.is_a?(Type)
|
@@ -91,8 +92,6 @@ module OpenHAB
|
|
91
92
|
[QuantityType.new(other.to_d.to_java, ONE), self]
|
92
93
|
elsif other.is_a?(String)
|
93
94
|
[QuantityType.new(other), self]
|
94
|
-
else
|
95
|
-
raise TypeError, "can't convert #{other.class} into #{self.class}"
|
96
95
|
end
|
97
96
|
end
|
98
97
|
|
@@ -123,9 +122,8 @@ module OpenHAB
|
|
123
122
|
# elsif other.respond_to?(:to_d)
|
124
123
|
# other = other.to_d.to_java
|
125
124
|
# add_quantity(self.class.new(other, Units.unit || unit))
|
126
|
-
# elsif other.respond_to?(:coerce)
|
127
|
-
# lhs
|
128
|
-
# lhs = rhs
|
125
|
+
# elsif other.respond_to?(:coerce) && (lhs, rhs = other.coerce(to_d))
|
126
|
+
# lhs + rhs
|
129
127
|
# else
|
130
128
|
# raise TypeError, "#{other.class} can't be coerced into #{self.class}"
|
131
129
|
# end
|
@@ -148,8 +146,7 @@ module OpenHAB
|
|
148
146
|
elsif other.respond_to?(:to_d)
|
149
147
|
other = other.to_d.to_java
|
150
148
|
#{java_op}_quantity(#{convert})
|
151
|
-
elsif other.respond_to?(:coerce)
|
152
|
-
lhs, rhs = other.coerce(to_d)
|
149
|
+
elsif other.respond_to?(:coerce) && (lhs, rhs = other.coerce(to_d))
|
153
150
|
lhs #{ruby_op} rhs
|
154
151
|
else
|
155
152
|
raise TypeError, "\#{other.class} can't be coerced into \#{self.class}"
|
@@ -179,8 +176,7 @@ module OpenHAB
|
|
179
176
|
# self * self.class.new(other)
|
180
177
|
# elsif other.respond_to?(:to_d)
|
181
178
|
# multiply(other.to_d.to_java)
|
182
|
-
# elsif other.respond_to?(:coerce)
|
183
|
-
# lhs, rhs = other.coerce(to_d)
|
179
|
+
# elsif other.respond_to?(:coerce) && (lhs, rhs = other.coerce(to_d))
|
184
180
|
# lhs * rhs
|
185
181
|
# else
|
186
182
|
# raise TypeError, "#{other.class} can't be coerced into #{self.class}"
|
@@ -202,8 +198,7 @@ module OpenHAB
|
|
202
198
|
self #{ruby_op} self.class.new(other)
|
203
199
|
elsif other.respond_to?(:to_d)
|
204
200
|
#{java_op}(other.to_d.to_java)
|
205
|
-
elsif other.respond_to?(:coerce)
|
206
|
-
lhs, rhs = other.coerce(to_d)
|
201
|
+
elsif other.respond_to?(:coerce) && (lhs, rhs = other.coerce(to_d))
|
207
202
|
lhs #{ruby_op} rhs
|
208
203
|
else
|
209
204
|
raise TypeError, "\#{other.class} can't be coerced into \#{self.class}"
|
@@ -52,7 +52,8 @@ module OpenHAB
|
|
52
52
|
elsif other.respond_to?(:to_str)
|
53
53
|
to_str <=> other.to_str
|
54
54
|
elsif other.respond_to?(:coerce)
|
55
|
-
lhs, rhs = other.coerce(self)
|
55
|
+
return nil unless (lhs, rhs = other.coerce(self))
|
56
|
+
|
56
57
|
lhs <=> rhs
|
57
58
|
end
|
58
59
|
end
|
@@ -70,13 +71,11 @@ module OpenHAB
|
|
70
71
|
def coerce(other)
|
71
72
|
logger.trace("Coercing #{self} as a request from #{other.class}")
|
72
73
|
if other.is_a?(Items::StringItem)
|
73
|
-
|
74
|
+
return unless other.state?
|
74
75
|
|
75
76
|
[other.state, self]
|
76
77
|
elsif other.respond_to?(:to_str)
|
77
78
|
[String.new(other.to_str), self]
|
78
|
-
else
|
79
|
-
raise TypeError, "can't convert #{other.class} into #{self.class}"
|
80
79
|
end
|
81
80
|
end
|
82
81
|
|
@@ -28,8 +28,6 @@ module OpenHAB
|
|
28
28
|
def coerce(other)
|
29
29
|
logger.trace("Coercing #{self} (#{self.class}) as a request from #{other.class}")
|
30
30
|
return [other.as(self.class), self] if other.is_a?(Type)
|
31
|
-
|
32
|
-
raise TypeError, "can't convert #{other.class} into #{self.class}"
|
33
31
|
end
|
34
32
|
|
35
33
|
#
|
@@ -49,7 +47,8 @@ module OpenHAB
|
|
49
47
|
# @return [Boolean] if the same value is represented, including
|
50
48
|
# type conversions
|
51
49
|
#
|
52
|
-
def ==(other)
|
50
|
+
def ==(other) # rubocop:disable Metrics
|
51
|
+
logger.trace("(#{self.class}) #{self} == #{other} (#{other.class})")
|
53
52
|
return true if equal?(other)
|
54
53
|
|
55
54
|
# i.e. ON == OFF, REFRESH == ON, ON == REFRESH
|
@@ -60,7 +59,17 @@ module OpenHAB
|
|
60
59
|
return self == other.raw_state if other.is_a?(Items::GenericItem)
|
61
60
|
|
62
61
|
if other.respond_to?(:coerce)
|
63
|
-
|
62
|
+
begin
|
63
|
+
return false unless (lhs, rhs = other.coerce(self))
|
64
|
+
rescue TypeError
|
65
|
+
# this one is a bit odd. 50 (Integer) == ON is internally
|
66
|
+
# flipping the argument and calling this method. but it responds
|
67
|
+
# to coerce, and then raises a TypeError (from Float???) that
|
68
|
+
# it couldn't convert to OnOffType. it probably should have
|
69
|
+
# returned nil. catch it and return false instead
|
70
|
+
return false
|
71
|
+
end
|
72
|
+
|
64
73
|
return lhs == rhs
|
65
74
|
end
|
66
75
|
|
data/lib/openhab/version.rb
CHANGED