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:
@@ -12,7 +12,6 @@
|
||||
*/
|
||||
package org.openhab.binding.venstarthermostat.internal;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@@ -34,7 +33,7 @@ public class VenstarThermostatBindingConstants {
|
||||
// List of all Thing Type UIDs
|
||||
public static final ThingTypeUID THING_TYPE_COLOR_TOUCH = new ThingTypeUID(BINDING_ID, "colorTouchThermostat");
|
||||
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_COLOR_TOUCH);
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_COLOR_TOUCH);
|
||||
// List of all Channel ids
|
||||
public static final String CHANNEL_TEMPERATURE = "temperature";
|
||||
public static final String CHANNEL_HUMIDITY = "humidity";
|
||||
|
||||
@@ -14,7 +14,6 @@ package org.openhab.binding.venstarthermostat.internal;
|
||||
|
||||
import static org.openhab.binding.venstarthermostat.internal.VenstarThermostatBindingConstants.THING_TYPE_COLOR_TOUCH;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@@ -37,7 +36,7 @@ import org.osgi.service.component.annotations.Component;
|
||||
@Component(service = ThingHandlerFactory.class, configurationPid = "binding.venstarthermostat")
|
||||
public class VenstarThermostatHandlerFactory extends BaseThingHandlerFactory {
|
||||
|
||||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_COLOR_TOUCH);
|
||||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_COLOR_TOUCH);
|
||||
|
||||
@Override
|
||||
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
|
||||
|
||||
@@ -53,8 +53,13 @@ import org.slf4j.LoggerFactory;
|
||||
@Component(service = DiscoveryService.class, configurationPid = "discovery.venstarthermostat")
|
||||
public class VenstarThermostatDiscoveryService extends AbstractDiscoveryService {
|
||||
private final Logger logger = LoggerFactory.getLogger(VenstarThermostatDiscoveryService.class);
|
||||
private static final String COLOR_TOUCH_DISCOVERY_MESSAGE = "M-SEARCH * HTTP/1.1\r\n"
|
||||
+ "Host: 239.255.255.250:1900\r\n" + "Man: ssdp:discover\r\n" + "ST: colortouch:ecp\r\n" + "\r\n";
|
||||
private static final String COLOR_TOUCH_DISCOVERY_MESSAGE = """
|
||||
M-SEARCH * HTTP/1.1
|
||||
Host: 239.255.255.250:1900
|
||||
Man: ssdp:discover
|
||||
ST: colortouch:ecp
|
||||
|
||||
""";
|
||||
private static final Pattern USN_PATTERN = Pattern
|
||||
.compile("^(colortouch:)?ecp((?::[0-9a-fA-F]{2}){6}):name:(.+)(?::type:(\\w+))");
|
||||
private static final String SSDP_MATCH = "colortouch:ecp";
|
||||
|
||||
@@ -29,7 +29,6 @@ public class VenstarFanStateSerializer implements JsonDeserializer<VenstarFanSta
|
||||
@Override
|
||||
public VenstarFanState deserialize(JsonElement element, Type arg1, JsonDeserializationContext arg2)
|
||||
throws JsonParseException {
|
||||
|
||||
int key = element.getAsInt();
|
||||
try {
|
||||
return VenstarFanState.fromInt(key);
|
||||
|
||||
@@ -188,8 +188,8 @@ public class VenstarThermostatHandler extends ConfigStatusThingHandler {
|
||||
} else if (channelUID.getId().equals(CHANNEL_SYSTEM_MODE)) {
|
||||
VenstarSystemMode value;
|
||||
try {
|
||||
if (command instanceof StringType) {
|
||||
value = VenstarSystemMode.valueOf(((StringType) command).toString().toUpperCase());
|
||||
if (command instanceof StringType stringCommand) {
|
||||
value = VenstarSystemMode.valueOf(stringCommand.toString().toUpperCase());
|
||||
} else {
|
||||
value = VenstarSystemMode.fromInt(((DecimalType) command).intValue());
|
||||
}
|
||||
@@ -202,8 +202,8 @@ public class VenstarThermostatHandler extends ConfigStatusThingHandler {
|
||||
} else if (channelUID.getId().equals(CHANNEL_AWAY_MODE)) {
|
||||
VenstarAwayMode value;
|
||||
try {
|
||||
if (command instanceof StringType) {
|
||||
value = VenstarAwayMode.valueOf(((StringType) command).toString().toUpperCase());
|
||||
if (command instanceof StringType stringCommand) {
|
||||
value = VenstarAwayMode.valueOf(stringCommand.toString().toUpperCase());
|
||||
} else {
|
||||
value = VenstarAwayMode.fromInt(((DecimalType) command).intValue());
|
||||
}
|
||||
@@ -217,8 +217,8 @@ public class VenstarThermostatHandler extends ConfigStatusThingHandler {
|
||||
} else if (channelUID.getId().equals(CHANNEL_FAN_MODE)) {
|
||||
VenstarFanMode value;
|
||||
try {
|
||||
if (command instanceof StringType) {
|
||||
value = VenstarFanMode.valueOf(((StringType) command).toString().toUpperCase());
|
||||
if (command instanceof StringType stringCommand) {
|
||||
value = VenstarFanMode.valueOf(stringCommand.toString().toUpperCase());
|
||||
} else {
|
||||
value = VenstarFanMode.fromInt(((DecimalType) command).intValue());
|
||||
}
|
||||
@@ -231,8 +231,8 @@ public class VenstarThermostatHandler extends ConfigStatusThingHandler {
|
||||
} else if (channelUID.getId().equals(CHANNEL_SCHEDULE_MODE)) {
|
||||
VenstarScheduleMode value;
|
||||
try {
|
||||
if (command instanceof StringType) {
|
||||
value = VenstarScheduleMode.valueOf(((StringType) command).toString().toUpperCase());
|
||||
if (command instanceof StringType stringCommand) {
|
||||
value = VenstarScheduleMode.valueOf(stringCommand.toString().toUpperCase());
|
||||
} else {
|
||||
value = VenstarScheduleMode.fromInt(((DecimalType) command).intValue());
|
||||
}
|
||||
@@ -325,7 +325,7 @@ public class VenstarThermostatHandler extends ConfigStatusThingHandler {
|
||||
|
||||
private State getTemperature() {
|
||||
Optional<VenstarSensor> optSensor = sensorData.stream()
|
||||
.filter(sensor -> sensor.getName().equalsIgnoreCase("Thermostat")).findAny();
|
||||
.filter(sensor -> "Thermostat".equalsIgnoreCase(sensor.getName())).findAny();
|
||||
if (optSensor.isPresent()) {
|
||||
return new QuantityType<Temperature>(optSensor.get().getTemp(), unitSystem);
|
||||
}
|
||||
@@ -335,7 +335,7 @@ public class VenstarThermostatHandler extends ConfigStatusThingHandler {
|
||||
|
||||
private State getHumidity() {
|
||||
Optional<VenstarSensor> optSensor = sensorData.stream()
|
||||
.filter(sensor -> sensor.getName().equalsIgnoreCase("Thermostat")).findAny();
|
||||
.filter(sensor -> "Thermostat".equalsIgnoreCase(sensor.getName())).findAny();
|
||||
if (optSensor.isPresent()) {
|
||||
return new QuantityType<Dimensionless>(optSensor.get().getHum(), Units.PERCENT);
|
||||
}
|
||||
@@ -345,7 +345,7 @@ public class VenstarThermostatHandler extends ConfigStatusThingHandler {
|
||||
|
||||
private State getOutdoorTemperature() {
|
||||
Optional<VenstarSensor> optSensor = sensorData.stream()
|
||||
.filter(sensor -> sensor.getName().equalsIgnoreCase("Outdoor")).findAny();
|
||||
.filter(sensor -> "Outdoor".equalsIgnoreCase(sensor.getName())).findAny();
|
||||
if (optSensor.isPresent()) {
|
||||
return new QuantityType<Temperature>(optSensor.get().getTemp(), unitSystem);
|
||||
}
|
||||
@@ -432,8 +432,7 @@ public class VenstarThermostatHandler extends ConfigStatusThingHandler {
|
||||
ZoneId zoneId = ZoneId.systemDefault();
|
||||
ZonedDateTime now = LocalDateTime.now().atZone(zoneId);
|
||||
int diff = now.getOffset().getTotalSeconds();
|
||||
ZonedDateTime z = ZonedDateTime.ofInstant(Instant.ofEpochSecond(runtime.getTimeStamp() - diff), zoneId);
|
||||
return z;
|
||||
return ZonedDateTime.ofInstant(Instant.ofEpochSecond(runtime.getTimeStamp() - diff), zoneId);
|
||||
}
|
||||
|
||||
private void updateScheduleMode(VenstarScheduleMode schedule) {
|
||||
@@ -634,8 +633,8 @@ public class VenstarThermostatHandler extends ConfigStatusThingHandler {
|
||||
}
|
||||
|
||||
protected DecimalType commandToDecimalType(Command command) {
|
||||
if (command instanceof DecimalType) {
|
||||
return (DecimalType) command;
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
return decimalCommand;
|
||||
}
|
||||
return new DecimalType(new BigDecimal(command.toString()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user