Refactor usage of deprecated HSBType.getRGB (#14883)

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen 2023-04-29 10:54:36 +02:00 committed by GitHub
parent bd55302ae7
commit 6a33668664
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 20 deletions

View File

@ -13,7 +13,6 @@
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
@ -27,20 +26,12 @@ public class Color {
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) {

View File

@ -38,6 +38,7 @@ import org.openhab.core.thing.ThingStatus;
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;
@ -99,11 +100,10 @@ public class HDPowerViewRepeaterHandler extends AbstractHubbedThingHandler {
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));
}
@ -119,11 +119,10 @@ public class HDPowerViewRepeaterHandler extends AbstractHubbedThingHandler {
}
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));
@ -131,8 +130,8 @@ public class HDPowerViewRepeaterHandler extends AbstractHubbedThingHandler {
}
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();