Skip to content

Commit caf4219

Browse files
committed
javadoc and min/max code style
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
1 parent 104712e commit caf4219

1 file changed

Lines changed: 23 additions & 19 deletions

File tree

  • bundles/org.openhab.core/src/main/java/org/openhab/core/util

bundles/org.openhab.core/src/main/java/org/openhab/core/util/LightUtil.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,31 @@ public class LightUtil {
4343
public static final PercentType DEFAULT_MAXIMUM_BRIGHTNESS = PercentType.HUNDRED;
4444

4545
/**
46-
* Minimum valid Kelvin value for conversion to HSB. Values below this will be clamped to this value.
46+
* Default minimum color temperature Kelvin value. Conversions are subject to the caveats mentioned in
47+
* {@link ColorUtil#xyToKelvin()} so when converting HSBType values to Kelvin, values below this will
48+
* be clamped to this value.
4749
*/
48-
public static final double DEFAULT_MINIMUM_KELVIN = 2000;
50+
public static final double DEFAULT_MINIMUM_KELVIN = 2000; // aka 500 mirek
4951

5052
/**
51-
* Maximum valid Kelvin value for conversion to HSB.
53+
* Default maximum color temperature Kelvin value.
5254
*/
53-
public static final double DEFAULT_MAXIMUM_KELVIN = 10000;
55+
public static final double DEFAULT_MAXIMUM_KELVIN = 6500; // aka 153 mirek
5456

5557
/**
5658
* Step value for IncreaseDecreaseType commands.
5759
*/
5860
public static final double INCREASE_DECREASE_STEP = 10.0;
5961

6062
/**
61-
* Private helper that returns the PercentType brightness state from the optionally provided brightness
63+
* Private helper that returns a PercentType brightness state from the optionally provided brightness
6264
* provider, or null if no valid brightness provider exists. Valid brightness providers are:
6365
* <p>
6466
* <li>a PercentType</li>
6567
* <li>an HSBType (from which the brightness is extracted)</li>
6668
* <li>a Number (which is converted to PercentType)</li>
6769
*
68-
* @param optionalBrightnessProvider an optional object argument that provides brightness information
70+
* @param optionalBrightnessProvider an optional single object argument that provides the target brightness
6971
*
7072
* @return the extracted brightness as PercentType, or null if not found
7173
*/
@@ -100,7 +102,7 @@ public static PercentType brightnessStateFrom(HSBType hsbState) {
100102
* brightness if no brightness is provided.
101103
*
102104
* @param onOffState the OnOffType state
103-
* @param optionalOnStateBrightnessProvider an optional object argument that provides brightness information
105+
* @param optionalOnStateBrightnessProvider an optional single object argument that provides the on state brightness
104106
*
105107
* @return the corresponding PercentType brightness state
106108
*/
@@ -122,15 +124,15 @@ public static PercentType brightnessStateFrom(OnOffType onOffState, Object... op
122124
public static PercentType brightnessStateFrom(PercentType priorBrightness, IncreaseDecreaseType incDec) {
123125
double brightness = ((IncreaseDecreaseType.INCREASE.equals(incDec) ? 1 : -1) * INCREASE_DECREASE_STEP)
124126
+ priorBrightness.doubleValue();
125-
return new PercentType(new BigDecimal(Math.min(100.0, Math.max(0.0, brightness))));
127+
return new PercentType(new BigDecimal(Math.min(Math.max(brightness, 0.0), 100.0)));
126128
}
127129

128130
/**
129131
* Returns a PercentType brightness state that results from applying the given Command to the prior brightness.
130132
*
131133
* @param priorBrightness the prior brightness PercentType
132134
* @param command the command from OH core
133-
* @param optionalOnStateBrightnessProvider an optional object argument that provides brightness information
135+
* @param optionalOnStateBrightnessProvider an optional single object argument that provides the on state brightness
134136
*
135137
* @return a new PercentType with the adjusted brightness
136138
*
@@ -153,7 +155,7 @@ public static PercentType brightnessStateFrom(PercentType priorBrightness, Comma
153155
* brightness. If no brightness is provided, the default maximum brightness percent is used.
154156
*
155157
* @param kelvin the color temperature in Kelvin
156-
* @param optionalBrightnessProvider an optional object argument that provides brightness information
158+
* @param optionalBrightnessProvider an optional single object argument that provides the target brightness
157159
*
158160
* @return the corresponding HSBType
159161
*/
@@ -169,7 +171,7 @@ public static HSBType colorStateFrom(double kelvin, Object... optionalBrightness
169171
* brightness. If no brightness is provided, the brightness from the original HSBType is retained.
170172
*
171173
* @param priorHSBState the original HSBType
172-
* @param optionalBrightnessProvider an optional object argument that provides brightness information
174+
* @param optionalBrightnessProvider an optional single object argument that provides the target brightness
173175
*
174176
* @return a new HSBType with the adjusted brightness
175177
*/
@@ -187,7 +189,7 @@ public static HSBType colorStateFrom(HSBType priorHSBState, Object... optionalBr
187189
*
188190
* @param priorHSBState the original HSBType
189191
* @param onOffState the OnOffType state
190-
* @param optionalOnStateBrightnessProvider an optional object argument that provides brightness information
192+
* @param optionalOnStateBrightnessProvider an optional single object argument that provides the on state brightness
191193
*
192194
* @return a new HSBType with the adjusted brightness
193195
*/
@@ -215,7 +217,7 @@ public static HSBType colorStateFrom(HSBType priorHSBState, IncreaseDecreaseType
215217
*
216218
* @param priorHSBState the prior HSBType state
217219
* @param command the command from OH core
218-
* @param optionalOnStateBrightnessProvider an optional object argument that provides brightness information
220+
* @param optionalOnStateBrightnessProvider an optional single object argument that provides the on state brightness
219221
*
220222
* @return a new HSBType with the adjusted brightness
221223
*
@@ -254,7 +256,8 @@ public static DecimalType approximateKelvinFrom(HSBType hsbState) {
254256
* used.
255257
*
256258
* @param colorTemperaturePercent the PercentType color temperature (0% = coolest, 100% = warmest)
257-
* @param optionalMinMaxKelvinProvider an optional object argument that provides minimum and maximum Kelvin values
259+
* @param optionalMinMaxKelvinProvider an optional argument of up to two doubles that provide minimum and maximum
260+
* Kelvin values. The first value is the minimum (coolest), the second is the maximum (warmest)
258261
*
259262
* @return the corresponding color temperature in Kelvin
260263
*/
@@ -273,18 +276,19 @@ public static DecimalType kelvinFrom(PercentType colorTemperaturePercent, double
273276
* used. The returned percent is clamped to the range of 0% to 100%.
274277
*
275278
* @param kelvin the color temperature in Kelvin
276-
* @param optionalMinMaxKelvinProvider an optional object argument that provides minimum and maximum Kelvin values
279+
* @param optionalMinMaxKelvinProvider an optional argument of up to two doubles that provide minimum and maximum
280+
* Kelvin values. The first value is the minimum (coolest), the second is the maximum (warmest)
277281
*
278282
* @return the corresponding PercentType color temperature
279283
*/
280284
public static PercentType colorTemperaturePercentFrom(DecimalType kelvin, double... optionalMinMaxKelvinProvider) {
281285
double thisMirek = 1000000
282-
/ Math.max(Math.min(kelvin.doubleValue(), DEFAULT_MAXIMUM_KELVIN), DEFAULT_MINIMUM_KELVIN);
286+
/ Math.min(Math.max(kelvin.doubleValue(), DEFAULT_MINIMUM_KELVIN), DEFAULT_MAXIMUM_KELVIN);
283287
double coolMirek = 1000000 / optionalMinMaxKelvinProvider.length > 0 ? optionalMinMaxKelvinProvider[0]
284288
: DEFAULT_MINIMUM_KELVIN;
285289
double warmMirek = 1000000 / optionalMinMaxKelvinProvider.length > 1 ? optionalMinMaxKelvinProvider[1]
286290
: DEFAULT_MAXIMUM_KELVIN;
287-
double percent = Math.max(0.0, Math.min(100.0, 100.0 * (thisMirek - coolMirek) / (warmMirek - coolMirek)));
291+
double percent = Math.min(Math.max(100.0 * (thisMirek - coolMirek) / (warmMirek - coolMirek), 0.0), 100.0);
288292
return new PercentType(new BigDecimal(percent));
289293
}
290294

@@ -294,7 +298,7 @@ public static PercentType colorTemperaturePercentFrom(DecimalType kelvin, double
294298
* provided, a default value is used.
295299
*
296300
* @param brightnessState the brightness PercentType to evaluate
297-
* @param optionalMinimumBrightnessPovider an optional object argument that provides a minimum brightness
301+
* @param optionalMinimumBrightnessPovider an optional single object argument that provides the minimum brightness
298302
*
299303
* @return OnOffType.ON if brightness >= minimum brightness, otherwise OnOffType.OFF
300304
*/
@@ -310,7 +314,7 @@ public static OnOffType onOffStateFrom(PercentType brightnessState, Object... op
310314
* minimum brightness is provided, a default value is used.
311315
*
312316
* @param hsbState the HSBType to evaluate
313-
* @param optionalMinimumBrightnessPovider an optional object argument that provides a minimum brightness
317+
* @param optionalMinimumBrightnessPovider an optional single object argument that provides the minimum brightness
314318
*
315319
* @return OnOffType.ON if brightness >= minimum brightness, otherwise OnOffType.OFF
316320
*/

0 commit comments

Comments
 (0)