From 1b122a53b974a1827ca1cef23abd730c7007f1ee Mon Sep 17 00:00:00 2001 From: Holger Friedrich Date: Thu, 21 Sep 2023 07:58:53 +0200 Subject: [PATCH] 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 --- .../tacmi/internal/message/AnalogMessage.java | 3 +- .../tacmi/internal/schema/ApiPageEntry.java | 2 +- .../tacmi/internal/schema/ChangerX2Entry.java | 2 +- .../tado/internal/CapabilitiesSupport.java | 12 +- .../tado/internal/TadoBindingConstants.java | 16 +- .../adapter/TadoZoneStateAdapter.java | 2 +- .../tado/internal/api/TadoApiTypeUtils.java | 4 +- .../builder/TerminationConditionBuilder.java | 3 +- .../internal/handler/TadoHandlerFactory.java | 7 +- .../internal/handler/TadoHomeHandler.java | 4 +- .../TankerkoenigBindingConstants.java | 5 +- .../internal/TankerkoenigHandlerFactory.java | 3 +- .../internal/TapoDiscoveryService.java | 3 +- .../internal/api/TapoCloudConnector.java | 3 +- .../internal/api/TapoDeviceHttpApi.java | 5 +- .../internal/device/TapoBridgeHandler.java | 4 +- .../internal/device/TapoDevice.java | 2 +- .../internal/device/TapoLightStrip.java | 24 +-- .../internal/device/TapoSmartBulb.java | 16 +- .../internal/device/TapoUniversalDevice.java | 18 +- .../internal/helpers/PayloadBuilder.java | 8 +- .../internal/helpers/TapoUtils.java | 3 +- .../internal/structures/TapoLightEffect.java | 2 +- .../internal/TapoDiscoveryService.java | 3 +- .../internal/device/TapoBridgeHandler.java | 4 +- .../internal/device/TapoUniversalDevice.java | 18 +- .../internal/structures/TapoLightEffect.java | 2 +- .../telegram/internal/TelegramHandler.java | 4 +- .../internal/TelegramHandlerFactory.java | 3 +- .../internal/action/TelegramActions.java | 8 +- .../internal/TeleinfoDiscoveryService.java | 4 +- .../TeleinfoAbstractControllerHandler.java | 3 +- .../internal/TellstickHandlerFactory.java | 4 +- .../core/TelldusCoreDeviceController.java | 28 ++-- .../discovery/TellstickDiscoveryService.java | 14 +- .../handler/TelldusDevicesHandler.java | 31 ++-- .../live/TelldusLiveDeviceController.java | 25 ++- .../local/TelldusLocalDeviceController.java | 24 +-- .../internal/TeslaChannelSelectorProxy.java | 2 +- .../internal/handler/TeslaAccountHandler.java | 3 +- .../internal/handler/TeslaVehicleHandler.java | 66 ++++---- .../tesla/internal/protocol/Vehicle.java | 2 +- .../tesla/internal/protocol/VehicleData.java | 2 +- .../tivo/internal/TiVoHandlerFactory.java | 3 +- .../discovery/TiVoDiscoveryParticipant.java | 3 +- .../tivo/internal/handler/TiVoHandler.java | 7 +- .../tivo/internal/service/TivoStatusData.java | 2 +- .../internal/service/TivoStatusProvider.java | 2 +- .../internal/TouchWandAlarmSensorHandler.java | 3 +- .../internal/TouchWandBSensorHandler.java | 12 +- .../internal/TouchWandBaseUnitHandler.java | 2 +- .../internal/TouchWandBridgeHandler.java | 5 +- .../internal/TouchWandDimmerHandler.java | 8 +- .../internal/TouchWandRestClient.java | 3 +- .../internal/TouchWandShutterHandler.java | 4 +- .../internal/TouchWandSwitchHandler.java | 8 +- .../internal/TouchWandThermostatHandler.java | 11 +- .../TouchWandWallControllerHandler.java | 4 +- .../internal/TouchWandWebSockets.java | 6 +- .../TouchWandControllerDiscoveryService.java | 4 +- .../TouchWandUnitDiscoveryService.java | 4 +- .../dto/AlarmSensorUnitDataDeserializer.java | 2 +- .../internal/device/BulbDevice.java | 12 +- .../internal/device/DimmerDevice.java | 8 +- .../internal/device/SwitchDevice.java | 2 +- .../handler/TPLinkSmartHomeActions.java | 4 +- .../tr064/internal/FritzboxActions.java | 2 +- .../tr064/internal/Tr064DiscoveryService.java | 4 +- .../tr064/internal/Tr064HandlerFactory.java | 4 +- .../tr064/internal/Tr064RootHandler.java | 4 +- .../internal/phonebook/PhonebookProfile.java | 16 +- .../tr064/internal/soap/SOAPConnector.java | 4 +- .../internal/soap/SOAPValueConverter.java | 15 +- .../binding/tr064/internal/util/Util.java | 8 +- .../internal/TradfriBindingConstants.java | 6 +- .../discovery/TradfriDiscoveryService.java | 4 +- .../handler/TradfriAirPurifierHandler.java | 12 +- .../internal/handler/TradfriBlindHandler.java | 4 +- .../handler/TradfriGatewayHandler.java | 3 +- .../internal/handler/TradfriLightHandler.java | 26 +-- .../internal/handler/TradfriPlugHandler.java | 4 +- .../model/TradfriAirPurifierData.java | 4 +- .../twitter/internal/TwitterHandler.java | 6 +- .../internal/action/TwitterActions.java | 4 +- .../internal/action/UniFiSiteActions.java | 4 +- .../internal/api/UniFiControllerRequest.java | 6 +- .../unifi/internal/api/dto/UniFiVoucher.java | 6 +- .../handler/UniFiClientThingHandler.java | 8 +- .../handler/UniFiControllerThingHandler.java | 4 +- .../handler/UniFiSiteThingHandler.java | 4 +- .../handler/UniFiThingDiscoveryService.java | 4 +- .../handler/UniFiWlanThingHandler.java | 4 +- .../UnifiedRemoteBindingConstants.java | 4 +- .../binding/upb/internal/UPBController.java | 10 +- .../upb/internal/handler/UPBThingHandler.java | 4 +- ...UpnpDynamicCommandDescriptionProvider.java | 3 +- .../UpnpDynamicStateDescriptionProvider.java | 3 +- .../internal/handler/UpnpHandler.java | 4 +- .../internal/handler/UpnpRendererHandler.java | 35 ++-- .../internal/handler/UpnpServerHandler.java | 4 +- .../internal/util/StringUtils.java | 20 +-- .../internal/util/UpnpControlUtil.java | 3 +- .../internal/handler/UpnpHandlerTest.java | 5 +- .../handler/UpnpRendererHandlerTest.java | 6 +- .../handler/UpnpServerHandlerTest.java | 8 +- .../urtsi/internal/UrtsiHandlerFactory.java | 4 +- .../internal/handler/RtsDeviceHandler.java | 17 +- .../internal/handler/UrtsiDeviceHandler.java | 3 +- .../internal/ValloxMVBindingConstants.java | 25 +-- .../internal/ValloxMVHandlerFactory.java | 3 +- .../binding/vdr/internal/VDRHandler.java | 2 +- .../vdr/internal/VDRHandlerFactory.java | 3 +- .../vdr/internal/svdrp/SVDRPChannel.java | 2 +- .../vdr/internal/svdrp/SVDRPClientImpl.java | 18 +- .../vdr/internal/SVDRPEpgEventTest.java | 88 +++++++--- .../vdr/internal/SVDRPTimerListTest.java | 12 +- .../internal/VektivaHandlerFactory.java | 3 +- .../handler/VektivaSmarwiHandler.java | 2 +- .../internal/VelbusBindingConstants.java | 30 ++-- .../VelbusThingDiscoveryService.java | 3 +- .../internal/handler/VelbusBlindsHandler.java | 14 +- .../internal/handler/VelbusBridgeHandler.java | 20 +-- .../internal/handler/VelbusDimmerHandler.java | 9 +- .../internal/handler/VelbusMemoHandler.java | 4 +- .../internal/handler/VelbusRelayHandler.java | 4 +- .../handler/VelbusRelayWithInputHandler.java | 8 +- .../internal/handler/VelbusSensorHandler.java | 23 +-- .../VelbusSensorWithAlarmClockHandler.java | 16 +- .../handler/VelbusThermostatHandler.java | 18 +- .../internal/handler/VelbusThingHandler.java | 3 +- .../internal/handler/VelbusVMB4ANHandler.java | 4 +- .../velux/internal/action/VeluxActions.java | 4 +- .../internal/bridge/json/JCgetFirmware.java | 3 +- .../internal/bridge/json/JCgetLANConfig.java | 5 +- .../internal/bridge/json/JCgetWLANConfig.java | 3 +- .../internal/factory/VeluxHandlerFactory.java | 4 +- .../handler/ChannelActuatorPosition.java | 18 +- .../internal/handler/VeluxBridgeHandler.java | 4 +- .../velux/internal/things/VeluxProduct.java | 6 +- .../internal/things/VeluxProductPosition.java | 2 +- .../internal/things/VeluxProductType.java | 2 +- .../internal/utils/ManifestInformation.java | 4 +- .../test/TestNotificationsAndDatabase.java | 42 +++-- .../VenstarThermostatBindingConstants.java | 3 +- .../VenstarThermostatHandlerFactory.java | 3 +- .../VenstarThermostatDiscoveryService.java | 9 +- .../dto/VenstarFanStateSerializer.java | 1 - .../handler/VenstarThermostatHandler.java | 29 ++-- .../ventaair/internal/Communicator.java | 2 - .../ventaair/internal/VentaThingHandler.java | 12 +- .../discovery/VentaDeviceDiscovery.java | 5 +- .../verisure/internal/VerisureSession.java | 2 +- .../VerisureThingDiscoveryService.java | 8 +- .../handler/VerisureAlarmThingHandler.java | 5 +- .../handler/VerisureBridgeHandler.java | 5 +- ...risureBroadbandConnectionThingHandler.java | 4 +- .../VerisureClimateDeviceThingHandler.java | 2 +- .../VerisureDoorWindowThingHandler.java | 5 +- .../handler/VerisureEventLogThingHandler.java | 4 +- .../handler/VerisureGatewayThingHandler.java | 3 +- .../VerisureMiceDetectionThingHandler.java | 15 +- .../VerisureSmartLockThingHandler.java | 5 +- .../VerisureSmartPlugThingHandler.java | 5 +- .../VerisureUserPresenceThingHandler.java | 5 +- .../internal/api/VeSyncV2ApiHelper.java | 14 +- .../discovery/VeSyncDiscoveryService.java | 7 +- .../handlers/VeSyncBaseDeviceHandler.java | 20 +-- .../handlers/VeSyncBridgeHandler.java | 15 +- .../VeSyncDeviceAirHumidifierHandler.java | 6 +- .../VeSyncDeviceAirPurifierHandler.java | 4 +- .../VesyncAuthenticatedRequestTest.java | 2 +- ...esyncRequestManagedDeviceBypassV2Test.java | 2 +- .../responses/VesyncLoginResponseTest.java | 72 +++++--- .../VesyncManagedDevicesPageTest.java | 82 ++++----- .../VesyncV1AirPurifierDeviceDetailsTest.java | 32 ++-- .../internal/VitotronicBindingConstants.java | 3 +- .../handler/VitotronicThingHandler.java | 4 +- .../vizio/internal/VizioBindingConstants.java | 3 +- .../vizio/internal/VizioHandlerFactory.java | 3 +- .../console/VizioCommandExtension.java | 4 +- .../internal/VolvoOnCallException.java | 4 +- .../internal/action/VolvoOnCallActions.java | 4 +- .../VolvoVehicleDiscoveryService.java | 5 +- .../internal/dto/PostResponse.java | 4 +- .../volvooncall/internal/dto/Status.java | 2 +- .../internal/dto/TyrePressure.java | 2 +- .../internal/handler/VehicleHandler.java | 10 +- .../handler/VolvoOnCallBridgeHandler.java | 4 +- .../warmup/internal/api/MyWarmupApi.java | 12 +- .../discovery/WarmupDiscoveryService.java | 4 +- .../handler/MyWarmupAccountHandler.java | 4 +- .../warmup/internal/handler/RoomHandler.java | 9 +- .../WeatherCompanyAbstractHandler.java | 3 +- .../WeatherUndergroundBindingConstants.java | 3 +- .../WeatherUndergroundDiscoveryService.java | 3 +- .../WeatherUndergroundBridgeHandler.java | 2 +- .../json/WeatherUndergroundJsonCurrent.java | 2 +- .../json/WeatherUndergroundJsonUtils.java | 4 +- .../internal/WebexTeamsActions.java | 28 ++-- .../internal/WebexTeamsHandler.java | 4 +- .../internal/WebexTeamsHandlerFactory.java | 4 +- .../internal/api/WebexTeamsApi.java | 6 +- .../internal/WebThingBindingConstants.java | 6 +- .../webthing/internal/WebThingHandler.java | 4 +- .../internal/client/ConsumedThingImpl.java | 2 +- .../internal/client/DescriptionLoader.java | 2 +- .../client/dto/WebThingDescription.java | 2 +- .../internal/link/TypeConverters.java | 6 +- .../webthing/internal/link/TypeMapping.java | 2 +- .../binding/wemo/internal/WemoUtil.java | 27 +-- .../discovery/WemoLinkDiscoveryService.java | 25 ++- .../internal/handler/WemoBridgeHandler.java | 3 +- .../internal/handler/WemoCoffeeHandler.java | 32 ++-- .../internal/handler/WemoCrockpotHandler.java | 12 +- .../internal/handler/WemoDimmerHandler.java | 91 ++++++---- .../internal/handler/WemoHolmesHandler.java | 14 +- .../internal/handler/WemoLightHandler.java | 35 ++-- .../internal/handler/WemoMakerHandler.java | 3 +- .../internal/WiFiLEDBindingConstants.java | 3 +- .../internal/WiFiLEDHandlerFactory.java | 3 +- .../internal/handler/WiFiLEDHandler.java | 55 +++--- .../WindcentraleDiscoveryService.java | 2 +- .../windcentrale/internal/dto/DataUtil.java | 2 +- .../esp32/WlanThermoEsp32CommandHandler.java | 21 ++- .../mini/WlanThermoMiniCommandHandler.java | 2 +- .../nano/WlanThermoNanoV1CommandHandler.java | 21 ++- .../binding/wled/internal/WLedActions.java | 8 +- .../wled/internal/WLedDiscoveryService.java | 2 +- .../internal/WLedSegmentDiscoveryService.java | 4 +- .../wled/internal/api/WledApiV084.java | 6 +- .../internal/handlers/WLedBridgeHandler.java | 34 ++-- .../internal/handlers/WLedSegmentHandler.java | 64 ++++--- .../internal/api/WolfSmartsetApi.java | 1 - .../WolfSmartsetAccountDiscoveryService.java | 4 +- .../WolfSmartsetSystemDiscoveryService.java | 6 +- .../WolfSmartsetAccountBridgeHandler.java | 5 +- .../WolfSmartsetSystemBridgeHandler.java | 4 +- .../WundergroundUpdateReceiverServlet.java | 2 + ...undUpdateReceiverDiscoveryServiceTest.java | 156 ++++++++++++++---- .../discovery/XmlTVDiscoveryService.java | 4 +- .../xmltv/internal/handler/XmlTVHandler.java | 3 +- .../xmltv/internal/jaxb/Programme.java | 3 +- .../internal/XMPPClientHandlerFactory.java | 5 +- .../internal/handler/XMPPClientHandler.java | 4 +- .../internal/YamahaMusiccastHandler.java | 10 +- .../ChannelsTypeProviderAvailableInputs.java | 4 +- .../internal/ChannelsTypeProviderPreset.java | 4 +- .../YamahaReceiverBindingConstants.java | 4 +- .../discovery/YamahaDiscoveryParticipant.java | 3 +- .../internal/handler/YamahaBridgeHandler.java | 6 +- .../protocol/xml/DeviceInformationXML.java | 3 +- .../xml/InputWithNavigationControlXML.java | 9 +- .../protocol/xml/XMLProtocolService.java | 3 +- .../state/NavigationControlState.java | 2 +- .../internal/handler/YeelightHandlerBase.java | 46 +++--- .../internal/lib/device/CeilingDevice.java | 4 +- .../internal/lib/device/CtBulbDevice.java | 4 +- .../internal/lib/device/DesklampDevice.java | 4 +- .../internal/lib/device/DeviceBase.java | 8 +- .../internal/lib/device/MonoDevice.java | 4 +- .../internal/lib/device/PitayaDevice.java | 4 +- .../internal/lib/device/WonderDevice.java | 4 +- .../internal/lib/services/DeviceManager.java | 33 ++-- .../internal/YIOremoteBindingConstants.java | 8 +- .../internal/YIOremoteDockHandler.java | 21 ++- .../internal/YIOremoteHandlerFactory.java | 3 +- .../zoneminder/internal/action/ZmActions.java | 4 +- .../discovery/MonitorDiscoveryService.java | 4 +- .../internal/handler/ZmBridgeHandler.java | 5 +- .../internal/handler/ZmMonitorHandler.java | 8 +- .../zway/internal/ZWayBindingConstants.java | 3 +- .../converter/ZWayDeviceStateConverter.java | 5 +- .../discovery/ZWayBridgeDiscoveryService.java | 2 +- .../discovery/ZWayDeviceDiscoveryService.java | 6 +- .../internal/handler/ZWayBridgeHandler.java | 2 +- .../internal/handler/ZWayDeviceHandler.java | 16 +- .../handler/ZWayZWaveDeviceHandler.java | 2 +- 277 files changed, 1402 insertions(+), 1298 deletions(-) diff --git a/bundles/org.openhab.binding.tacmi/src/main/java/org/openhab/binding/tacmi/internal/message/AnalogMessage.java b/bundles/org.openhab.binding.tacmi/src/main/java/org/openhab/binding/tacmi/internal/message/AnalogMessage.java index e07c8afc57c..e23da979cc7 100644 --- a/bundles/org.openhab.binding.tacmi/src/main/java/org/openhab/binding/tacmi/internal/message/AnalogMessage.java +++ b/bundles/org.openhab.binding.tacmi/src/main/java/org/openhab/binding/tacmi/internal/message/AnalogMessage.java @@ -93,8 +93,7 @@ public final class AnalogMessage extends Message { public AnalogValue getAnalogValue(int portNumber) { // Get the internal index for portNumber within the message int idx = (portNumber - 1) % 4; - AnalogValue value = new AnalogValue(this.getValue(idx), getMeasureType(idx)); - return value; + return new AnalogValue(this.getValue(idx), getMeasureType(idx)); } /** diff --git a/bundles/org.openhab.binding.tacmi/src/main/java/org/openhab/binding/tacmi/internal/schema/ApiPageEntry.java b/bundles/org.openhab.binding.tacmi/src/main/java/org/openhab/binding/tacmi/internal/schema/ApiPageEntry.java index 7aaffdb87ff..0c42c4c8ce4 100644 --- a/bundles/org.openhab.binding.tacmi/src/main/java/org/openhab/binding/tacmi/internal/schema/ApiPageEntry.java +++ b/bundles/org.openhab.binding.tacmi/src/main/java/org/openhab/binding/tacmi/internal/schema/ApiPageEntry.java @@ -26,7 +26,7 @@ import org.openhab.core.types.State; @NonNullByDefault public class ApiPageEntry { - static enum Type { + enum Type { READ_ONLY_SWITCH(true), READ_ONLY_NUMERIC(true), NUMERIC_FORM(false), diff --git a/bundles/org.openhab.binding.tacmi/src/main/java/org/openhab/binding/tacmi/internal/schema/ChangerX2Entry.java b/bundles/org.openhab.binding.tacmi/src/main/java/org/openhab/binding/tacmi/internal/schema/ChangerX2Entry.java index fecdcce5a3d..0b15c8ba523 100644 --- a/bundles/org.openhab.binding.tacmi/src/main/java/org/openhab/binding/tacmi/internal/schema/ChangerX2Entry.java +++ b/bundles/org.openhab.binding.tacmi/src/main/java/org/openhab/binding/tacmi/internal/schema/ChangerX2Entry.java @@ -30,7 +30,7 @@ public class ChangerX2Entry { public static final String NUMBER_MAX = "max"; public static final String NUMBER_STEP = "step"; - static enum OptionType { + enum OptionType { NUMBER, SELECT, } diff --git a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/CapabilitiesSupport.java b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/CapabilitiesSupport.java index c4b061e0062..573668de71e 100644 --- a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/CapabilitiesSupport.java +++ b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/CapabilitiesSupport.java @@ -73,12 +73,12 @@ public class CapabilitiesSupport { // iterate over all mode capability elements and build the superset of their inner capabilities allCapabilities.forEach(e -> { if (e != null) { - light |= e.getLight() != null ? e.getLight().size() > 0 : false; - swing |= e.getSwings() != null ? e.getSwings().size() > 0 : false; - fanLevel |= e.getFanLevel() != null ? e.getFanLevel().size() > 0 : false; - fanSpeed |= e.getFanSpeeds() != null ? e.getFanSpeeds().size() > 0 : false; - verticalSwing |= e.getVerticalSwing() != null ? e.getVerticalSwing().size() > 0 : false; - horizontalSwing |= e.getHorizontalSwing() != null ? e.getHorizontalSwing().size() > 0 : false; + light |= e.getLight() != null ? !e.getLight().isEmpty() : false; + swing |= e.getSwings() != null ? !e.getSwings().isEmpty() : false; + fanLevel |= e.getFanLevel() != null ? !e.getFanLevel().isEmpty() : false; + fanSpeed |= e.getFanSpeeds() != null ? !e.getFanSpeeds().isEmpty() : false; + verticalSwing |= e.getVerticalSwing() != null ? !e.getVerticalSwing().isEmpty() : false; + horizontalSwing |= e.getHorizontalSwing() != null ? !e.getHorizontalSwing().isEmpty() : false; } }); } diff --git a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/TadoBindingConstants.java b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/TadoBindingConstants.java index bee2a393e9b..2607a289e24 100644 --- a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/TadoBindingConstants.java +++ b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/TadoBindingConstants.java @@ -36,7 +36,7 @@ public class TadoBindingConstants { // List of all Channel IDs public static final String PROPERTY_HOME_TEMPERATURE_UNIT = "temperatureUnit"; - public static enum TemperatureUnit { + public enum TemperatureUnit { CELSIUS, FAHRENHEIT } @@ -52,7 +52,7 @@ public class TadoBindingConstants { public static final String CHANNEL_ZONE_HVAC_MODE = "hvacMode"; - public static enum HvacMode { + public enum HvacMode { OFF, HEAT, COOL, @@ -69,7 +69,7 @@ public class TadoBindingConstants { public static final String CHANNEL_ZONE_FAN_SPEED = "fanspeed"; - public static enum FanSpeed { + public enum FanSpeed { LOW, MIDDLE, HIGH, @@ -78,7 +78,7 @@ public class TadoBindingConstants { public static final String CHANNEL_ZONE_FAN_LEVEL = "fanLevel"; - public static enum FanLevel { + public enum FanLevel { SILENT, LEVEL1, LEVEL2, @@ -90,7 +90,7 @@ public class TadoBindingConstants { public static final String CHANNEL_ZONE_HORIZONTAL_SWING = "horizontalSwing"; - public static enum HorizontalSwing { + public enum HorizontalSwing { OFF, ON, LEFT, @@ -103,7 +103,7 @@ public class TadoBindingConstants { public static final String CHANNEL_ZONE_VERTICAL_SWING = "verticalSwing"; - public static enum VerticalSwing { + public enum VerticalSwing { OFF, ON, UP, @@ -116,7 +116,7 @@ public class TadoBindingConstants { public static final String CHANNEL_ZONE_OPERATION_MODE = "operationMode"; - public static enum OperationMode { + public enum OperationMode { SCHEDULE, TIMER, MANUAL, @@ -141,7 +141,7 @@ public class TadoBindingConstants { public static final String PROPERTY_ZONE_NAME = "name"; public static final String PROPERTY_ZONE_TYPE = "type"; - public static enum ZoneType { + public enum ZoneType { HEATING, AIR_CONDITIONING, HOT_WATER diff --git a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/adapter/TadoZoneStateAdapter.java b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/adapter/TadoZoneStateAdapter.java index c38358a411f..c770340a645 100644 --- a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/adapter/TadoZoneStateAdapter.java +++ b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/adapter/TadoZoneStateAdapter.java @@ -221,7 +221,7 @@ public class TadoZoneStateAdapter { break; } - return power.getValue().equals("ON"); + return "ON".equals(power.getValue()); } private static DecimalType toDecimalType(double value) { diff --git a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/api/TadoApiTypeUtils.java b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/api/TadoApiTypeUtils.java index f63d8874254..cc2069e75ad 100644 --- a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/api/TadoApiTypeUtils.java +++ b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/api/TadoApiTypeUtils.java @@ -226,8 +226,8 @@ public class TadoApiTypeUtils { @Nullable GenericZoneCapabilities capabilities) { AirConditioningCapabilities acCapabilities; - if (capabilities instanceof AirConditioningCapabilities) { - acCapabilities = (AirConditioningCapabilities) capabilities; + if (capabilities instanceof AirConditioningCapabilities conditioningCapabilities) { + acCapabilities = conditioningCapabilities; } else { acCapabilities = new AirConditioningCapabilities(); } diff --git a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/builder/TerminationConditionBuilder.java b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/builder/TerminationConditionBuilder.java index 02586f3645c..e600f2f44fe 100644 --- a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/builder/TerminationConditionBuilder.java +++ b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/builder/TerminationConditionBuilder.java @@ -84,8 +84,7 @@ public class TerminationConditionBuilder { } private OverlayTerminationCondition getDefaultTerminationCondition() throws IOException, ApiException { - OverlayTerminationCondition defaultTerminationCondition = zoneHandler.getDefaultTerminationCondition(); - return defaultTerminationCondition; + return zoneHandler.getDefaultTerminationCondition(); } private TimerTerminationCondition getCurrentOrDefaultTimerTermination(ZoneStateProvider zoneStateProvider) diff --git a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/handler/TadoHandlerFactory.java b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/handler/TadoHandlerFactory.java index 781401896b6..7b067810847 100644 --- a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/handler/TadoHandlerFactory.java +++ b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/handler/TadoHandlerFactory.java @@ -14,10 +14,7 @@ package org.openhab.binding.tado.internal.handler; import static org.openhab.binding.tado.internal.TadoBindingConstants.*; -import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.Hashtable; import java.util.Map; import java.util.Set; @@ -48,8 +45,8 @@ import org.osgi.service.component.annotations.Reference; @Component(configurationPid = "binding.tado", service = ThingHandlerFactory.class) public class TadoHandlerFactory extends BaseThingHandlerFactory { - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections - .unmodifiableSet(new HashSet<>(Arrays.asList(THING_TYPE_HOME, THING_TYPE_ZONE, THING_TYPE_MOBILE_DEVICE))); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_HOME, THING_TYPE_ZONE, + THING_TYPE_MOBILE_DEVICE); private final Map> discoveryServiceRegs = new HashMap<>(); diff --git a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/handler/TadoHomeHandler.java b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/handler/TadoHomeHandler.java index cc9f0ed2704..faa86f2f7d9 100644 --- a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/handler/TadoHomeHandler.java +++ b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/handler/TadoHomeHandler.java @@ -179,8 +179,8 @@ public class TadoHomeHandler extends BaseBridgeHandler { switch (id) { case TadoBindingConstants.CHANNEL_HOME_PRESENCE_MODE: HomePresence presence = new HomePresence(); - presence.setHomePresence(command.toFullString().toUpperCase().equals("ON") - || command.toFullString().toUpperCase().equals("HOME") ? PresenceState.HOME + presence.setHomePresence("ON".equals(command.toFullString().toUpperCase()) + || "HOME".equals(command.toFullString().toUpperCase()) ? PresenceState.HOME : PresenceState.AWAY); try { api.updatePresenceLock(homeId, presence); diff --git a/bundles/org.openhab.binding.tankerkoenig/src/main/java/org/openhab/binding/tankerkoenig/internal/TankerkoenigBindingConstants.java b/bundles/org.openhab.binding.tankerkoenig/src/main/java/org/openhab/binding/tankerkoenig/internal/TankerkoenigBindingConstants.java index 6d3463ffe35..e8ef99a1069 100644 --- a/bundles/org.openhab.binding.tankerkoenig/src/main/java/org/openhab/binding/tankerkoenig/internal/TankerkoenigBindingConstants.java +++ b/bundles/org.openhab.binding.tankerkoenig/src/main/java/org/openhab/binding/tankerkoenig/internal/TankerkoenigBindingConstants.java @@ -12,7 +12,6 @@ */ package org.openhab.binding.tankerkoenig.internal; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -33,8 +32,8 @@ public class TankerkoenigBindingConstants { public static final ThingTypeUID THING_TYPE_TANKSTELLE = new ThingTypeUID(BINDING_ID, "station"); public static final ThingTypeUID BRIDGE_THING_TYPE = new ThingTypeUID(BINDING_ID, "webservice"); - public static final Set BRIDGE_THING_TYPES_UIDS = Collections.singleton(BRIDGE_THING_TYPE); - public static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_TANKSTELLE); + public static final Set BRIDGE_THING_TYPES_UIDS = Set.of(BRIDGE_THING_TYPE); + public static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_TANKSTELLE); // List of all Channel ids public static final String CHANNEL_DIESEL = "diesel"; diff --git a/bundles/org.openhab.binding.tankerkoenig/src/main/java/org/openhab/binding/tankerkoenig/internal/TankerkoenigHandlerFactory.java b/bundles/org.openhab.binding.tankerkoenig/src/main/java/org/openhab/binding/tankerkoenig/internal/TankerkoenigHandlerFactory.java index 21a11759495..0b686addbe7 100644 --- a/bundles/org.openhab.binding.tankerkoenig/src/main/java/org/openhab/binding/tankerkoenig/internal/TankerkoenigHandlerFactory.java +++ b/bundles/org.openhab.binding.tankerkoenig/src/main/java/org/openhab/binding/tankerkoenig/internal/TankerkoenigHandlerFactory.java @@ -53,8 +53,7 @@ public class TankerkoenigHandlerFactory extends BaseThingHandlerFactory { protected @Nullable ThingHandler createHandler(Thing thing) { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); if (thingTypeUID.equals(BRIDGE_THING_TYPE)) { - WebserviceHandler handler = new WebserviceHandler((Bridge) thing); - return handler; + return new WebserviceHandler((Bridge) thing); } else if (thingTypeUID.equals(THING_TYPE_TANKSTELLE)) { return new StationHandler(thing); } diff --git a/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/TapoDiscoveryService.java b/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/TapoDiscoveryService.java index d0284ad3123..5a2381423b2 100644 --- a/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/TapoDiscoveryService.java +++ b/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/TapoDiscoveryService.java @@ -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; } diff --git a/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/api/TapoCloudConnector.java b/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/api/TapoCloudConnector.java index 81cf005e911..468948e0740 100644 --- a/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/api/TapoCloudConnector.java +++ b/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/api/TapoCloudConnector.java @@ -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)); diff --git a/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/api/TapoDeviceHttpApi.java b/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/api/TapoDeviceHttpApi.java index 26ed25aebae..e1c06b3af79 100644 --- a/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/api/TapoDeviceHttpApi.java +++ b/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/api/TapoDeviceHttpApi.java @@ -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)); diff --git a/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/device/TapoBridgeHandler.java b/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/device/TapoBridgeHandler.java index a1582e18214..de19b13ce3a 100644 --- a/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/device/TapoBridgeHandler.java +++ b/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/device/TapoBridgeHandler.java @@ -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> getServices() { - return Collections.singleton(TapoDiscoveryService.class); + return Set.of(TapoDiscoveryService.class); } /** diff --git a/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/device/TapoDevice.java b/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/device/TapoDevice.java index d62bd192c0f..50d42e1d172 100644 --- a/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/device/TapoDevice.java +++ b/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/device/TapoDevice.java @@ -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; } diff --git a/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/device/TapoLightStrip.java b/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/device/TapoLightStrip.java index 29f1a9c59e0..f453cd87cb1 100644 --- a/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/device/TapoLightStrip.java +++ b/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/device/TapoLightStrip.java @@ -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: diff --git a/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/device/TapoSmartBulb.java b/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/device/TapoSmartBulb.java index d55c2c27d9e..fc76768ac30 100644 --- a/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/device/TapoSmartBulb.java +++ b/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/device/TapoSmartBulb.java @@ -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; diff --git a/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/device/TapoUniversalDevice.java b/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/device/TapoUniversalDevice.java index 083e73f45f5..20b80f78b47 100644 --- a/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/device/TapoUniversalDevice.java +++ b/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/device/TapoUniversalDevice.java @@ -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 + "#", ""); diff --git a/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/helpers/PayloadBuilder.java b/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/helpers/PayloadBuilder.java index 810347e2a7c..06ac60316a9 100644 --- a/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/helpers/PayloadBuilder.java +++ b/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/helpers/PayloadBuilder.java @@ -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()); } diff --git a/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/helpers/TapoUtils.java b/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/helpers/TapoUtils.java index 72db563011c..83cd3f86e1d 100644 --- a/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/helpers/TapoUtils.java +++ b/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/helpers/TapoUtils.java @@ -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); } /** diff --git a/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/structures/TapoLightEffect.java b/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/structures/TapoLightEffect.java index 65d0cfcb8f4..209b0576147 100644 --- a/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/structures/TapoLightEffect.java +++ b/bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/structures/TapoLightEffect.java @@ -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(); diff --git a/bundles/org.openhab.binding.tapocontrol/src/test/java/org/openhab/binding/tapocontrol/internal/TapoDiscoveryService.java b/bundles/org.openhab.binding.tapocontrol/src/test/java/org/openhab/binding/tapocontrol/internal/TapoDiscoveryService.java index 26f377033be..0f49a5e3dfc 100644 --- a/bundles/org.openhab.binding.tapocontrol/src/test/java/org/openhab/binding/tapocontrol/internal/TapoDiscoveryService.java +++ b/bundles/org.openhab.binding.tapocontrol/src/test/java/org/openhab/binding/tapocontrol/internal/TapoDiscoveryService.java @@ -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; } diff --git a/bundles/org.openhab.binding.tapocontrol/src/test/java/org/openhab/binding/tapocontrol/internal/device/TapoBridgeHandler.java b/bundles/org.openhab.binding.tapocontrol/src/test/java/org/openhab/binding/tapocontrol/internal/device/TapoBridgeHandler.java index 9357d4bbdbb..2654ce9cb86 100644 --- a/bundles/org.openhab.binding.tapocontrol/src/test/java/org/openhab/binding/tapocontrol/internal/device/TapoBridgeHandler.java +++ b/bundles/org.openhab.binding.tapocontrol/src/test/java/org/openhab/binding/tapocontrol/internal/device/TapoBridgeHandler.java @@ -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> getServices() { - return Collections.singleton(TapoDiscoveryService.class); + return Set.of(TapoDiscoveryService.class); } /** diff --git a/bundles/org.openhab.binding.tapocontrol/src/test/java/org/openhab/binding/tapocontrol/internal/device/TapoUniversalDevice.java b/bundles/org.openhab.binding.tapocontrol/src/test/java/org/openhab/binding/tapocontrol/internal/device/TapoUniversalDevice.java index 257466f5ec7..36bece8ac74 100644 --- a/bundles/org.openhab.binding.tapocontrol/src/test/java/org/openhab/binding/tapocontrol/internal/device/TapoUniversalDevice.java +++ b/bundles/org.openhab.binding.tapocontrol/src/test/java/org/openhab/binding/tapocontrol/internal/device/TapoUniversalDevice.java @@ -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 + "#", ""); diff --git a/bundles/org.openhab.binding.tapocontrol/src/test/java/org/openhab/binding/tapocontrol/internal/structures/TapoLightEffect.java b/bundles/org.openhab.binding.tapocontrol/src/test/java/org/openhab/binding/tapocontrol/internal/structures/TapoLightEffect.java index 0e4e9fe49f3..857eab04c28 100644 --- a/bundles/org.openhab.binding.tapocontrol/src/test/java/org/openhab/binding/tapocontrol/internal/structures/TapoLightEffect.java +++ b/bundles/org.openhab.binding.tapocontrol/src/test/java/org/openhab/binding/tapocontrol/internal/structures/TapoLightEffect.java @@ -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(); diff --git a/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/TelegramHandler.java b/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/TelegramHandler.java index 627363113dd..27fbb6d8561 100644 --- a/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/TelegramHandler.java +++ b/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/TelegramHandler.java @@ -22,12 +22,12 @@ import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -473,7 +473,7 @@ public class TelegramHandler extends BaseThingHandler { @Override public Collection> getServices() { - return Collections.singleton(TelegramActions.class); + return Set.of(TelegramActions.class); } /** diff --git a/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/TelegramHandlerFactory.java b/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/TelegramHandlerFactory.java index 709982b8857..96870348478 100644 --- a/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/TelegramHandlerFactory.java +++ b/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/TelegramHandlerFactory.java @@ -14,7 +14,6 @@ package org.openhab.binding.telegram.internal; import static org.openhab.binding.telegram.internal.TelegramBindingConstants.TELEGRAM_THING; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -40,7 +39,7 @@ import org.osgi.service.component.annotations.Reference; @Component(configurationPid = "binding.telegram", service = ThingHandlerFactory.class) public class TelegramHandlerFactory extends BaseThingHandlerFactory { - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(TELEGRAM_THING); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(TELEGRAM_THING); private final HttpClient httpClient; diff --git a/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/action/TelegramActions.java b/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/action/TelegramActions.java index 4f3dedc4e25..3b43d4a4e34 100644 --- a/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/action/TelegramActions.java +++ b/bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/action/TelegramActions.java @@ -672,11 +672,11 @@ public class TelegramActions implements ThingActions { public static boolean sendTelegramAnswer(ThingActions actions, @Nullable String chatId, @Nullable String replyId, @Nullable String message) { - if (actions instanceof TelegramActions) { + if (actions instanceof TelegramActions telegramActions) { if (chatId == null) { return false; } - return ((TelegramActions) actions).sendTelegramAnswer(Long.valueOf(chatId), replyId, message); + return telegramActions.sendTelegramAnswer(Long.valueOf(chatId), replyId, message); } else { throw new IllegalArgumentException("Actions is not an instance of TelegramActions"); } @@ -689,11 +689,11 @@ public class TelegramActions implements ThingActions { public static boolean sendTelegramAnswer(ThingActions actions, @Nullable String chatId, @Nullable String callbackId, @Nullable String messageId, @Nullable String message) { - if (actions instanceof TelegramActions) { + if (actions instanceof TelegramActions telegramActions) { if (chatId == null) { return false; } - return ((TelegramActions) actions).sendTelegramAnswer(Long.valueOf(chatId), callbackId, + return telegramActions.sendTelegramAnswer(Long.valueOf(chatId), callbackId, messageId != null ? Long.parseLong(messageId) : null, message); } else { throw new IllegalArgumentException("Actions is not an instance of TelegramActions"); diff --git a/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/TeleinfoDiscoveryService.java b/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/TeleinfoDiscoveryService.java index fdf05c0f047..ac8d1529b68 100644 --- a/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/TeleinfoDiscoveryService.java +++ b/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/TeleinfoDiscoveryService.java @@ -187,8 +187,8 @@ public class TeleinfoDiscoveryService extends AbstractDiscoveryService @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof TeleinfoAbstractControllerHandler) { - controllerHandler = (TeleinfoAbstractControllerHandler) handler; + if (handler instanceof TeleinfoAbstractControllerHandler teleinfoAbstractControllerHandler) { + controllerHandler = teleinfoAbstractControllerHandler; } } diff --git a/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/handler/TeleinfoAbstractControllerHandler.java b/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/handler/TeleinfoAbstractControllerHandler.java index f15d4e4d964..308e1235c8f 100644 --- a/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/handler/TeleinfoAbstractControllerHandler.java +++ b/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/handler/TeleinfoAbstractControllerHandler.java @@ -13,7 +13,6 @@ package org.openhab.binding.teleinfo.internal.handler; import java.util.Collection; -import java.util.Collections; import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; @@ -52,6 +51,6 @@ public abstract class TeleinfoAbstractControllerHandler extends BaseBridgeHandle @Override public Collection> getServices() { - return Collections.singleton(TeleinfoDiscoveryService.class); + return Set.of(TeleinfoDiscoveryService.class); } } diff --git a/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/TellstickHandlerFactory.java b/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/TellstickHandlerFactory.java index 302085dacb9..aa4ce7c1f8a 100644 --- a/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/TellstickHandlerFactory.java +++ b/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/TellstickHandlerFactory.java @@ -120,8 +120,8 @@ public class TellstickHandlerFactory extends BaseThingHandlerFactory { @Override protected void removeHandler(ThingHandler thingHandler) { - if (thingHandler instanceof TelldusBridgeHandler) { - unregisterDeviceDiscoveryService((TelldusBridgeHandler) thingHandler); + if (thingHandler instanceof TelldusBridgeHandler telldusBridgeHandler) { + unregisterDeviceDiscoveryService(telldusBridgeHandler); } } } diff --git a/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/core/TelldusCoreDeviceController.java b/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/core/TelldusCoreDeviceController.java index c7687c5bcc8..e04878168af 100644 --- a/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/core/TelldusCoreDeviceController.java +++ b/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/core/TelldusCoreDeviceController.java @@ -156,10 +156,10 @@ public class TelldusCoreDeviceController implements DeviceChangeListener, Sensor turnOn(device); } else if (command == OnOffType.OFF) { turnOff(device); - } else if (command instanceof PercentType) { - dim(device, (PercentType) command); - } else if (command instanceof IncreaseDecreaseType) { - increaseDecrease(device, ((IncreaseDecreaseType) command)); + } else if (command instanceof PercentType percentCommand) { + dim(device, percentCommand); + } else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) { + increaseDecrease(device, increaseDecreaseCommand); } } else if (device instanceof SwitchableDevice) { if (command == OnOffType.ON) { @@ -198,29 +198,29 @@ public class TelldusCoreDeviceController implements DeviceChangeListener, Sensor double value = command.doubleValue(); // 0 means OFF and 100 means ON - if (value == 0 && dev instanceof SwitchableDevice) { - ((SwitchableDevice) dev).off(); - } else if (value == 100 && dev instanceof SwitchableDevice) { - ((SwitchableDevice) dev).on(); - } else if (dev instanceof DimmableDevice) { + if (value == 0 && dev instanceof SwitchableDevice device) { + device.off(); + } else if (value == 100 && dev instanceof SwitchableDevice device) { + device.on(); + } else if (dev instanceof DimmableDevice device) { long tdVal = Math.round((value / 100) * 255); - ((DimmableDevice) dev).dim((int) tdVal); + device.dim((int) tdVal); } else { throw new TelldusBindingException("Cannot send DIM to " + dev); } } private void turnOff(Device dev) throws TellstickException { - if (dev instanceof SwitchableDevice) { - ((SwitchableDevice) dev).off(); + if (dev instanceof SwitchableDevice device) { + device.off(); } else { throw new TelldusBindingException("Cannot send OFF to " + dev); } } private void turnOn(Device dev) throws TellstickException { - if (dev instanceof SwitchableDevice) { - ((SwitchableDevice) dev).on(); + if (dev instanceof SwitchableDevice device) { + device.on(); } else { throw new TelldusBindingException("Cannot send ON to " + dev); } diff --git a/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/discovery/TellstickDiscoveryService.java b/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/discovery/TellstickDiscoveryService.java index 0f2216527c8..83ae3e257ac 100644 --- a/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/discovery/TellstickDiscoveryService.java +++ b/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/discovery/TellstickDiscoveryService.java @@ -135,16 +135,16 @@ public class TellstickDiscoveryService extends AbstractDiscoveryService implemen } else if (device instanceof SwitchableDevice) { thingUID = new ThingUID(TellstickBindingConstants.SWITCH_THING_TYPE, bridge.getUID(), device.getUUId()); - } else if (device instanceof TellstickNetDevice) { - if ((((TellstickNetDevice) device).getMethods() & JNA.CLibrary.TELLSTICK_DIM) > 0) { + } else if (device instanceof TellstickNetDevice netDevice) { + if ((netDevice.getMethods() & JNA.CLibrary.TELLSTICK_DIM) > 0) { thingUID = new ThingUID(TellstickBindingConstants.DIMMER_THING_TYPE, bridge.getUID(), device.getUUId()); } else { thingUID = new ThingUID(TellstickBindingConstants.SWITCH_THING_TYPE, bridge.getUID(), device.getUUId()); } - } else if (device instanceof TellstickLocalDeviceDTO) { - if ((((TellstickLocalDeviceDTO) device).getMethods() & JNA.CLibrary.TELLSTICK_DIM) > 0) { + } else if (device instanceof TellstickLocalDeviceDTO localDevice) { + if ((localDevice.getMethods() & JNA.CLibrary.TELLSTICK_DIM) > 0) { thingUID = new ThingUID(TellstickBindingConstants.DIMMER_THING_TYPE, bridge.getUID(), device.getUUId()); } else { @@ -162,8 +162,7 @@ public class TellstickDiscoveryService extends AbstractDiscoveryService implemen private ThingTypeUID findSensorType(Device device) { logger.debug("Device: {}", device); ThingTypeUID sensorThingId; - if (device instanceof TellstickSensor) { - TellstickSensor sensor = (TellstickSensor) device; + if (device instanceof TellstickSensor sensor) { logger.debug("Sensor: {}", device); if (sensor.getData(DataType.WINDAVERAGE) != null || sensor.getData(DataType.WINDGUST) != null || sensor.getData(DataType.WINDDIRECTION) != null) { @@ -173,8 +172,7 @@ public class TellstickDiscoveryService extends AbstractDiscoveryService implemen } else { sensorThingId = TellstickBindingConstants.SENSOR_THING_TYPE; } - } else if (device instanceof TellstickNetSensor) { - TellstickNetSensor sensor = (TellstickNetSensor) device; + } else if (device instanceof TellstickNetSensor sensor) { if (sensor.isSensorOfType(LiveDataType.WINDAVERAGE) || sensor.isSensorOfType(LiveDataType.WINDDIRECTION) || sensor.isSensorOfType(LiveDataType.WINDGUST)) { sensorThingId = TellstickBindingConstants.WINDSENSOR_THING_TYPE; diff --git a/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/handler/TelldusDevicesHandler.java b/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/handler/TelldusDevicesHandler.java index c3c2cdf9e2b..b1fef0d7c70 100644 --- a/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/handler/TelldusDevicesHandler.java +++ b/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/handler/TelldusDevicesHandler.java @@ -241,29 +241,29 @@ public class TelldusDevicesHandler extends BaseThingHandler implements DeviceSta } private boolean isSensor() { - return (getThing().getThingTypeUID().equals(TellstickBindingConstants.SENSOR_THING_TYPE) + return getThing().getThingTypeUID().equals(TellstickBindingConstants.SENSOR_THING_TYPE) || getThing().getThingTypeUID().equals(TellstickBindingConstants.RAINSENSOR_THING_TYPE) || getThing().getThingTypeUID().equals(TellstickBindingConstants.WINDSENSOR_THING_TYPE) - || getThing().getThingTypeUID().equals(TellstickBindingConstants.POWERSENSOR_THING_TYPE)); + || getThing().getThingTypeUID().equals(TellstickBindingConstants.POWERSENSOR_THING_TYPE); } private void updateSensorStates(Device dev) { - if (dev instanceof TellstickSensor) { + if (dev instanceof TellstickSensor sensor) { updateStatus(ThingStatus.ONLINE); - for (DataType type : ((TellstickSensor) dev).getData().keySet()) { - updateSensorDataState(type, ((TellstickSensor) dev).getData(type)); + for (DataType type : sensor.getData().keySet()) { + updateSensorDataState(type, sensor.getData(type)); } - } else if (dev instanceof TellstickNetSensor) { - if (((TellstickNetSensor) dev).getOnline()) { + } else if (dev instanceof TellstickNetSensor netSensor) { + if (netSensor.getOnline()) { updateStatus(ThingStatus.ONLINE); } else { updateStatus(ThingStatus.OFFLINE); } - for (DataTypeValue type : ((TellstickNetSensor) dev).getData()) { + for (DataTypeValue type : netSensor.getData()) { updateSensorDataState(type); } - } else if (dev instanceof TellstickLocalSensorDTO) { - for (LocalDataTypeValueDTO type : ((TellstickLocalSensorDTO) dev).getData()) { + } else if (dev instanceof TellstickLocalSensorDTO localSensor) { + for (LocalDataTypeValueDTO type : localSensor.getData()) { updateSensorDataState(type); } } @@ -283,14 +283,11 @@ public class TelldusDevicesHandler extends BaseThingHandler implements DeviceSta if (device.getUUId().equals(deviceId)) { if (event instanceof TellstickDeviceEvent) { updateDeviceState(device); - } else if (event instanceof TellstickNetSensorEvent) { - TellstickNetSensorEvent sensorevent = (TellstickNetSensorEvent) event; + } else if (event instanceof TellstickNetSensorEvent sensorevent) { updateSensorDataState(sensorevent.getDataTypeValue()); - } else if (event instanceof TellstickLocalSensorEventDTO) { - TellstickLocalSensorEventDTO sensorevent = (TellstickLocalSensorEventDTO) event; + } else if (event instanceof TellstickLocalSensorEventDTO sensorevent) { updateSensorDataState(sensorevent.getDataTypeValue()); - } else if (event instanceof TellstickSensorEvent) { - TellstickSensorEvent sensorevent = (TellstickSensorEvent) event; + } else if (event instanceof TellstickSensorEvent sensorevent) { updateSensorDataState(sensorevent.getDataType(), sensorevent.getData()); } else { logger.debug("Unhandled Device {}.", device.getDeviceType()); @@ -356,7 +353,7 @@ public class TelldusDevicesHandler extends BaseThingHandler implements DeviceSta new QuantityType<>(new BigDecimal(dataType.getValue()), WIND_SPEED_UNIT_MS)); break; case WATT: - if (dataType.getUnit() != null && dataType.getUnit().equals("A")) { + if ("A".equals(dataType.getUnit())) { updateState(ampereChannel, new QuantityType<>(new BigDecimal(dataType.getValue()), ELECTRIC_UNIT)); } else { updateState(wattChannel, new QuantityType<>(new BigDecimal(dataType.getValue()), POWER_UNIT)); diff --git a/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/live/TelldusLiveDeviceController.java b/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/live/TelldusLiveDeviceController.java index 3d4b5b55c10..5952a305fc7 100644 --- a/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/live/TelldusLiveDeviceController.java +++ b/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/live/TelldusLiveDeviceController.java @@ -129,10 +129,10 @@ public class TelldusLiveDeviceController implements DeviceChangeListener, Sensor turnOn(device); } else if (command == OnOffType.OFF) { turnOff(device); - } else if (command instanceof PercentType) { - dim(device, (PercentType) command); - } else if (command instanceof IncreaseDecreaseType) { - increaseDecrease(device, ((IncreaseDecreaseType) command)); + } else if (command instanceof PercentType percentCommand) { + dim(device, percentCommand); + } else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) { + increaseDecrease(device, increaseDecreaseCommand); } } else if (device instanceof SwitchableDevice) { if (command == OnOffType.ON) { @@ -172,22 +172,21 @@ public class TelldusLiveDeviceController implements DeviceChangeListener, Sensor turnOff(dev); } else if (value == 100 && dev instanceof TellstickNetDevice) { turnOn(dev); - } else if (dev instanceof TellstickNetDevice - && (((TellstickNetDevice) dev).getMethods() & JNA.CLibrary.TELLSTICK_DIM) > 0) { + } else if (dev instanceof TellstickNetDevice device && (device.getMethods() & JNA.CLibrary.TELLSTICK_DIM) > 0) { long tdVal = Math.round((value / 100) * 255); TelldusLiveResponse response = callRestMethod(String.format(HTTP_TELLDUS_DEVICE_DIM, dev.getId(), tdVal), TelldusLiveResponse.class); - handleResponse((TellstickNetDevice) dev, response); + handleResponse(device, response); } else { throw new TelldusBindingException("Cannot send DIM to " + dev); } } private void turnOff(Device dev) throws TellstickException { - if (dev instanceof TellstickNetDevice) { + if (dev instanceof TellstickNetDevice device) { TelldusLiveResponse response = callRestMethod(String.format(HTTP_TELLDUS_DEVICE_TURNOFF, dev.getId()), TelldusLiveResponse.class); - handleResponse((TellstickNetDevice) dev, response); + handleResponse(device, response); } else { throw new TelldusBindingException("Cannot send OFF to " + dev); } @@ -197,21 +196,21 @@ public class TelldusLiveDeviceController implements DeviceChangeListener, Sensor if (response == null || (response.status == null && response.error == null)) { throw new TelldusBindingException("No response " + response); } else if (response.error != null) { - if (response.error.equals("The client for this device is currently offline")) { + if ("The client for this device is currently offline".equals(response.error)) { device.setOnline(false); device.setUpdated(true); } throw new TelldusBindingException("Error " + response.error); - } else if (!response.status.trim().equals("success")) { + } else if (!"success".equals(response.status.trim())) { throw new TelldusBindingException("Response " + response.status); } } private void turnOn(Device dev) throws TellstickException { - if (dev instanceof TellstickNetDevice) { + if (dev instanceof TellstickNetDevice device) { TelldusLiveResponse response = callRestMethod(String.format(HTTP_TELLDUS_DEVICE_TURNON, dev.getId()), TelldusLiveResponse.class); - handleResponse((TellstickNetDevice) dev, response); + handleResponse(device, response); } else { throw new TelldusBindingException("Cannot send ON to " + dev); } diff --git a/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/local/TelldusLocalDeviceController.java b/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/local/TelldusLocalDeviceController.java index 12dbe685b64..2da7a014620 100644 --- a/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/local/TelldusLocalDeviceController.java +++ b/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/local/TelldusLocalDeviceController.java @@ -90,10 +90,10 @@ public class TelldusLocalDeviceController implements DeviceChangeListener, Senso turnOn(device); } else if (command == OnOffType.OFF) { turnOff(device); - } else if (command instanceof PercentType) { - dim(device, (PercentType) command); - } else if (command instanceof IncreaseDecreaseType) { - increaseDecrease(device, ((IncreaseDecreaseType) command)); + } else if (command instanceof PercentType percentCommand) { + dim(device, percentCommand); + } else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) { + increaseDecrease(device, increaseDecreaseCommand); } } else if (device instanceof SwitchableDevice) { if (command == OnOffType.ON) { @@ -137,22 +137,22 @@ public class TelldusLocalDeviceController implements DeviceChangeListener, Senso turnOff(dev); } else if (value == 100 && dev instanceof TellstickLocalDeviceDTO) { turnOn(dev); - } else if (dev instanceof TellstickLocalDeviceDTO - && (((TellstickLocalDeviceDTO) dev).getMethods() & JNA.CLibrary.TELLSTICK_DIM) > 0) { + } else if (dev instanceof TellstickLocalDeviceDTO device + && (device.getMethods() & JNA.CLibrary.TELLSTICK_DIM) > 0) { long tdVal = Math.round((value / 100) * 255); TelldusLocalResponseDTO response = callRestMethod( String.format(HTTP_LOCAL_API_DEVICE_DIM, dev.getId(), tdVal), TelldusLocalResponseDTO.class); - handleResponse((TellstickLocalDeviceDTO) dev, response); + handleResponse(device, response); } else { throw new TelldusBindingException("Cannot send DIM to " + dev); } } private void turnOff(Device dev) throws TellstickException, InterruptedException { - if (dev instanceof TellstickLocalDeviceDTO) { + if (dev instanceof TellstickLocalDeviceDTO device) { TelldusLocalResponseDTO response = callRestMethod(String.format(HTTP_LOCAL_API_DEVICE_TURNOFF, dev.getId()), TelldusLocalResponseDTO.class); - handleResponse((TellstickLocalDeviceDTO) dev, response); + handleResponse(device, response); } else { throw new TelldusBindingException("Cannot send OFF to " + dev); } @@ -165,16 +165,16 @@ public class TelldusLocalDeviceController implements DeviceChangeListener, Senso } else if (response.getError() != null) { device.setUpdated(true); throw new TelldusBindingException("Error " + response.getError()); - } else if (!response.getStatus().trim().equals("success")) { + } else if (!"success".equals(response.getStatus().trim())) { throw new TelldusBindingException("Response " + response.getStatus()); } } private void turnOn(Device dev) throws TellstickException, InterruptedException { - if (dev instanceof TellstickLocalDeviceDTO) { + if (dev instanceof TellstickLocalDeviceDTO device) { TelldusLocalResponseDTO response = callRestMethod(String.format(HTTP_LOCAL_DEVICE_TURNON, dev.getId()), TelldusLocalResponseDTO.class); - handleResponse((TellstickLocalDeviceDTO) dev, response); + handleResponse(device, response); } else { throw new TelldusBindingException("Cannot send ON to " + dev); } diff --git a/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/TeslaChannelSelectorProxy.java b/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/TeslaChannelSelectorProxy.java index 58836d35c4f..40d5a990ba8 100644 --- a/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/TeslaChannelSelectorProxy.java +++ b/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/TeslaChannelSelectorProxy.java @@ -964,7 +964,7 @@ public class TeslaChannelSelectorProxy { VEHICLE_NAME("vehicle_name", "name", StringType.class, true) { @Override public State getState(String s, TeslaChannelSelectorProxy proxy, Map properties) { - return super.getState(s.replaceAll("\"", "")); + return super.getState(s.replace("\"", "")); } }, VALET_MODE("valet_mode", "valetmode", OnOffType.class, false) { diff --git a/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/handler/TeslaAccountHandler.java b/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/handler/TeslaAccountHandler.java index 993ebf7eea9..62dbc82830a 100644 --- a/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/handler/TeslaAccountHandler.java +++ b/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/handler/TeslaAccountHandler.java @@ -18,7 +18,6 @@ import java.time.Instant; import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.Collection; -import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -472,6 +471,6 @@ public class TeslaAccountHandler extends BaseBridgeHandler { @Override public Collection> getServices() { - return Collections.singletonList(TeslaVehicleDiscoveryService.class); + return List.of(TeslaVehicleDiscoveryService.class); } } diff --git a/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/handler/TeslaVehicleHandler.java b/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/handler/TeslaVehicleHandler.java index 04bc9341e31..826316f5e6e 100644 --- a/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/handler/TeslaVehicleHandler.java +++ b/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/handler/TeslaVehicleHandler.java @@ -256,8 +256,8 @@ public class TeslaVehicleHandler extends BaseThingHandler { try { switch (selector) { case CHARGE_LIMIT_SOC: { - if (command instanceof PercentType) { - setChargeLimit(((PercentType) command).intValue()); + if (command instanceof PercentType percentCommand) { + setChargeLimit(percentCommand.intValue()); } else if (command instanceof OnOffType && command == OnOffType.ON) { setChargeLimit(100); } else if (command instanceof OnOffType && command == OnOffType.OFF) { @@ -273,11 +273,11 @@ public class TeslaVehicleHandler extends BaseThingHandler { } case CHARGE_AMPS: Integer amps = null; - if (command instanceof DecimalType) { - amps = ((DecimalType) command).intValue(); + if (command instanceof DecimalType decimalCommand) { + amps = decimalCommand.intValue(); } - if (command instanceof QuantityType) { - QuantityType qamps = ((QuantityType) command).toUnit(Units.AMPERE); + if (command instanceof QuantityType quantityCommand) { + QuantityType qamps = quantityCommand.toUnit(Units.AMPERE); if (qamps != null) { amps = qamps.intValue(); } @@ -324,8 +324,8 @@ public class TeslaVehicleHandler extends BaseThingHandler { break; } case CHARGE_TO_MAX: { - if (command instanceof OnOffType) { - if (((OnOffType) command) == OnOffType.ON) { + if (command instanceof OnOffType onOffCommand) { + if (onOffCommand == OnOffType.ON) { setMaxRangeCharging(true); } else { setMaxRangeCharging(false); @@ -334,8 +334,8 @@ public class TeslaVehicleHandler extends BaseThingHandler { break; } case CHARGE: { - if (command instanceof OnOffType) { - if (((OnOffType) command) == OnOffType.ON) { + if (command instanceof OnOffType onOffCommand) { + if (onOffCommand == OnOffType.ON) { charge(true); } else { charge(false); @@ -344,32 +344,32 @@ public class TeslaVehicleHandler extends BaseThingHandler { break; } case FLASH: { - if (command instanceof OnOffType) { - if (((OnOffType) command) == OnOffType.ON) { + if (command instanceof OnOffType onOffCommand) { + if (onOffCommand == OnOffType.ON) { flashLights(); } } break; } case HONK_HORN: { - if (command instanceof OnOffType) { - if (((OnOffType) command) == OnOffType.ON) { + if (command instanceof OnOffType onOffCommand) { + if (onOffCommand == OnOffType.ON) { honkHorn(); } } break; } case CHARGEPORT: { - if (command instanceof OnOffType) { - if (((OnOffType) command) == OnOffType.ON) { + if (command instanceof OnOffType onOffCommand) { + if (onOffCommand == OnOffType.ON) { openChargePort(); } } break; } case DOOR_LOCK: { - if (command instanceof OnOffType) { - if (((OnOffType) command) == OnOffType.ON) { + if (command instanceof OnOffType onOffCommand) { + if (onOffCommand == OnOffType.ON) { lockDoors(true); } else { lockDoors(false); @@ -378,8 +378,8 @@ public class TeslaVehicleHandler extends BaseThingHandler { break; } case AUTO_COND: { - if (command instanceof OnOffType) { - if (((OnOffType) command) == OnOffType.ON) { + if (command instanceof OnOffType onOffCommand) { + if (onOffCommand == OnOffType.ON) { autoConditioning(true); } else { autoConditioning(false); @@ -388,24 +388,24 @@ public class TeslaVehicleHandler extends BaseThingHandler { break; } case WAKEUP: { - if (command instanceof OnOffType) { - if (((OnOffType) command) == OnOffType.ON) { + if (command instanceof OnOffType onOffCommand) { + if (onOffCommand == OnOffType.ON) { wakeUp(); } } break; } case FT: { - if (command instanceof OnOffType) { - if (((OnOffType) command) == OnOffType.ON) { + if (command instanceof OnOffType onOffCommand) { + if (onOffCommand == OnOffType.ON) { openFrunk(); } } break; } case RT: { - if (command instanceof OnOffType) { - if (((OnOffType) command) == OnOffType.ON) { + if (command instanceof OnOffType onOffCommand) { + if (onOffCommand == OnOffType.ON) { if (vehicleState.rt == 0) { openTrunk(); } @@ -416,9 +416,9 @@ public class TeslaVehicleHandler extends BaseThingHandler { break; } case VALET_MODE: { - if (command instanceof OnOffType) { + if (command instanceof OnOffType onOffCommand) { int valetpin = ((BigDecimal) getConfig().get(VALETPIN)).intValue(); - if (((OnOffType) command) == OnOffType.ON) { + if (onOffCommand == OnOffType.ON) { setValetMode(true, valetpin); } else { setValetMode(false, valetpin); @@ -427,16 +427,16 @@ public class TeslaVehicleHandler extends BaseThingHandler { break; } case RESET_VALET_PIN: { - if (command instanceof OnOffType) { - if (((OnOffType) command) == OnOffType.ON) { + if (command instanceof OnOffType onOffCommand) { + if (onOffCommand == OnOffType.ON) { resetValetPin(); } } break; } case STEERINGWHEEL_HEATER: { - if (command instanceof OnOffType) { - boolean commandBooleanValue = ((OnOffType) command) == OnOffType.ON ? true : false; + if (command instanceof OnOffType onOffCommand) { + boolean commandBooleanValue = onOffCommand == OnOffType.ON ? true : false; setSteeringWheelHeater(commandBooleanValue); } break; @@ -1025,7 +1025,7 @@ public class TeslaVehicleHandler extends BaseThingHandler { case "data:update": logger.debug("Event : Received an update: '{}'", event.value); - String vals[] = event.value.split(","); + String[] vals = event.value.split(","); long currentTimeStamp = Long.parseLong(vals[0]); long systemTimeStamp = System.currentTimeMillis(); if (logger.isDebugEnabled()) { diff --git a/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/protocol/Vehicle.java b/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/protocol/Vehicle.java index 68ec816fe8e..7cb93eb8e0e 100644 --- a/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/protocol/Vehicle.java +++ b/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/protocol/Vehicle.java @@ -26,7 +26,7 @@ public class Vehicle { public String option_codes; public String vehicle_id; public String vin; - public String tokens[]; + public String[] tokens; public String state; public boolean remote_start_enabled; public boolean calendar_enabled; diff --git a/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/protocol/VehicleData.java b/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/protocol/VehicleData.java index 2295434cb00..57195bdfaed 100644 --- a/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/protocol/VehicleData.java +++ b/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/protocol/VehicleData.java @@ -26,7 +26,7 @@ public class VehicleData { public String option_codes; public String vehicle_id; public String vin; - public String tokens[]; + public String[] tokens; public String state; public boolean remote_start_enabled; public boolean calendar_enabled; diff --git a/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/TiVoHandlerFactory.java b/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/TiVoHandlerFactory.java index 87b9915409e..8e70d4f0bbf 100644 --- a/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/TiVoHandlerFactory.java +++ b/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/TiVoHandlerFactory.java @@ -14,7 +14,6 @@ package org.openhab.binding.tivo.internal; import static org.openhab.binding.tivo.internal.TiVoBindingConstants.THING_TYPE_TIVO; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -39,7 +38,7 @@ import org.osgi.service.component.annotations.Component; @NonNullByDefault @Component(configurationPid = "binding.tivo", service = ThingHandlerFactory.class) public class TiVoHandlerFactory extends BaseThingHandlerFactory { - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_TIVO); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_TIVO); @Override public boolean supportsThingType(ThingTypeUID thingTypeUID) { diff --git a/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/discovery/TiVoDiscoveryParticipant.java b/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/discovery/TiVoDiscoveryParticipant.java index 2bee2f756e1..9fdf28ce02d 100644 --- a/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/discovery/TiVoDiscoveryParticipant.java +++ b/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/discovery/TiVoDiscoveryParticipant.java @@ -15,7 +15,6 @@ package org.openhab.binding.tivo.internal.discovery; import static org.openhab.binding.tivo.internal.TiVoBindingConstants.*; import java.net.InetAddress; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -48,7 +47,7 @@ public class TiVoDiscoveryParticipant implements MDNSDiscoveryParticipant { @Override public Set getSupportedThingTypeUIDs() { - return Collections.singleton(THING_TYPE_TIVO); + return Set.of(THING_TYPE_TIVO); } @Override diff --git a/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/handler/TiVoHandler.java b/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/handler/TiVoHandler.java index 0f29e59a9fb..5abfb938fc0 100644 --- a/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/handler/TiVoHandler.java +++ b/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/handler/TiVoHandler.java @@ -73,7 +73,7 @@ public class TiVoHandler extends BaseThingHandler { // Handles the commands from the various TiVo channel objects logger.debug("handleCommand '{}', parameter: {}", channelUID, command); - if (!isInitialized() || !tivoConnection.isPresent()) { + if (!isInitialized() || tivoConnection.isEmpty()) { logger.debug("handleCommand '{}' device is not initialized yet, command '{}' will be ignored.", getThing().getUID(), channelUID + " " + command); return; @@ -122,7 +122,7 @@ public class TiVoHandler extends BaseThingHandler { private void sendCommand(String commandKeyword, String commandParameter, TivoStatusData currentStatus) throws InterruptedException { - if (!tivoConnection.isPresent()) { + if (tivoConnection.isEmpty()) { return; } @@ -299,8 +299,7 @@ public class TiVoHandler extends BaseThingHandler { } } catch (NumberFormatException e) { - logger.warn("TiVo'{}' unable to parse channel integer, value sent was: '{}'", getThing().getUID(), - command.toString()); + logger.warn("TiVo'{}' unable to parse channel integer, value sent was: '{}'", getThing().getUID(), command); } return tmpStatus; } diff --git a/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/service/TivoStatusData.java b/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/service/TivoStatusData.java index 6ec8f5fa005..ea38df75a1c 100644 --- a/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/service/TivoStatusData.java +++ b/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/service/TivoStatusData.java @@ -78,7 +78,7 @@ public class TivoStatusData { UNKNOWN, OFFLINE, STANDBY, - ONLINE; + ONLINE } /** diff --git a/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/service/TivoStatusProvider.java b/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/service/TivoStatusProvider.java index 6362fc3ff54..51581a9c8f9 100644 --- a/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/service/TivoStatusProvider.java +++ b/bundles/org.openhab.binding.tivo/src/main/java/org/openhab/binding/tivo/internal/service/TivoStatusProvider.java @@ -124,7 +124,7 @@ public class TivoStatusProvider { } for (int i = 1; i <= repeatCount; i++) { // Send the command - streamWriter.println(tivoCommand.toString() + "\r"); + streamWriter.println(tivoCommand + "\r"); if (streamWriter.checkError()) { logger.debug("TiVo '{}' - called cmdTivoSend and encountered an IO error", tivoConfigData.getCfgIdentifier()); diff --git a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandAlarmSensorHandler.java b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandAlarmSensorHandler.java index c2cb4554501..1fcef007d56 100644 --- a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandAlarmSensorHandler.java +++ b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandAlarmSensorHandler.java @@ -57,8 +57,7 @@ public class TouchWandAlarmSensorHandler extends TouchWandBaseUnitHandler { @Override void updateTouchWandUnitState(TouchWandUnitData unitData) { - if (unitData instanceof TouchWandUnitDataAlarmSensor) { - TouchWandUnitDataAlarmSensor sensor = (TouchWandUnitDataAlarmSensor) unitData; + if (unitData instanceof TouchWandUnitDataAlarmSensor sensor) { if (isFirstUpdateTouchWandUnitState) { removeUnsupportedChannels(sensor); isFirstUpdateTouchWandUnitState = false; diff --git a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandBSensorHandler.java b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandBSensorHandler.java index 12721517844..4094d637b69 100644 --- a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandBSensorHandler.java +++ b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandBSensorHandler.java @@ -42,21 +42,21 @@ public class TouchWandBSensorHandler extends TouchWandBaseUnitHandler { @Override void updateTouchWandUnitState(TouchWandUnitData unitData) { - if (unitData instanceof TouchWandBSensorUnitData) { + if (unitData instanceof TouchWandBSensorUnitData bSensorUnitData) { if (isFirstUpdateTouchWandUnitState) { - removeUnsupportedChannels((TouchWandBSensorUnitData) unitData); + removeUnsupportedChannels(bSensorUnitData); isFirstUpdateTouchWandUnitState = false; } - String sensorSubType = ((TouchWandBSensorUnitData) unitData).getIdData().getSubType(); + String sensorSubType = bSensorUnitData.getIdData().getSubType(); switch (sensorSubType) { case BSENSOR_SUBTYPE_DOORWINDOW: - updateChannelDoorWindow((TouchWandBSensorUnitData) unitData); + updateChannelDoorWindow(bSensorUnitData); break; case BSENSOR_SUBTYPE_MOTION: - updateChannelMotion((TouchWandBSensorUnitData) unitData); + updateChannelMotion(bSensorUnitData); break; case BSENSOR_SUBTYPE_SMOKE: - updateChannelSmoke((TouchWandBSensorUnitData) unitData); + updateChannelSmoke(bSensorUnitData); break; default: } diff --git a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandBaseUnitHandler.java b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandBaseUnitHandler.java index ba009faefa8..edcef223ecc 100644 --- a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandBaseUnitHandler.java +++ b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandBaseUnitHandler.java @@ -137,7 +137,7 @@ public abstract class TouchWandBaseUnitHandler extends BaseThingHandler implemen @Override public void onItemStatusUpdate(TouchWandUnitData unitData) { - if (unitData.getStatus().equals("ALIVE")) { + if ("ALIVE".equals(unitData.getStatus())) { updateStatus(ThingStatus.ONLINE); } else { // updateStatus(ThingStatus.OFFLINE); // comment - OFFLINE status is not accurate at the moment diff --git a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandBridgeHandler.java b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandBridgeHandler.java index b84b3c12db2..17f068b2602 100644 --- a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandBridgeHandler.java +++ b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandBridgeHandler.java @@ -15,7 +15,6 @@ package org.openhab.binding.touchwand.internal; import static org.openhab.binding.touchwand.internal.TouchWandBindingConstants.THING_TYPE_BRIDGE; import java.util.Collection; -import java.util.Collections; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -45,7 +44,7 @@ import org.slf4j.LoggerFactory; */ @NonNullByDefault public class TouchWandBridgeHandler extends BaseBridgeHandler implements TouchWandUnitStatusUpdateListener { - public static final Set SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_BRIDGE); + public static final Set SUPPORTED_THING_TYPES = Set.of(THING_TYPE_BRIDGE); private final Logger logger = LoggerFactory.getLogger(TouchWandBridgeHandler.class); private boolean addSecondaryUnits; private @Nullable TouchWandWebSockets touchWandWebSockets; @@ -138,6 +137,6 @@ public class TouchWandBridgeHandler extends BaseBridgeHandler implements TouchWa @Override public Collection> getServices() { - return Collections.singleton(TouchWandUnitDiscoveryService.class); + return Set.of(TouchWandUnitDiscoveryService.class); } } diff --git a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandDimmerHandler.java b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandDimmerHandler.java index 3ab7173a4cb..377b8d6423b 100644 --- a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandDimmerHandler.java +++ b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandDimmerHandler.java @@ -39,8 +39,8 @@ public class TouchWandDimmerHandler extends TouchWandBaseUnitHandler { void touchWandUnitHandleCommand(Command command) { TouchWandBridgeHandler touchWandBridgeHandler = bridgeHandler; if (touchWandBridgeHandler != null) { - if (command instanceof OnOffType) { - touchWandBridgeHandler.touchWandClient.cmdSwitchOnOff(unitId, (OnOffType) command); + if (command instanceof OnOffType onOffCommand) { + touchWandBridgeHandler.touchWandClient.cmdSwitchOnOff(unitId, onOffCommand); } else { touchWandBridgeHandler.touchWandClient.cmdDimmerPosition(unitId, command.toString()); } @@ -49,8 +49,8 @@ public class TouchWandDimmerHandler extends TouchWandBaseUnitHandler { @Override void updateTouchWandUnitState(TouchWandUnitData unitData) { - if (unitData instanceof TouchWandShutterSwitchUnitData) { - int status = ((TouchWandShutterSwitchUnitData) unitData).getCurrStatus(); + if (unitData instanceof TouchWandShutterSwitchUnitData shutterSwitchUnitData) { + int status = shutterSwitchUnitData.getCurrStatus(); PercentType state = PercentType.ZERO; int convertStatus = status; state = new PercentType(convertStatus); diff --git a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandRestClient.java b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandRestClient.java index adc776a5bd7..cfeaddbe603 100644 --- a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandRestClient.java +++ b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandRestClient.java @@ -203,8 +203,7 @@ public class TouchWandRestClient { } private String buildUrl(String command) { - String url = "http://" + touchWandIpAddr + ":" + touchWandPort + COMMAND_MAP.get(command); - return url; + return "http://" + touchWandIpAddr + ":" + touchWandPort + COMMAND_MAP.get(command); } private synchronized String sendCommand(String command, HttpMethod method, String content) { diff --git a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandShutterHandler.java b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandShutterHandler.java index 6bfdb144b62..1bc0ecc8646 100644 --- a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandShutterHandler.java +++ b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandShutterHandler.java @@ -59,8 +59,8 @@ public class TouchWandShutterHandler extends TouchWandBaseUnitHandler { @Override void updateTouchWandUnitState(TouchWandUnitData unitData) { - if (unitData instanceof TouchWandShutterSwitchUnitData) { - int status = ((TouchWandShutterSwitchUnitData) unitData).getCurrStatus(); + if (unitData instanceof TouchWandShutterSwitchUnitData shutterSwitchUnitData) { + int status = shutterSwitchUnitData.getCurrStatus(); PercentType state = PercentType.ZERO; int convertStatus = 100 - status; state = new PercentType(convertStatus); diff --git a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandSwitchHandler.java b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandSwitchHandler.java index 5244e09b2b5..311a10cd880 100644 --- a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandSwitchHandler.java +++ b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandSwitchHandler.java @@ -37,9 +37,9 @@ public class TouchWandSwitchHandler extends TouchWandBaseUnitHandler { @Override void updateTouchWandUnitState(TouchWandUnitData unitData) { - if (unitData instanceof TouchWandShutterSwitchUnitData) { + if (unitData instanceof TouchWandShutterSwitchUnitData shutterSwitchUnitData) { OnOffType state; - int status = ((TouchWandShutterSwitchUnitData) unitData).getCurrStatus(); + int status = shutterSwitchUnitData.getCurrStatus(); String sStatus = Integer.toString(status); if (sStatus.equals(SWITCH_STATUS_OFF)) { @@ -58,10 +58,10 @@ public class TouchWandSwitchHandler extends TouchWandBaseUnitHandler { @Override void touchWandUnitHandleCommand(Command command) { - if (command instanceof OnOffType) { + if (command instanceof OnOffType onOffCommand) { TouchWandBridgeHandler touchWandBridgeHandler = bridgeHandler; if (touchWandBridgeHandler != null) { - touchWandBridgeHandler.touchWandClient.cmdSwitchOnOff(unitId, (OnOffType) command); + touchWandBridgeHandler.touchWandClient.cmdSwitchOnOff(unitId, onOffCommand); } } } diff --git a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandThermostatHandler.java b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandThermostatHandler.java index 45ccd1b34b5..82cc78b7db4 100644 --- a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandThermostatHandler.java +++ b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandThermostatHandler.java @@ -40,8 +40,7 @@ public class TouchWandThermostatHandler extends TouchWandBaseUnitHandler { @Override void updateTouchWandUnitState(TouchWandUnitData unitData) { - if (unitData instanceof TouchWandThermostatUnitData) { - TouchWandThermostatUnitData thermostat = (TouchWandThermostatUnitData) unitData; + if (unitData instanceof TouchWandThermostatUnitData thermostat) { updateThermostatState(thermostat); updateTargetTemperature(thermostat); updateRoomTemperature(thermostat); @@ -56,12 +55,12 @@ public class TouchWandThermostatHandler extends TouchWandBaseUnitHandler { void touchWandUnitHandleCommand(Command command) { TouchWandBridgeHandler touchWandBridgeHandler = bridgeHandler; if (touchWandBridgeHandler != null) { - if (command instanceof OnOffType) { - touchWandBridgeHandler.touchWandClient.cmdThermostatOnOff(unitId, (OnOffType) command); + if (command instanceof OnOffType onOffCommand) { + touchWandBridgeHandler.touchWandClient.cmdThermostatOnOff(unitId, onOffCommand); return; } - if (command instanceof QuantityType) { - final QuantityType value = ((QuantityType) command).toUnit(SIUnits.CELSIUS); + if (command instanceof QuantityType quantityCommand) { + final QuantityType value = quantityCommand.toUnit(SIUnits.CELSIUS); String targetTemperature = String.valueOf(value.intValue()); touchWandBridgeHandler.touchWandClient.cmdThermostatTargetTemperature(unitId, targetTemperature); return; diff --git a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandWallControllerHandler.java b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandWallControllerHandler.java index 83c9066be5e..54c0e66349d 100644 --- a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandWallControllerHandler.java +++ b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandWallControllerHandler.java @@ -48,8 +48,8 @@ public class TouchWandWallControllerHandler extends TouchWandBaseUnitHandler { @Override void updateTouchWandUnitState(TouchWandUnitData unitData) { - if (unitData instanceof TouchWandUnitDataWallController) { - Csc status = ((TouchWandUnitDataWallController) unitData).getCurrStatus(); + if (unitData instanceof TouchWandUnitDataWallController unitDataWallController) { + Csc status = unitDataWallController.getCurrStatus(); long ts = status.getTs(); long timeDiff = ts - timeLastEventMs; if ((timeDiff) > ADJACENT_EVENT_FILTER_TIME_MILLISEC) { diff --git a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandWebSockets.java b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandWebSockets.java index 57e8ff3befd..9d2c99ba36c 100644 --- a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandWebSockets.java +++ b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/TouchWandWebSockets.java @@ -79,7 +79,7 @@ public class TouchWandWebSockets { public void connect() { try { - uri = new URI("ws://" + controllerAddress + ":" + String.valueOf(port) + WS_ENDPOINT_TOUCHWAND); + uri = new URI("ws://" + controllerAddress + ":" + port + WS_ENDPOINT_TOUCHWAND); } catch (URISyntaxException e) { logger.warn("URI not valid {} message {}", uri, e.getMessage()); return; @@ -152,12 +152,12 @@ public class TouchWandWebSockets { TouchWandUnitData touchWandUnit; try { JsonObject unitObj = JsonParser.parseString(msg).getAsJsonObject(); - boolean eventUnitChanged = unitObj.get("type").getAsString().equals("UNIT_CHANGED"); + boolean eventUnitChanged = "UNIT_CHANGED".equals(unitObj.get("type").getAsString()); if (!eventUnitChanged) { return; } touchWandUnit = TouchWandUnitFromJson.parseResponse(unitObj.get("unit").getAsJsonObject()); - if (!touchWandUnit.getStatus().equals("ALIVE")) { + if (!"ALIVE".equals(touchWandUnit.getStatus())) { logger.debug("UNIT_CHANGED unit status not ALIVE : {}", touchWandUnit.getStatus()); } boolean supportedUnitType = Arrays.asList(SUPPORTED_TOUCHWAND_TYPES).contains(touchWandUnit.getType()); diff --git a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/discovery/TouchWandControllerDiscoveryService.java b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/discovery/TouchWandControllerDiscoveryService.java index d603724d43e..048ba30ef3b 100644 --- a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/discovery/TouchWandControllerDiscoveryService.java +++ b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/discovery/TouchWandControllerDiscoveryService.java @@ -91,7 +91,7 @@ public class TouchWandControllerDiscoveryService extends AbstractDiscoveryServic } private void addDeviceDiscoveryResult(String label, String ip) { - String id = ip.replaceAll("\\.", ""); + String id = ip.replace(".", ""); ThingUID thingUID = new ThingUID(THING_TYPE_BRIDGE, id); Map properties = new HashMap<>(); properties.put("label", label); @@ -138,7 +138,7 @@ public class TouchWandControllerDiscoveryService extends AbstractDiscoveryServic String sentence = new String(dgram.getData(), 0, dgram.getLength(), StandardCharsets.US_ASCII); JsonObject bridge = JsonParser.parseString(sentence).getAsJsonObject();// String name = bridge.get("name").getAsString(); - addDeviceDiscoveryResult(name, address.getHostAddress().toString()); + addDeviceDiscoveryResult(name, address.getHostAddress()); logger.debug("Received Datagram from {}:{} on Port {} message {}", address.getHostAddress(), dgram.getPort(), mySocket.getLocalPort(), sentence); } diff --git a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/discovery/TouchWandUnitDiscoveryService.java b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/discovery/TouchWandUnitDiscoveryService.java index ea1588d22a8..e9d826a8f41 100644 --- a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/discovery/TouchWandUnitDiscoveryService.java +++ b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/discovery/TouchWandUnitDiscoveryService.java @@ -191,8 +191,8 @@ public class TouchWandUnitDiscoveryService extends AbstractDiscoveryService impl @Override public void setThingHandler(@NonNullByDefault({}) ThingHandler handler) { - if (handler instanceof TouchWandBridgeHandler) { - touchWandBridgeHandler = (TouchWandBridgeHandler) handler; + if (handler instanceof TouchWandBridgeHandler touchWandBridgeHandler) { + this.touchWandBridgeHandler = touchWandBridgeHandler; } } diff --git a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/dto/AlarmSensorUnitDataDeserializer.java b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/dto/AlarmSensorUnitDataDeserializer.java index 995030b1871..f9d7c757ef1 100644 --- a/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/dto/AlarmSensorUnitDataDeserializer.java +++ b/bundles/org.openhab.binding.touchwand/src/main/java/org/openhab/binding/touchwand/internal/dto/AlarmSensorUnitDataDeserializer.java @@ -69,7 +69,7 @@ public class AlarmSensorUnitDataDeserializer implements JsonDeserializer entry : currentStatusObj.entrySet()) { String key = entry.getKey(); - String splits[] = key.split("_"); // the key is xxxx_n where xxx is sensor type and n is + String[] splits = key.split("_"); // the key is xxxx_n where xxx is sensor type and n is String keyName = splits[0]; int index = 0; diff --git a/bundles/org.openhab.binding.tplinksmarthome/src/main/java/org/openhab/binding/tplinksmarthome/internal/device/BulbDevice.java b/bundles/org.openhab.binding.tplinksmarthome/src/main/java/org/openhab/binding/tplinksmarthome/internal/device/BulbDevice.java index 392d25700ba..8baeada1d12 100644 --- a/bundles/org.openhab.binding.tplinksmarthome/src/main/java/org/openhab/binding/tplinksmarthome/internal/device/BulbDevice.java +++ b/bundles/org.openhab.binding.tplinksmarthome/src/main/java/org/openhab/binding/tplinksmarthome/internal/device/BulbDevice.java @@ -70,12 +70,12 @@ public class BulbDevice extends SmartHomeDevice { final int transitionPeriod = configuration.transitionPeriod; final HasErrorResponse response; - if (command instanceof OnOffType && CHANNELS_BULB_SWITCH.contains(channelId)) { - response = handleOnOffType(channelId, (OnOffType) command, transitionPeriod); - } else if (command instanceof HSBType && CHANNEL_COLOR.equals(channelId)) { - response = handleHSBType(channelId, (HSBType) command, transitionPeriod); - } else if (command instanceof DecimalType) { - response = handleDecimalType(channelId, (DecimalType) command, transitionPeriod); + if (command instanceof OnOffType onOffCommand && CHANNELS_BULB_SWITCH.contains(channelId)) { + response = handleOnOffType(channelId, onOffCommand, transitionPeriod); + } else if (command instanceof HSBType hsbCommand && CHANNEL_COLOR.equals(channelId)) { + response = handleHSBType(channelId, hsbCommand, transitionPeriod); + } else if (command instanceof DecimalType decimalCommand) { + response = handleDecimalType(channelId, decimalCommand, transitionPeriod); } else { return false; } diff --git a/bundles/org.openhab.binding.tplinksmarthome/src/main/java/org/openhab/binding/tplinksmarthome/internal/device/DimmerDevice.java b/bundles/org.openhab.binding.tplinksmarthome/src/main/java/org/openhab/binding/tplinksmarthome/internal/device/DimmerDevice.java index e91395db5e4..9c17ff20229 100644 --- a/bundles/org.openhab.binding.tplinksmarthome/src/main/java/org/openhab/binding/tplinksmarthome/internal/device/DimmerDevice.java +++ b/bundles/org.openhab.binding.tplinksmarthome/src/main/java/org/openhab/binding/tplinksmarthome/internal/device/DimmerDevice.java @@ -56,11 +56,9 @@ public class DimmerDevice extends SwitchDevice { private boolean handleBrightnessChannel(ChannelUID channelUid, Command command) throws IOException { HasErrorResponse response = null; - if (command instanceof OnOffType) { - response = setOnOffState(channelUid, (OnOffType) command); - } else if (command instanceof PercentType) { - PercentType percentCommand = (PercentType) command; - + if (command instanceof OnOffType onOffCommand) { + response = setOnOffState(channelUid, onOffCommand); + } else if (command instanceof PercentType percentCommand) { // Don't send value 0 as brightness value as it will give an error from the device. if (percentCommand.intValue() > 0) { response = commands.setDimmerBrightnessResponse( diff --git a/bundles/org.openhab.binding.tplinksmarthome/src/main/java/org/openhab/binding/tplinksmarthome/internal/device/SwitchDevice.java b/bundles/org.openhab.binding.tplinksmarthome/src/main/java/org/openhab/binding/tplinksmarthome/internal/device/SwitchDevice.java index 69e4fa64cc8..d096a1298e5 100644 --- a/bundles/org.openhab.binding.tplinksmarthome/src/main/java/org/openhab/binding/tplinksmarthome/internal/device/SwitchDevice.java +++ b/bundles/org.openhab.binding.tplinksmarthome/src/main/java/org/openhab/binding/tplinksmarthome/internal/device/SwitchDevice.java @@ -41,7 +41,7 @@ public class SwitchDevice extends SmartHomeDevice { @Override public boolean handleCommand(ChannelUID channelUid, Command command) throws IOException { - return command instanceof OnOffType && handleOnOffType(channelUid, (OnOffType) command); + return command instanceof OnOffType onOffCommand && handleOnOffType(channelUid, onOffCommand); } /** diff --git a/bundles/org.openhab.binding.tplinksmarthome/src/main/java/org/openhab/binding/tplinksmarthome/internal/handler/TPLinkSmartHomeActions.java b/bundles/org.openhab.binding.tplinksmarthome/src/main/java/org/openhab/binding/tplinksmarthome/internal/handler/TPLinkSmartHomeActions.java index ad77be3dc56..105fd1bdca9 100644 --- a/bundles/org.openhab.binding.tplinksmarthome/src/main/java/org/openhab/binding/tplinksmarthome/internal/handler/TPLinkSmartHomeActions.java +++ b/bundles/org.openhab.binding.tplinksmarthome/src/main/java/org/openhab/binding/tplinksmarthome/internal/handler/TPLinkSmartHomeActions.java @@ -58,8 +58,8 @@ public class TPLinkSmartHomeActions implements ThingActions, ThingHandlerService @Override public void setThingHandler(final ThingHandler handler) { - if (handler instanceof SmartHomeHandler) { - this.handler = (SmartHomeHandler) handler; + if (handler instanceof SmartHomeHandler smartHomeHandler) { + this.handler = smartHomeHandler; } } diff --git a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/FritzboxActions.java b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/FritzboxActions.java index c905ae6ae1a..1f61c94bec2 100644 --- a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/FritzboxActions.java +++ b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/FritzboxActions.java @@ -122,7 +122,7 @@ public class FritzboxActions implements ThingActions { Optional scpdService = scpdUtil.getDevice("") .flatMap(deviceType -> deviceType.getServiceList().stream().filter( - service -> service.getServiceId().equals("urn:DeviceConfig-com:serviceId:DeviceConfig1")) + service -> "urn:DeviceConfig-com:serviceId:DeviceConfig1".equals(service.getServiceId())) .findFirst()); if (scpdService.isEmpty()) { logger.warn("Could not get service."); diff --git a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/Tr064DiscoveryService.java b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/Tr064DiscoveryService.java index f209416d044..93ae8383e1a 100644 --- a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/Tr064DiscoveryService.java +++ b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/Tr064DiscoveryService.java @@ -53,8 +53,8 @@ public class Tr064DiscoveryService extends AbstractDiscoveryService implements T @Override public void setThingHandler(ThingHandler thingHandler) { - if (thingHandler instanceof Tr064RootHandler) { - this.bridgeHandler = (Tr064RootHandler) thingHandler; + if (thingHandler instanceof Tr064RootHandler tr064RootHandler) { + this.bridgeHandler = tr064RootHandler; } } diff --git a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/Tr064HandlerFactory.java b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/Tr064HandlerFactory.java index a23ae326485..dcd41460e10 100644 --- a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/Tr064HandlerFactory.java +++ b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/Tr064HandlerFactory.java @@ -111,8 +111,8 @@ public class Tr064HandlerFactory extends BaseThingHandlerFactory { @Override protected void removeHandler(ThingHandler thingHandler) { - if (thingHandler instanceof Tr064RootHandler) { - phonebookProfileFactory.unregisterPhonebookProvider((Tr064RootHandler) thingHandler); + if (thingHandler instanceof Tr064RootHandler tr064RootHandler) { + phonebookProfileFactory.unregisterPhonebookProvider(tr064RootHandler); } } } diff --git a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/Tr064RootHandler.java b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/Tr064RootHandler.java index 17c42a2f220..4bed5ba0394 100644 --- a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/Tr064RootHandler.java +++ b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/Tr064RootHandler.java @@ -242,7 +242,7 @@ public class Tr064RootHandler extends BaseBridgeHandler implements PhonebookProv SCPDDeviceType device = scpdUtil.getDevice("") .orElseThrow(() -> new SCPDException("Root device not found")); SCPDServiceType deviceService = device.getServiceList().stream() - .filter(service -> service.getServiceId().equals("urn:DeviceInfo-com:serviceId:DeviceInfo1")) + .filter(service -> "urn:DeviceInfo-com:serviceId:DeviceInfo1".equals(service.getServiceId())) .findFirst().orElseThrow(() -> new SCPDException( "service 'urn:DeviceInfo-com:serviceId:DeviceInfo1' not found")); @@ -282,7 +282,7 @@ public class Tr064RootHandler extends BaseBridgeHandler implements PhonebookProv SCPDActionType getInfoAction = scpdUtil.getService(deviceService.getServiceId()) .orElseThrow(() -> new SCPDException( "Could not get service definition for 'urn:DeviceInfo-com:serviceId:DeviceInfo1'")) - .getActionList().stream().filter(action -> action.getName().equals("GetInfo")).findFirst() + .getActionList().stream().filter(action -> "GetInfo".equals(action.getName())).findFirst() .orElseThrow(() -> new SCPDException("Action 'GetInfo' not found")); SOAPMessage soapResponse1 = soapConnector .doSOAPRequest(new SOAPRequest(deviceService, getInfoAction.getName())); diff --git a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/phonebook/PhonebookProfile.java b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/phonebook/PhonebookProfile.java index d0292a2a9e5..aab94ff02be 100644 --- a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/phonebook/PhonebookProfile.java +++ b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/phonebook/PhonebookProfile.java @@ -98,17 +98,17 @@ public class PhonebookProfile implements StateProfile { phonebookName = UIDUtils.decode(phonebookParams[1]); } if (matchCountParam != null) { - if (matchCountParam instanceof BigDecimal) { - matchCount = ((BigDecimal) matchCountParam).intValue(); - } else if (matchCountParam instanceof String) { - matchCount = Integer.parseInt((String) matchCountParam); + if (matchCountParam instanceof BigDecimal bigDecimal) { + matchCount = bigDecimal.intValue(); + } else if (matchCountParam instanceof String string) { + matchCount = Integer.parseInt(string); } } if (phoneNumberIndexParam != null) { - if (phoneNumberIndexParam instanceof BigDecimal) { - phoneNumberIndex = ((BigDecimal) phoneNumberIndexParam).intValue(); - } else if (phoneNumberIndexParam instanceof String) { - phoneNumberIndex = Integer.parseInt((String) phoneNumberIndexParam); + if (phoneNumberIndexParam instanceof BigDecimal bigDecimal) { + phoneNumberIndex = bigDecimal.intValue(); + } else if (phoneNumberIndexParam instanceof String string) { + phoneNumberIndex = Integer.parseInt(string); } } } catch (IllegalArgumentException e) { diff --git a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPConnector.java b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPConnector.java index 7c6c72b2818..3e1d3c4a6b4 100644 --- a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPConnector.java +++ b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPConnector.java @@ -153,8 +153,8 @@ public class SOAPConnector { return soapMessage; } catch (IllegalArgumentException e) { Throwable cause = e.getCause(); - if (cause instanceof Tr064CommunicationException) { - throw (Tr064CommunicationException) cause; + if (cause instanceof Tr064CommunicationException tr064CommunicationException) { + throw tr064CommunicationException; } else { throw e; } diff --git a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPValueConverter.java b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPValueConverter.java index 5f90f4d7f72..48b36bb78d4 100644 --- a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPValueConverter.java +++ b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/SOAPValueConverter.java @@ -78,9 +78,8 @@ public class SOAPValueConverter { // we don't have data to send return Optional.of(""); } - if (command instanceof QuantityType) { - QuantityType value = (unit.isEmpty()) ? ((QuantityType) command) - : ((QuantityType) command).toUnit(unit); + if (command instanceof QuantityType quantityCommand) { + QuantityType value = (unit.isEmpty()) ? quantityCommand : quantityCommand.toUnit(unit); if (value == null) { logger.warn("Could not convert {} to unit {}", command, unit); return Optional.empty(); @@ -95,8 +94,8 @@ public class SOAPValueConverter { default -> { } } - } else if (command instanceof DecimalType) { - BigDecimal value = ((DecimalType) command).toBigDecimal(); + } else if (command instanceof DecimalType decimalCommand) { + BigDecimal value = decimalCommand.toBigDecimal(); switch (dataType) { case "ui1", "ui2" -> { return Optional.of(String.valueOf(value.shortValue())); @@ -139,7 +138,7 @@ public class SOAPValueConverter { // map rawValue to State switch (dataType) { case "boolean" -> { - return rawValue.equals("0") ? OnOffType.OFF : OnOffType.ON; + return "0".equals(rawValue) ? OnOffType.OFF : OnOffType.ON; } case "string" -> { return new StringType(rawValue); @@ -170,8 +169,8 @@ public class SOAPValueConverter { Method method = SOAPValueConverter.class.getDeclaredMethod(postProcessor, State.class, Tr064ChannelConfig.class); Object o = method.invoke(this, state, channelConfig); - if (o instanceof State) { - return (State) o; + if (o instanceof State stateInstance) { + return stateInstance; } } catch (NoSuchMethodException | IllegalAccessException e) { logger.warn("Postprocessor {} not found, this most likely is a programming error", postProcessor, e); diff --git a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/util/Util.java b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/util/Util.java index dc4c7c37b33..8990432da1b 100644 --- a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/util/Util.java +++ b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/util/Util.java @@ -281,10 +281,10 @@ public class Util { // get parameters by reflection from thing config Field paramField = thingConfig.getClass().getField(parameter.getThingParameter()); Object rawFieldValue = paramField.get(thingConfig); - if ((rawFieldValue instanceof List)) { - ((List) rawFieldValue).forEach(obj -> { - if (obj instanceof String) { - parameters.add((String) obj); + if ((rawFieldValue instanceof List list)) { + list.forEach(obj -> { + if (obj instanceof String string) { + parameters.add(string); } }); } diff --git a/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/TradfriBindingConstants.java b/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/TradfriBindingConstants.java index da11d714fa2..ac3c9cea459 100644 --- a/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/TradfriBindingConstants.java +++ b/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/TradfriBindingConstants.java @@ -52,9 +52,9 @@ public class TradfriBindingConstants { .unmodifiableSet(Stream.of(THING_TYPE_DIMMABLE_LIGHT, THING_TYPE_COLOR_TEMP_LIGHT, THING_TYPE_COLOR_LIGHT) .collect(Collectors.toSet())); - public static final Set SUPPORTED_PLUG_TYPES_UIDS = Collections.singleton(THING_TYPE_ONOFF_PLUG); + public static final Set SUPPORTED_PLUG_TYPES_UIDS = Set.of(THING_TYPE_ONOFF_PLUG); - public static final Set SUPPORTED_BLINDS_TYPES_UIDS = Collections.singleton(THING_TYPE_BLINDS); + public static final Set SUPPORTED_BLINDS_TYPES_UIDS = Set.of(THING_TYPE_BLINDS); public static final Set SUPPORTED_AIR_PURIFIER_TYPES_UIDS = Set.of(THING_TYPE_AIR_PURIFIER); @@ -70,7 +70,7 @@ public class TradfriBindingConstants { .unmodifiableSet(Stream.of(THING_TYPE_DIMMER, THING_TYPE_REMOTE_CONTROL, THING_TYPE_OPEN_CLOSE_REMOTE_CONTROL, THING_TYPE_MOTION_SENSOR).collect(Collectors.toSet())); - public static final Set SUPPORTED_BRIDGE_TYPES_UIDS = Collections.singleton(GATEWAY_TYPE_UID); + public static final Set SUPPORTED_BRIDGE_TYPES_UIDS = Set.of(GATEWAY_TYPE_UID); public static final Set SUPPORTED_DEVICE_TYPES_UIDS = Collections.unmodifiableSet(Stream .of(SUPPORTED_LIGHT_TYPES_UIDS.stream(), SUPPORTED_CONTROLLER_TYPES_UIDS.stream(), diff --git a/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/discovery/TradfriDiscoveryService.java b/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/discovery/TradfriDiscoveryService.java index 5fd3fbcb671..6fe7f8dc051 100644 --- a/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/discovery/TradfriDiscoveryService.java +++ b/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/discovery/TradfriDiscoveryService.java @@ -86,8 +86,8 @@ public class TradfriDiscoveryService extends AbstractDiscoveryService @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof TradfriGatewayHandler) { - this.handler = (TradfriGatewayHandler) handler; + if (handler instanceof TradfriGatewayHandler gatewayHandler) { + this.handler = gatewayHandler; } } diff --git a/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/handler/TradfriAirPurifierHandler.java b/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/handler/TradfriAirPurifierHandler.java index 149d09bf361..23057ab5115 100644 --- a/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/handler/TradfriAirPurifierHandler.java +++ b/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/handler/TradfriAirPurifierHandler.java @@ -75,8 +75,8 @@ public class TradfriAirPurifierHandler extends TradfriThingHandler { } private void handleFanModeCommand(Command command) { - if (command instanceof Number) { - set(new TradfriAirPurifierData().setFanMode((Number) command).getJsonString()); + if (command instanceof Number numberCommand) { + set(new TradfriAirPurifierData().setFanMode(numberCommand).getJsonString()); } else { logger.debug("Cannot handle command '{}' of type {} for channel '{}'", command, command.getClass(), CHANNEL_FAN_MODE); @@ -84,8 +84,8 @@ public class TradfriAirPurifierHandler extends TradfriThingHandler { } private void handleDisableLed(Command command) { - if (command instanceof OnOffType) { - set(new TradfriAirPurifierData().setDisableLed((OnOffType) command).getJsonString()); + if (command instanceof OnOffType onOffCommand) { + set(new TradfriAirPurifierData().setDisableLed(onOffCommand).getJsonString()); } else { logger.debug("Cannot handle command '{}' of type {} for channel '{}'", command, command.getClass(), CHANNEL_DISABLE_LED); @@ -93,8 +93,8 @@ public class TradfriAirPurifierHandler extends TradfriThingHandler { } private void handleLockButton(Command command) { - if (command instanceof OnOffType) { - set(new TradfriAirPurifierData().setLockPhysicalButton((OnOffType) command).getJsonString()); + if (command instanceof OnOffType onOffCommand) { + set(new TradfriAirPurifierData().setLockPhysicalButton(onOffCommand).getJsonString()); } else { logger.debug("Cannot handle command '{}' of type {} for channel '{}'", command, command.getClass(), CHANNEL_DISABLE_LED); diff --git a/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/handler/TradfriBlindHandler.java b/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/handler/TradfriBlindHandler.java index 0acc6d59eec..d7a69672703 100644 --- a/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/handler/TradfriBlindHandler.java +++ b/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/handler/TradfriBlindHandler.java @@ -108,8 +108,8 @@ public class TradfriBlindHandler extends TradfriThingHandler { } private void handlePositionCommand(Command command) { - if (command instanceof PercentType) { - setPosition((PercentType) command); + if (command instanceof PercentType percentCommand) { + setPosition(percentCommand); } else if (command instanceof StopMoveType) { if (StopMoveType.STOP.equals(command)) { triggerStop(); diff --git a/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/handler/TradfriGatewayHandler.java b/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/handler/TradfriGatewayHandler.java index 6ea12fad69a..18aeb6a7947 100644 --- a/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/handler/TradfriGatewayHandler.java +++ b/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/handler/TradfriGatewayHandler.java @@ -18,7 +18,6 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.util.Collection; -import java.util.Collections; import java.util.Objects; import java.util.Set; import java.util.UUID; @@ -137,7 +136,7 @@ public class TradfriGatewayHandler extends BaseBridgeHandler implements CoapCall @Override public Collection> getServices() { - return Collections.singleton(TradfriDiscoveryService.class); + return Set.of(TradfriDiscoveryService.class); } private void establishConnection() { diff --git a/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/handler/TradfriLightHandler.java b/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/handler/TradfriLightHandler.java index b935450192b..03fc20a9a0a 100644 --- a/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/handler/TradfriLightHandler.java +++ b/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/handler/TradfriLightHandler.java @@ -154,10 +154,10 @@ public class TradfriLightHandler extends TradfriThingHandler { } private void handleBrightnessCommand(Command command) { - if (command instanceof PercentType) { - setBrightness((PercentType) command); - } else if (command instanceof OnOffType) { - setState(((OnOffType) command)); + if (command instanceof PercentType percentCommand) { + setBrightness(percentCommand); + } else if (command instanceof OnOffType onOffCommand) { + setState(onOffCommand); } else if (command instanceof IncreaseDecreaseType) { final TradfriLightData state = this.state; if (state != null && state.getBrightness() != null) { @@ -177,8 +177,8 @@ public class TradfriLightHandler extends TradfriThingHandler { } private void handleColorTemperatureCommand(Command command) { - if (command instanceof PercentType) { - setColorTemperature((PercentType) command); + if (command instanceof PercentType percentCommand) { + setColorTemperature(percentCommand); } else if (command instanceof IncreaseDecreaseType) { final TradfriLightData state = this.state; if (state != null && state.getColorTemperature() != null) { @@ -198,13 +198,13 @@ public class TradfriLightHandler extends TradfriThingHandler { } private void handleColorCommand(Command command) { - if (command instanceof HSBType) { - setColor((HSBType) command); - setBrightness(((HSBType) command).getBrightness()); - } else if (command instanceof OnOffType) { - setState(((OnOffType) command)); - } else if (command instanceof PercentType) { - setBrightness((PercentType) command); + if (command instanceof HSBType hsbCommand) { + setColor(hsbCommand); + setBrightness(hsbCommand.getBrightness()); + } else if (command instanceof OnOffType onOffCommand) { + setState(onOffCommand); + } else if (command instanceof PercentType percentCommand) { + setBrightness(percentCommand); } else if (command instanceof IncreaseDecreaseType) { final TradfriLightData state = this.state; // increase or decrease only the brightness, but keep color diff --git a/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/handler/TradfriPlugHandler.java b/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/handler/TradfriPlugHandler.java index db0b3598e42..5cf4ec779f0 100644 --- a/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/handler/TradfriPlugHandler.java +++ b/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/handler/TradfriPlugHandler.java @@ -75,8 +75,8 @@ public class TradfriPlugHandler extends TradfriThingHandler { switch (channelUID.getId()) { case CHANNEL_POWER: - if (command instanceof OnOffType) { - setState(((OnOffType) command)); + if (command instanceof OnOffType onOffCommand) { + setState(onOffCommand); } else { logger.debug("Cannot handle command '{}' for channel '{}'", command, CHANNEL_POWER); } diff --git a/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/model/TradfriAirPurifierData.java b/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/model/TradfriAirPurifierData.java index 8d67f4a9623..d5d83d2cc3e 100644 --- a/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/model/TradfriAirPurifierData.java +++ b/bundles/org.openhab.binding.tradfri/src/main/java/org/openhab/binding/tradfri/internal/model/TradfriAirPurifierData.java @@ -135,8 +135,8 @@ public class TradfriAirPurifierData extends TradfriDeviceData { public @Nullable State getAirQualityRating() { State pm25State = getAirQualityPM25(); if (pm25State != null) { - if (pm25State instanceof Number) { - int pm25Value = ((Number) pm25State).intValue(); + if (pm25State instanceof Number number) { + int pm25Value = number.intValue(); int qualityRating = 1; if (pm25Value >= AIR_PURIFIER_AIR_QUALITY_BAD) { diff --git a/bundles/org.openhab.binding.twitter/src/main/java/org/openhab/binding/twitter/internal/TwitterHandler.java b/bundles/org.openhab.binding.twitter/src/main/java/org/openhab/binding/twitter/internal/TwitterHandler.java index f2db46d783f..8b962d7902e 100644 --- a/bundles/org.openhab.binding.twitter/src/main/java/org/openhab/binding/twitter/internal/TwitterHandler.java +++ b/bundles/org.openhab.binding.twitter/src/main/java/org/openhab/binding/twitter/internal/TwitterHandler.java @@ -21,7 +21,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.Collection; -import java.util.Collections; +import java.util.List; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -82,7 +82,7 @@ public class TwitterHandler extends BaseThingHandler { // creates list of available Actions @Override public Collection> getServices() { - return Collections.singletonList(TwitterActions.class); + return List.of(TwitterActions.class); } @Override @@ -118,7 +118,7 @@ public class TwitterHandler extends BaseThingHandler { Twitter localClient = client; if (localClient != null) { ResponseList statuses = localClient.getUserTimeline(); - if (statuses.size() > 0) { + if (!statuses.isEmpty()) { updateState(CHANNEL_LASTTWEET, StringType.valueOf(statuses.get(0).getText())); } else { logger.debug("No Statuses Found"); diff --git a/bundles/org.openhab.binding.twitter/src/main/java/org/openhab/binding/twitter/internal/action/TwitterActions.java b/bundles/org.openhab.binding.twitter/src/main/java/org/openhab/binding/twitter/internal/action/TwitterActions.java index 81a9ba5f19e..a1390f27f4a 100644 --- a/bundles/org.openhab.binding.twitter/src/main/java/org/openhab/binding/twitter/internal/action/TwitterActions.java +++ b/bundles/org.openhab.binding.twitter/src/main/java/org/openhab/binding/twitter/internal/action/TwitterActions.java @@ -112,8 +112,8 @@ public class TwitterActions implements ThingActions { @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof TwitterHandler) { - this.handler = (TwitterHandler) handler; + if (handler instanceof TwitterHandler twitterHandler) { + this.handler = twitterHandler; } } diff --git a/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/action/UniFiSiteActions.java b/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/action/UniFiSiteActions.java index 59b7cfb376f..b0cd37163f2 100644 --- a/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/action/UniFiSiteActions.java +++ b/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/action/UniFiSiteActions.java @@ -259,8 +259,8 @@ public class UniFiSiteActions implements ThingActions { @Override public void setThingHandler(ThingHandler handler) { - if (handler instanceof UniFiSiteThingHandler) { - this.handler = (UniFiSiteThingHandler) handler; + if (handler instanceof UniFiSiteThingHandler siteThingHandler) { + this.handler = siteThingHandler; } } diff --git a/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/api/UniFiControllerRequest.java b/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/api/UniFiControllerRequest.java index 0e450dd0940..fc0439e3b59 100644 --- a/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/api/UniFiControllerRequest.java +++ b/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/api/UniFiControllerRequest.java @@ -206,13 +206,13 @@ class UniFiControllerRequest { } else if (cause instanceof SSLException) { // cannot establish ssl connection throw new UniFiSSLException(cause); - } else if (cause instanceof HttpResponseException - && ((HttpResponseException) cause).getResponse() instanceof ContentResponse) { + } else if (cause instanceof HttpResponseException httpResponseException + && httpResponseException.getResponse() instanceof ContentResponse) { // the UniFi controller violates the HTTP protocol // - it returns 401 UNAUTHORIZED without the WWW-Authenticate response header // - this causes an ExecutionException to be thrown // - we unwrap the response from the exception for proper handling of the 401 status code - response = ((HttpResponseException) cause).getResponse(); + response = httpResponseException.getResponse(); } else { // catch all throw new UniFiException(cause); diff --git a/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/api/dto/UniFiVoucher.java b/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/api/dto/UniFiVoucher.java index 55d581fd313..6023e255271 100644 --- a/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/api/dto/UniFiVoucher.java +++ b/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/api/dto/UniFiVoucher.java @@ -107,8 +107,10 @@ public class UniFiVoucher implements HasId { @Override public String toString() { return String.format( - "UniFiVoucher{id: '%s', code: '%s', created: '%s', duration: '%s', quota: '%s', used: '%s', qosUsageQuota: '%s', " - + "qosRateMaxUp: '%s', qosRateMaxDown: '%s', qosOverwrite: '%s', note: '%s', status: '%s', site: %s}", + """ + UniFiVoucher{id: '%s', code: '%s', created: '%s', duration: '%s', quota: '%s', used: '%s', qosUsageQuota: '%s', \ + qosRateMaxUp: '%s', qosRateMaxDown: '%s', qosOverwrite: '%s', note: '%s', status: '%s', site: %s}\ + """, id, code, createTime, duration, quota, used, qosUsageQuota, qosRateMaxUp, qosRateMaxDown, qosOverwrite, note, status, getSite()); } diff --git a/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiClientThingHandler.java b/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiClientThingHandler.java index 7b725657c89..b5ef263970e 100644 --- a/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiClientThingHandler.java +++ b/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiClientThingHandler.java @@ -245,13 +245,13 @@ public class UniFiClientThingHandler extends UniFiBaseThingHandler { final ThingHandler handler = thing.getHandler(); - if (handler instanceof UniFiBaseThingHandler) { - ((UniFiBaseThingHandler) handler).refresh(); + if (handler instanceof UniFiBaseThingHandler baseThingHandler) { + baseThingHandler.refresh(); } }); } diff --git a/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiSiteThingHandler.java b/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiSiteThingHandler.java index 7ec1c0d1fa2..5011c34d173 100644 --- a/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiSiteThingHandler.java +++ b/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiSiteThingHandler.java @@ -15,7 +15,7 @@ package org.openhab.binding.unifi.internal.handler; import static org.openhab.binding.unifi.internal.UniFiBindingConstants.*; import java.util.Collection; -import java.util.Collections; +import java.util.Set; import java.util.function.Predicate; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -134,6 +134,6 @@ public class UniFiSiteThingHandler extends UniFiBaseThingHandler> getServices() { - return Collections.singleton(UniFiSiteActions.class); + return Set.of(UniFiSiteActions.class); } } diff --git a/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiThingDiscoveryService.java b/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiThingDiscoveryService.java index 46aeace7017..560530c24c3 100644 --- a/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiThingDiscoveryService.java +++ b/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiThingDiscoveryService.java @@ -76,8 +76,8 @@ public class UniFiThingDiscoveryService extends AbstractDiscoveryService @Override public void setThingHandler(final ThingHandler handler) { - if (handler instanceof UniFiControllerThingHandler) { - bridgeHandler = (UniFiControllerThingHandler) handler; + if (handler instanceof UniFiControllerThingHandler controllerThingHandler) { + bridgeHandler = controllerThingHandler; } } diff --git a/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiWlanThingHandler.java b/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiWlanThingHandler.java index 72f2fc4aea1..da3d31f0467 100644 --- a/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiWlanThingHandler.java +++ b/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiWlanThingHandler.java @@ -135,8 +135,8 @@ public class UniFiWlanThingHandler extends UniFiBaseThingHandler c instanceof UniFiWirelessClient - && (wlan.getName() != null && wlan.getName().equals(((UniFiWirelessClient) c).getEssid())) + c -> c instanceof UniFiWirelessClient wirelessClient + && (wlan.getName() != null && wlan.getName().equals(wirelessClient.getEssid())) && filter.test(c))); } } diff --git a/bundles/org.openhab.binding.unifiedremote/src/main/java/org/openhab/binding/unifiedremote/internal/UnifiedRemoteBindingConstants.java b/bundles/org.openhab.binding.unifiedremote/src/main/java/org/openhab/binding/unifiedremote/internal/UnifiedRemoteBindingConstants.java index 53b51e1dd0f..d02602754c9 100644 --- a/bundles/org.openhab.binding.unifiedremote/src/main/java/org/openhab/binding/unifiedremote/internal/UnifiedRemoteBindingConstants.java +++ b/bundles/org.openhab.binding.unifiedremote/src/main/java/org/openhab/binding/unifiedremote/internal/UnifiedRemoteBindingConstants.java @@ -12,7 +12,6 @@ */ package org.openhab.binding.unifiedremote.internal; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -31,8 +30,7 @@ public class UnifiedRemoteBindingConstants { // List of all Thing Type UIDs public static final ThingTypeUID THING_TYPE_UNIFIED_REMOTE_SERVER = new ThingTypeUID(BINDING_ID, "server"); - public static final Set SUPPORTED_THING_TYPES = Collections - .singleton(THING_TYPE_UNIFIED_REMOTE_SERVER); + public static final Set SUPPORTED_THING_TYPES = Set.of(THING_TYPE_UNIFIED_REMOTE_SERVER); // List of all Channel ids public static final String MOUSE_CHANNEL = "mouse-move"; diff --git a/bundles/org.openhab.binding.upb/src/main/java/org/openhab/binding/upb/internal/UPBController.java b/bundles/org.openhab.binding.upb/src/main/java/org/openhab/binding/upb/internal/UPBController.java index 5dea21026ba..f261b15eab1 100644 --- a/bundles/org.openhab.binding.upb/src/main/java/org/openhab/binding/upb/internal/UPBController.java +++ b/bundles/org.openhab.binding.upb/src/main/java/org/openhab/binding/upb/internal/UPBController.java @@ -87,16 +87,14 @@ public class UPBController { } public void deviceAdded(final ThingHandler childHandler, final Thing childThing) { - if (childHandler instanceof UPBThingHandler) { - final UPBThingHandler hnd = (UPBThingHandler) childHandler; - things.put(mkAddr(hnd.getNetworkId(), hnd.getUnitId()), hnd); + if (childHandler instanceof UPBThingHandler upbThingHandler) { + things.put(mkAddr(upbThingHandler.getNetworkId(), upbThingHandler.getUnitId()), upbThingHandler); } } public void deviceRemoved(final ThingHandler childHandler, final Thing childThing) { - if (childHandler instanceof UPBThingHandler) { - final UPBThingHandler hnd = (UPBThingHandler) childHandler; - things.remove(mkAddr(hnd.getNetworkId(), hnd.getUnitId()), hnd); + if (childHandler instanceof UPBThingHandler upbThingHandler) { + things.remove(mkAddr(upbThingHandler.getNetworkId(), upbThingHandler.getUnitId()), upbThingHandler); } } diff --git a/bundles/org.openhab.binding.upb/src/main/java/org/openhab/binding/upb/internal/handler/UPBThingHandler.java b/bundles/org.openhab.binding.upb/src/main/java/org/openhab/binding/upb/internal/handler/UPBThingHandler.java index 67b21e2de0d..ce97b2768ca 100644 --- a/bundles/org.openhab.binding.upb/src/main/java/org/openhab/binding/upb/internal/handler/UPBThingHandler.java +++ b/bundles/org.openhab.binding.upb/src/main/java/org/openhab/binding/upb/internal/handler/UPBThingHandler.java @@ -144,8 +144,8 @@ public class UPBThingHandler extends BaseThingHandler { message = MessageBuilder.forCommand(ACTIVATE); } else if (cmd == OnOffType.OFF) { message = MessageBuilder.forCommand(DEACTIVATE); - } else if (cmd instanceof PercentType) { - message = MessageBuilder.forCommand(GOTO).args(((PercentType) cmd).byteValue()); + } else if (cmd instanceof PercentType percentCommand) { + message = MessageBuilder.forCommand(GOTO).args(percentCommand.byteValue()); } else if (cmd == RefreshType.REFRESH) { refreshDeviceState(); return; diff --git a/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/UpnpDynamicCommandDescriptionProvider.java b/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/UpnpDynamicCommandDescriptionProvider.java index 882f43bdd22..38c7820aa1c 100644 --- a/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/UpnpDynamicCommandDescriptionProvider.java +++ b/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/UpnpDynamicCommandDescriptionProvider.java @@ -52,8 +52,7 @@ public class UpnpDynamicCommandDescriptionProvider implements DynamicCommandDesc @Override public @Nullable CommandDescription getCommandDescription(Channel channel, @Nullable CommandDescription originalCommandDescription, @Nullable Locale locale) { - CommandDescription description = descriptions.get(channel.getUID()); - return description; + return descriptions.get(channel.getUID()); } @Deactivate diff --git a/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/UpnpDynamicStateDescriptionProvider.java b/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/UpnpDynamicStateDescriptionProvider.java index 6af9891fdff..e916a49215e 100644 --- a/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/UpnpDynamicStateDescriptionProvider.java +++ b/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/UpnpDynamicStateDescriptionProvider.java @@ -52,8 +52,7 @@ public class UpnpDynamicStateDescriptionProvider implements DynamicStateDescript @Override public @Nullable StateDescription getStateDescription(Channel channel, @Nullable StateDescription originalStateDescription, @Nullable Locale locale) { - StateDescription description = descriptions.get(channel.getUID()); - return description; + return descriptions.get(channel.getUID()); } @Deactivate diff --git a/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/handler/UpnpHandler.java b/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/handler/UpnpHandler.java index b22baa73d66..9c694718c4c 100644 --- a/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/handler/UpnpHandler.java +++ b/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/handler/UpnpHandler.java @@ -333,7 +333,7 @@ public abstract class UpnpHandler extends BaseThingHandler implements UpnpIOPart * Invoke ConnectionComplete on UPnP Connection Manager. */ protected void connectionComplete() { - Map inputs = Collections.singletonMap(CONNECTION_ID, Integer.toString(connectionId)); + Map inputs = Map.of(CONNECTION_ID, Integer.toString(connectionId)); invokeAction(CONNECTION_MANAGER, "ConnectionComplete", inputs); } @@ -367,7 +367,7 @@ public abstract class UpnpHandler extends BaseThingHandler implements UpnpIOPart isRcsIdSet = new CompletableFuture(); // ConnectionID will default to 0 if not set through prepareForConnection method - Map inputs = Collections.singletonMap(CONNECTION_ID, Integer.toString(connectionId)); + Map inputs = Map.of(CONNECTION_ID, Integer.toString(connectionId)); invokeAction(CONNECTION_MANAGER, "GetCurrentConnectionInfo", inputs); } diff --git a/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/handler/UpnpRendererHandler.java b/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/handler/UpnpRendererHandler.java index 2ece784b1fe..1acf8740392 100644 --- a/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/handler/UpnpRendererHandler.java +++ b/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/handler/UpnpRendererHandler.java @@ -19,7 +19,6 @@ import java.nio.charset.StandardCharsets; import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -317,7 +316,7 @@ public class UpnpRendererHandler extends UpnpHandler { // received } - Map inputs = Collections.singletonMap(INSTANCE_ID, Integer.toString(avTransportId)); + Map inputs = Map.of(INSTANCE_ID, Integer.toString(avTransportId)); invokeAction(AV_TRANSPORT, "Stop", inputs); } @@ -353,7 +352,7 @@ public class UpnpRendererHandler extends UpnpHandler { * Invoke Pause on UPnP AV Transport. */ protected void pause() { - Map inputs = Collections.singletonMap(INSTANCE_ID, Integer.toString(avTransportId)); + Map inputs = Map.of(INSTANCE_ID, Integer.toString(avTransportId)); invokeAction(AV_TRANSPORT, "Pause", inputs); } @@ -362,7 +361,7 @@ public class UpnpRendererHandler extends UpnpHandler { * Invoke Next on UPnP AV Transport. */ protected void next() { - Map inputs = Collections.singletonMap(INSTANCE_ID, Integer.toString(avTransportId)); + Map inputs = Map.of(INSTANCE_ID, Integer.toString(avTransportId)); invokeAction(AV_TRANSPORT, "Next", inputs); } @@ -371,7 +370,7 @@ public class UpnpRendererHandler extends UpnpHandler { * Invoke Previous on UPnP AV Transport. */ protected void previous() { - Map inputs = Collections.singletonMap(INSTANCE_ID, Integer.toString(avTransportId)); + Map inputs = Map.of(INSTANCE_ID, Integer.toString(avTransportId)); invokeAction(AV_TRANSPORT, "Previous", inputs); } @@ -456,7 +455,7 @@ public class UpnpRendererHandler extends UpnpHandler { * Result is received in {@link #onValueReceived}. */ protected void getTransportState() { - Map inputs = Collections.singletonMap(INSTANCE_ID, Integer.toString(avTransportId)); + Map inputs = Map.of(INSTANCE_ID, Integer.toString(avTransportId)); invokeAction(AV_TRANSPORT, "GetTransportInfo", inputs); } @@ -466,7 +465,7 @@ public class UpnpRendererHandler extends UpnpHandler { * Result is received in {@link #onValueReceived}. */ protected void getPositionInfo() { - Map inputs = Collections.singletonMap(INSTANCE_ID, Integer.toString(avTransportId)); + Map inputs = Map.of(INSTANCE_ID, Integer.toString(avTransportId)); invokeAction(AV_TRANSPORT, "GetPositionInfo", inputs); } @@ -476,7 +475,7 @@ public class UpnpRendererHandler extends UpnpHandler { * Result is received in {@link #onValueReceived}. */ protected void getMediaInfo() { - Map inputs = Collections.singletonMap(INSTANCE_ID, Integer.toString(avTransportId)); + Map inputs = Map.of(INSTANCE_ID, Integer.toString(avTransportId)); invokeAction(AV_TRANSPORT, "smarthome:audio stream http://icecast.vrtcdn.be/stubru_tijdloze-high.mp3", inputs); } @@ -696,24 +695,24 @@ public class UpnpRendererHandler extends UpnpHandler { private void handleCommandVolume(Command command, String id) { if (command instanceof RefreshType) { getVolume("volume".equals(id) ? UPNP_MASTER : id.replace("volume", "")); - } else if (command instanceof PercentType) { - setVolume("volume".equals(id) ? UPNP_MASTER : id.replace("volume", ""), (PercentType) command); + } else if (command instanceof PercentType percentCommand) { + setVolume("volume".equals(id) ? UPNP_MASTER : id.replace("volume", ""), percentCommand); } } private void handleCommandMute(Command command, String id) { if (command instanceof RefreshType) { getMute("mute".equals(id) ? UPNP_MASTER : id.replace("mute", "")); - } else if (command instanceof OnOffType) { - setMute("mute".equals(id) ? UPNP_MASTER : id.replace("mute", ""), (OnOffType) command); + } else if (command instanceof OnOffType onOffCommand) { + setMute("mute".equals(id) ? UPNP_MASTER : id.replace("mute", ""), onOffCommand); } } private void handleCommandLoudness(Command command, String id) { if (command instanceof RefreshType) { getLoudness("loudness".equals(id) ? UPNP_MASTER : id.replace("loudness", "")); - } else if (command instanceof OnOffType) { - setLoudness("loudness".equals(id) ? UPNP_MASTER : id.replace("loudness", ""), (OnOffType) command); + } else if (command instanceof OnOffType onOffCommand) { + setLoudness("loudness".equals(id) ? UPNP_MASTER : id.replace("loudness", ""), onOffCommand); } } @@ -884,8 +883,8 @@ public class UpnpRendererHandler extends UpnpHandler { private void handleCommandTrackPosition(ChannelUID channelUID, Command command) { if (command instanceof RefreshType) { updateState(channelUID, new QuantityType<>(trackPosition, Units.SECOND)); - } else if (command instanceof QuantityType) { - QuantityType position = ((QuantityType) command).toUnit(Units.SECOND); + } else if (command instanceof QuantityType quantityCommand) { + QuantityType position = quantityCommand.toUnit(Units.SECOND); if (position != null) { int pos = Integer.min(trackDuration, position.intValue()); seek(String.format("%02d:%02d:%02d", pos / 3600, (pos % 3600) / 60, pos % 60)); @@ -897,8 +896,8 @@ public class UpnpRendererHandler extends UpnpHandler { if (command instanceof RefreshType) { int relPosition = (trackDuration != 0) ? (trackPosition * 100) / trackDuration : 0; updateState(channelUID, new PercentType(relPosition)); - } else if (command instanceof PercentType) { - int pos = ((PercentType) command).intValue() * trackDuration / 100; + } else if (command instanceof PercentType percentCommand) { + int pos = percentCommand.intValue() * trackDuration / 100; seek(String.format("%02d:%02d:%02d", pos / 3600, (pos % 3600) / 60, pos % 60)); } } diff --git a/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/handler/UpnpServerHandler.java b/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/handler/UpnpServerHandler.java index 8355367f0eb..5846895f734 100644 --- a/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/handler/UpnpServerHandler.java +++ b/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/handler/UpnpServerHandler.java @@ -321,8 +321,8 @@ public class UpnpServerHandler extends UpnpHandler { private void handleCommandUpnpRenderer(ChannelUID channelUID, Command command) { UpnpRendererHandler renderer = null; UpnpRendererHandler previousRenderer = currentRendererHandler; - if (command instanceof StringType) { - renderer = (upnpRenderers.get(((StringType) command).toString())); + if (command instanceof StringType stringCommand) { + renderer = (upnpRenderers.get(stringCommand.toString())); currentRendererHandler = renderer; if (config.filter) { // only refresh title list if filtering by renderer capabilities diff --git a/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/util/StringUtils.java b/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/util/StringUtils.java index 080d4b66239..59839cce842 100644 --- a/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/util/StringUtils.java +++ b/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/util/StringUtils.java @@ -32,11 +32,11 @@ public class StringUtils { * ' - ' */ public static String escapeXml(String xml) { - xml = xml.replaceAll("&", "&"); - xml = xml.replaceAll("<", "<"); - xml = xml.replaceAll(">", ">"); - xml = xml.replaceAll("\"", """); - xml = xml.replaceAll("'", "'"); + xml = xml.replace("&", "&"); + xml = xml.replace("<", "<"); + xml = xml.replace(">", ">"); + xml = xml.replace("\"", """); + xml = xml.replace("'", "'"); return xml; } @@ -50,11 +50,11 @@ public class StringUtils { * ' - ' */ public static String unEscapeXml(String xml) { - xml = xml.replaceAll("&", "&"); - xml = xml.replaceAll("<", "<"); - xml = xml.replaceAll(">", ">"); - xml = xml.replaceAll(""", "\""); - xml = xml.replaceAll("'", "'"); + xml = xml.replace("&", "&"); + xml = xml.replace("<", "<"); + xml = xml.replace(">", ">"); + xml = xml.replace(""", "\""); + xml = xml.replace("'", "'"); return xml; } } diff --git a/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/util/UpnpControlUtil.java b/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/util/UpnpControlUtil.java index c4207b75f77..de15d104b26 100644 --- a/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/util/UpnpControlUtil.java +++ b/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/util/UpnpControlUtil.java @@ -113,9 +113,8 @@ public final class UpnpControlUtil { return Collections.emptyList(); } - List result = (Arrays.asList(files)).stream().map(p -> p.getName().replace(extension, "")) + return (Arrays.asList(files)).stream().map(p -> p.getName().replace(extension, "")) .collect(Collectors.toList()); - return result; } private static void delete(String name, @Nullable String path, String extension) { diff --git a/bundles/org.openhab.binding.upnpcontrol/src/test/java/org/openhab/binding/upnpcontrol/internal/handler/UpnpHandlerTest.java b/bundles/org.openhab.binding.upnpcontrol/src/test/java/org/openhab/binding/upnpcontrol/internal/handler/UpnpHandlerTest.java index c227f1fc8dc..2afebf708f9 100644 --- a/bundles/org.openhab.binding.upnpcontrol/src/test/java/org/openhab/binding/upnpcontrol/internal/handler/UpnpHandlerTest.java +++ b/bundles/org.openhab.binding.upnpcontrol/src/test/java/org/openhab/binding/upnpcontrol/internal/handler/UpnpHandlerTest.java @@ -145,9 +145,8 @@ public class UpnpHandlerTest { ((Runnable) invocation.getArguments()[0]).run(); return null; }).when(executor).scheduleWithFixedDelay(any(Runnable.class), eq(0L), anyLong(), any(TimeUnit.class)); - doAnswer(invocation -> { - return SCHEDULER.schedule((Runnable) invocation.getArguments()[0], 500, TimeUnit.MILLISECONDS); - }).when(executor).schedule(any(Runnable.class), anyLong(), any(TimeUnit.class)); + doAnswer(invocation -> SCHEDULER.schedule((Runnable) invocation.getArguments()[0], 500, TimeUnit.MILLISECONDS)) + .when(executor).schedule(any(Runnable.class), anyLong(), any(TimeUnit.class)); } public void tearDown() { diff --git a/bundles/org.openhab.binding.upnpcontrol/src/test/java/org/openhab/binding/upnpcontrol/internal/handler/UpnpRendererHandlerTest.java b/bundles/org.openhab.binding.upnpcontrol/src/test/java/org/openhab/binding/upnpcontrol/internal/handler/UpnpRendererHandlerTest.java index 985760c2060..8d8de3526e0 100644 --- a/bundles/org.openhab.binding.upnpcontrol/src/test/java/org/openhab/binding/upnpcontrol/internal/handler/UpnpRendererHandlerTest.java +++ b/bundles/org.openhab.binding.upnpcontrol/src/test/java/org/openhab/binding/upnpcontrol/internal/handler/UpnpRendererHandlerTest.java @@ -74,8 +74,10 @@ public class UpnpRendererHandlerTest extends UpnpHandlerTest { private static final String THING_TYPE_UID = "upnpcontrol:upnprenderer"; private static final String THING_UID = THING_TYPE_UID + ":mockrenderer"; - private static final String LAST_CHANGE_HEADER = "" - + ""; + private static final String LAST_CHANGE_HEADER = """ + \ + \ + """; private static final String LAST_CHANGE_FOOTER = ""; private static final String AV_TRANSPORT_URI = ""; + private static final String RESPONSE_HEADER = """ + \ + """; private static final String RESPONSE_FOOTER = ""; private static final String BASE_CONTAINER = RESPONSE_HEADER diff --git a/bundles/org.openhab.binding.urtsi/src/main/java/org/openhab/binding/urtsi/internal/UrtsiHandlerFactory.java b/bundles/org.openhab.binding.urtsi/src/main/java/org/openhab/binding/urtsi/internal/UrtsiHandlerFactory.java index 44a40418f96..d93ae25a198 100644 --- a/bundles/org.openhab.binding.urtsi/src/main/java/org/openhab/binding/urtsi/internal/UrtsiHandlerFactory.java +++ b/bundles/org.openhab.binding.urtsi/src/main/java/org/openhab/binding/urtsi/internal/UrtsiHandlerFactory.java @@ -61,8 +61,8 @@ public class UrtsiHandlerFactory extends BaseThingHandlerFactory { protected @Nullable ThingHandler createHandler(Thing thing) { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); - if (thingTypeUID.equals(URTSI_DEVICE_THING_TYPE) && thing instanceof Bridge) { - return new UrtsiDeviceHandler((Bridge) thing, serialPortManager); + if (thingTypeUID.equals(URTSI_DEVICE_THING_TYPE) && thing instanceof Bridge bridge) { + return new UrtsiDeviceHandler(bridge, serialPortManager); } else if (thingTypeUID.equals(RTS_DEVICE_THING_TYPE)) { return new RtsDeviceHandler(thing); } diff --git a/bundles/org.openhab.binding.urtsi/src/main/java/org/openhab/binding/urtsi/internal/handler/RtsDeviceHandler.java b/bundles/org.openhab.binding.urtsi/src/main/java/org/openhab/binding/urtsi/internal/handler/RtsDeviceHandler.java index 9b164232bf7..95d66ac63a5 100644 --- a/bundles/org.openhab.binding.urtsi/src/main/java/org/openhab/binding/urtsi/internal/handler/RtsDeviceHandler.java +++ b/bundles/org.openhab.binding.urtsi/src/main/java/org/openhab/binding/urtsi/internal/handler/RtsDeviceHandler.java @@ -42,8 +42,8 @@ public class RtsDeviceHandler extends BaseThingHandler { public void handleCommand(ChannelUID channelUID, Command command) { if (channelUID.getId().equals(UrtsiBindingConstants.POSITION)) { RtsCommand rtsCommand = null; - if (command instanceof UpDownType) { - switch ((UpDownType) command) { + if (command instanceof UpDownType upDownCommand) { + switch (upDownCommand) { case UP: rtsCommand = RtsCommand.UP; break; @@ -53,8 +53,8 @@ public class RtsDeviceHandler extends BaseThingHandler { default: break; } - } else if (command instanceof StopMoveType) { - switch ((StopMoveType) command) { + } else if (command instanceof StopMoveType stopMoveCommand) { + switch (stopMoveCommand) { case STOP: rtsCommand = RtsCommand.STOP; break; @@ -65,11 +65,10 @@ public class RtsDeviceHandler extends BaseThingHandler { if (rtsCommand != null) { // We delegate the execution to the bridge handler ThingHandler bridgeHandler = getBridge().getHandler(); - if (bridgeHandler instanceof UrtsiDeviceHandler) { - boolean executedSuccessfully = ((UrtsiDeviceHandler) bridgeHandler).executeRtsCommand(getThing(), - rtsCommand); - if (executedSuccessfully && command instanceof State) { - updateState(channelUID, (State) command); + if (bridgeHandler instanceof UrtsiDeviceHandler deviceHandler) { + boolean executedSuccessfully = deviceHandler.executeRtsCommand(getThing(), rtsCommand); + if (executedSuccessfully && command instanceof State state) { + updateState(channelUID, state); } } } diff --git a/bundles/org.openhab.binding.urtsi/src/main/java/org/openhab/binding/urtsi/internal/handler/UrtsiDeviceHandler.java b/bundles/org.openhab.binding.urtsi/src/main/java/org/openhab/binding/urtsi/internal/handler/UrtsiDeviceHandler.java index f0ba662b180..796a470e57c 100644 --- a/bundles/org.openhab.binding.urtsi/src/main/java/org/openhab/binding/urtsi/internal/handler/UrtsiDeviceHandler.java +++ b/bundles/org.openhab.binding.urtsi/src/main/java/org/openhab/binding/urtsi/internal/handler/UrtsiDeviceHandler.java @@ -91,8 +91,7 @@ public class UrtsiDeviceHandler extends BaseBridgeHandler { } String urtsiCommand = new StringBuilder(address).append(mappedChannel).append(rtsCommand.getActionKey()) .toString(); - boolean executedSuccessfully = writeString(urtsiCommand); - return executedSuccessfully; + return writeString(urtsiCommand); } /** diff --git a/bundles/org.openhab.binding.valloxmv/src/main/java/org/openhab/binding/valloxmv/internal/ValloxMVBindingConstants.java b/bundles/org.openhab.binding.valloxmv/src/main/java/org/openhab/binding/valloxmv/internal/ValloxMVBindingConstants.java index 387b768d4a3..453b8f0a582 100644 --- a/bundles/org.openhab.binding.valloxmv/src/main/java/org/openhab/binding/valloxmv/internal/ValloxMVBindingConstants.java +++ b/bundles/org.openhab.binding.valloxmv/src/main/java/org/openhab/binding/valloxmv/internal/ValloxMVBindingConstants.java @@ -12,9 +12,6 @@ */ package org.openhab.binding.valloxmv.internal; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -241,28 +238,24 @@ public class ValloxMVBindingConstants { /** * Set of writable channels that are Switches */ - public static final Set WRITABLE_CHANNELS_SWITCHES = Collections - .unmodifiableSet(new HashSet<>(Arrays.asList(CHANNEL_ONOFF, CHANNEL_BOOST_TIMER_ENABLED, - CHANNEL_FIREPLACE_TIMER_ENABLED, CHANNEL_EXTRA_TIMER_ENABLED, CHANNEL_WEEKLY_TIMER_ENABLED))); + public static final Set WRITABLE_CHANNELS_SWITCHES = Set.of(CHANNEL_ONOFF, CHANNEL_BOOST_TIMER_ENABLED, + CHANNEL_FIREPLACE_TIMER_ENABLED, CHANNEL_EXTRA_TIMER_ENABLED, CHANNEL_WEEKLY_TIMER_ENABLED); /** * * Set of writable channels that are dimensionless */ - public static final Set WRITABLE_CHANNELS_DIMENSIONLESS = Collections - .unmodifiableSet(new HashSet<>(Arrays.asList(CHANNEL_EXTR_FAN_BALANCE_BASE, CHANNEL_SUPP_FAN_BALANCE_BASE, - CHANNEL_HOME_SPEED_SETTING, CHANNEL_AWAY_SPEED_SETTING, CHANNEL_BOOST_SPEED_SETTING, - CHANNEL_BOOST_TIME, CHANNEL_BOOST_TIMER_ENABLED, CHANNEL_FIREPLACE_EXTR_FAN, - CHANNEL_FIREPLACE_SUPP_FAN, CHANNEL_FIREPLACE_TIME, CHANNEL_FIREPLACE_TIMER_ENABLED, - CHANNEL_EXTRA_EXTR_FAN, CHANNEL_EXTRA_SUPP_FAN, CHANNEL_EXTRA_TIME, CHANNEL_EXTRA_TIMER_ENABLED, - CHANNEL_WEEKLY_TIMER_ENABLED))); + public static final Set WRITABLE_CHANNELS_DIMENSIONLESS = Set.of(CHANNEL_EXTR_FAN_BALANCE_BASE, + CHANNEL_SUPP_FAN_BALANCE_BASE, CHANNEL_HOME_SPEED_SETTING, CHANNEL_AWAY_SPEED_SETTING, + CHANNEL_BOOST_SPEED_SETTING, CHANNEL_BOOST_TIME, CHANNEL_BOOST_TIMER_ENABLED, CHANNEL_FIREPLACE_EXTR_FAN, + CHANNEL_FIREPLACE_SUPP_FAN, CHANNEL_FIREPLACE_TIME, CHANNEL_FIREPLACE_TIMER_ENABLED, CHANNEL_EXTRA_EXTR_FAN, + CHANNEL_EXTRA_SUPP_FAN, CHANNEL_EXTRA_TIME, CHANNEL_EXTRA_TIMER_ENABLED, CHANNEL_WEEKLY_TIMER_ENABLED); /** * Set of writable channels that are temperatures */ - public static final Set WRITABLE_CHANNELS_TEMPERATURE = Collections - .unmodifiableSet(new HashSet<>(Arrays.asList(CHANNEL_HOME_AIR_TEMP_TARGET, CHANNEL_AWAY_AIR_TEMP_TARGET, - CHANNEL_BOOST_AIR_TEMP_TARGET, CHANNEL_EXTRA_AIR_TEMP_TARGET))); + public static final Set WRITABLE_CHANNELS_TEMPERATURE = Set.of(CHANNEL_HOME_AIR_TEMP_TARGET, + CHANNEL_AWAY_AIR_TEMP_TARGET, CHANNEL_BOOST_AIR_TEMP_TARGET, CHANNEL_EXTRA_AIR_TEMP_TARGET); // Thing configuration /** diff --git a/bundles/org.openhab.binding.valloxmv/src/main/java/org/openhab/binding/valloxmv/internal/ValloxMVHandlerFactory.java b/bundles/org.openhab.binding.valloxmv/src/main/java/org/openhab/binding/valloxmv/internal/ValloxMVHandlerFactory.java index fb8ab7eb038..b113fbd3c61 100644 --- a/bundles/org.openhab.binding.valloxmv/src/main/java/org/openhab/binding/valloxmv/internal/ValloxMVHandlerFactory.java +++ b/bundles/org.openhab.binding.valloxmv/src/main/java/org/openhab/binding/valloxmv/internal/ValloxMVHandlerFactory.java @@ -14,7 +14,6 @@ package org.openhab.binding.valloxmv.internal; import static org.openhab.binding.valloxmv.internal.ValloxMVBindingConstants.THING_TYPE_VALLOXMV; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -40,7 +39,7 @@ import org.osgi.service.component.annotations.Reference; @NonNullByDefault() public class ValloxMVHandlerFactory extends BaseThingHandlerFactory { - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_VALLOXMV); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_VALLOXMV); private final WebSocketClient webSocketClient; diff --git a/bundles/org.openhab.binding.vdr/src/main/java/org/openhab/binding/vdr/internal/VDRHandler.java b/bundles/org.openhab.binding.vdr/src/main/java/org/openhab/binding/vdr/internal/VDRHandler.java index 42cf79b847c..4d04b6f202a 100644 --- a/bundles/org.openhab.binding.vdr/src/main/java/org/openhab/binding/vdr/internal/VDRHandler.java +++ b/bundles/org.openhab.binding.vdr/src/main/java/org/openhab/binding/vdr/internal/VDRHandler.java @@ -101,7 +101,7 @@ public class VDRHandler extends BaseThingHandler { Map properties = editProperties(); // set vdr version to properties of thing String version = client.getSVDRPVersion(); - properties.put(VDRBindingConstants.PROPERTY_VERSION, version.toString()); + properties.put(VDRBindingConstants.PROPERTY_VERSION, version); // persist changes only if there are any changes. if (!editProperties().equals(properties)) { diff --git a/bundles/org.openhab.binding.vdr/src/main/java/org/openhab/binding/vdr/internal/VDRHandlerFactory.java b/bundles/org.openhab.binding.vdr/src/main/java/org/openhab/binding/vdr/internal/VDRHandlerFactory.java index e69ab663efa..dd37ca70850 100644 --- a/bundles/org.openhab.binding.vdr/src/main/java/org/openhab/binding/vdr/internal/VDRHandlerFactory.java +++ b/bundles/org.openhab.binding.vdr/src/main/java/org/openhab/binding/vdr/internal/VDRHandlerFactory.java @@ -14,7 +14,6 @@ package org.openhab.binding.vdr.internal; import static org.openhab.binding.vdr.internal.VDRBindingConstants.THING_TYPE_VDR; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -39,7 +38,7 @@ import org.osgi.service.component.annotations.Reference; @Component(configurationPid = "binding.vdr", service = ThingHandlerFactory.class) public class VDRHandlerFactory extends BaseThingHandlerFactory { - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_VDR); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_VDR); private final TimeZoneProvider timeZoneProvider; diff --git a/bundles/org.openhab.binding.vdr/src/main/java/org/openhab/binding/vdr/internal/svdrp/SVDRPChannel.java b/bundles/org.openhab.binding.vdr/src/main/java/org/openhab/binding/vdr/internal/svdrp/SVDRPChannel.java index f5dc9dc3655..88affe4316b 100644 --- a/bundles/org.openhab.binding.vdr/src/main/java/org/openhab/binding/vdr/internal/svdrp/SVDRPChannel.java +++ b/bundles/org.openhab.binding.vdr/src/main/java/org/openhab/binding/vdr/internal/svdrp/SVDRPChannel.java @@ -90,7 +90,7 @@ public class SVDRPChannel { public String toString() { StringBuilder sb = new StringBuilder(); if (number >= 0) { - sb.append("Number: " + String.valueOf(number) + System.lineSeparator()); + sb.append("Number: " + number + System.lineSeparator()); } sb.append("Name: " + name + System.lineSeparator()); return sb.toString(); diff --git a/bundles/org.openhab.binding.vdr/src/main/java/org/openhab/binding/vdr/internal/svdrp/SVDRPClientImpl.java b/bundles/org.openhab.binding.vdr/src/main/java/org/openhab/binding/vdr/internal/svdrp/SVDRPClientImpl.java index 669a6112b80..5941a666c4d 100644 --- a/bundles/org.openhab.binding.vdr/src/main/java/org/openhab/binding/vdr/internal/svdrp/SVDRPClientImpl.java +++ b/bundles/org.openhab.binding.vdr/src/main/java/org/openhab/binding/vdr/internal/svdrp/SVDRPClientImpl.java @@ -219,8 +219,7 @@ public class SVDRPClientImpl implements SVDRPClient { res = execute("STAT disk"); if (res.getCode() == 250) { - SVDRPDiskStatus status = SVDRPDiskStatus.parse(res.getMessage()); - return status; + return SVDRPDiskStatus.parse(res.getMessage()); } else { throw new SVDRPParseResponseException(res); } @@ -249,8 +248,7 @@ public class SVDRPClientImpl implements SVDRPClient { } if (res != null && res.getCode() == 215) { - SVDRPEpgEvent entry = SVDRPEpgEvent.parse(res.getMessage()); - return entry; + return SVDRPEpgEvent.parse(res.getMessage()); } else if (res != null) { throw new SVDRPParseResponseException(res); } else { @@ -272,8 +270,7 @@ public class SVDRPClientImpl implements SVDRPClient { res = execute("VOLU"); if (res.getCode() == 250) { - SVDRPVolume volume = SVDRPVolume.parse(res.getMessage()); - return volume; + return SVDRPVolume.parse(res.getMessage()); } else { throw new SVDRPParseResponseException(res); } @@ -295,8 +292,7 @@ public class SVDRPClientImpl implements SVDRPClient { res = execute(String.format("VOLU %s", String.valueOf(Math.round(newVolumeDouble)))); if (res.getCode() == 250) { - SVDRPVolume volume = SVDRPVolume.parse(res.getMessage()); - return volume; + return SVDRPVolume.parse(res.getMessage()); } else { throw new SVDRPParseResponseException(res); } @@ -352,8 +348,7 @@ public class SVDRPClientImpl implements SVDRPClient { res = execute("CHAN"); if (res.getCode() == 250) { - SVDRPChannel channel = SVDRPChannel.parse(res.getMessage()); - return channel; + return SVDRPChannel.parse(res.getMessage()); } else { throw new SVDRPParseResponseException(res); } @@ -374,8 +369,7 @@ public class SVDRPClientImpl implements SVDRPClient { res = execute(String.format("CHAN %s", number)); if (res.getCode() == 250) { - SVDRPChannel channel = SVDRPChannel.parse(res.getMessage()); - return channel; + return SVDRPChannel.parse(res.getMessage()); } else { throw new SVDRPParseResponseException(res); } diff --git a/bundles/org.openhab.binding.vdr/src/test/java/org/openhab/binding/vdr/internal/SVDRPEpgEventTest.java b/bundles/org.openhab.binding.vdr/src/test/java/org/openhab/binding/vdr/internal/SVDRPEpgEventTest.java index 9d8f66d6eb3..d0943f381df 100644 --- a/bundles/org.openhab.binding.vdr/src/test/java/org/openhab/binding/vdr/internal/SVDRPEpgEventTest.java +++ b/bundles/org.openhab.binding.vdr/src/test/java/org/openhab/binding/vdr/internal/SVDRPEpgEventTest.java @@ -33,32 +33,72 @@ import org.openhab.binding.vdr.internal.svdrp.SVDRPParseResponseException; */ @NonNullByDefault public class SVDRPEpgEventTest { - private final String epgResponseComplete = "C S19.2E-1-1201-28326 WDR HD Bielefeld\n" - + "E 9886 1610391600 900 4E F\n" + "T Tagesschau\n" + "S Aktuelle Nachrichten aus der Welt\n" - + "D Themen u.a.:|* Corona-Pandemie in Deutschland: Verschärfter Lockdown bundesweit in Kraft|* Entmachtung des US-Präsidenten: Demokraten planen Schritte gegen Trump|* Wintereinbruch in Bosnien-Herzegowina: Dramatische Lage der Flüchtlinge an der Grenze zu Kroatien\n" - + "G 20 80\n" + "X 2 03 deu stereo\n" + "X 2 03 deu ohne Audiodeskription\n" - + "X 3 01 deu Teletext-Untertitel\n" + "X 3 20 deu mit DVB-Untertitel\n" + "X 5 0B deu HD-Video\n" - + "V 1610391600\n" + "e\n" + "c\n" + "End of EPG data"; - private final String epgMissingSubtitle = "C S19.2E-1-1201-28326 WDR HD Bielefeld\n" - + "E 9886 1610391600 900 4E F\n" + "T Tagesschau\n" - + "D Themen u.a.:|* Corona-Pandemie in Deutschland: Verschärfter Lockdown bundesweit in Kraft|* Entmachtung des US-Präsidenten: Demokraten planen Schritte gegen Trump|* Wintereinbruch in Bosnien-Herzegowina: Dramatische Lage der Flüchtlinge an der Grenze zu Kroatien\n" - + "G 20 80\n" + "X 2 03 deu stereo\n" + "X 2 03 deu ohne Audiodeskription\n" - + "X 3 01 deu Teletext-Untertitel\n" + "X 3 20 deu mit DVB-Untertitel\n" + "X 5 0B deu HD-Video\n" - + "V 1610391600\n" + "e\n" + "c\n" + "End of EPG data"; + private final String epgResponseComplete = """ + C S19.2E-1-1201-28326 WDR HD Bielefeld + E 9886 1610391600 900 4E F + T Tagesschau + S Aktuelle Nachrichten aus der Welt + D Themen u.a.:|* Corona-Pandemie in Deutschland: Verschärfter Lockdown bundesweit in Kraft|* Entmachtung des US-Präsidenten: Demokraten planen Schritte gegen Trump|* Wintereinbruch in Bosnien-Herzegowina: Dramatische Lage der Flüchtlinge an der Grenze zu Kroatien + G 20 80 + X 2 03 deu stereo + X 2 03 deu ohne Audiodeskription + X 3 01 deu Teletext-Untertitel + X 3 20 deu mit DVB-Untertitel + X 5 0B deu HD-Video + V 1610391600 + e + c + End of EPG data\ + """; + private final String epgMissingSubtitle = """ + C S19.2E-1-1201-28326 WDR HD Bielefeld + E 9886 1610391600 900 4E F + T Tagesschau + D Themen u.a.:|* Corona-Pandemie in Deutschland: Verschärfter Lockdown bundesweit in Kraft|* Entmachtung des US-Präsidenten: Demokraten planen Schritte gegen Trump|* Wintereinbruch in Bosnien-Herzegowina: Dramatische Lage der Flüchtlinge an der Grenze zu Kroatien + G 20 80 + X 2 03 deu stereo + X 2 03 deu ohne Audiodeskription + X 3 01 deu Teletext-Untertitel + X 3 20 deu mit DVB-Untertitel + X 5 0B deu HD-Video + V 1610391600 + e + c + End of EPG data\ + """; private final String epgParseError = "E 9999999999999999999999999"; - private final String epgCorruptDate = "C S19.2E-1-1201-28326 WDR HD Bielefeld\n" + "E 9886 2a10391600 900 4E F\n" - + "T Tagesschau\n" - + "D Themen u.a.:|* Corona-Pandemie in Deutschland: Verschärfter Lockdown bundesweit in Kraft|* Entmachtung des US-Präsidenten: Demokraten planen Schritte gegen Trump|* Wintereinbruch in Bosnien-Herzegowina: Dramatische Lage der Flüchtlinge an der Grenze zu Kroatien\n" - + "G 20 80\n" + "X 2 03 deu stereo\n" + "X 2 03 deu ohne Audiodeskription\n" - + "X 3 01 deu Teletext-Untertitel\n" + "X 3 20 deu mit DVB-Untertitel\n" + "X 5 0B deu HD-Video\n" - + "V 1610391600\n" + "e\n" + "c\n" + "End of EPG data"; + private final String epgCorruptDate = """ + C S19.2E-1-1201-28326 WDR HD Bielefeld + E 9886 2a10391600 900 4E F + T Tagesschau + D Themen u.a.:|* Corona-Pandemie in Deutschland: Verschärfter Lockdown bundesweit in Kraft|* Entmachtung des US-Präsidenten: Demokraten planen Schritte gegen Trump|* Wintereinbruch in Bosnien-Herzegowina: Dramatische Lage der Flüchtlinge an der Grenze zu Kroatien + G 20 80 + X 2 03 deu stereo + X 2 03 deu ohne Audiodeskription + X 3 01 deu Teletext-Untertitel + X 3 20 deu mit DVB-Untertitel + X 5 0B deu HD-Video + V 1610391600 + e + c + End of EPG data\ + """; - private final String epgMissingEnd = "C S19.2E-1-1201-28326 WDR HD Bielefeld\n" + "E 9886 1610391600 900 4E F\n" - + "T Tagesschau\n" - + "D Themen u.a.:|* Corona-Pandemie in Deutschland: Verschärfter Lockdown bundesweit in Kraft|* Entmachtung des US-Präsidenten: Demokraten planen Schritte gegen Trump|* Wintereinbruch in Bosnien-Herzegowina: Dramatische Lage der Flüchtlinge an der Grenze zu Kroatien\n" - + "G 20 80\n" + "X 2 03 deu stereo\n" + "X 2 03 deu ohne Audiodeskription\n" - + "X 3 01 deu Teletext-Untertitel\n" + "X 3 20 deu mit DVB-Untertitel\n" + "X 5 0B deu HD-Video\n" - + "V 1610391600\n" + "e\n" + "c\n"; + private final String epgMissingEnd = """ + C S19.2E-1-1201-28326 WDR HD Bielefeld + E 9886 1610391600 900 4E F + T Tagesschau + D Themen u.a.:|* Corona-Pandemie in Deutschland: Verschärfter Lockdown bundesweit in Kraft|* Entmachtung des US-Präsidenten: Demokraten planen Schritte gegen Trump|* Wintereinbruch in Bosnien-Herzegowina: Dramatische Lage der Flüchtlinge an der Grenze zu Kroatien + G 20 80 + X 2 03 deu stereo + X 2 03 deu ohne Audiodeskription + X 3 01 deu Teletext-Untertitel + X 3 20 deu mit DVB-Untertitel + X 5 0B deu HD-Video + V 1610391600 + e + c + """; @Test public void testParseEpgEventComplete() throws SVDRPException, ParseException { diff --git a/bundles/org.openhab.binding.vdr/src/test/java/org/openhab/binding/vdr/internal/SVDRPTimerListTest.java b/bundles/org.openhab.binding.vdr/src/test/java/org/openhab/binding/vdr/internal/SVDRPTimerListTest.java index 0ced7f52f5c..6804db4f1ce 100644 --- a/bundles/org.openhab.binding.vdr/src/test/java/org/openhab/binding/vdr/internal/SVDRPTimerListTest.java +++ b/bundles/org.openhab.binding.vdr/src/test/java/org/openhab/binding/vdr/internal/SVDRPTimerListTest.java @@ -27,10 +27,14 @@ import org.openhab.binding.vdr.internal.svdrp.SVDRPTimerList; */ @NonNullByDefault public class SVDRPTimerListTest { - private final String timerListResponseTimerActive = "1 1:1:2021-01-12:2013:2110:50:99:Charité (1/6)~Eiserne Lunge:Test\n" - + "2 9:1:2021-01-12:2058:2200:50:99:Charité (2/6)~Blutsauger:Test"; - private final String timerListResponseTimerNotActive = "1 1:1:2021-01-12:2013:2110:50:99:Charité (1/6)~Eiserne Lunge:Test\n" - + "2 1:1:2021-01-12:2058:2200:50:99:Charité (2/6)~Blutsauger:Test"; + private final String timerListResponseTimerActive = """ + 1 1:1:2021-01-12:2013:2110:50:99:Charité (1/6)~Eiserne Lunge:Test + 2 9:1:2021-01-12:2058:2200:50:99:Charité (2/6)~Blutsauger:Test\ + """; + private final String timerListResponseTimerNotActive = """ + 1 1:1:2021-01-12:2013:2110:50:99:Charité (1/6)~Eiserne Lunge:Test + 2 1:1:2021-01-12:2058:2200:50:99:Charité (2/6)~Blutsauger:Test\ + """; @Test public void testParseTimerList() throws SVDRPException { diff --git a/bundles/org.openhab.binding.vektiva/src/main/java/org/openhab/binding/vektiva/internal/VektivaHandlerFactory.java b/bundles/org.openhab.binding.vektiva/src/main/java/org/openhab/binding/vektiva/internal/VektivaHandlerFactory.java index 131a386083d..a96367b3c2d 100644 --- a/bundles/org.openhab.binding.vektiva/src/main/java/org/openhab/binding/vektiva/internal/VektivaHandlerFactory.java +++ b/bundles/org.openhab.binding.vektiva/src/main/java/org/openhab/binding/vektiva/internal/VektivaHandlerFactory.java @@ -14,7 +14,6 @@ package org.openhab.binding.vektiva.internal; import static org.openhab.binding.vektiva.internal.VektivaBindingConstants.THING_TYPE_SMARWI; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -43,7 +42,7 @@ import org.osgi.service.component.annotations.Reference; @Component(configurationPid = "binding.vektiva", service = ThingHandlerFactory.class) public class VektivaHandlerFactory extends BaseThingHandlerFactory { - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_SMARWI); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_SMARWI); /** * the shared http client diff --git a/bundles/org.openhab.binding.vektiva/src/main/java/org/openhab/binding/vektiva/internal/handler/VektivaSmarwiHandler.java b/bundles/org.openhab.binding.vektiva/src/main/java/org/openhab/binding/vektiva/internal/handler/VektivaSmarwiHandler.java index 404be96695b..ceee0ff2d4f 100644 --- a/bundles/org.openhab.binding.vektiva/src/main/java/org/openhab/binding/vektiva/internal/handler/VektivaSmarwiHandler.java +++ b/bundles/org.openhab.binding.vektiva/src/main/java/org/openhab/binding/vektiva/internal/handler/VektivaSmarwiHandler.java @@ -241,7 +241,7 @@ public class VektivaSmarwiHandler extends BaseThingHandler { statusMessage = "Blocked"; } - int position = values.getOrDefault("pos", NA).equals("o") ? 0 : 100; + int position = "o".equals(values.getOrDefault("pos", NA)) ? 0 : 100; if (position == 0 && lastPosition != -1) { position = lastPosition; } diff --git a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/VelbusBindingConstants.java b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/VelbusBindingConstants.java index de5b7c77b46..7c975d992f4 100644 --- a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/VelbusBindingConstants.java +++ b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/VelbusBindingConstants.java @@ -12,9 +12,6 @@ */ package org.openhab.binding.velbus.internal; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -89,20 +86,19 @@ public class VelbusBindingConstants { public static final ThingTypeUID THING_TYPE_VMB4PB = new ThingTypeUID(BINDING_ID, "vmb4pb"); // thing type sets - public static final Set BRIDGE_THING_TYPES_UIDS = Collections - .unmodifiableSet(new HashSet<>(Arrays.asList(BRIDGE_THING_TYPE, NETWORK_BRIDGE_THING_TYPE))); - public static final Set SUPPORTED_THING_TYPES_UIDS = Collections.unmodifiableSet( - new HashSet<>(Arrays.asList(THING_TYPE_VMB1BL, THING_TYPE_VMB1BLS, THING_TYPE_VMB1DM, THING_TYPE_VMB1LED, - THING_TYPE_VMB1RY, THING_TYPE_VMB1RYNO, THING_TYPE_VMB1RYNOS, THING_TYPE_VMB1RYS, THING_TYPE_VMB1TS, - THING_TYPE_VMB2BL, THING_TYPE_VMB2BLE, THING_TYPE_VMB2PBN, THING_TYPE_VMB4AN, THING_TYPE_VMB4DC, - THING_TYPE_VMB4RY, THING_TYPE_VMB4RYLD, THING_TYPE_VMB4RYNO, THING_TYPE_VMB6IN, THING_TYPE_VMB6PBN, - THING_TYPE_VMB7IN, THING_TYPE_VMB8IR, THING_TYPE_VMB8PB, THING_TYPE_VMB8PBU, THING_TYPE_VMBDME, - THING_TYPE_VMBDMI, THING_TYPE_VMBDMIR, THING_TYPE_VMBEL1, THING_TYPE_VMBEL2, THING_TYPE_VMBEL4, - THING_TYPE_VMBELO, THING_TYPE_VMBELPIR, THING_TYPE_VMBGP1, THING_TYPE_VMBGP1_2, THING_TYPE_VMBGP2, - THING_TYPE_VMBGP2_2, THING_TYPE_VMBGP4, THING_TYPE_VMBGP4_2, THING_TYPE_VMBGP4PIR, - THING_TYPE_VMBGP4PIR_2, THING_TYPE_VMBGPO, THING_TYPE_VMBGPOD, THING_TYPE_VMBGPOD_2, - THING_TYPE_VMBMETEO, THING_TYPE_VMBPIRC, THING_TYPE_VMBPIRM, THING_TYPE_VMBPIRO, - THING_TYPE_VMBRFR8S, THING_TYPE_VMBVP1, THING_TYPE_VMBKP, THING_TYPE_VMBIN, THING_TYPE_VMB4PB))); + public static final Set BRIDGE_THING_TYPES_UIDS = Set.of(BRIDGE_THING_TYPE, + NETWORK_BRIDGE_THING_TYPE); + public static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_VMB1BL, THING_TYPE_VMB1BLS, + THING_TYPE_VMB1DM, THING_TYPE_VMB1LED, THING_TYPE_VMB1RY, THING_TYPE_VMB1RYNO, THING_TYPE_VMB1RYNOS, + THING_TYPE_VMB1RYS, THING_TYPE_VMB1TS, THING_TYPE_VMB2BL, THING_TYPE_VMB2BLE, THING_TYPE_VMB2PBN, + THING_TYPE_VMB4AN, THING_TYPE_VMB4DC, THING_TYPE_VMB4RY, THING_TYPE_VMB4RYLD, THING_TYPE_VMB4RYNO, + THING_TYPE_VMB6IN, THING_TYPE_VMB6PBN, THING_TYPE_VMB7IN, THING_TYPE_VMB8IR, THING_TYPE_VMB8PB, + THING_TYPE_VMB8PBU, THING_TYPE_VMBDME, THING_TYPE_VMBDMI, THING_TYPE_VMBDMIR, THING_TYPE_VMBEL1, + THING_TYPE_VMBEL2, THING_TYPE_VMBEL4, THING_TYPE_VMBELO, THING_TYPE_VMBELPIR, THING_TYPE_VMBGP1, + THING_TYPE_VMBGP1_2, THING_TYPE_VMBGP2, THING_TYPE_VMBGP2_2, THING_TYPE_VMBGP4, THING_TYPE_VMBGP4_2, + THING_TYPE_VMBGP4PIR, THING_TYPE_VMBGP4PIR_2, THING_TYPE_VMBGPO, THING_TYPE_VMBGPOD, THING_TYPE_VMBGPOD_2, + THING_TYPE_VMBMETEO, THING_TYPE_VMBPIRC, THING_TYPE_VMBPIRM, THING_TYPE_VMBPIRO, THING_TYPE_VMBRFR8S, + THING_TYPE_VMBVP1, THING_TYPE_VMBKP, THING_TYPE_VMBIN, THING_TYPE_VMB4PB); // Velbus module types public static final byte MODULE_TYPE_VMB8PB = 0x01; diff --git a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/discovery/VelbusThingDiscoveryService.java b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/discovery/VelbusThingDiscoveryService.java index 18bfb839951..0ea2bac0ebf 100644 --- a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/discovery/VelbusThingDiscoveryService.java +++ b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/discovery/VelbusThingDiscoveryService.java @@ -384,8 +384,7 @@ public class VelbusThingDiscoveryService extends AbstractDiscoveryService @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof VelbusBridgeHandler) { - final VelbusBridgeHandler velbusBridgeHandler = (VelbusBridgeHandler) handler; + if (handler instanceof VelbusBridgeHandler velbusBridgeHandler) { this.velbusBridgeHandler = velbusBridgeHandler; velbusBridgeHandler.setDefaultPacketListener(this); } diff --git a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusBlindsHandler.java b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusBlindsHandler.java index c191cdf9e28..d6cf637141a 100644 --- a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusBlindsHandler.java +++ b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusBlindsHandler.java @@ -69,9 +69,8 @@ public class VelbusBlindsHandler extends VelbusThingHandler { byte[] packetBytes = packet.getBytes(); velbusBridgeHandler.sendPacket(packetBytes); - } else if (command instanceof UpDownType) { - UpDownType s = (UpDownType) command; - if (s == UpDownType.UP) { + } else if (command instanceof UpDownType upDownCommand) { + if (upDownCommand == UpDownType.UP) { byte commandByte = COMMAND_BLIND_UP; VelbusBlindUpDownPacket packet = new VelbusBlindUpDownPacket( @@ -88,18 +87,17 @@ public class VelbusBlindsHandler extends VelbusThingHandler { byte[] packetBytes = packet.getBytes(); velbusBridgeHandler.sendPacket(packetBytes); } - } else if (command instanceof StopMoveType) { - StopMoveType s = (StopMoveType) command; - if (s == StopMoveType.STOP) { + } else if (command instanceof StopMoveType stopMoveCommand) { + if (stopMoveCommand == StopMoveType.STOP) { VelbusBlindOffPacket packet = new VelbusBlindOffPacket( getModuleAddress().getChannelIdentifier(channelUID)); byte[] packetBytes = packet.getBytes(); velbusBridgeHandler.sendPacket(packetBytes); } - } else if (command instanceof PercentType) { + } else if (command instanceof PercentType percentCommand) { VelbusBlindPositionPacket packet = new VelbusBlindPositionPacket( - getModuleAddress().getChannelIdentifier(channelUID), ((PercentType) command).byteValue()); + getModuleAddress().getChannelIdentifier(channelUID), percentCommand.byteValue()); byte[] packetBytes = packet.getBytes(); velbusBridgeHandler.sendPacket(packetBytes); diff --git a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusBridgeHandler.java b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusBridgeHandler.java index 8d11b846292..7d7fa266eff 100644 --- a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusBridgeHandler.java +++ b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusBridgeHandler.java @@ -20,9 +20,9 @@ import java.io.OutputStream; import java.time.Instant; import java.time.ZonedDateTime; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.Set; import java.util.TimeZone; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -172,32 +172,32 @@ public abstract class VelbusBridgeHandler extends BaseBridgeHandler { } case CHANNEL_BRIDGE_CLOCK_ALARM1_WAKEUP_HOUR: case CHANNEL_BRIDGE_CLOCK_ALARM2_WAKEUP_HOUR: { - if (command instanceof DecimalType) { - byte wakeupHour = ((DecimalType) command).byteValue(); + if (command instanceof DecimalType decimalCommand) { + byte wakeupHour = decimalCommand.byteValue(); alarmClock.setWakeupHour(wakeupHour); } break; } case CHANNEL_BRIDGE_CLOCK_ALARM1_WAKEUP_MINUTE: case CHANNEL_BRIDGE_CLOCK_ALARM2_WAKEUP_MINUTE: { - if (command instanceof DecimalType) { - byte wakeupMinute = ((DecimalType) command).byteValue(); + if (command instanceof DecimalType decimalCommand) { + byte wakeupMinute = decimalCommand.byteValue(); alarmClock.setWakeupMinute(wakeupMinute); } break; } case CHANNEL_BRIDGE_CLOCK_ALARM1_BEDTIME_HOUR: case CHANNEL_BRIDGE_CLOCK_ALARM2_BEDTIME_HOUR: { - if (command instanceof DecimalType) { - byte bedTimeHour = ((DecimalType) command).byteValue(); + if (command instanceof DecimalType decimalCommand) { + byte bedTimeHour = decimalCommand.byteValue(); alarmClock.setBedtimeHour(bedTimeHour); } break; } case CHANNEL_BRIDGE_CLOCK_ALARM1_BEDTIME_MINUTE: case CHANNEL_BRIDGE_CLOCK_ALARM2_BEDTIME_MINUTE: { - if (command instanceof DecimalType) { - byte bedTimeMinute = ((DecimalType) command).byteValue(); + if (command instanceof DecimalType decimalCommand) { + byte bedTimeMinute = decimalCommand.byteValue(); alarmClock.setBedtimeMinute(bedTimeMinute); } break; @@ -361,7 +361,7 @@ public abstract class VelbusBridgeHandler extends BaseBridgeHandler { @Override public Collection> getServices() { - return Collections.singleton(VelbusThingDiscoveryService.class); + return Set.of(VelbusThingDiscoveryService.class); } public void setDefaultPacketListener(VelbusPacketListener velbusPacketListener) { diff --git a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusDimmerHandler.java b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusDimmerHandler.java index 77f21b8d7ce..5042378cc0c 100644 --- a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusDimmerHandler.java +++ b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusDimmerHandler.java @@ -72,17 +72,16 @@ public class VelbusDimmerHandler extends VelbusThingHandler { byte[] packetBytes = packet.getBytes(); velbusBridgeHandler.sendPacket(packetBytes); - } else if (command instanceof PercentType) { + } else if (command instanceof PercentType percentCommand) { byte commandByte = COMMAND_SET_VALUE; VelbusDimmerPacket packet = new VelbusDimmerPacket(getModuleAddress().getChannelIdentifier(channelUID), - commandByte, ((PercentType) command).byteValue(), this.dimmerConfig.dimspeed, - isFirstGenerationDevice()); + commandByte, percentCommand.byteValue(), this.dimmerConfig.dimspeed, isFirstGenerationDevice()); byte[] packetBytes = packet.getBytes(); velbusBridgeHandler.sendPacket(packetBytes); - } else if (command instanceof OnOffType) { - byte commandByte = determineCommandByte((OnOffType) command); + } else if (command instanceof OnOffType onOffCommand) { + byte commandByte = determineCommandByte(onOffCommand); VelbusDimmerPacket packet = new VelbusDimmerPacket(getModuleAddress().getChannelIdentifier(channelUID), commandByte, (byte) 0x00, this.dimmerConfig.dimspeed, isFirstGenerationDevice()); diff --git a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusMemoHandler.java b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusMemoHandler.java index 291d94296aa..86fcb928886 100644 --- a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusMemoHandler.java +++ b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusMemoHandler.java @@ -47,8 +47,8 @@ public abstract class VelbusMemoHandler extends VelbusThermostatHandler { return; } - if (channelUID.equals(memoChannel) && command instanceof StringType) { - String memoText = ((StringType) command).toFullString(); + if (channelUID.equals(memoChannel) && command instanceof StringType stringCommand) { + String memoText = stringCommand.toFullString(); String trucatedMemoText = memoText.substring(0, Math.min(memoText.length(), MEMO_TEXT_MAX_LENGTH)); String[] splittedMemoText = trucatedMemoText.split("(?<=\\G.....)"); diff --git a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusRelayHandler.java b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusRelayHandler.java index 7209ce76f7a..13931d71c74 100644 --- a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusRelayHandler.java +++ b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusRelayHandler.java @@ -61,8 +61,8 @@ public class VelbusRelayHandler extends VelbusThingHandler { byte[] packetBytes = packet.getBytes(); velbusBridgeHandler.sendPacket(packetBytes); - } else if (command instanceof OnOffType) { - byte commandByte = determineCommandByte((OnOffType) command); + } else if (command instanceof OnOffType onOffCommand) { + byte commandByte = determineCommandByte(onOffCommand); VelbusRelayPacket packet = new VelbusRelayPacket(getModuleAddress().getChannelIdentifier(channelUID), commandByte); diff --git a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusRelayWithInputHandler.java b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusRelayWithInputHandler.java index daf91de7d32..a543bae88b1 100644 --- a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusRelayWithInputHandler.java +++ b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusRelayWithInputHandler.java @@ -58,17 +58,15 @@ public class VelbusRelayWithInputHandler extends VelbusRelayHandler { return; } - if (isButtonChannel(channelUID) && command instanceof StringType) { - StringType stringTypeCommand = (StringType) command; - - if (stringTypeCommand.equals(PRESSED) || stringTypeCommand.equals(LONG_PRESSED)) { + if (isButtonChannel(channelUID) && command instanceof StringType stringCommand) { + if (stringCommand.equals(PRESSED) || stringCommand.equals(LONG_PRESSED)) { VelbusButtonPacket packet = new VelbusButtonPacket(getModuleAddress().getChannelIdentifier(channelUID)); packet.Pressed(); velbusBridgeHandler.sendPacket(packet.getBytes()); triggerChannel("CH6t", CommonTriggerEvents.PRESSED); - if (stringTypeCommand.equals(LONG_PRESSED)) { + if (stringCommand.equals(LONG_PRESSED)) { packet.LongPressed(); velbusBridgeHandler.sendPacket(packet.getBytes()); triggerChannel("CH6t", CommonTriggerEvents.LONG_PRESSED); diff --git a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusSensorHandler.java b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusSensorHandler.java index b86cf3e3d9e..72a3a54c82e 100644 --- a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusSensorHandler.java +++ b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusSensorHandler.java @@ -69,19 +69,17 @@ public class VelbusSensorHandler extends VelbusThingHandler { return; } - if (isFeedbackChannel(channelUID) && command instanceof StringType) { + if (isFeedbackChannel(channelUID) && command instanceof StringType stringCommand) { byte commandByte; - - StringType stringTypeCommand = (StringType) command; - if (stringTypeCommand.equals(SET_LED)) { + if (stringCommand.equals(SET_LED)) { commandByte = COMMAND_SET_LED; - } else if (stringTypeCommand.equals(SLOW_BLINK_LED)) { + } else if (stringCommand.equals(SLOW_BLINK_LED)) { commandByte = COMMAND_SLOW_BLINK_LED; - } else if (stringTypeCommand.equals(FAST_BLINK_LED)) { + } else if (stringCommand.equals(FAST_BLINK_LED)) { commandByte = COMMAND_FAST_BLINK_LED; - } else if (stringTypeCommand.equals(VERY_FAST_BLINK_LED)) { + } else if (stringCommand.equals(VERY_FAST_BLINK_LED)) { commandByte = COMMAND_VERY_FAST_BLINK_LED; - } else if (stringTypeCommand.equals(CLEAR_LED)) { + } else if (stringCommand.equals(CLEAR_LED)) { commandByte = COMMAND_CLEAR_LED; } else { throw new UnsupportedOperationException( @@ -95,10 +93,8 @@ public class VelbusSensorHandler extends VelbusThingHandler { velbusBridgeHandler.sendPacket(packetBytes); } - if (isButtonChannel(channelUID) && command instanceof StringType) { - StringType stringTypeCommand = (StringType) command; - - if (stringTypeCommand.equals(PRESSED) || stringTypeCommand.equals(LONG_PRESSED)) { + if (isButtonChannel(channelUID) && command instanceof StringType stringCommand) { + if (stringCommand.equals(PRESSED) || stringCommand.equals(LONG_PRESSED)) { VelbusButtonPacket packet = new VelbusButtonPacket(getModuleAddress().getChannelIdentifier(channelUID)); packet.Pressed(); @@ -106,7 +102,7 @@ public class VelbusSensorHandler extends VelbusThingHandler { triggerChannel("input#CH" + getModuleAddress().getChannelNumber(channelUID), CommonTriggerEvents.PRESSED); - if (stringTypeCommand.equals(LONG_PRESSED)) { + if (stringCommand.equals(LONG_PRESSED)) { packet.LongPressed(); velbusBridgeHandler.sendPacket(packet.getBytes()); triggerChannel("input#CH" + getModuleAddress().getChannelNumber(channelUID), @@ -141,7 +137,6 @@ public class VelbusSensorHandler extends VelbusThingHandler { byte command = packet[4]; if (command == COMMAND_PUSH_BUTTON_STATUS && packet.length >= 6) { - for (int channel = 0; channel < 8; channel++) { byte channelMask = (byte) Math.pow(2, channel); diff --git a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusSensorWithAlarmClockHandler.java b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusSensorWithAlarmClockHandler.java index e6258b6e9d1..364411c1d72 100644 --- a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusSensorWithAlarmClockHandler.java +++ b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusSensorWithAlarmClockHandler.java @@ -180,32 +180,32 @@ public class VelbusSensorWithAlarmClockHandler extends VelbusSensorHandler { } case CHANNEL_MODULE_CLOCK_ALARM1_WAKEUP_HOUR: case CHANNEL_MODULE_CLOCK_ALARM2_WAKEUP_HOUR: { - if (command instanceof DecimalType) { - byte wakeupHour = ((DecimalType) command).byteValue(); + if (command instanceof DecimalType decimalCommand) { + byte wakeupHour = decimalCommand.byteValue(); alarmClock.setWakeupHour(wakeupHour); } break; } case CHANNEL_MODULE_CLOCK_ALARM1_WAKEUP_MINUTE: case CHANNEL_MODULE_CLOCK_ALARM2_WAKEUP_MINUTE: { - if (command instanceof DecimalType) { - byte wakeupMinute = ((DecimalType) command).byteValue(); + if (command instanceof DecimalType decimalCommand) { + byte wakeupMinute = decimalCommand.byteValue(); alarmClock.setWakeupMinute(wakeupMinute); } break; } case CHANNEL_MODULE_CLOCK_ALARM1_BEDTIME_HOUR: case CHANNEL_MODULE_CLOCK_ALARM2_BEDTIME_HOUR: { - if (command instanceof DecimalType) { - byte bedTimeHour = ((DecimalType) command).byteValue(); + if (command instanceof DecimalType decimalCommand) { + byte bedTimeHour = decimalCommand.byteValue(); alarmClock.setBedtimeHour(bedTimeHour); } break; } case CHANNEL_MODULE_CLOCK_ALARM1_BEDTIME_MINUTE: case CHANNEL_MODULE_CLOCK_ALARM2_BEDTIME_MINUTE: { - if (command instanceof DecimalType) { - byte bedTimeMinute = ((DecimalType) command).byteValue(); + if (command instanceof DecimalType decimalCommand) { + byte bedTimeMinute = decimalCommand.byteValue(); alarmClock.setBedtimeMinute(bedTimeMinute); } break; diff --git a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusThermostatHandler.java b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusThermostatHandler.java index a4169030e76..281d22c0a38 100644 --- a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusThermostatHandler.java +++ b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusThermostatHandler.java @@ -110,8 +110,8 @@ public abstract class VelbusThermostatHandler extends VelbusTemperatureSensorHan } else if (isThermostatChannel(channelUID) && (command instanceof QuantityType || command instanceof DecimalType)) { byte temperatureVariable = determineTemperatureVariable(channelUID); - QuantityType temperatureInDegreesCelcius = (command instanceof QuantityType) - ? ((QuantityType) command).toUnit(SIUnits.CELSIUS) + QuantityType temperatureInDegreesCelcius = (command instanceof QuantityType qt) + ? qt.toUnit(SIUnits.CELSIUS) : new QuantityType<>(((DecimalType) command), SIUnits.CELSIUS); if (temperatureInDegreesCelcius != null) { @@ -124,8 +124,8 @@ public abstract class VelbusThermostatHandler extends VelbusTemperatureSensorHan byte[] packetBytes = packet.getBytes(); velbusBridgeHandler.sendPacket(packetBytes); } - } else if (channelUID.equals(operatingModeChannel) && command instanceof StringType) { - byte commandByte = ((StringType) command).equals(OPERATING_MODE_HEATING) ? COMMAND_SET_HEATING_MODE + } else if (channelUID.equals(operatingModeChannel) && command instanceof StringType stringCommand) { + byte commandByte = stringCommand.equals(OPERATING_MODE_HEATING) ? COMMAND_SET_HEATING_MODE : COMMAND_SET_COOLING_MODE; VelbusThermostatOperatingModePacket packet = new VelbusThermostatOperatingModePacket( @@ -133,15 +133,13 @@ public abstract class VelbusThermostatHandler extends VelbusTemperatureSensorHan byte[] packetBytes = packet.getBytes(); velbusBridgeHandler.sendPacket(packetBytes); - } else if (channelUID.equals(modeChannel) && command instanceof StringType) { + } else if (channelUID.equals(modeChannel) && command instanceof StringType stringCommand) { byte commandByte = COMMAND_SWITCH_TO_SAFE_MODE; - - StringType stringTypeCommand = (StringType) command; - if (stringTypeCommand.equals(MODE_COMFORT)) { + if (stringCommand.equals(MODE_COMFORT)) { commandByte = COMMAND_SWITCH_TO_COMFORT_MODE; - } else if (stringTypeCommand.equals(MODE_DAY)) { + } else if (stringCommand.equals(MODE_DAY)) { commandByte = COMMAND_SWITCH_TO_DAY_MODE; - } else if (stringTypeCommand.equals(MODE_NIGHT)) { + } else if (stringCommand.equals(MODE_NIGHT)) { commandByte = COMMAND_SWITCH_TO_NIGHT_MODE; } diff --git a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusThingHandler.java b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusThingHandler.java index cd0e9af631b..2f2acabd322 100644 --- a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusThingHandler.java +++ b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusThingHandler.java @@ -222,8 +222,7 @@ public abstract class VelbusThingHandler extends BaseThingHandler implements Vel return null; } ThingHandler bridgeHandler = bridge.getHandler(); - if (bridgeHandler instanceof VelbusBridgeHandler) { - VelbusBridgeHandler velbusBridgeHandler = (VelbusBridgeHandler) bridgeHandler; + if (bridgeHandler instanceof VelbusBridgeHandler velbusBridgeHandler) { this.velbusBridgeHandler = velbusBridgeHandler; if (velbusModuleAddress != null) { diff --git a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusVMB4ANHandler.java b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusVMB4ANHandler.java index 22f0bdc6ab9..482c96d3ba7 100644 --- a/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusVMB4ANHandler.java +++ b/bundles/org.openhab.binding.velbus/src/main/java/org/openhab/binding/velbus/internal/handler/VelbusVMB4ANHandler.java @@ -124,10 +124,10 @@ public class VelbusVMB4ANHandler extends VelbusSensorWithAlarmClockHandler { byte[] packetBytes = packet.getBytes(); velbusBridgeHandler.sendPacket(packetBytes); - } else if (command instanceof PercentType && isAnalogOutputChannel(channelUID)) { + } else if (command instanceof PercentType percentCommand && isAnalogOutputChannel(channelUID)) { VelbusDimmerPacket packet = new VelbusDimmerPacket( new VelbusChannelIdentifier(this.getModuleAddress().getAddress(), channelByte), COMMAND_SET_VALUE, - ((PercentType) command).byteValue(), 0x00, false); + percentCommand.byteValue(), 0x00, false); byte[] packetBytes = packet.getBytes(); velbusBridgeHandler.sendPacket(packetBytes); diff --git a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/action/VeluxActions.java b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/action/VeluxActions.java index de803dc5667..7fcd0842c74 100644 --- a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/action/VeluxActions.java +++ b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/action/VeluxActions.java @@ -41,8 +41,8 @@ public class VeluxActions implements ThingActions { @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof VeluxBridgeHandler) { - this.bridgeHandler = (VeluxBridgeHandler) handler; + if (handler instanceof VeluxBridgeHandler veluxBridgeHandler) { + this.bridgeHandler = veluxBridgeHandler; } } diff --git a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/bridge/json/JCgetFirmware.java b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/bridge/json/JCgetFirmware.java index 5d35febd6fc..cbdf1f37b55 100644 --- a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/bridge/json/JCgetFirmware.java +++ b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/bridge/json/JCgetFirmware.java @@ -156,7 +156,6 @@ class JCgetFirmware extends GetFirmware implements JsonBridgeCommunicationProtoc */ @Override public VeluxGwFirmware getFirmware() { - VeluxGwFirmware gwFirmware = new VeluxGwFirmware(response.data.version); - return gwFirmware; + return new VeluxGwFirmware(response.data.version); } } diff --git a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/bridge/json/JCgetLANConfig.java b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/bridge/json/JCgetLANConfig.java index e584773588b..80d8fc7e4cc 100644 --- a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/bridge/json/JCgetLANConfig.java +++ b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/bridge/json/JCgetLANConfig.java @@ -179,8 +179,7 @@ class JCgetLANConfig extends GetLANConfig implements BridgeCommunicationProtocol */ @Override public VeluxGwLAN getLANConfig() { - VeluxGwLAN gwLAN = new VeluxGwLAN(response.data.ipAddress, response.data.subnetMask, - response.data.defaultGateway, response.data.dhcp); - return gwLAN; + return new VeluxGwLAN(response.data.ipAddress, response.data.subnetMask, response.data.defaultGateway, + response.data.dhcp); } } diff --git a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/bridge/json/JCgetWLANConfig.java b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/bridge/json/JCgetWLANConfig.java index 07302c32bb6..1c1900d13c1 100644 --- a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/bridge/json/JCgetWLANConfig.java +++ b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/bridge/json/JCgetWLANConfig.java @@ -175,7 +175,6 @@ class JCgetWLANConfig extends GetWLANConfig implements JsonBridgeCommunicationPr */ @Override public VeluxGwWLAN getWLANConfig() { - VeluxGwWLAN gwWLAN = new VeluxGwWLAN(response.data.name, response.data.password); - return gwWLAN; + return new VeluxGwWLAN(response.data.name, response.data.password); } } diff --git a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/factory/VeluxHandlerFactory.java b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/factory/VeluxHandlerFactory.java index 628d9f023f3..952f3c8ee21 100644 --- a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/factory/VeluxHandlerFactory.java +++ b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/factory/VeluxHandlerFactory.java @@ -199,10 +199,10 @@ public class VeluxHandlerFactory extends BaseThingHandlerFactory { veluxBindingHandlers.remove(thingHandler); } else // Handle Bridge removal - if (thingHandler instanceof VeluxBridgeHandler) { + if (thingHandler instanceof VeluxBridgeHandler veluxBridgeHandler) { logger.trace("removeHandler() removing bridge '{}'.", thingHandler.toString()); veluxBridgeHandlers.remove(thingHandler); - unregisterDeviceDiscoveryService((VeluxBridgeHandler) thingHandler); + unregisterDeviceDiscoveryService(veluxBridgeHandler); } else // Handle removal of Things behind the Bridge if (thingHandler instanceof VeluxHandler) { diff --git a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/handler/ChannelActuatorPosition.java b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/handler/ChannelActuatorPosition.java index bf9a9ee5619..3e78acb2b78 100644 --- a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/handler/ChannelActuatorPosition.java +++ b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/handler/ChannelActuatorPosition.java @@ -228,10 +228,10 @@ final class ChannelActuatorPosition extends ChannelHandlerTemplate { switch (channelId) { case CHANNEL_VANE_POSITION: - if (command instanceof PercentType) { + if (command instanceof PercentType percentCommand) { VeluxProduct existingProductClone = existingProducts.get(productBridgeIndex).clone(); - existingProductClone.setVanePosition( - new VeluxProductPosition((PercentType) command).getPositionAsVeluxType()); + existingProductClone + .setVanePosition(new VeluxProductPosition(percentCommand).getPositionAsVeluxType()); functionalParameters = existingProductClone.getFunctionalParameters(); } break; @@ -243,12 +243,12 @@ final class ChannelActuatorPosition extends ChannelHandlerTemplate { : new VeluxProductPosition(PercentType.HUNDRED); } else if (command instanceof StopMoveType) { mainParameter = StopMoveType.STOP.equals(command) ? new VeluxProductPosition() : mainParameter; - } else if (command instanceof PercentType) { - PercentType ptCommand = (PercentType) command; + } else if (command instanceof PercentType percentCommand) { if (veluxActuator.isInverted()) { - ptCommand = new PercentType(PercentType.HUNDRED.intValue() - ptCommand.intValue()); + percentCommand = new PercentType( + PercentType.HUNDRED.intValue() - percentCommand.intValue()); } - mainParameter = new VeluxProductPosition(ptCommand); + mainParameter = new VeluxProductPosition(percentCommand); } break; @@ -268,7 +268,7 @@ final class ChannelActuatorPosition extends ChannelHandlerTemplate { LOGGER.debug("handleCommand(): sending command '{}' for channel id '{}'.", command, channelId); RunProductCommand bcp = thisBridgeHandler.thisBridge.bridgeAPI().runProductCommand(); boolean success = false; - if (bcp instanceof SCrunProductCommand) { + if (bcp instanceof SCrunProductCommand productCommand) { synchronized (bcp) { if (bcp.setNodeIdAndParameters(productBridgeIndex.toInt(), mainParameter, functionalParameters) && thisBridgeHandler.thisBridge.bridgeCommunicate(bcp) @@ -278,7 +278,7 @@ final class ChannelActuatorPosition extends ChannelHandlerTemplate { .autoRefresh(thisBridgeHandler.thisBridge)) { LOGGER.trace("handleCommand(): actuator position will be updated via polling."); } - if (existingProducts.update(((SCrunProductCommand) bcp).getProduct())) { + if (existingProducts.update(productCommand.getProduct())) { LOGGER.trace("handleCommand(): actuator position immediate update requested."); } } diff --git a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/handler/VeluxBridgeHandler.java b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/handler/VeluxBridgeHandler.java index 5d096d02f84..4e009a9d551 100644 --- a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/handler/VeluxBridgeHandler.java +++ b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/handler/VeluxBridgeHandler.java @@ -1029,8 +1029,8 @@ public class VeluxBridgeHandler extends ExtendedBaseBridgeHandler implements Vel private void updateDynamicChannels() { getThing().getThings().stream().forEach(thing -> { ThingHandler thingHandler = thing.getHandler(); - if (thingHandler instanceof VeluxHandler) { - ((VeluxHandler) thingHandler).updateDynamicChannels(this); + if (thingHandler instanceof VeluxHandler veluxHandler) { + veluxHandler.updateDynamicChannels(this); } }); } diff --git a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/things/VeluxProduct.java b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/things/VeluxProduct.java index 6d8e30cb6ef..e885112aced 100644 --- a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/things/VeluxProduct.java +++ b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/things/VeluxProduct.java @@ -68,7 +68,7 @@ public class VeluxProduct { * * @author AndrewFG - Initial contribution. */ - public static enum ProductState { + public enum ProductState { NON_EXECUTING(0), ERROR(1), NOT_USED(2), @@ -137,9 +137,9 @@ public class VeluxProduct { * * @author AndrewFG - Initial contribution. */ - public static enum DataSource { + public enum DataSource { GATEWAY, - BINDING; + BINDING } // Class internal diff --git a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/things/VeluxProductPosition.java b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/things/VeluxProductPosition.java index 851e277b1f7..77dbaa9cbee 100644 --- a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/things/VeluxProductPosition.java +++ b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/things/VeluxProductPosition.java @@ -73,7 +73,7 @@ public class VeluxProductPosition { * * @author AndrewFG - Initial contribution. */ - public static enum PositionType { + public enum PositionType { ABSOLUTE_VALUE(0f), OFFSET_POSITIVE(1f), OFFSET_NEGATIVE(-1f); diff --git a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/things/VeluxProductType.java b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/things/VeluxProductType.java index a8ba69e4caf..1a4dfb32432 100644 --- a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/things/VeluxProductType.java +++ b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/things/VeluxProductType.java @@ -44,7 +44,7 @@ public enum VeluxProductType { SWITCH, UNDEFTYPE; - public static enum ActuatorType { + public enum ActuatorType { UNDEFTYPE((short) 0xffff, VeluxBindingConstants.UNKNOWN, VeluxProductType.SWITCH), BLIND_1_0((short) 0x0040, "Interior Venetian Blind", VeluxProductType.SLIDER_SHUTTER), ROLLERSHUTTER_2_0((short) 0x0080, "Roller Shutter", VeluxProductType.SLIDER_SHUTTER), diff --git a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/utils/ManifestInformation.java b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/utils/ManifestInformation.java index 9b7174634c1..da69b6ead88 100644 --- a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/utils/ManifestInformation.java +++ b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/utils/ManifestInformation.java @@ -49,8 +49,6 @@ public class ManifestInformation { * @return bundleVersion the resulted bundle version as {@link String}. */ public static String getBundleVersion() { - String osgiBundleVersion = FrameworkUtil.getBundle(ManifestInformation.class).getBundleContext().getBundle() - .toString(); - return osgiBundleVersion; + return FrameworkUtil.getBundle(ManifestInformation.class).getBundleContext().getBundle().toString(); } } diff --git a/bundles/org.openhab.binding.velux/src/test/java/org/openhab/binding/velux/test/TestNotificationsAndDatabase.java b/bundles/org.openhab.binding.velux/src/test/java/org/openhab/binding/velux/test/TestNotificationsAndDatabase.java index 6efce926347..9260e56a9f3 100644 --- a/bundles/org.openhab.binding.velux/src/test/java/org/openhab/binding/velux/test/TestNotificationsAndDatabase.java +++ b/bundles/org.openhab.binding.velux/src/test/java/org/openhab/binding/velux/test/TestNotificationsAndDatabase.java @@ -107,10 +107,12 @@ public class TestNotificationsAndDatabase { @Order(3) public void testSCgetProduct() { // initialise the test parameters - final String packet = "06 00 06 00 48 6F 62 62 79 6B 61 6D 65 72 00 00 00 00 00 00 00 00 00 00 00 00 00 00" - + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" - + " 00 00 00 00 00 01 04 40 00 00 00 00 00 00 00 00 00 00 00 00 00 2D C8 00 C8 00 F7 FF F7 FF 00 00 F7 FF 00" - + " 00 4F 00 4A EA 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"; + final String packet = """ + 06 00 06 00 48 6F 62 62 79 6B 61 6D 65 72 00 00 00 00 00 00 00 00 00 00 00 00 00 00\ + 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\ + 00 00 00 00 00 01 04 40 00 00 00 00 00 00 00 00 00 00 00 00 00 2D C8 00 C8 00 F7 FF F7 FF 00 00 F7 FF 00\ + 00 4F 00 4A EA 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\ + """; final Command command = VeluxKLFAPI.Command.GW_GET_NODE_INFORMATION_NTF; // initialise the BCP @@ -198,8 +200,10 @@ public class TestNotificationsAndDatabase { @Order(5) public void testSCgetProductStatus() { // initialise the test parameters - final String packet = "00 D8 01 06 00 01 01 02 00 C8 00 03 63 4F 00 00 00 00 00 00 00 00 00 00 00 00 00" - + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"; + final String packet = """ + 00 D8 01 06 00 01 01 02 00 C8 00 03 63 4F 00 00 00 00 00 00 00 00 00 00 00 00 00\ + 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\ + """; final Command command = VeluxKLFAPI.Command.GW_STATUS_REQUEST_NTF; // initialise the BCP @@ -334,10 +338,12 @@ public class TestNotificationsAndDatabase { @Order(9) public void testSCgetProductOnVelux() { // initialise the test parameters - final String packet = "00 00 00 00 53 68 65 64 20 57 69 6E 64 6F 77 00 00 00 00 00 00 00 00 00 00 00 00 00" - + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" - + " 00 00 00 00 00 00 00 00 01 01 01 03 07 00 01 16 56 24 5C 26 14 19 00 FC 05 46 00 46 00 F7 FF F7" - + " FF F7 FF F7 FF 00 00 4F 05 B3 5F 01 D8 03 B2 1C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"; + final String packet = """ + 00 00 00 00 53 68 65 64 20 57 69 6E 64 6F 77 00 00 00 00 00 00 00 00 00 00 00 00 00\ + 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\ + 00 00 00 00 00 00 00 00 01 01 01 03 07 00 01 16 56 24 5C 26 14 19 00 FC 05 46 00 46 00 F7 FF F7\ + FF F7 FF F7 FF 00 00 4F 05 B3 5F 01 D8 03 B2 1C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\ + """; final short command = VeluxKLFAPI.Command.GW_GET_NODE_INFORMATION_NTF.getShort(); // initialise the BCP @@ -454,9 +460,11 @@ public class TestNotificationsAndDatabase { @Test @Order(12) public void testSCrunProductA() { - final String expectedString = "02 1C 08 05 00 20 00 90 00 00 00 00 00 A0 00 00 00 00 00 00 00 00 00 00 00" - + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00" - + " 00 00 00 00 00 00 00 00 00"; + final String expectedString = """ + 02 1C 08 05 00 20 00 90 00 00 00 00 00 A0 00 00 00 00 00 00 00 00 00 00 00\ + 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00\ + 00 00 00 00 00 00 00 00 00\ + """; final byte[] expectedPacket = toByteArray(expectedString); final int targetMainPosition = 0x9000; final int targetVanePosition = 0xA000; @@ -885,9 +893,11 @@ public class TestNotificationsAndDatabase { @Order(21) public void testErrorStateMapping() { // initialise the test parameters - final String packet = "0F A3 01 06 01 00 01 02 00 9A 36 03 00 00 00 00 00 00 00 00 00 00 00 00 00" - + " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" - + " 00 00 00 00 00"; + final String packet = """ + 0F A3 01 06 01 00 01 02 00 9A 36 03 00 00 00 00 00 00 00 00 00 00 00 00 00\ + 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\ + 00 00 00 00 00\ + """; final Command command = VeluxKLFAPI.Command.GW_STATUS_REQUEST_NTF; // initialise the BCP diff --git a/bundles/org.openhab.binding.venstarthermostat/src/main/java/org/openhab/binding/venstarthermostat/internal/VenstarThermostatBindingConstants.java b/bundles/org.openhab.binding.venstarthermostat/src/main/java/org/openhab/binding/venstarthermostat/internal/VenstarThermostatBindingConstants.java index e4c330e0f8d..ca0773cb77b 100644 --- a/bundles/org.openhab.binding.venstarthermostat/src/main/java/org/openhab/binding/venstarthermostat/internal/VenstarThermostatBindingConstants.java +++ b/bundles/org.openhab.binding.venstarthermostat/src/main/java/org/openhab/binding/venstarthermostat/internal/VenstarThermostatBindingConstants.java @@ -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 SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_COLOR_TOUCH); + public static final Set 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"; diff --git a/bundles/org.openhab.binding.venstarthermostat/src/main/java/org/openhab/binding/venstarthermostat/internal/VenstarThermostatHandlerFactory.java b/bundles/org.openhab.binding.venstarthermostat/src/main/java/org/openhab/binding/venstarthermostat/internal/VenstarThermostatHandlerFactory.java index 0184e7d8d74..9fe49e1dc08 100644 --- a/bundles/org.openhab.binding.venstarthermostat/src/main/java/org/openhab/binding/venstarthermostat/internal/VenstarThermostatHandlerFactory.java +++ b/bundles/org.openhab.binding.venstarthermostat/src/main/java/org/openhab/binding/venstarthermostat/internal/VenstarThermostatHandlerFactory.java @@ -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 SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_COLOR_TOUCH); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_COLOR_TOUCH); @Override public boolean supportsThingType(ThingTypeUID thingTypeUID) { diff --git a/bundles/org.openhab.binding.venstarthermostat/src/main/java/org/openhab/binding/venstarthermostat/internal/discovery/VenstarThermostatDiscoveryService.java b/bundles/org.openhab.binding.venstarthermostat/src/main/java/org/openhab/binding/venstarthermostat/internal/discovery/VenstarThermostatDiscoveryService.java index 7a9c3631b7f..7aea198193d 100644 --- a/bundles/org.openhab.binding.venstarthermostat/src/main/java/org/openhab/binding/venstarthermostat/internal/discovery/VenstarThermostatDiscoveryService.java +++ b/bundles/org.openhab.binding.venstarthermostat/src/main/java/org/openhab/binding/venstarthermostat/internal/discovery/VenstarThermostatDiscoveryService.java @@ -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"; diff --git a/bundles/org.openhab.binding.venstarthermostat/src/main/java/org/openhab/binding/venstarthermostat/internal/dto/VenstarFanStateSerializer.java b/bundles/org.openhab.binding.venstarthermostat/src/main/java/org/openhab/binding/venstarthermostat/internal/dto/VenstarFanStateSerializer.java index e8e71919f50..e2fa62fd568 100644 --- a/bundles/org.openhab.binding.venstarthermostat/src/main/java/org/openhab/binding/venstarthermostat/internal/dto/VenstarFanStateSerializer.java +++ b/bundles/org.openhab.binding.venstarthermostat/src/main/java/org/openhab/binding/venstarthermostat/internal/dto/VenstarFanStateSerializer.java @@ -29,7 +29,6 @@ public class VenstarFanStateSerializer implements JsonDeserializer optSensor = sensorData.stream() - .filter(sensor -> sensor.getName().equalsIgnoreCase("Thermostat")).findAny(); + .filter(sensor -> "Thermostat".equalsIgnoreCase(sensor.getName())).findAny(); if (optSensor.isPresent()) { return new QuantityType(optSensor.get().getTemp(), unitSystem); } @@ -335,7 +335,7 @@ public class VenstarThermostatHandler extends ConfigStatusThingHandler { private State getHumidity() { Optional optSensor = sensorData.stream() - .filter(sensor -> sensor.getName().equalsIgnoreCase("Thermostat")).findAny(); + .filter(sensor -> "Thermostat".equalsIgnoreCase(sensor.getName())).findAny(); if (optSensor.isPresent()) { return new QuantityType(optSensor.get().getHum(), Units.PERCENT); } @@ -345,7 +345,7 @@ public class VenstarThermostatHandler extends ConfigStatusThingHandler { private State getOutdoorTemperature() { Optional optSensor = sensorData.stream() - .filter(sensor -> sensor.getName().equalsIgnoreCase("Outdoor")).findAny(); + .filter(sensor -> "Outdoor".equalsIgnoreCase(sensor.getName())).findAny(); if (optSensor.isPresent()) { return new QuantityType(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())); } diff --git a/bundles/org.openhab.binding.ventaair/src/main/java/org/openhab/binding/ventaair/internal/Communicator.java b/bundles/org.openhab.binding.ventaair/src/main/java/org/openhab/binding/ventaair/internal/Communicator.java index 638fb8b183b..479da6f850c 100644 --- a/bundles/org.openhab.binding.ventaair/src/main/java/org/openhab/binding/ventaair/internal/Communicator.java +++ b/bundles/org.openhab.binding.ventaair/src/main/java/org/openhab/binding/ventaair/internal/Communicator.java @@ -110,7 +110,6 @@ public class Communicator { } } br.close(); - socket.close(); } catch (IOException e) { callback.communicationProblem(); } @@ -150,7 +149,6 @@ public class Communicator { logger.debug("sendingArray: {}", Arrays.toString(dataToSend)); output.write(dataToSend); - socket.close(); } } diff --git a/bundles/org.openhab.binding.ventaair/src/main/java/org/openhab/binding/ventaair/internal/VentaThingHandler.java b/bundles/org.openhab.binding.ventaair/src/main/java/org/openhab/binding/ventaair/internal/VentaThingHandler.java index 4c08b334cab..21b27c74003 100644 --- a/bundles/org.openhab.binding.ventaair/src/main/java/org/openhab/binding/ventaair/internal/VentaThingHandler.java +++ b/bundles/org.openhab.binding.ventaair/src/main/java/org/openhab/binding/ventaair/internal/VentaThingHandler.java @@ -92,20 +92,20 @@ public class VentaThingHandler extends BaseThingHandler { } break; case VentaAirBindingConstants.CHANNEL_FAN_SPEED: - if (command instanceof DecimalType) { - int fanStage = ((DecimalType) command).intValue(); + if (command instanceof DecimalType decimalCommand) { + int fanStage = decimalCommand.intValue(); dispatchActionToDevice(new FanAction(fanStage)); } break; case VentaAirBindingConstants.CHANNEL_TARGET_HUMIDITY: - if (command instanceof DecimalType) { - int targetHumidity = ((DecimalType) command).intValue(); + if (command instanceof DecimalType decimalCommand) { + int targetHumidity = decimalCommand.intValue(); dispatchActionToDevice(new HumidityAction(targetHumidity)); } break; case VentaAirBindingConstants.CHANNEL_TIMER: - if (command instanceof DecimalType) { - int timer = ((DecimalType) command).intValue(); + if (command instanceof DecimalType decimalCommand) { + int timer = decimalCommand.intValue(); dispatchActionToDevice(new TimerAction(timer)); } break; diff --git a/bundles/org.openhab.binding.ventaair/src/main/java/org/openhab/binding/ventaair/internal/discovery/VentaDeviceDiscovery.java b/bundles/org.openhab.binding.ventaair/src/main/java/org/openhab/binding/ventaair/internal/discovery/VentaDeviceDiscovery.java index 771e862d31b..7433d1a14ec 100644 --- a/bundles/org.openhab.binding.ventaair/src/main/java/org/openhab/binding/ventaair/internal/discovery/VentaDeviceDiscovery.java +++ b/bundles/org.openhab.binding.ventaair/src/main/java/org/openhab/binding/ventaair/internal/discovery/VentaDeviceDiscovery.java @@ -18,7 +18,6 @@ import java.net.DatagramSocket; import java.net.SocketException; import java.nio.charset.StandardCharsets; import java.time.Duration; -import java.util.Collections; import java.util.HashMap; import java.util.Set; import java.util.concurrent.ScheduledFuture; @@ -53,8 +52,8 @@ import com.google.gson.JsonSyntaxException; @Component(service = DiscoveryService.class, configurationPid = "discovery.ventaair") public class VentaDeviceDiscovery extends AbstractDiscoveryService { private static final String REPRESENTATION_PROPERTY = "macAddress"; - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections - .singleton(VentaAirBindingConstants.THING_TYPE_LW60T); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set + .of(VentaAirBindingConstants.THING_TYPE_LW60T); // defined as int, because AbstractDiscoveryService wants and int and not long as provided by Duration.getSeconds() private static final int MANUAL_DISCOVERY_TIME = 30; private static final Duration TIME_BETWEEN_SCANS = Duration.ofSeconds(30); diff --git a/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/VerisureSession.java b/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/VerisureSession.java index 3381938b680..3b892cc3a1a 100644 --- a/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/VerisureSession.java +++ b/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/VerisureSession.java @@ -761,7 +761,7 @@ public class VerisureSession { if (deviceId != null) { deviceId = VerisureThingConfiguration.normalizeDeviceId(deviceId); VerisureThingDTO mouseThing = verisureThings.get(deviceId); - if (mouseThing != null && mouseThing instanceof VerisureMiceDetectionDTO) { + if (mouseThing instanceof VerisureMiceDetectionDTO) { VerisureMiceDetectionDTO miceDetectorThing = (VerisureMiceDetectionDTO) mouseThing; miceDetectorThing.setTemperatureValue(climate.getTemperatureValue()); miceDetectorThing.setTemperatureTime(climate.getTemperatureTimestamp()); diff --git a/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/discovery/VerisureThingDiscoveryService.java b/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/discovery/VerisureThingDiscoveryService.java index 878543256bd..6d20e224368 100644 --- a/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/discovery/VerisureThingDiscoveryService.java +++ b/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/discovery/VerisureThingDiscoveryService.java @@ -13,7 +13,7 @@ package org.openhab.binding.verisure.internal.discovery; import java.util.Collection; -import java.util.Collections; +import java.util.Map; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -107,7 +107,7 @@ public class VerisureThingDiscoveryService extends AbstractDiscoveryService @Override public void activate() { - super.activate(Collections.singletonMap(DiscoveryService.CONFIG_PROPERTY_BACKGROUND_DISCOVERY, true)); + super.activate(Map.of(DiscoveryService.CONFIG_PROPERTY_BACKGROUND_DISCOVERY, true)); } @Override @@ -117,8 +117,8 @@ public class VerisureThingDiscoveryService extends AbstractDiscoveryService @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof VerisureBridgeHandler) { - verisureBridgeHandler = (VerisureBridgeHandler) handler; + if (handler instanceof VerisureBridgeHandler verisureBridgeHandler) { + this.verisureBridgeHandler = verisureBridgeHandler; bridgeUID = verisureBridgeHandler.getUID(); } } diff --git a/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureAlarmThingHandler.java b/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureAlarmThingHandler.java index 06f5ec5ded7..61b97ae6bf3 100644 --- a/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureAlarmThingHandler.java +++ b/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureAlarmThingHandler.java @@ -16,7 +16,6 @@ import static org.openhab.binding.verisure.internal.VerisureBindingConstants.*; import java.math.BigDecimal; import java.util.ArrayList; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -45,7 +44,7 @@ import org.openhab.core.types.UnDefType; @NonNullByDefault public class VerisureAlarmThingHandler extends VerisureThingHandler { - public static final Set SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_ALARM); + public static final Set SUPPORTED_THING_TYPES = Set.of(THING_TYPE_ALARM); private static final int REFRESH_DELAY_SECONDS = 10; @@ -143,7 +142,7 @@ public class VerisureAlarmThingHandler extends VerisureThingHandler isLinked(channelUID) && !channelUID.getId().equals("timestamp")) + .filter(channelUID -> isLinked(channelUID) && !"timestamp".equals(channelUID.getId())) .forEach(channelUID -> { State state = getValue(channelUID.getId(), armState); updateState(channelUID, state); diff --git a/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureBridgeHandler.java b/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureBridgeHandler.java index 28d2e6591b1..2479cc72003 100644 --- a/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureBridgeHandler.java +++ b/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureBridgeHandler.java @@ -15,7 +15,6 @@ package org.openhab.binding.verisure.internal.handler; import static org.openhab.binding.verisure.internal.VerisureBindingConstants.*; import java.util.Collection; -import java.util.Collections; import java.util.Set; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.ScheduledFuture; @@ -53,7 +52,7 @@ import org.slf4j.LoggerFactory; @NonNullByDefault public class VerisureBridgeHandler extends BaseBridgeHandler { - public static final Set SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_BRIDGE); + public static final Set SUPPORTED_THING_TYPES = Set.of(THING_TYPE_BRIDGE); private static final int REFRESH_DELAY_SECONDS = 30; private final Logger logger = LoggerFactory.getLogger(VerisureBridgeHandler.class); @@ -159,7 +158,7 @@ public class VerisureBridgeHandler extends BaseBridgeHandler { @Override public Collection> getServices() { - return Collections.singleton(VerisureThingDiscoveryService.class); + return Set.of(VerisureThingDiscoveryService.class); } private void refreshAndUpdateStatus() { diff --git a/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureBroadbandConnectionThingHandler.java b/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureBroadbandConnectionThingHandler.java index 556189ad8df..487b2154af7 100644 --- a/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureBroadbandConnectionThingHandler.java +++ b/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureBroadbandConnectionThingHandler.java @@ -14,7 +14,6 @@ package org.openhab.binding.verisure.internal.handler; import static org.openhab.binding.verisure.internal.VerisureBindingConstants.*; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -34,8 +33,7 @@ import org.openhab.core.thing.ThingTypeUID; @NonNullByDefault public class VerisureBroadbandConnectionThingHandler extends VerisureThingHandler { - public static final Set SUPPORTED_THING_TYPES = Collections - .singleton(THING_TYPE_BROADBAND_CONNECTION); + public static final Set SUPPORTED_THING_TYPES = Set.of(THING_TYPE_BROADBAND_CONNECTION); public VerisureBroadbandConnectionThingHandler(Thing thing) { super(thing); diff --git a/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureClimateDeviceThingHandler.java b/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureClimateDeviceThingHandler.java index a387be9a678..f6d4f18ec8e 100644 --- a/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureClimateDeviceThingHandler.java +++ b/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureClimateDeviceThingHandler.java @@ -71,7 +71,7 @@ public class VerisureClimateDeviceThingHandler extends VerisureThingHandler isLinked(channelUID) && !channelUID.getId().equals("timestamp")) + .filter(channelUID -> isLinked(channelUID) && !"timestamp".equals(channelUID.getId())) .forEach(channelUID -> { State state = getValue(channelUID.getId(), climateJSON); updateState(channelUID, state); diff --git a/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureDoorWindowThingHandler.java b/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureDoorWindowThingHandler.java index 9a7571f3ad4..075ec780ed1 100644 --- a/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureDoorWindowThingHandler.java +++ b/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureDoorWindowThingHandler.java @@ -14,7 +14,6 @@ package org.openhab.binding.verisure.internal.handler; import static org.openhab.binding.verisure.internal.VerisureBindingConstants.*; -import java.util.Collections; import java.util.List; import java.util.Set; @@ -41,7 +40,7 @@ import org.openhab.core.types.UnDefType; @NonNullByDefault public class VerisureDoorWindowThingHandler extends VerisureThingHandler { - public static final Set SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_DOORWINDOW); + public static final Set SUPPORTED_THING_TYPES = Set.of(THING_TYPE_DOORWINDOW); public VerisureDoorWindowThingHandler(Thing thing) { super(thing); @@ -64,7 +63,7 @@ public class VerisureDoorWindowThingHandler extends VerisureThingHandler isLinked(channelUID) && !channelUID.getId().equals("timestamp")) + .filter(channelUID -> isLinked(channelUID) && !"timestamp".equals(channelUID.getId())) .forEach(channelUID -> { State state = getValue(channelUID.getId(), doorWindow, doorWindowJSON); updateState(channelUID, state); diff --git a/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureEventLogThingHandler.java b/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureEventLogThingHandler.java index 8b37c11c49a..c29955ab929 100644 --- a/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureEventLogThingHandler.java +++ b/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureEventLogThingHandler.java @@ -51,7 +51,7 @@ public class VerisureEventLogThingHandler extends VerisureThingHandler SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_EVENT_LOG); + public static final Set SUPPORTED_THING_TYPES = Set.of(THING_TYPE_EVENT_LOG); public VerisureEventLogThingHandler(Thing thing) { super(thing); @@ -83,7 +83,7 @@ public class VerisureEventLogThingHandler extends VerisureThingHandler 0) { + if (!eventLog.getPagedList().isEmpty()) { getThing().getChannels().stream().map(Channel::getUID).filter(channelUID -> isLinked(channelUID)) .forEach(channelUID -> { State state = getValue(channelUID.getId(), eventLogJSON, eventLog); diff --git a/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureGatewayThingHandler.java b/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureGatewayThingHandler.java index 1f23c28eb67..a4e44caa6cc 100644 --- a/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureGatewayThingHandler.java +++ b/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureGatewayThingHandler.java @@ -14,7 +14,6 @@ package org.openhab.binding.verisure.internal.handler; import static org.openhab.binding.verisure.internal.VerisureBindingConstants.*; -import java.util.Collections; import java.util.List; import java.util.Set; @@ -38,7 +37,7 @@ import org.openhab.core.types.UnDefType; @NonNullByDefault public class VerisureGatewayThingHandler extends VerisureThingHandler { - public static final Set SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_GATEWAY); + public static final Set SUPPORTED_THING_TYPES = Set.of(THING_TYPE_GATEWAY); public VerisureGatewayThingHandler(Thing thing) { super(thing); diff --git a/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureMiceDetectionThingHandler.java b/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureMiceDetectionThingHandler.java index 5ade277f913..7ee00619733 100644 --- a/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureMiceDetectionThingHandler.java +++ b/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureMiceDetectionThingHandler.java @@ -14,7 +14,6 @@ package org.openhab.binding.verisure.internal.handler; import static org.openhab.binding.verisure.internal.VerisureBindingConstants.*; -import java.util.Collections; import java.util.List; import java.util.Set; @@ -46,7 +45,7 @@ import org.openhab.core.types.UnDefType; @NonNullByDefault public class VerisureMiceDetectionThingHandler extends VerisureThingHandler { - public static final Set SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_MICE_DETECTION); + public static final Set SUPPORTED_THING_TYPES = Set.of(THING_TYPE_MICE_DETECTION); public VerisureMiceDetectionThingHandler(Thing thing) { super(thing); @@ -68,12 +67,12 @@ public class VerisureMiceDetectionThingHandler extends VerisureThingHandler isLinked(channelUID) - && !channelUID.getId().equals("timestamp") && !channelUID.getId().equals("temperatureTimestamp")) + && !"timestamp".equals(channelUID.getId()) && !"temperatureTimestamp".equals(channelUID.getId())) .forEach(channelUID -> { State state = getValue(channelUID.getId(), miceDetectionJSON, mouse); updateState(channelUID, state); }); - if (mouse.getDetections().size() != 0) { + if (!mouse.getDetections().isEmpty()) { updateTimeStamp(mouse.getDetections().get(0).getNodeTime()); } updateTimeStamp(miceDetectionJSON.getTemperatureTime(), CHANNEL_TEMPERATURE_TIMESTAMP); @@ -86,25 +85,25 @@ public class VerisureMiceDetectionThingHandler extends VerisureThingHandler(0, Units.SECOND); } else { return new QuantityType