@@ -72,10 +72,10 @@ public class Setters {
72
72
* @return the target resource.
73
73
*/
74
74
public static Resource setAlert (Resource target , Command command , @ Nullable Resource source ) {
75
- if ((command instanceof StringType ) && Objects .nonNull (source )) {
75
+ if ((command instanceof StringType alert ) && Objects .nonNull (source )) {
76
76
Alerts otherAlert = source .getAlerts ();
77
77
if (Objects .nonNull (otherAlert )) {
78
- ActionType actionType = ActionType .of ((( StringType ) command ) .toString ());
78
+ ActionType actionType = ActionType .of (alert .toString ());
79
79
if (otherAlert .getActionValues ().contains (actionType )) {
80
80
target .setAlerts (new Alerts ().setAction (actionType ));
81
81
}
@@ -98,8 +98,7 @@ public static Resource setAlert(Resource target, Command command, @Nullable Reso
98
98
*/
99
99
public static Resource setColorTemperatureAbsolute (Resource target , Command command , @ Nullable Resource source ) {
100
100
QuantityType <?> mirek ;
101
- if (command instanceof QuantityType <?>) {
102
- QuantityType <?> quantity = (QuantityType <?>) command ;
101
+ if (command instanceof QuantityType <?> quantity ) {
103
102
Unit <?> unit = quantity .getUnit ();
104
103
if (Units .KELVIN .equals (unit )) {
105
104
mirek = quantity .toInvertibleUnit (Units .MIRED );
@@ -109,9 +108,8 @@ public static Resource setColorTemperatureAbsolute(Resource target, Command comm
109
108
QuantityType <?> kelvin = quantity .toInvertibleUnit (Units .KELVIN );
110
109
mirek = Objects .nonNull (kelvin ) ? kelvin .toInvertibleUnit (Units .MIRED ) : null ;
111
110
}
112
- } else if (command instanceof DecimalType ) {
113
- mirek = QuantityType .valueOf (((DecimalType ) command ).doubleValue (), Units .KELVIN )
114
- .toInvertibleUnit (Units .MIRED );
111
+ } else if (command instanceof DecimalType decimal ) {
112
+ mirek = QuantityType .valueOf (decimal .doubleValue (), Units .KELVIN ).toInvertibleUnit (Units .MIRED );
115
113
} else {
116
114
mirek = null ;
117
115
}
@@ -141,15 +139,15 @@ public static Resource setColorTemperatureAbsolute(Resource target, Command comm
141
139
* @return the target resource.
142
140
*/
143
141
public static Resource setColorTemperaturePercent (Resource target , Command command , @ Nullable Resource source ) {
144
- if (command instanceof PercentType ) {
142
+ if (command instanceof PercentType mirek ) {
145
143
MirekSchema schema = target .getMirekSchema ();
146
144
schema = Objects .nonNull (schema ) ? schema : Objects .nonNull (source ) ? source .getMirekSchema () : null ;
147
145
schema = Objects .nonNull (schema ) ? schema : MirekSchema .DEFAULT_SCHEMA ;
148
146
ColorTemperature colorTemperature = target .getColorTemperature ();
149
147
colorTemperature = Objects .nonNull (colorTemperature ) ? colorTemperature : new ColorTemperature ();
150
148
double min = schema .getMirekMinimum ();
151
149
double max = schema .getMirekMaximum ();
152
- double val = min + ((max - min ) * (( PercentType ) command ) .doubleValue () / 100f );
150
+ double val = min + ((max - min ) * mirek .doubleValue () / 100f );
153
151
target .setColorTemperature (colorTemperature .setMirek (val ));
154
152
}
155
153
return target ;
@@ -168,13 +166,10 @@ public static Resource setColorTemperaturePercent(Resource target, Command comma
168
166
* @return the target resource.
169
167
*/
170
168
public static Resource setColorXy (Resource target , Command command , @ Nullable Resource source ) {
171
- if (command instanceof HSBType ) {
172
- Gamut gamut = target .getGamut ();
173
- gamut = Objects .nonNull (gamut ) ? gamut : Objects .nonNull (source ) ? source .getGamut () : null ;
174
- gamut = Objects .nonNull (gamut ) ? gamut : ColorUtil .DEFAULT_GAMUT ;
175
- HSBType hsb = (HSBType ) command ;
169
+ if (command instanceof HSBType hsb ) {
170
+ hsb = new HSBType (hsb .getHue (), hsb .getSaturation (), PercentType .HUNDRED );
176
171
ColorXy color = target .getColorXy ();
177
- target .setColorXy ((Objects .nonNull (color ) ? color : new ColorXy ()).setXY (ColorUtil .hsbToXY (hsb , gamut )));
172
+ target .setColorXy ((Objects .nonNull (color ) ? color : new ColorXy ()).setXY (ColorUtil .hsbToXY (hsb )));
178
173
}
179
174
return target ;
180
175
}
@@ -191,11 +186,10 @@ public static Resource setColorXy(Resource target, Command command, @Nullable Re
191
186
* @return the target resource.
192
187
*/
193
188
public static Resource setDimming (Resource target , Command command , @ Nullable Resource source ) {
194
- if (command instanceof PercentType ) {
189
+ if (command instanceof PercentType brightness ) {
195
190
Double min = target .getMinimumDimmingLevel ();
196
191
min = Objects .nonNull (min ) ? min : Objects .nonNull (source ) ? source .getMinimumDimmingLevel () : null ;
197
192
min = Objects .nonNull (min ) ? min : Dimming .DEFAULT_MINIMUM_DIMMIMG_LEVEL ;
198
- PercentType brightness = (PercentType ) command ;
199
193
if (brightness .doubleValue () < min .doubleValue ()) {
200
194
brightness = new PercentType (new BigDecimal (min , Resource .PERCENT_MATH_CONTEXT ));
201
195
}
@@ -219,8 +213,8 @@ public static Resource setDimming(Resource target, Command command, @Nullable Re
219
213
* @return the target resource.
220
214
*/
221
215
public static Resource setEffect (Resource target , Command command , @ Nullable Resource source ) {
222
- if ((command instanceof StringType ) && Objects .nonNull (source )) {
223
- EffectType commandEffectType = EffectType .of ((( StringType ) command ) .toString ());
216
+ if ((command instanceof StringType effect ) && Objects .nonNull (source )) {
217
+ EffectType commandEffectType = EffectType .of (effect .toString ());
224
218
Effects sourceFixedEffects = source .getFixedEffects ();
225
219
if (Objects .nonNull (sourceFixedEffects ) && sourceFixedEffects .allows (commandEffectType )) {
226
220
target .setFixedEffects (new Effects ().setEffect (commandEffectType ));
0 commit comments