Java 17 features (T-Z) (#15576)
- add missing @override - Java style array syntax - remove redundant modifiers - always move String constants to left side in comparisons - simplify lambda expressions and return statements - use replace instead of replaceAll w/o regex - instanceof matching and multiline strings - remove null check before instanceof Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
@@ -84,8 +84,7 @@ public class TapoDiscoveryService extends AbstractDiscoveryService implements Th
|
||||
|
||||
@Override
|
||||
public void setThingHandler(@Nullable ThingHandler handler) {
|
||||
if (handler instanceof TapoBridgeHandler) {
|
||||
TapoBridgeHandler tapoBridge = (TapoBridgeHandler) handler;
|
||||
if (handler instanceof TapoBridgeHandler tapoBridge) {
|
||||
tapoBridge.setDiscoveryService(this);
|
||||
this.bridge = tapoBridge;
|
||||
}
|
||||
|
||||
@@ -222,8 +222,7 @@ public class TapoCloudConnector {
|
||||
httpRequest.content(new StringContentProvider(payload, CONTENT_CHARSET), CONTENT_TYPE_JSON);
|
||||
|
||||
try {
|
||||
ContentResponse httpResponse = httpRequest.send();
|
||||
return httpResponse;
|
||||
return httpRequest.send();
|
||||
} catch (InterruptedException e) {
|
||||
logger.debug("({}) sending request interrupted: {}", uid, e.toString());
|
||||
handleError(new TapoErrorHandler(e));
|
||||
|
||||
@@ -158,7 +158,7 @@ public class TapoDeviceHttpApi {
|
||||
String payload = plBuilder.getPayload();
|
||||
|
||||
/* send request (create ) */
|
||||
logger.trace("({}) create handhsake with payload: {}", uid, payload.toString());
|
||||
logger.trace("({}) create handhsake with payload: {}", uid, payload);
|
||||
ContentResponse response = sendRequest(this.deviceURL, payload);
|
||||
if (response != null && getErrorCode(response) == 0) {
|
||||
String encryptedKey = getKeyFromResponse(response);
|
||||
@@ -308,8 +308,7 @@ public class TapoDeviceHttpApi {
|
||||
httpRequest.content(new StringContentProvider(payload, CONTENT_CHARSET), CONTENT_TYPE_JSON);
|
||||
|
||||
try {
|
||||
ContentResponse httpResponse = httpRequest.send();
|
||||
return httpResponse;
|
||||
return httpRequest.send();
|
||||
} catch (InterruptedException e) {
|
||||
logger.debug("({}) sending request interrupted: {}", uid, e.toString());
|
||||
handleError(new TapoErrorHandler(e));
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
package org.openhab.binding.tapocontrol.internal.device;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -114,7 +114,7 @@ public class TapoBridgeHandler extends BaseBridgeHandler {
|
||||
*/
|
||||
@Override
|
||||
public Collection<Class<? extends ThingHandlerService>> getServices() {
|
||||
return Collections.singleton(TapoDiscoveryService.class);
|
||||
return Set.of(TapoDiscoveryService.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -140,7 +140,7 @@ public abstract class TapoDevice extends BaseThingHandler {
|
||||
TapoErrorHandler configErr = new TapoErrorHandler();
|
||||
|
||||
/* check bridge */
|
||||
if (bridge == null || !(bridge instanceof TapoBridgeHandler)) {
|
||||
if (!(bridge instanceof TapoBridgeHandler)) {
|
||||
configErr.raiseError(ERR_CONFIG_NO_BRIDGE);
|
||||
return configErr;
|
||||
}
|
||||
|
||||
@@ -76,24 +76,24 @@ public class TapoLightStrip extends TapoDevice {
|
||||
refreshInfo = true;
|
||||
break;
|
||||
case CHANNEL_BRIGHTNESS:
|
||||
if (command instanceof PercentType) {
|
||||
Float percent = ((PercentType) command).floatValue();
|
||||
if (command instanceof PercentType percentCommand) {
|
||||
Float percent = percentCommand.floatValue();
|
||||
setBrightness(percent.intValue()); // 0..100% = 0..100
|
||||
refreshInfo = true;
|
||||
} else if (command instanceof DecimalType) {
|
||||
setBrightness(((DecimalType) command).intValue());
|
||||
} else if (command instanceof DecimalType decimalCommand) {
|
||||
setBrightness(decimalCommand.intValue());
|
||||
refreshInfo = true;
|
||||
}
|
||||
break;
|
||||
case CHANNEL_COLOR_TEMP:
|
||||
if (command instanceof DecimalType) {
|
||||
setColorTemp(((DecimalType) command).intValue());
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
setColorTemp(decimalCommand.intValue());
|
||||
refreshInfo = true;
|
||||
}
|
||||
break;
|
||||
case CHANNEL_COLOR:
|
||||
if (command instanceof HSBType) {
|
||||
setColor((HSBType) command);
|
||||
if (command instanceof HSBType hsbCommand) {
|
||||
setColor(hsbCommand);
|
||||
refreshInfo = true;
|
||||
}
|
||||
break;
|
||||
@@ -163,11 +163,11 @@ public class TapoLightStrip extends TapoDevice {
|
||||
TapoLightEffect lightEffect = deviceInfo.getLightEffect();
|
||||
switch (channel) {
|
||||
case CHANNEL_FX_BRIGHTNESS:
|
||||
if (command instanceof PercentType) {
|
||||
Float percent = ((PercentType) command).floatValue();
|
||||
if (command instanceof PercentType percentCommand) {
|
||||
Float percent = percentCommand.floatValue();
|
||||
lightEffect.setBrightness(percent.intValue()); // 0..100% = 0..100
|
||||
} else if (command instanceof DecimalType) {
|
||||
lightEffect.setBrightness(((DecimalType) command).intValue());
|
||||
} else if (command instanceof DecimalType decimalCommand) {
|
||||
lightEffect.setBrightness(decimalCommand.intValue());
|
||||
}
|
||||
break;
|
||||
case CHANNEL_FX_COLORS:
|
||||
|
||||
@@ -71,24 +71,24 @@ public class TapoSmartBulb extends TapoDevice {
|
||||
refreshInfo = true;
|
||||
break;
|
||||
case CHANNEL_BRIGHTNESS:
|
||||
if (command instanceof PercentType) {
|
||||
Float percent = ((PercentType) command).floatValue();
|
||||
if (command instanceof PercentType percentCommand) {
|
||||
Float percent = percentCommand.floatValue();
|
||||
setBrightness(percent.intValue()); // 0..100% = 0..100
|
||||
refreshInfo = true;
|
||||
} else if (command instanceof DecimalType) {
|
||||
setBrightness(((DecimalType) command).intValue());
|
||||
} else if (command instanceof DecimalType decimalCommand) {
|
||||
setBrightness(decimalCommand.intValue());
|
||||
refreshInfo = true;
|
||||
}
|
||||
break;
|
||||
case CHANNEL_COLOR_TEMP:
|
||||
if (command instanceof DecimalType) {
|
||||
setColorTemp(((DecimalType) command).intValue());
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
setColorTemp(decimalCommand.intValue());
|
||||
refreshInfo = true;
|
||||
}
|
||||
break;
|
||||
case CHANNEL_COLOR:
|
||||
if (command instanceof HSBType) {
|
||||
setColor((HSBType) command);
|
||||
if (command instanceof HSBType hsbCommand) {
|
||||
setColor(hsbCommand);
|
||||
refreshInfo = true;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -70,24 +70,24 @@ public class TapoUniversalDevice extends TapoDevice {
|
||||
refreshInfo = true;
|
||||
break;
|
||||
case CHANNEL_BRIGHTNESS:
|
||||
if (command instanceof PercentType) {
|
||||
Float percent = ((PercentType) command).floatValue();
|
||||
if (command instanceof PercentType percentCommand) {
|
||||
Float percent = percentCommand.floatValue();
|
||||
setBrightness(percent.intValue()); // 0..100% = 0..100
|
||||
refreshInfo = true;
|
||||
} else if (command instanceof DecimalType) {
|
||||
setBrightness(((DecimalType) command).intValue());
|
||||
} else if (command instanceof DecimalType decimalCommand) {
|
||||
setBrightness(decimalCommand.intValue());
|
||||
refreshInfo = true;
|
||||
}
|
||||
break;
|
||||
case CHANNEL_COLOR_TEMP:
|
||||
if (command instanceof DecimalType) {
|
||||
setColorTemp(((DecimalType) command).intValue());
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
setColorTemp(decimalCommand.intValue());
|
||||
refreshInfo = true;
|
||||
}
|
||||
break;
|
||||
case CHANNEL_COLOR:
|
||||
if (command instanceof HSBType) {
|
||||
setColor((HSBType) command);
|
||||
if (command instanceof HSBType hsbCommand) {
|
||||
setColor(hsbCommand);
|
||||
refreshInfo = true;
|
||||
}
|
||||
break;
|
||||
@@ -173,6 +173,7 @@ public class TapoUniversalDevice extends TapoDevice {
|
||||
*
|
||||
* @param responseBody
|
||||
*/
|
||||
@Override
|
||||
public void responsePasstrough(String responseBody) {
|
||||
logger.debug("({}) received response {}", uid, responseBody);
|
||||
publishState(getChannelID(CHANNEL_GROUP_DEBUG, CHANNEL_RESPONSE), getStringType(responseBody));
|
||||
@@ -224,6 +225,7 @@ public class TapoUniversalDevice extends TapoDevice {
|
||||
* @param channelID String channelID
|
||||
* @return String channel-name
|
||||
*/
|
||||
@Override
|
||||
protected String getChannelFromID(ChannelUID channelID) {
|
||||
String channel = channelID.getIdWithoutGroup();
|
||||
channel = channel.replace(CHANNEL_GROUP_ACTUATOR + "#", "");
|
||||
|
||||
@@ -44,10 +44,10 @@ public class PayloadBuilder {
|
||||
* @param value parameter value (typeOf Bool,Number or String)
|
||||
*/
|
||||
public void addParameter(String name, Object value) {
|
||||
if (value instanceof Boolean) {
|
||||
this.parameters.addProperty(name, (Boolean) value);
|
||||
} else if (value instanceof Number) {
|
||||
this.parameters.addProperty(name, (Number) value);
|
||||
if (value instanceof Boolean bool) {
|
||||
this.parameters.addProperty(name, bool);
|
||||
} else if (value instanceof Number number) {
|
||||
this.parameters.addProperty(name, number);
|
||||
} else {
|
||||
this.parameters.addProperty(name, value.toString());
|
||||
}
|
||||
|
||||
@@ -82,8 +82,7 @@ public class TapoUtils {
|
||||
*/
|
||||
public static String formatMac(String mac, char newDivisionChar) {
|
||||
String unformatedMac = unformatMac(mac);
|
||||
String formatedMac = unformatedMac.replaceAll("(.{2})", "$1" + newDivisionChar).substring(0, 17);
|
||||
return formatedMac;
|
||||
return unformatedMac.replaceAll("(.{2})", "$1" + newDivisionChar).substring(0, 17);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,7 +34,7 @@ public class TapoLightEffect {
|
||||
private Boolean custom = false;
|
||||
private Integer brightness = 0;
|
||||
private Integer[] colorTempRange = { 9000, 9000 }; // :[9000,9000]
|
||||
private Color displayColors[] = { Color.WHITE };
|
||||
private Color[] displayColors = { Color.WHITE };
|
||||
|
||||
private JsonObject jsonObject = new JsonObject();
|
||||
|
||||
|
||||
@@ -84,8 +84,7 @@ public class TapoDiscoveryService extends AbstractDiscoveryService implements Th
|
||||
|
||||
@Override
|
||||
public void setThingHandler(@Nullable ThingHandler handler) {
|
||||
if (handler instanceof TapoBridgeHandler) {
|
||||
TapoBridgeHandler tapoBridge = (TapoBridgeHandler) handler;
|
||||
if (handler instanceof TapoBridgeHandler tapoBridge) {
|
||||
tapoBridge.setDiscoveryService(this);
|
||||
this.bridge = tapoBridge;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
package org.openhab.binding.tapocontrol.internal.device;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -116,7 +116,7 @@ public class TapoBridgeHandler extends BaseBridgeHandler {
|
||||
*/
|
||||
@Override
|
||||
public Collection<Class<? extends ThingHandlerService>> getServices() {
|
||||
return Collections.singleton(TapoDiscoveryService.class);
|
||||
return Set.of(TapoDiscoveryService.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -70,24 +70,24 @@ public class TapoUniversalDevice extends TapoDevice {
|
||||
refreshInfo = true;
|
||||
break;
|
||||
case CHANNEL_BRIGHTNESS:
|
||||
if (command instanceof PercentType) {
|
||||
Float percent = ((PercentType) command).floatValue();
|
||||
if (command instanceof PercentType percentCommand) {
|
||||
Float percent = percentCommand.floatValue();
|
||||
setBrightness(percent.intValue()); // 0..100% = 0..100
|
||||
refreshInfo = true;
|
||||
} else if (command instanceof DecimalType) {
|
||||
setBrightness(((DecimalType) command).intValue());
|
||||
} else if (command instanceof DecimalType decimalCommand) {
|
||||
setBrightness(decimalCommand.intValue());
|
||||
refreshInfo = true;
|
||||
}
|
||||
break;
|
||||
case CHANNEL_COLOR_TEMP:
|
||||
if (command instanceof DecimalType) {
|
||||
setColorTemp(((DecimalType) command).intValue());
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
setColorTemp(decimalCommand.intValue());
|
||||
refreshInfo = true;
|
||||
}
|
||||
break;
|
||||
case CHANNEL_COLOR:
|
||||
if (command instanceof HSBType) {
|
||||
setColor((HSBType) command);
|
||||
if (command instanceof HSBType hsbCommand) {
|
||||
setColor(hsbCommand);
|
||||
refreshInfo = true;
|
||||
}
|
||||
break;
|
||||
@@ -173,6 +173,7 @@ public class TapoUniversalDevice extends TapoDevice {
|
||||
*
|
||||
* @param responseBody
|
||||
*/
|
||||
@Override
|
||||
public void responsePasstrough(String responseBody) {
|
||||
logger.info("({}) received response {}", uid, responseBody);
|
||||
publishState(getChannelID(CHANNEL_GROUP_DEBUG, CHANNEL_RESPONSE), getStringType(responseBody));
|
||||
@@ -224,6 +225,7 @@ public class TapoUniversalDevice extends TapoDevice {
|
||||
* @param channelID String channelID
|
||||
* @return String channel-name
|
||||
*/
|
||||
@Override
|
||||
protected String getChannelFromID(ChannelUID channelID) {
|
||||
String channel = channelID.getIdWithoutGroup();
|
||||
channel = channel.replace(CHANNEL_GROUP_ACTUATOR + "#", "");
|
||||
|
||||
@@ -34,7 +34,7 @@ public class TapoLightEffect {
|
||||
private Integer custom = 0;
|
||||
private Integer brightness = 0;
|
||||
private Integer[] colorTempRange = { 9000, 9000 }; // :[9000,9000]
|
||||
private Color displayColors[] = { Color.WHITE };
|
||||
private Color[] displayColors = { Color.WHITE };
|
||||
|
||||
private JsonObject jsonObject = new JsonObject();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user