openhab-scripting 4.12.1 → 4.13.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/types/percent_type.rb +26 -0
- 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: 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
|
@@ -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
|
data/lib/openhab/version.rb
CHANGED