openhab-scripting 4.23.0 → 4.24.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: 6a1dda09cc4876b335d5da064fa1e19a1196f56d030225e96f6c6efe0c22d3f6
4
- data.tar.gz: 23cac17429e99d6757db5f7232e53f8d77a656fb9bfb15d2ee4984fde63d691c
3
+ metadata.gz: 2b0032a1e364c6042f9f01f21c8315f0cbaf2e3b311c7e227073eb26394f8f8a
4
+ data.tar.gz: c3c2279228081ec8f9a565dd9e3fd8a2d42b1c09d01c6de85951493a79f8f098
5
5
  SHA512:
6
- metadata.gz: 5e473c9f0e2764d041613fd728377895430e790846986d3aca9b508f1ef3c0999c72473402cc0094d42c866871fa3161daeb0d4eedc3173b5485e9e33ab9f979
7
- data.tar.gz: fdddf783a82f71c0e1364f47f8397daa394ded4935bd16f7746000f9c6f466db074000a2bf065ee1f1daf05f43f1fa1a3d94db3169144cadc7cb2114b5a96a36
6
+ metadata.gz: 9ac07684db4dc05fa66423d2d775d8bbddeb197b672d6e7bd87a3ff811e0c1d9ea1a93da26a9775bfa4d2fba3b07d915783caf3eadaace99d6e09b2fe65ceb2e
7
+ data.tar.gz: 9f5be2827c0dddc7224b91d2fb9afbeffeb276b9395ff2439910415aade2019c8f2f374e07e47b38719f8c70ace700d3c4f3b7d8509086404037d21f338e3c7f
@@ -25,7 +25,14 @@ module OpenHAB
25
25
  super
26
26
  end
27
27
 
28
- #
28
+ # Support conversion to location items from a hash
29
+ # @!visibility private
30
+ def format_type(command)
31
+ return PointType.new(command.to_hash) if command.respond_to?(:to_hash)
32
+
33
+ super
34
+ end
35
+
29
36
  # Type Coercion
30
37
  #
31
38
  # Coerce object to a PointType
@@ -17,6 +17,7 @@ module OpenHAB
17
17
  # @param longitude [DecimalType, QuantityType, StringType, Numeric]
18
18
  # @param altitude [DecimalType, QuantityType, StringType, Numeric]
19
19
  def initialize(*args) # rubocop:disable Metrics
20
+ args = from_hash(args.first.to_hash) if args.first.respond_to? :to_hash
20
21
  if (2..3).cover?(args.length)
21
22
  args = args.each_with_index.map do |value, index|
22
23
  if value.is_a?(DecimalType) || value.is_a?(StringType)
@@ -118,6 +119,13 @@ module OpenHAB
118
119
  QuantityType.new(raw_altitude.to_big_decimal, Units::METRE)
119
120
  end
120
121
 
122
+ #
123
+ # Convert the PointType to a hash
124
+ # @return [Hash] with keys latitude/longitude/altitude
125
+ def to_h
126
+ { latitude: latitude, longitude: longitude, altitude: altitude }
127
+ end
128
+
121
129
  #
122
130
  # Calculate the distance in meters from other, ignoring altitude.
123
131
  #
@@ -138,7 +146,7 @@ module OpenHAB
138
146
 
139
147
  # coerce an object to a PointType
140
148
  # @return [PointType]
141
- def coerce_single(other)
149
+ def coerce_single(other) # rubocop:disable Metrics
142
150
  logger.trace("Coercing #{self} as a request from #{other.class}")
143
151
  if other.is_a?(PointType)
144
152
  other
@@ -148,7 +156,22 @@ module OpenHAB
148
156
  other.state
149
157
  elsif other.respond_to?(:to_str)
150
158
  PointType.new(other.to_str)
159
+ elsif other.respond_to?(:to_hash)
160
+ PointType.new(other.to_hash)
161
+ end
162
+ end
163
+
164
+ #
165
+ # Convert hash into ordered arguments for constructor
166
+ #
167
+ def from_hash(hash)
168
+ keys = [%i[lat long alt], %i[latitude longitude altitude]]
169
+ keys.each do |key_set|
170
+ values = hash.transform_keys(&:to_sym).values_at(*key_set)
171
+
172
+ return *values.compact if values[0..1].all?
151
173
  end
174
+ raise ArgumentError, "Supplied arguments (#{hash}) must contain one of the following sets #{keys}"
152
175
  end
153
176
  end
154
177
  end
@@ -5,5 +5,5 @@
5
5
  #
6
6
  module OpenHAB
7
7
  # @return [String] Version of OpenHAB helper libraries
8
- VERSION = '4.23.0'
8
+ VERSION = '4.24.0'
9
9
  end
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.23.0
4
+ version: 4.24.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian O'Connell