28
28
import org .eclipse .smarthome .core .types .Command ;
29
29
import org .eclipse .smarthome .core .types .UnDefType ;
30
30
import org .openhab .binding .zigbee .ZigBeeBindingConstants ;
31
+ import org .openhab .binding .zigbee .action .ZigBeeThingActionParameters ;
31
32
import org .openhab .binding .zigbee .converter .ZigBeeBaseChannelConverter ;
32
33
import org .openhab .binding .zigbee .internal .converter .config .ZclLevelControlConfig ;
33
34
import org .slf4j .Logger ;
@@ -244,12 +245,12 @@ public void handleRefresh() {
244
245
}
245
246
}
246
247
247
- private void changeOnOff (OnOffType onoff ) throws InterruptedException , ExecutionException {
248
+ private void changeOnOff (OnOffType onoff , int transitionTime ) throws InterruptedException , ExecutionException {
248
249
boolean on = onoff == OnOffType .ON ;
249
250
PercentType brightness = on ? PercentType .HUNDRED : PercentType .ZERO ;
250
251
251
252
if (clusterLevelControl != null ) {
252
- changeBrightness (brightness );
253
+ changeBrightness (brightness , transitionTime );
253
254
return ;
254
255
}
255
256
@@ -269,10 +270,10 @@ private void changeOnOff(OnOffType onoff) throws InterruptedException, Execution
269
270
}
270
271
}
271
272
272
- private void changeBrightness (PercentType brightness ) throws InterruptedException , ExecutionException {
273
+ private void changeBrightness (PercentType brightness , int transitionTime ) throws InterruptedException , ExecutionException {
273
274
if (clusterLevelControl == null ) {
274
275
if (clusterOnOff != null ) {
275
- changeOnOff (brightness .intValue () == 0 ? OnOffType .OFF : OnOffType .ON );
276
+ changeOnOff (brightness .intValue () == 0 ? OnOffType .OFF : OnOffType .ON , transitionTime );
276
277
} else {
277
278
logger .warn ("{}: ignoring brightness command" , endpoint .getIeeeAddress ());
278
279
}
@@ -289,25 +290,25 @@ private void changeBrightness(PercentType brightness) throws InterruptedExceptio
289
290
if (brightness .equals (PercentType .ZERO )) {
290
291
clusterOnOff .offCommand ();
291
292
} else {
292
- clusterLevelControl .moveToLevelWithOnOffCommand (level , configLevelControl . getDefaultTransitionTime () )
293
+ clusterLevelControl .moveToLevelWithOnOffCommand (level , transitionTime )
293
294
.get ();
294
295
}
295
296
} else {
296
- clusterLevelControl .moveToLevelCommand (level , configLevelControl . getDefaultTransitionTime () ).get ();
297
+ clusterLevelControl .moveToLevelCommand (level , transitionTime ).get ();
297
298
}
298
299
}
299
300
300
- private void changeColorHueSaturation (HSBType color ) throws InterruptedException , ExecutionException {
301
+ private void changeColorHueSaturation (HSBType color , int transitionTime ) throws InterruptedException , ExecutionException {
301
302
HSBType oldHSB = currentHSB ;
302
303
currentHSB = new HSBType (color .getHue (), color .getSaturation (), oldHSB .getBrightness ());
303
304
int hue = (int ) (color .getHue ().floatValue () * 254.0f / 360.0f + 0.5f );
304
305
int saturation = percentToLevel (color .getSaturation ());
305
306
306
307
clusterColorControl
307
- .moveToHueAndSaturationCommand (hue , saturation , configLevelControl . getDefaultTransitionTime () ).get ();
308
+ .moveToHueAndSaturationCommand (hue , saturation , transitionTime ).get ();
308
309
}
309
310
310
- private void changeColorXY (HSBType color ) throws InterruptedException , ExecutionException {
311
+ private void changeColorXY (HSBType color , int transitionTime ) throws InterruptedException , ExecutionException {
311
312
PercentType xy [] = color .toXY ();
312
313
313
314
HSBType oldHSB = currentHSB ;
@@ -318,11 +319,12 @@ private void changeColorXY(HSBType color) throws InterruptedException, Execution
318
319
int x = (int ) (xy [0 ].floatValue () / 100.0f * 65536.0f + 0.5f ); // up to 65279
319
320
int y = (int ) (xy [1 ].floatValue () / 100.0f * 65536.0f + 0.5f ); // up to 65279
320
321
321
- clusterColorControl .moveToColorCommand (x , y , configLevelControl . getDefaultTransitionTime () ).get ();
322
+ clusterColorControl .moveToColorCommand (x , y , transitionTime ).get ();
322
323
}
323
324
324
325
@ Override
325
- public void handleCommand (final Command command ) {
326
+ public void handleCommand (final Command command , final Map <String , Object > params ) {
327
+ int transitionTime = ZigBeeThingActionParameters .TRANSITION_TIME .getFromMap (params ).orElseGet (configLevelControl ::getDefaultTransitionTime );
326
328
try {
327
329
if (command instanceof HSBType ) {
328
330
HSBType current = currentHSB ;
@@ -339,23 +341,23 @@ public void handleCommand(final Command command) {
339
341
}
340
342
341
343
if (brightness .intValue () != currentHSB .getBrightness ().intValue ()) {
342
- changeBrightness (brightness );
344
+ changeBrightness (brightness , transitionTime );
343
345
if (changeColor && delayedColorChange ) {
344
346
Thread .sleep (1100 );
345
347
}
346
348
}
347
349
348
350
if (changeColor ) {
349
351
if (supportsHue ) {
350
- changeColorHueSaturation (color );
352
+ changeColorHueSaturation (color , transitionTime );
351
353
} else {
352
- changeColorXY (color );
354
+ changeColorXY (color , transitionTime );
353
355
}
354
356
}
355
357
} else if (command instanceof PercentType ) {
356
- changeBrightness ((PercentType ) command );
358
+ changeBrightness ((PercentType ) command , transitionTime );
357
359
} else if (command instanceof OnOffType ) {
358
- changeOnOff ((OnOffType ) command );
360
+ changeOnOff ((OnOffType ) command , transitionTime );
359
361
}
360
362
} catch (InterruptedException | ExecutionException e ) {
361
363
logger .warn ("{}: Exception processing command" , endpoint .getIeeeAddress (), e );
0 commit comments