diff --git a/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/GardenaSmartImpl.java b/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/GardenaSmartImpl.java index 12dd5d8ab8f..bb596f42a03 100644 --- a/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/GardenaSmartImpl.java +++ b/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/GardenaSmartImpl.java @@ -199,8 +199,8 @@ public class GardenaSmartImpl implements GardenaSmart, GardenaSmartWebSocketList AbstractTypedContentProvider contentProvider = null; String contentType = "application/vnd.api+json"; if (content != null) { - if (content instanceof Fields) { - contentProvider = new FormContentProvider((Fields) content); + if (content instanceof Fields contentAsFields) { + contentProvider = new FormContentProvider(contentAsFields); contentType = "application/x-www-form-urlencoded"; } else { contentProvider = new StringContentProvider(gson.toJson(content)); diff --git a/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/GardenaSmartWebSocket.java b/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/GardenaSmartWebSocket.java index 9ef2ca5078b..6c4e06910ae 100644 --- a/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/GardenaSmartWebSocket.java +++ b/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/GardenaSmartWebSocket.java @@ -48,7 +48,7 @@ import org.slf4j.LoggerFactory; public class GardenaSmartWebSocket { private final Logger logger = LoggerFactory.getLogger(GardenaSmartWebSocket.class); private final GardenaSmartWebSocketListener socketEventListener; - private final int MAX_UNANSWERED_PINGS = 5; + private static final int MAX_UNANSWERED_PINGS = 5; private WebSocketSession session; private WebSocketClient webSocketClient; diff --git a/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/discovery/GardenaDeviceDiscoveryService.java b/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/discovery/GardenaDeviceDiscoveryService.java index 88a6dbf3dc8..0c7c71ce466 100644 --- a/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/discovery/GardenaDeviceDiscoveryService.java +++ b/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/discovery/GardenaDeviceDiscoveryService.java @@ -62,8 +62,8 @@ public class GardenaDeviceDiscoveryService extends AbstractDiscoveryService @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof GardenaAccountHandler) { - this.accountHandler = (GardenaAccountHandler) handler; + if (handler instanceof GardenaAccountHandler gardenaAccountHandler) { + this.accountHandler = gardenaAccountHandler; this.accountHandler.setDiscoveryService(this); } } diff --git a/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/handler/GardenaAccountHandler.java b/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/handler/GardenaAccountHandler.java index adbf9d7d913..7f6896b2d85 100644 --- a/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/handler/GardenaAccountHandler.java +++ b/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/handler/GardenaAccountHandler.java @@ -279,11 +279,10 @@ public class GardenaAccountHandler extends BaseBridgeHandler implements GardenaS continue; } final ThingHandler thingHandler = gardenaThing.getHandler(); - if (!(thingHandler instanceof GardenaThingHandler)) { + if (!(thingHandler instanceof GardenaThingHandler gardenaThingHandler)) { logger.debug("Handler for thingUID:{} is not a 'GardenaThingHandler' ({})", thingUID, thingHandler); continue; } - final GardenaThingHandler gardenaThingHandler = (GardenaThingHandler) thingHandler; try { gardenaThingHandler.updateProperties(device); for (Channel channel : gardenaThing.getChannels()) { diff --git a/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/handler/GardenaThingHandler.java b/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/handler/GardenaThingHandler.java index a8aa0ee4258..cb03291d6f0 100644 --- a/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/handler/GardenaThingHandler.java +++ b/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/handler/GardenaThingHandler.java @@ -261,14 +261,14 @@ public class GardenaThingHandler extends BaseThingHandler { String commandName = channelUID.getIdWithoutGroup().toUpperCase(); String groupId = channelUID.getGroupId(); if (groupId != null) { - if (groupId.startsWith("valve") && groupId.endsWith("_commands")) { + if ("valveSet_commands".equals(groupId)) { + return new ValveSetCommand(ValveSetControl.valueOf(commandName)); + } else if (groupId.startsWith("valve") && groupId.endsWith("_commands")) { return new ValveCommand(ValveControl.valueOf(commandName), getDevice().getLocalService(dataItemProperty).commandDuration); } else if ("mower_commands".equals(groupId)) { return new MowerCommand(MowerControl.valueOf(commandName), getDevice().getLocalService(dataItemProperty).commandDuration); - } else if ("valveSet_commands".equals(groupId)) { - return new ValveSetCommand(ValveSetControl.valueOf(commandName)); } else if ("powerSocket_commands".equals(groupId)) { return new PowerSocketCommand(PowerSocketControl.valueOf(commandName), getDevice().getLocalService(dataItemProperty).commandDuration); diff --git a/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/model/dto/Device.java b/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/model/dto/Device.java index 29839ae4428..6ecdfcf1973 100644 --- a/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/model/dto/Device.java +++ b/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/model/dto/Device.java @@ -113,38 +113,37 @@ public class Device { public void setDataItem(DataItem dataItem) throws GardenaException { if (dataItem instanceof DeviceDataItem) { // ignore - } else if (dataItem instanceof LocationDataItem) { - LocationDataItem locationDataItem = (LocationDataItem) dataItem; + } else if (dataItem instanceof LocationDataItem locationDataItem) { Location locationAttributes = locationDataItem.attributes; if (locationAttributes != null) { location = locationAttributes.name; } - } else if (dataItem instanceof CommonServiceDataItem) { - common = (CommonServiceDataItem) dataItem; - } else if (dataItem instanceof MowerServiceDataItem) { - mower = (MowerServiceDataItem) dataItem; - } else if (dataItem instanceof PowerSocketServiceDataItem) { - powerSocket = (PowerSocketServiceDataItem) dataItem; - } else if (dataItem instanceof SensorServiceDataItem) { - sensor = (SensorServiceDataItem) dataItem; - } else if (dataItem instanceof ValveSetServiceDataItem) { - valveSet = (ValveSetServiceDataItem) dataItem; - } else if (dataItem instanceof ValveServiceDataItem) { + } else if (dataItem instanceof CommonServiceDataItem commonServiceItem) { + common = commonServiceItem; + } else if (dataItem instanceof MowerServiceDataItem mowerServiceItemm) { + mower = mowerServiceItemm; + } else if (dataItem instanceof PowerSocketServiceDataItem powerSocketItem) { + powerSocket = powerSocketItem; + } else if (dataItem instanceof SensorServiceDataItem sensorServiceItem) { + sensor = sensorServiceItem; + } else if (dataItem instanceof ValveSetServiceDataItem valveSetServiceItem) { + valveSet = valveSetServiceItem; + } else if (dataItem instanceof ValveServiceDataItem valveServiceItem) { String valveNumber = StringUtils.substringAfterLast(dataItem.id, ":"); if ("".equals(valveNumber) || "wc".equals(valveNumber) || "0".equals(valveNumber)) { - valve = (ValveServiceDataItem) dataItem; + valve = valveServiceItem; } else if ("1".equals(valveNumber)) { - valveOne = (ValveServiceDataItem) dataItem; + valveOne = valveServiceItem; } else if ("2".equals(valveNumber)) { - valveTwo = (ValveServiceDataItem) dataItem; + valveTwo = valveServiceItem; } else if ("3".equals(valveNumber)) { - valveThree = (ValveServiceDataItem) dataItem; + valveThree = valveServiceItem; } else if ("4".equals(valveNumber)) { - valveFour = (ValveServiceDataItem) dataItem; + valveFour = valveServiceItem; } else if ("5".equals(valveNumber)) { - valveFive = (ValveServiceDataItem) dataItem; + valveFive = valveServiceItem; } else if ("6".equals(valveNumber)) { - valveSix = (ValveServiceDataItem) dataItem; + valveSix = valveServiceItem; } else { throw new GardenaException("Unknown valveNumber in dataItem with id: " + dataItem.id); }