package org.openhab.binding.hdpowerview.internal.dto;
import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.openhab.core.library.types.HSBType;
/**
* Color and brightness information for HD PowerView repeater
public int green;
public int blue;
- public Color(int brightness, HSBType hsbType) {
- this.brightness = brightness;
- int rgb = hsbType.getRGB();
- java.awt.Color color = new java.awt.Color(rgb);
- red = color.getRed();
- green = color.getGreen();
- blue = color.getBlue();
+ public Color(int brightness, int srgb) {
+ this(brightness, new java.awt.Color(srgb));
}
public Color(int brightness, java.awt.Color color) {
- this.brightness = brightness;
- red = color.getRed();
- green = color.getGreen();
- blue = color.getBlue();
+ this(brightness, color.getRed(), color.getGreen(), color.getBlue());
}
public Color(int brightness, int red, int green, int blue) {
import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.types.Command;
import org.openhab.core.types.UnDefType;
+import org.openhab.core.util.ColorUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
switch (channelUID.getId()) {
case CHANNEL_REPEATER_COLOR:
- if (command instanceof HSBType) {
+ if (command instanceof HSBType hsbCommand) {
Color currentColor = webTargets.getRepeater(repeaterId).color;
if (currentColor != null) {
- HSBType hsbCommand = (HSBType) command;
- var color = new Color(currentColor.brightness, hsbCommand);
+ var color = new Color(currentColor.brightness, ColorUtil.hsbTosRgb(hsbCommand));
repeaterData = webTargets.setRepeaterColor(repeaterId, color);
scheduler.submit(() -> updatePropertyAndStates(repeaterData));
}
}
break;
case CHANNEL_REPEATER_BRIGHTNESS:
- if (command instanceof PercentType) {
+ if (command instanceof PercentType brightnessCommand) {
Color currentColor = webTargets.getRepeater(repeaterId).color;
if (currentColor != null) {
- PercentType brightness = (PercentType) command;
- var color = new Color(brightness.intValue(), currentColor.red, currentColor.green,
+ var color = new Color(brightnessCommand.intValue(), currentColor.red, currentColor.green,
currentColor.blue);
repeaterData = webTargets.setRepeaterColor(repeaterId, color);
scheduler.submit(() -> updatePropertyAndStates(repeaterData));
}
break;
case CHANNEL_REPEATER_IDENTIFY:
- if (command instanceof StringType) {
- if (COMMAND_IDENTIFY.equals(((StringType) command).toString())) {
+ if (command instanceof StringType stringCommand) {
+ if (COMMAND_IDENTIFY.equals(stringCommand.toString())) {
repeaterData = webTargets.identifyRepeater(repeaterId);
scheduler.submit(() -> updatePropertyAndStates(repeaterData));
cancelResetIdentifyStateJob();