Java 17 features (A-G) (#15516)
- 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 Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
@@ -14,7 +14,6 @@ package org.openhab.binding.goecharger.internal;
|
||||
|
||||
import static org.openhab.binding.goecharger.internal.GoEChargerBindingConstants.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@@ -41,7 +40,7 @@ import org.osgi.service.component.annotations.Reference;
|
||||
@NonNullByDefault
|
||||
@Component(configurationPid = "binding.goecharger", service = ThingHandlerFactory.class)
|
||||
public class GoEChargerHandlerFactory extends BaseThingHandlerFactory {
|
||||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_GOE);
|
||||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_GOE);
|
||||
private final HttpClient httpClient;
|
||||
|
||||
@Activate
|
||||
|
||||
@@ -254,16 +254,16 @@ public class GoEChargerHandler extends GoEChargerBaseHandler {
|
||||
switch (channelUID.getId()) {
|
||||
case MAX_CURRENT:
|
||||
key = "amp";
|
||||
if (command instanceof DecimalType) {
|
||||
value = String.valueOf(((DecimalType) command).intValue());
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
value = String.valueOf(decimalCommand.intValue());
|
||||
} else if (command instanceof QuantityType<?>) {
|
||||
value = String.valueOf(((QuantityType<ElectricCurrent>) command).toUnit(Units.AMPERE).intValue());
|
||||
}
|
||||
break;
|
||||
case MAX_CURRENT_TEMPORARY:
|
||||
key = "amx";
|
||||
if (command instanceof DecimalType) {
|
||||
value = String.valueOf(((DecimalType) command).intValue());
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
value = String.valueOf(decimalCommand.intValue());
|
||||
} else if (command instanceof QuantityType<?>) {
|
||||
value = String.valueOf(((QuantityType<ElectricCurrent>) command).toUnit(Units.AMPERE).intValue());
|
||||
}
|
||||
@@ -271,8 +271,8 @@ public class GoEChargerHandler extends GoEChargerBaseHandler {
|
||||
case SESSION_CHARGE_CONSUMPTION_LIMIT:
|
||||
key = "dwo";
|
||||
var multiplier = 10;
|
||||
if (command instanceof DecimalType) {
|
||||
value = String.valueOf(((DecimalType) command).intValue() * multiplier);
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
value = String.valueOf(decimalCommand.intValue() * multiplier);
|
||||
} else if (command instanceof QuantityType<?>) {
|
||||
value = String.valueOf(
|
||||
((QuantityType<Energy>) command).toUnit(Units.KILOWATT_HOUR).intValue() * multiplier);
|
||||
|
||||
@@ -143,7 +143,7 @@ public class GoEChargerV2Handler extends GoEChargerBaseHandler {
|
||||
}
|
||||
return new DecimalType(goeResponse.transaction);
|
||||
case ALLOW_CHARGING:
|
||||
return goeResponse.allowCharging == true ? OnOffType.ON : OnOffType.OFF;
|
||||
return goeResponse.allowCharging ? OnOffType.ON : OnOffType.OFF;
|
||||
case TEMPERATURE_TYPE2_PORT:
|
||||
// It was reported that the temperature is invalid when only one value is returned
|
||||
// That's why it is checked that at least 2 values are returned
|
||||
@@ -244,8 +244,8 @@ public class GoEChargerV2Handler extends GoEChargerBaseHandler {
|
||||
switch (channelUID.getId()) {
|
||||
case MAX_CURRENT:
|
||||
key = "amp";
|
||||
if (command instanceof DecimalType) {
|
||||
value = String.valueOf(((DecimalType) command).intValue());
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
value = String.valueOf(decimalCommand.intValue());
|
||||
} else if (command instanceof QuantityType<?>) {
|
||||
value = String.valueOf(((QuantityType<ElectricCurrent>) command).toUnit(Units.AMPERE).intValue());
|
||||
}
|
||||
@@ -253,8 +253,8 @@ public class GoEChargerV2Handler extends GoEChargerBaseHandler {
|
||||
case SESSION_CHARGE_CONSUMPTION_LIMIT:
|
||||
key = "dwo";
|
||||
var multiplier = 1000;
|
||||
if (command instanceof DecimalType) {
|
||||
value = String.valueOf(((DecimalType) command).intValue() * multiplier);
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
value = String.valueOf(decimalCommand.intValue() * multiplier);
|
||||
} else if (command instanceof QuantityType<?>) {
|
||||
value = String.valueOf(
|
||||
((QuantityType<Energy>) command).toUnit(Units.KILOWATT_HOUR).intValue() * multiplier);
|
||||
@@ -262,10 +262,9 @@ public class GoEChargerV2Handler extends GoEChargerBaseHandler {
|
||||
break;
|
||||
case PHASES:
|
||||
key = "psm";
|
||||
if (command instanceof DecimalType) {
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
var phases = 1;
|
||||
var help = (DecimalType) command;
|
||||
if (help.intValue() == 3) {
|
||||
if (decimalCommand.intValue() == 3) {
|
||||
// set value 2 for 3 phases
|
||||
phases = 2;
|
||||
}
|
||||
@@ -274,14 +273,14 @@ public class GoEChargerV2Handler extends GoEChargerBaseHandler {
|
||||
break;
|
||||
case FORCE_STATE:
|
||||
key = "frc";
|
||||
if (command instanceof DecimalType) {
|
||||
value = String.valueOf(((DecimalType) command).intValue());
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
value = String.valueOf(decimalCommand.intValue());
|
||||
}
|
||||
break;
|
||||
case TRANSACTION:
|
||||
key = "trx";
|
||||
if (command instanceof DecimalType) {
|
||||
value = String.valueOf(((DecimalType) command).intValue());
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
value = String.valueOf(decimalCommand.intValue());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user