openhab-scripting 4.22.2 → 4.25.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/color_item.rb +41 -0
- data/lib/openhab/dsl/items/location_item.rb +8 -1
- data/lib/openhab/dsl/time/month_day.rb +23 -2
- data/lib/openhab/dsl/timers/manager.rb +6 -2
- data/lib/openhab/dsl/types/point_type.rb +24 -1
- 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: 9311e047c09ea5409e82e4650a2ef22d26513e10a566445370772e568552e0bd
|
4
|
+
data.tar.gz: c21b7970c72bf749d6403b212b8e84ab255b1dd07ef3d695c7881e5205edd72a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f62960bbd5fc2e51064bc63c4a3cc7e2e9de322233a1f489311ca20c3df51381c04449a4af0dff455ceb998f4e43ab4ac2668101aa7838c3445e0c4093f6074
|
7
|
+
data.tar.gz: df255a6f1e8a5b573d6b37b0ec6637cd7ccdea4e6abdd937f19b0f8f484713406133cb86fb2c080bdb132717a3efa313c626c4b4cd89ea62baf4bca31b26f58b
|
@@ -48,10 +48,51 @@ module OpenHAB
|
|
48
48
|
# convert it to an HSBType
|
49
49
|
# @!visibility private
|
50
50
|
def format_type(command)
|
51
|
+
return format_hash(command.to_hash) if command.respond_to?(:to_hash)
|
51
52
|
return Types::HSBType.new(command) if command.respond_to?(:to_str)
|
52
53
|
|
53
54
|
super
|
54
55
|
end
|
56
|
+
|
57
|
+
#
|
58
|
+
# Convert the ColorItem to a hash
|
59
|
+
# @param [:hsb, :rgb] format for hash
|
60
|
+
# @return [Hash] in requested format
|
61
|
+
def to_h(format = :hsb)
|
62
|
+
values = to_a(format)
|
63
|
+
keys = (format == :hsb ? %i[hue saturation brightness] : %i[red green blue])
|
64
|
+
keys.zip(values).to_h
|
65
|
+
end
|
66
|
+
|
67
|
+
#
|
68
|
+
# Convert the ColorItem to an array of values
|
69
|
+
# @param [:hsb, :rgb] format for elements in the array
|
70
|
+
# @return [Array] of ColorItem components in requested format
|
71
|
+
def to_a(format = :hsb)
|
72
|
+
case format
|
73
|
+
when :hsb then [hue, saturation, brightness]
|
74
|
+
when :rgb then [red, green, blue].map(&:to_byte)
|
75
|
+
else
|
76
|
+
raise ArgumentError, "Unsupported format #{format}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
# Mapping of hash values sets to conversion methods
|
83
|
+
HASH_KEYS = { %i[r g b] => :from_rgb,
|
84
|
+
%i[red green blue] => :from_rgb,
|
85
|
+
%i[h s b] => :from_hsb,
|
86
|
+
%i[hue saturation brightness] => :from_hsb }.freeze
|
87
|
+
|
88
|
+
def format_hash(hash)
|
89
|
+
hash = hash.transform_keys(&:to_sym)
|
90
|
+
HASH_KEYS.each do |key_set, method|
|
91
|
+
values = hash.values_at(*key_set).compact
|
92
|
+
return Types::HSBType.public_send(method, *values) if values.length == 3
|
93
|
+
end
|
94
|
+
raise ArgumentError, "Supplied hash (#{hash}) must contain one of the following keysets #{keys.keys}"
|
95
|
+
end
|
55
96
|
end
|
56
97
|
end
|
57
98
|
end
|
@@ -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
|
@@ -107,10 +107,28 @@ module OpenHAB
|
|
107
107
|
# Extend MonthDay java object with some helper methods
|
108
108
|
class MonthDay
|
109
109
|
include OpenHAB::Log
|
110
|
+
java_import java.time.format.DateTimeFormatter
|
111
|
+
|
112
|
+
#
|
113
|
+
# Constructor
|
114
|
+
#
|
115
|
+
# @param [Integer] m month
|
116
|
+
# @param [Integer] d day of month
|
117
|
+
#
|
118
|
+
# @return [Object] MonthDay object
|
119
|
+
#
|
120
|
+
# rubocop: disable Naming/MethodParameterName
|
121
|
+
def self.new(m:, d:)
|
122
|
+
MonthDay.of(m, d)
|
123
|
+
end
|
124
|
+
# rubocop: enable Naming/MethodParameterName
|
125
|
+
|
110
126
|
# Parse MonthDay string as defined with by Monthday class without leading double dash "--"
|
111
127
|
def self.parse(string)
|
112
|
-
|
113
|
-
java_send :parse, [java.lang.CharSequence],
|
128
|
+
logger.trace("#{self.class}.parse #{string} (#{string.class})")
|
129
|
+
java_send :parse, [java.lang.CharSequence, java.time.format.DateTimeFormatter],
|
130
|
+
string.to_s,
|
131
|
+
DateTimeFormatter.ofPattern('[--]M-d')
|
114
132
|
end
|
115
133
|
|
116
134
|
# Can the supplied object be parsed into a MonthDay
|
@@ -123,6 +141,9 @@ module OpenHAB
|
|
123
141
|
to_string.delete_prefix('--')
|
124
142
|
end
|
125
143
|
|
144
|
+
# remove the inherited #== method to use our <=> below
|
145
|
+
remove_method :==
|
146
|
+
|
126
147
|
# Extends MonthDay comparison to support Strings
|
127
148
|
# Necessary to support mixed ranges of Strings and MonthDay types
|
128
149
|
# @return [Number, nil] -1,0,1 if other MonthDay is less than, equal to, or greater than this MonthDay
|
@@ -19,7 +19,7 @@ module OpenHAB
|
|
19
19
|
|
20
20
|
def initialize
|
21
21
|
# Track timer IDs
|
22
|
-
@timer_ids =
|
22
|
+
@timer_ids = {}
|
23
23
|
|
24
24
|
# Reentrant timer lookups
|
25
25
|
@reentrant_timers = {}
|
@@ -39,6 +39,7 @@ module OpenHAB
|
|
39
39
|
|
40
40
|
if timer.respond_to? :id
|
41
41
|
logger.trace("Adding #{timer} with id #{timer.id.inspect} timer ids")
|
42
|
+
@timer_ids[timer.id] = Set.new unless @timer_ids[timer.id]
|
42
43
|
@timer_ids[timer.id] << timer
|
43
44
|
end
|
44
45
|
|
@@ -68,7 +69,10 @@ module OpenHAB
|
|
68
69
|
def delete(timer)
|
69
70
|
logger.trace("Removing #{timer} from timers")
|
70
71
|
@timers.delete(timer)
|
71
|
-
|
72
|
+
if timer.respond_to? :id
|
73
|
+
@timer_ids[timer.id]&.delete(timer)
|
74
|
+
@timer_ids.delete(timer.id) unless @timer_ids[timer.id].any?
|
75
|
+
end
|
72
76
|
@reentrant_timers.delete(timer.reentrant_id) if timer.respond_to? :reentrant_id
|
73
77
|
end
|
74
78
|
|
@@ -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
|
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: 4.
|
4
|
+
version: 4.25.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-12-
|
11
|
+
date: 2021-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|