mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[feican] Use new core class ColorUtil for RGB conversion (#14771)
Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
parent
2c8f639060
commit
feee01d65c
@ -12,13 +12,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.openhab.binding.feican.internal;
|
package org.openhab.binding.feican.internal;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.math.RoundingMode;
|
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.openhab.core.library.types.HSBType;
|
import org.openhab.core.library.types.HSBType;
|
||||||
import org.openhab.core.library.types.OnOffType;
|
import org.openhab.core.library.types.OnOffType;
|
||||||
import org.openhab.core.library.types.PercentType;
|
import org.openhab.core.library.types.PercentType;
|
||||||
|
import org.openhab.core.util.ColorUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates commands to send to Feican devices.
|
* Creates commands to send to Feican devices.
|
||||||
@ -67,25 +65,13 @@ public class Commands {
|
|||||||
*/
|
*/
|
||||||
public byte[] color(HSBType color) {
|
public byte[] color(HSBType color) {
|
||||||
byte[] command = RGB_COMMAND.clone();
|
byte[] command = RGB_COMMAND.clone();
|
||||||
PercentType[] rgb = color.toRGB();
|
int[] rgb = ColorUtil.hsbToRgb(color);
|
||||||
command[4] = convertColorPercentToByte(rgb[0]);
|
command[4] = (byte) rgb[0];
|
||||||
command[5] = convertColorPercentToByte(rgb[1]);
|
command[5] = (byte) rgb[1];
|
||||||
command[6] = convertColorPercentToByte(rgb[2]);
|
command[6] = (byte) rgb[2];
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a percentage (0-100) to a color range value (0-255). This is needed because {@link HSBType} returns
|
|
||||||
* color values in the 100-range while a 255 range is needed.
|
|
||||||
*
|
|
||||||
* @param percent value to be converted.
|
|
||||||
* @return converted value as a byte value
|
|
||||||
*/
|
|
||||||
private byte convertColorPercentToByte(PercentType percent) {
|
|
||||||
return percent.toBigDecimal().multiply(BigDecimal.valueOf(255))
|
|
||||||
.divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP).byteValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the command to set the color temperature to a value between 0 and 100.
|
* Returns the command to set the color temperature to a value between 0 and 100.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user