Java 17 features (H-M) (#15520)
- 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:
@@ -46,14 +46,11 @@ public class MelCloudHandlerFactory extends BaseThingHandlerFactory {
|
||||
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
|
||||
|
||||
if (THING_TYPE_MELCLOUD_ACCOUNT.equals(thingTypeUID)) {
|
||||
MelCloudAccountHandler handler = new MelCloudAccountHandler((Bridge) thing);
|
||||
return handler;
|
||||
return new MelCloudAccountHandler((Bridge) thing);
|
||||
} else if (THING_TYPE_ACDEVICE.equals(thingTypeUID)) {
|
||||
MelCloudDeviceHandler handler = new MelCloudDeviceHandler(thing);
|
||||
return handler;
|
||||
return new MelCloudDeviceHandler(thing);
|
||||
} else if (THING_TYPE_HEATPUMPDEVICE.equals(thingTypeUID)) {
|
||||
MelCloudHeatpumpDeviceHandler handler = new MelCloudHeatpumpDeviceHandler(thing);
|
||||
return handler;
|
||||
return new MelCloudHeatpumpDeviceHandler(thing);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -137,8 +137,7 @@ public class MelCloudConnection {
|
||||
try {
|
||||
String response = HttpUtil.executeUrl("GET", url, getHeaderProperties(), null, null, TIMEOUT_MILLISECONDS);
|
||||
logger.debug("Device status response: {}", response);
|
||||
DeviceStatus deviceStatus = gson.fromJson(response, DeviceStatus.class);
|
||||
return deviceStatus;
|
||||
return gson.fromJson(response, DeviceStatus.class);
|
||||
} catch (IOException | JsonSyntaxException e) {
|
||||
setConnected(false);
|
||||
throw new MelCloudCommException("Error occurred during device status fetch", e);
|
||||
@@ -167,8 +166,7 @@ public class MelCloudConnection {
|
||||
try {
|
||||
String response = HttpUtil.executeUrl("GET", url, getHeaderProperties(), null, null, TIMEOUT_MILLISECONDS);
|
||||
logger.debug("Device heatpump status response: {}", response);
|
||||
HeatpumpDeviceStatus heatpumpDeviceStatus = gson.fromJson(response, HeatpumpDeviceStatus.class);
|
||||
return heatpumpDeviceStatus;
|
||||
return gson.fromJson(response, HeatpumpDeviceStatus.class);
|
||||
} catch (IOException | JsonSyntaxException e) {
|
||||
setConnected(false);
|
||||
throw new MelCloudCommException("Error occurred during heatpump device status fetch", e);
|
||||
|
||||
@@ -130,9 +130,9 @@ public class MelCloudDiscoveryService extends AbstractDiscoveryService
|
||||
|
||||
Map<String, Object> deviceProperties = new HashMap<>();
|
||||
deviceProperties.put(PROPERTY_DEVICE_ID, device.getDeviceID().toString());
|
||||
deviceProperties.put(Thing.PROPERTY_SERIAL_NUMBER, device.getSerialNumber().toString());
|
||||
deviceProperties.put(Thing.PROPERTY_MAC_ADDRESS, device.getMacAddress().toString());
|
||||
deviceProperties.put("deviceName", device.getDeviceName().toString());
|
||||
deviceProperties.put(Thing.PROPERTY_SERIAL_NUMBER, device.getSerialNumber());
|
||||
deviceProperties.put(Thing.PROPERTY_MAC_ADDRESS, device.getMacAddress());
|
||||
deviceProperties.put("deviceName", device.getDeviceName());
|
||||
deviceProperties.put("buildingID", device.getBuildingID().toString());
|
||||
|
||||
String label = createLabel(device);
|
||||
@@ -158,7 +158,7 @@ public class MelCloudDiscoveryService extends AbstractDiscoveryService
|
||||
} else if (device.getType() == 1) {
|
||||
sb.append("Heatpump Device - ");
|
||||
}
|
||||
if (device.getBuildingName() != null && device.getBuildingName() instanceof String) {
|
||||
if (device.getBuildingName() instanceof String) {
|
||||
sb.append(device.getBuildingName()).append(" - ");
|
||||
}
|
||||
sb.append(device.getDeviceName());
|
||||
@@ -167,8 +167,8 @@ public class MelCloudDiscoveryService extends AbstractDiscoveryService
|
||||
|
||||
@Override
|
||||
public void setThingHandler(@Nullable ThingHandler handler) {
|
||||
if (handler instanceof MelCloudAccountHandler) {
|
||||
melCloudHandler = (MelCloudAccountHandler) handler;
|
||||
if (handler instanceof MelCloudAccountHandler accountHandler) {
|
||||
melCloudHandler = accountHandler;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -61,7 +62,7 @@ public class MelCloudAccountHandler extends BaseBridgeHandler {
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends ThingHandlerService>> getServices() {
|
||||
return Collections.singleton(MelCloudDiscoveryService.class);
|
||||
return Set.of(MelCloudDiscoveryService.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user