From cf10b3e9c7ae3763601f2f4ec63ce48b6129211f Mon Sep 17 00:00:00 2001 From: Holger Friedrich Date: Tue, 5 Sep 2023 22:30:16 +0200 Subject: [PATCH] Java 17 features (A-G) (#15516) - add missing @override - Java style array syntax - remove redundant modifiers - always move String constants to left side in comparisons - simplify lambda expressions and return statements - use replace instead of replaceAll w/o regex - instanceof matching and multiline strings Signed-off-by: Holger Friedrich --- .../discovery/AdorneDiscoveryService.java | 11 +- .../internal/handler/AdorneDimmerHandler.java | 4 +- .../internal/hub/AdorneHubConnection.java | 4 +- .../internal/AhaCollectionScheduleImpl.java | 4 +- .../airq/internal/AirqHandlerFactory.java | 3 +- .../airquality/internal/api/Pollutant.java | 4 +- .../internal/api/dto/ResponseRoot.java | 4 +- .../config/SensitiveGroupConfiguration.java | 3 +- .../discovery/AirQualityDiscoveryService.java | 8 +- .../AirVisualNodeBindingConstants.java | 13 +- .../AirVisualNodeDiscoveryService.java | 4 +- .../internal/dto/airvisual/Measurements.java | 8 ++ .../internal/dto/airvisual/NodeData.java | 5 + .../dto/airvisualpro/Measurements.java | 10 ++ .../dto/airvisualpro/ProNodeData.java | 5 + .../internal/actions/BridgeActions.java | 4 +- .../internal/handler/ADBridgeHandler.java | 4 +- .../internal/handler/KeypadHandler.java | 8 +- .../internal/handler/VZoneHandler.java | 4 +- .../internal/handler/ZoneHandler.java | 2 +- .../internal/protocol/EXPMessage.java | 2 +- .../internal/protocol/KeypadMessage.java | 3 +- .../internal/protocol/LRRMessage.java | 2 +- .../internal/protocol/RFXMessage.java | 2 +- .../internal/protocol/VersionMessage.java | 2 +- .../internal/AllPlayBindingProperties.java | 4 +- .../internal/AllPlayHandlerFactory.java | 3 +- .../AllPlaySpeakerDiscoveryService.java | 3 +- .../internal/handler/AllPlayHandler.java | 4 +- .../AmazonDashButtonHandlerFactory.java | 3 +- .../AmazonDashButtonDiscoveryService.java | 3 +- .../internal/pcap/PcapUtil.java | 5 +- .../AmazonEchoControlHandlerFactory.java | 8 +- .../ChannelHandlerAnnouncement.java | 4 +- .../channelhandler/IEchoThingHandler.java | 1 + .../discovery/SmartHomeDevicesDiscovery.java | 8 +- .../internal/handler/AccountHandler.java | 3 +- .../internal/handler/EchoHandler.java | 45 +++--- .../handler/SmartHomeDeviceHandler.java | 56 ++++---- .../DynamicStateDescriptionSmartHome.java | 7 +- .../handler/AmbientWeatherEventListener.java | 9 +- .../amplipi/internal/model/StreamCommand.java | 2 +- .../amplipi/internal/AmpliPiGroupHandler.java | 9 +- .../amplipi/internal/AmpliPiHandler.java | 12 +- .../amplipi/internal/AmpliPiZoneHandler.java | 8 +- .../internal/InputStateOptionProvider.java | 2 +- .../AmpliPiMDNSDiscoveryParticipant.java | 5 +- .../internal/AndroidDebugBridgeDevice.java | 4 +- .../AndroidDebugBridgeDiscoveryService.java | 2 +- .../AndroidTVMDNSDiscoveryParticipant.java | 2 +- .../FireTVStickMDNSDiscoveryParticipant.java | 2 +- .../anel/internal/AnelStateUpdaterTest.java | 4 +- .../anel/internal/AnelUdpConnectorTest.java | 2 +- .../anel/internal/IAnelTestStatus.java | 58 +++++--- .../internal/handler/AnthemHandler.java | 10 +- .../astro/internal/action/AstroActions.java | 9 +- .../binding/astro/internal/calc/MoonCalc.java | 11 +- .../internal/handler/AstroThingHandler.java | 3 +- .../binding/astro/internal/job/Job.java | 3 +- .../astro/internal/job/SunPhaseJob.java | 5 +- .../astro/internal/model/EclipseKind.java | 2 +- .../astro/internal/model/EclipseType.java | 2 +- .../astro/internal/util/PropertyUtils.java | 7 +- .../atlona/internal/AtlonaHandlerFactory.java | 3 +- .../internal/discovery/AtlonaDiscovery.java | 8 +- .../internal/net/SocketChannelSession.java | 8 +- .../internal/pro3/AtlonaPro3Handler.java | 36 ++--- .../pro3/AtlonaPro3PortocolHandler.java | 8 +- .../AutelisDiscoveryParticipant.java | 2 +- .../bridge/AutomowerBridgeHandler.java | 3 +- .../discovery/AutomowerDiscoveryService.java | 4 +- .../internal/things/AutomowerHandler.java | 12 +- .../discovery/AVMFritzDiscoveryService.java | 10 +- .../handler/AVMFritzBaseBridgeHandler.java | 17 ++- .../handler/AVMFritzBaseThingHandler.java | 54 ++++--- .../handler/AVMFritzButtonHandler.java | 3 +- .../AVMFritzHeatingActionsHandler.java | 4 +- .../internal/handler/GroupHandler.java | 3 +- .../dto/AVMFritzDeviceListModelTest.java | 134 +++++++++--------- .../dto/AVMFritzTemplateListModelTest.java | 10 +- .../AwattarBestpriceConfiguration.java | 1 + .../AwattarConsecutiveBestPriceResult.java | 2 + .../AwattarNonConsecutiveBestPriceResult.java | 2 + .../awattar/internal/AwattarPrice.java | 1 + .../binding/awattar/internal/AwattarUtil.java | 4 +- .../internal/handler/AwattarPriceHandler.java | 1 + .../benqprojector/internal/enums/Switch.java | 2 +- .../internal/handler/BigAssFanHandler.java | 63 ++++---- .../internal/AM43DiscoveryParticipant.java | 3 +- .../bluetooth/am43/internal/AM43Handler.java | 24 ++-- .../am43/internal/AM43HandlerFactory.java | 4 +- .../BlueGigaBluetoothCharacteristic.java | 1 + .../bluegiga/BlueGigaBluetoothDevice.java | 28 ++-- .../handler/BlueGigaBridgeHandler.java | 9 +- .../internal/BlueGigaConfiguration.java | 10 +- .../internal/BlueGigaResponsePackets.java | 3 +- .../internal/BlueGigaSerialHandler.java | 6 +- .../internal/BlueGigaTransactionManager.java | 7 +- .../factory/BlueGigaHandlerFactory.java | 9 +- .../bluez/internal/BlueZBridgeHandler.java | 3 +- .../bluez/internal/BlueZDiscoveryService.java | 4 +- .../bluez/internal/BlueZHandlerFactory.java | 8 +- .../internal/BlukiiDiscoveryParticipant.java | 3 +- .../blukii/internal/BlukiiHandlerFactory.java | 5 +- .../internal/DaikinMadokaHandlerFactory.java | 3 +- .../EnoceanBleDiscoveryParticipant.java | 3 +- .../internal/EnoceanBleHandlerFactory.java | 5 +- .../CharacteristicChannelTypeProvider.java | 2 +- .../internal/RoamingBindingConstants.java | 3 +- .../internal/RoamingBridgeHandler.java | 2 +- .../internal/RoamingHandlerFactory.java | 5 +- .../RuuviTagDiscoveryParticipant.java | 3 +- .../internal/RuuviTagHandlerFactory.java | 5 +- .../bluetooth/ConnectedBluetoothHandler.java | 14 +- .../binding/bluetooth/util/RetryFuture.java | 3 +- .../BluetoothDiscoveryServiceTest.java | 2 +- .../internal/BondHomeHandlerFactory.java | 3 +- .../bondhome/internal/api/BondHttpApi.java | 2 +- .../discovery/BondDiscoveryService.java | 4 +- .../internal/handler/BondBridgeHandler.java | 10 +- .../internal/handler/BondDeviceHandler.java | 56 ++++---- .../internal/AuthorizationController.java | 1 + .../internal/IndegoController.java | 12 +- .../internal/IndegoDeviceController.java | 4 +- .../internal/handler/BoschAccountHandler.java | 3 + .../internal/handler/BoschIndegoHandler.java | 7 +- .../devices/bridge/BridgeHandler.java | 3 +- .../climatecontrol/ClimateControlHandler.java | 4 +- .../intrusion/IntrusionDetectionHandler.java | 12 +- .../services/intrusion/dto/AlarmState.java | 2 +- .../services/intrusion/dto/ArmingState.java | 2 +- .../shuttercontact/ShutterContactState.java | 2 +- .../shuttercontrol/OperationState.java | 2 +- .../SmokeDetectorCheckService.java | 6 +- ...stractBatteryPoweredDeviceHandlerTest.java | 98 +++++++++---- .../AbstractPowerSwitchHandlerTest.java | 9 +- .../devices/bridge/BoschHttpClientTest.java | 16 +-- .../devices/bridge/BridgeHandlerTest.java | 90 ++++++++---- .../devices/bridge/LongPollingTest.java | 10 +- .../ClimateControlHandlerTest.java | 16 ++- .../IntrusionDetectionHandlerTest.java | 102 +++++++++---- .../MotionDetectorHandlerTest.java | 8 +- .../smartbulb/SmartBulbHandlerTest.java | 12 +- .../thermostat/ThermostatHandlerTest.java | 8 +- .../twinguard/TwinguardHandlerTest.java | 6 +- .../WallThermostatHandlerTest.java | 8 +- ...usionDetectionControlStateServiceTest.java | 36 ++++- .../BoseSoundTouchHandlerFactory.java | 4 +- .../bosesoundtouch/internal/ContentItem.java | 15 +- .../discovery/BroadlinkDiscoveryService.java | 6 +- .../handler/FloureonThermostatHandler.java | 8 +- .../handler/BsbLanBaseThingHandler.java | 4 +- .../helper/BsbLanParameterConverter.java | 6 +- .../api/BsbLanApiContentConverterTests.java | 13 +- .../internal/api/SmartherApiConnector.java | 4 +- .../internal/api/dto/Location.java | 2 +- .../internal/api/dto/Modules.java | 2 +- .../SmartherModuleDiscoveryService.java | 6 +- .../factory/SmartherHandlerFactory.java | 4 +- .../handler/SmartherBridgeHandler.java | 3 +- .../handler/SmartherModuleHandler.java | 16 +-- .../internal/util/StringUtil.java | 2 +- .../internal/BuienradarHandler.java | 2 +- .../internal/BuienradarHandlerFactory.java | 3 +- .../caddx/internal/CaddxMessageContext.java | 2 +- .../internal/action/CaddxBridgeActions.java | 4 +- .../internal/action/CaddxKeypadActions.java | 4 +- .../internal/action/CaddxPanelActions.java | 4 +- .../action/CaddxPartitionActions.java | 4 +- .../internal/action/CaddxZoneActions.java | 4 +- .../discovery/CaddxDiscoveryService.java | 11 +- .../handler/CaddxBaseThingHandler.java | 4 +- .../internal/handler/CaddxBridgeHandler.java | 2 +- .../internal/handler/CaddxThingType.java | 2 +- .../internal/handler/ThingHandlerKeypad.java | 4 +- .../internal/handler/ThingHandlerPanel.java | 4 +- .../handler/ThingHandlerPartition.java | 4 +- .../internal/handler/ThingHandlerZone.java | 4 +- .../message/CaddxMessageParseTest.java | 2 +- .../cbus/handler/CBusCGateHandler.java | 8 +- .../binding/cbus/handler/CBusDaliHandler.java | 6 +- .../cbus/handler/CBusGroupHandler.java | 4 +- .../cbus/handler/CBusLightHandler.java | 6 +- .../cbus/handler/CBusNetworkHandler.java | 8 +- .../cbus/handler/CBusTemperatureHandler.java | 1 + .../cbus/handler/CBusTriggerHandler.java | 5 +- .../internal/ChromecastAudioSink.java | 5 +- .../internal/ChromecastCommander.java | 12 +- .../internal/ChromecastStatusUpdater.java | 4 +- .../internal/action/ChromecastActions.java | 4 +- .../cm11a/internal/Cm11aHandlerFactory.java | 6 +- .../cm11a/internal/X10ReceivedData.java | 4 +- .../internal/handler/Cm11aLampHandler.java | 12 +- .../internal/handler/HVACHandler.java | 23 ++- .../handler/CoronaStatsCountryHandler.java | 4 +- .../handler/CoronaStatsWorldHandler.java | 7 +- .../internal/api/airbase/AirbaseZoneInfo.java | 2 +- .../DaikinACUnitDiscoveryService.java | 4 +- .../internal/handler/DaikinAcUnitHandler.java | 12 +- .../internal/handler/DaikinBaseHandler.java | 16 +-- .../internal/handler/DaliDeviceHandler.java | 14 +- .../handler/DaliDt8DeviceHandler.java | 12 +- .../dali/internal/handler/DaliRgbHandler.java | 12 +- .../handler/DaliserverBridgeHandler.java | 3 +- .../internal/DanfossAirUnit.java | 8 +- ...DanfossAirUnitCommunicationController.java | 4 + .../DanfossAirUnitHandlerFactory.java | 3 +- .../dbquery/action/DBQueryActions.java | 14 +- .../dbquery/internal/QueryHandler.java | 4 +- .../internal/Value2StateConverter.java | 57 ++++---- .../dbimpl/influx2/Influx2Database.java | 3 +- .../internal/domain/DBQueryJSONEncoder.java | 16 +-- .../deconz/internal/action/BridgeActions.java | 4 +- .../deconz/internal/action/GroupActions.java | 4 +- .../discovery/BridgeDiscoveryParticipant.java | 3 +- .../discovery/ThingDiscoveryService.java | 4 +- .../internal/handler/GroupThingHandler.java | 8 +- .../handler/SensorThermostatThingHandler.java | 11 +- .../internal/DenonMarantzHandlerFactory.java | 3 +- .../connector/DenonMarantzConnector.java | 8 +- .../telnet/DenonMarantzTelnetConnector.java | 2 +- .../DenonMarantzDiscoveryParticipant.java | 6 +- .../internal/xml/adapters/OnOffAdapter.java | 2 +- .../internal/xml/adapters/VolumeAdapter.java | 2 +- .../deutschebahn/internal/EventAttribute.java | 23 ++- .../internal/TripLabelAttribute.java | 4 +- .../communication/events/TroubleStatus.java | 2 +- .../discovery/DigiplexDiscoveryService.java | 13 +- .../internal/handler/DigiplexAreaHandler.java | 4 +- .../handler/DigiplexBridgeHandler.java | 6 +- .../internal/DigitalSTROMHandlerFactory.java | 11 +- .../BridgeMDNSDiscoveryParticipant.java | 3 +- .../discovery/DeviceDiscoveryService.java | 26 ++-- .../discovery/DiscoveryServiceManager.java | 40 +++--- .../discovery/SceneDiscoveryService.java | 3 +- ...oneTemperatureControlDiscoveryService.java | 3 +- .../internal/handler/BridgeHandler.java | 19 +-- .../internal/handler/CircuitHandler.java | 12 +- .../internal/handler/DeviceHandler.java | 46 +++--- .../internal/handler/SceneHandler.java | 4 +- .../ZoneTemperatureControlHandler.java | 5 +- .../manager/impl/DeviceStatusManagerImpl.java | 4 +- .../lib/manager/impl/SceneManagerImpl.java | 2 +- .../impl/DeviceConsumptionSensorJob.java | 3 +- .../impl/DeviceOutputValueSensorJob.java | 3 +- .../sensorjob/impl/SceneConfigReadingJob.java | 3 +- .../impl/SceneOutputValueReadingJob.java | 3 +- .../lib/serverconnection/impl/DsAPIImpl.java | 5 +- .../impl/JSONResponseHandler.java | 2 +- .../SimpleRequestBuilder.java | 8 +- .../devices/deviceparameters/impl/DSID.java | 4 +- .../devices/deviceparameters/impl/DSUID.java | 4 +- .../impl/DeviceStateUpdateImpl.java | 16 +-- .../structure/devices/impl/DeviceImpl.java | 5 +- .../impl/JSONDetailedGroupInfoImpl.java | 3 +- .../lib/structure/impl/JSONZoneImpl.java | 3 +- .../providers/DsDeviceThingTypeProvider.java | 2 +- .../DLinkSmartHomeBindingConstants.java | 3 +- .../DLinkSmartHomeDiscoveryParticipant.java | 2 +- .../dmx/internal/DmxBindingConstants.java | 2 +- .../dmx/internal/DmxBridgeHandler.java | 3 +- .../dmx/internal/DmxHandlerFactory.java | 21 +-- .../dmx/internal/action/DmxActions.java | 4 +- .../internal/handler/ArtnetBridgeHandler.java | 2 +- .../internal/handler/ChaserThingHandler.java | 12 +- .../internal/handler/ColorThingHandler.java | 24 ++-- .../internal/handler/DimmerThingHandler.java | 20 ++- .../internal/handler/SacnBridgeHandler.java | 4 +- .../handler/TunableWhiteThingHandler.java | 20 ++- .../internal/multiverse/BaseDmxChannel.java | 4 +- .../binding/dmx/test/TestBridgeHandler.java | 3 +- .../internal/action/DoorbirdActions.java | 4 +- .../doorbird/internal/DoorbirdInfoTest.java | 56 ++++---- .../doorbird/internal/SipStatusTest.java | 56 ++++---- .../DraytonWiserBindingConstants.java | 8 +- .../DraytonWiserDiscoveryService.java | 4 +- .../DraytonWiserMDNSDiscoveryParticipant.java | 3 +- .../internal/handler/HeatHubHandler.java | 4 +- .../internal/handler/RoomHandler.java | 8 +- .../dscalarm/internal/DSCAlarmMessage.java | 8 +- .../discovery/DSCAlarmDiscoveryService.java | 8 +- .../discovery/EnvisalinkBridgeDiscovery.java | 2 +- .../internal/handler/PanelThingHandler.java | 8 +- .../internal/handler/ZoneThingHandler.java | 2 +- .../internal/device/cosem/OBISIdentifier.java | 4 +- .../discovery/DSMRBridgeDiscoveryService.java | 8 +- .../discovery/DSMRMeterDiscoveryService.java | 26 ++-- .../dsmr/internal/meter/DSMRMeter.java | 3 +- .../p1telegram/P1TelegramParserTest.java | 2 +- .../discovery/DSMRMeterDetectorTest.java | 2 +- .../handler/DWDPollenflugBridgeHandler.java | 7 +- .../handler/DWDPollenflugRegionHandler.java | 3 +- .../factory/DwdUnwetterHandlerFactory.java | 3 +- .../handler/DwdUnwetterHandlerTest.java | 2 +- .../openhab/binding/easee/internal/Utils.java | 3 +- .../internal/command/AbstractCommand.java | 8 +- .../command/AbstractWriteCommand.java | 4 +- .../discovery/EaseeSiteDiscoveryService.java | 4 +- .../internal/handler/EaseeSiteHandler.java | 4 +- .../internal/handler/EaseeThingHandler.java | 3 +- .../model/CustomResponseTransformer.java | 6 +- .../echonetlite/internal/EchonetClass.java | 1 + .../echonetlite/internal/EchonetDevice.java | 5 + .../internal/EchonetDiscoveryService.java | 4 +- .../internal/EchonetLiteBridgeHandler.java | 32 ++--- .../internal/EchonetLiteHandler.java | 9 +- .../echonetlite/internal/EchonetObject.java | 1 + .../internal/EchonetPropertyMap.java | 1 + .../binding/echonetlite/internal/Epc.java | 12 ++ .../echonetlite/internal/InstanceKey.java | 3 + .../echonetlite/internal/StateCodec.java | 18 +++ .../ecobee/internal/action/EcobeeActions.java | 4 +- .../ecobee/internal/api/EcobeeAuthState.java | 2 +- .../discovery/EcobeeDiscoveryService.java | 4 +- .../handler/EcobeeAccountBridgeHandler.java | 3 +- .../EcobeeThermostatBridgeHandler.java | 20 +-- .../ecotouch/internal/EcoTouchConnector.java | 6 +- .../ecotouch/internal/EcoTouchHandler.java | 6 +- .../internal/action/EcovacsVacuumActions.java | 8 +- .../api/commands/GetActiveMapIdCommand.java | 5 +- .../api/commands/GetBatteryInfoCommand.java | 5 +- .../api/commands/GetChargeStateCommand.java | 5 +- .../api/commands/GetCleanStateCommand.java | 3 +- .../commands/GetComponentLifeSpanCommand.java | 4 +- .../GetContinuousCleaningCommand.java | 5 +- .../api/commands/GetErrorCommand.java | 4 +- .../GetMapSpotAreasWithMapIdCommand.java | 5 +- .../GetMoppingWaterAmountCommand.java | 5 +- .../api/commands/GetNetworkInfoCommand.java | 5 +- .../api/commands/GetSuctionPowerCommand.java | 4 +- .../api/commands/GetTotalStatsCommand.java | 4 +- .../api/commands/GetVolumeCommand.java | 5 +- .../GetWaterSystemPresentCommand.java | 5 +- .../internal/api/impl/EcovacsApiImpl.java | 4 +- .../internal/api/impl/EcovacsIotMqDevice.java | 4 +- .../internal/api/impl/EcovacsXmppDevice.java | 7 +- .../ecovacs/internal/api/impl/PortalTodo.java | 2 +- .../internal/api/model/ChargeMode.java | 2 +- .../EcovacsDeviceDiscoveryService.java | 8 +- .../internal/handler/EcovacsApiHandler.java | 4 +- .../handler/EcovacsVacuumHandler.java | 14 +- .../internal/handler/EcowattHandler.java | 6 +- .../ElectroluxAirDiscoveryService.java | 4 +- .../handler/ElectroluxAirBridgeHandler.java | 5 +- .../EleroTransmitterStickHandlerFactory.java | 4 +- .../EleroChannelDiscoveryService.java | 4 +- .../internal/handler/EleroChannelHandler.java | 16 +-- .../internal/stick/TransmitterStick.java | 9 +- .../ElroConnectsBindingConstants.java | 4 +- ...nnectsDynamicStateDescriptionProvider.java | 3 +- .../internal/devices/ElroConnectsDevice.java | 2 +- .../ElroConnectsBridgeDiscoveryService.java | 13 +- .../ElroConnectsDiscoveryService.java | 11 +- .../handler/ElroConnectsAccountHandler.java | 4 +- .../handler/ElroConnectsBridgeHandler.java | 8 +- .../action/EnergiDataServiceActions.java | 34 +++-- .../internal/retry/strategy/FixedTime.java | 3 +- .../internal/Enigma2BindingConstants.java | 3 +- .../internal/handler/Enigma2Handler.java | 12 +- .../enigma2/internal/Enigma2ClientTest.java | 32 +++-- .../EnOceanDeviceDiscoveryService.java | 2 +- .../enocean/internal/eep/A5_20/A5_20_04.java | 2 +- .../internal/eep/A5_38/A5_38_08_Blinds.java | 12 +- .../internal/eep/A5_38/A5_38_08_Dimming.java | 18 ++- .../eep/A5_3F/A5_3F_7F_EltakoFRM.java | 17 ++- .../eep/A5_3F/A5_3F_7F_EltakoFSB.java | 24 ++-- .../enocean/internal/eep/D2_01/D2_01.java | 6 +- .../internal/eep/D2_01/D2_01_09_Permundo.java | 8 +- .../internal/eep/D2_01/D2_01_0F_NodON.java | 4 +- .../internal/eep/D2_01/D2_01_12_NodON.java | 4 +- .../enocean/internal/eep/D2_05/D2_05_00.java | 4 +- .../internal/eep/D2_05/D2_05_00_NodON.java | 4 +- .../enocean/internal/eep/D2_50/D2_50.java | 8 +- .../enocean/internal/eep/EEPFactory.java | 2 +- .../enocean/internal/eep/F6_02/F6_02_01.java | 4 +- .../enocean/internal/eep/F6_02/F6_02_02.java | 4 +- .../handler/EnOceanBaseThingHandler.java | 4 +- .../handler/EnOceanBridgeHandler.java | 10 +- .../handler/EnOceanClassicDeviceHandler.java | 4 +- .../enocean/internal/messages/ESP2Packet.java | 4 +- .../enocean/internal/messages/ESP3Packet.java | 4 +- .../EnphaseDevicesDiscoveryService.java | 8 +- .../discovery/EnvoyDiscoveryParticipant.java | 3 +- .../internal/handler/EnvoyBridgeHandler.java | 13 +- .../internal/EnturNoHandlerFactory.java | 3 +- .../epsonprojector/internal/enums/Switch.java | 2 +- .../internal/EtherRainBindingConstants.java | 3 +- .../config/EtherRainConfiguration.java | 3 +- .../binding/evcc/internal/EvccHandler.java | 2 +- .../handler/EvohomeAccountBridgeHandler.java | 6 +- .../handler/EvohomeHeatingZoneHandler.java | 4 +- .../exec/internal/ExecHandlerFactory.java | 3 +- .../internal/FeicanBindingConstants.java | 3 +- .../internal/handler/FeicanHandler.java | 16 +-- ...ineOffsetWeatherStationHandlerFactory.java | 4 +- .../FineOffsetGatewayDiscoveryService.java | 4 +- .../internal/domain/Measurand.java | 1 + .../io/flic/fliclib/javaclient/Packets.java | 6 +- .../internal/FlicButtonBindingConstants.java | 4 +- .../internal/handler/ChildThingHandler.java | 5 +- .../fmiweather/internal/client/FMISID.java | 3 +- .../fmiweather/internal/client/LatLon.java | 3 +- .../AbstractWeatherHandlerTest.java | 6 +- .../binding/fmiweather/FMIRequestTest.java | 30 ++-- .../folderwatcher/internal/api/S3Actions.java | 2 +- .../internal/api/auth/AWS4SignerBase.java | 8 +- .../AWS4SignerForAuthorizationHeader.java | 5 +- .../handler/FtpFolderWatcherHandler.java | 2 +- .../FoldingSlotDiscoveryService.java | 4 +- .../handler/FoldingClientHandler.java | 4 +- .../folding/internal/handler/SlotHandler.java | 4 +- .../foobot/internal/FoobotHandlerFactory.java | 2 +- .../FoobotAccountDiscoveryService.java | 4 +- .../handler/FoobotAccountHandler.java | 10 +- .../internal/FreeboxBindingConstants.java | 3 +- .../internal/api/FreeboxApiManager.java | 3 +- .../model/FreeboxAirMediaReceiverRequest.java | 4 +- .../api/model/FreeboxAuthorizationStatus.java | 2 +- .../console/FreeboxCommandExtension.java | 4 +- .../discovery/FreeboxDiscoveryService.java | 4 +- .../internal/handler/FreeboxHandler.java | 26 ++-- .../freeboxos/internal/api/Response.java | 4 +- .../internal/api/rest/APManager.java | 8 +- .../internal/api/rest/AfpManager.java | 4 +- .../internal/api/rest/CallManager.java | 4 +- .../internal/api/rest/ConnectionManager.java | 12 +- .../internal/api/rest/FreeboxOsSession.java | 8 +- .../internal/api/rest/FreeplugManager.java | 4 +- .../internal/api/rest/HomeManager.java | 24 ++-- .../internal/api/rest/LanBrowserManager.java | 16 +-- .../internal/api/rest/LanManager.java | 4 +- .../internal/api/rest/LoginManager.java | 8 +- .../api/rest/MediaReceiverManager.java | 8 +- .../internal/api/rest/PhoneManager.java | 6 +- .../internal/api/rest/PlayerManager.java | 30 ++-- .../internal/api/rest/RepeaterManager.java | 12 +- .../internal/api/rest/SystemManager.java | 10 +- .../internal/api/rest/VmManager.java | 4 +- .../console/FreeboxOsCommandExtension.java | 4 +- .../internal/handler/ActivePlayerHandler.java | 4 +- .../internal/handler/CallHandler.java | 4 +- .../internal/handler/DectHandler.java | 11 +- .../internal/handler/FreeboxOsHandler.java | 4 +- .../internal/handler/FreeplugHandler.java | 4 +- .../internal/handler/PlayerHandler.java | 3 +- .../internal/handler/RepeaterHandler.java | 4 +- .../internal/handler/RevolutionHandler.java | 8 +- .../internal/handler/ServerHandler.java | 4 +- .../handler/FroniusBridgeHandler.java | 4 +- .../FSInternetRadioDiscoveryParticipant.java | 3 +- .../FSInternetRadioHandlerFactory.java | 3 +- .../handler/FSInternetRadioHandler.java | 16 +-- .../radio/FrontierSiliconRadioApiResult.java | 13 +- .../test/FSInternetRadioHandlerJavaTest.java | 4 +- .../internal/FtpUploadHandlerFactory.java | 3 +- .../handler/GardenaAccountHandler.java | 4 +- .../internal/handler/GardenaThingHandler.java | 2 +- .../model/dto/command/ValveCommand.java | 2 +- .../gce/internal/action/Ipx800Actions.java | 4 +- .../gce/internal/handler/Ipx800v3Handler.java | 7 +- .../gce/internal/model/M2MMessageParser.java | 2 +- .../internal/model/StatusFileInterpreter.java | 4 +- .../GeneracMobileLinkDiscoveryService.java | 2 +- .../GeneracMobileLinkAccountHandler.java | 10 +- .../GeneracMobileLinkGeneratorHandler.java | 2 +- .../internal/command/CommandGetserial.java | 2 +- .../internal/command/CommandSendir.java | 2 +- .../internal/command/CommandSendserial.java | 2 +- .../internal/command/CommandSetserial.java | 2 +- .../internal/command/CommandSetstate.java | 2 +- .../internal/handler/GlobalCacheHandler.java | 2 +- .../internal/GoEChargerHandlerFactory.java | 3 +- .../internal/handler/GoEChargerHandler.java | 12 +- .../internal/handler/GoEChargerV2Handler.java | 23 ++- .../internal/message/NotificationHandler.java | 4 +- .../provider/AbstractCallbackServlet.java | 5 +- .../gree/internal/GreeBindingConstants.java | 3 +- .../internal/discovery/GreeDeviceFinder.java | 2 +- .../gree/internal/handler/GreeAirDevice.java | 13 +- .../gree/internal/handler/GreeHandler.java | 26 ++-- .../handler/GroheOndusSenseGuardHandler.java | 2 +- .../handler/GroheOndusSenseHandler.java | 2 +- .../bridge/GroupePSABridgeHandler.java | 5 +- .../discovery/GroupePSADiscoveryService.java | 8 +- .../rest/api/GroupePSAConnectApi.java | 4 +- .../internal/things/GroupePSAHandler.java | 4 +- 486 files changed, 2053 insertions(+), 1955 deletions(-) diff --git a/bundles/org.openhab.binding.adorne/src/main/java/org/openhab/binding/adorne/internal/discovery/AdorneDiscoveryService.java b/bundles/org.openhab.binding.adorne/src/main/java/org/openhab/binding/adorne/internal/discovery/AdorneDiscoveryService.java index 33dec534d..40064794e 100644 --- a/bundles/org.openhab.binding.adorne/src/main/java/org/openhab/binding/adorne/internal/discovery/AdorneDiscoveryService.java +++ b/bundles/org.openhab.binding.adorne/src/main/java/org/openhab/binding/adorne/internal/discovery/AdorneDiscoveryService.java @@ -14,7 +14,7 @@ package org.openhab.binding.adorne.internal.discovery; import static org.openhab.binding.adorne.internal.AdorneBindingConstants.*; -import java.util.Collections; +import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -52,7 +52,7 @@ public class AdorneDiscoveryService extends AbstractDiscoveryService implements */ public AdorneDiscoveryService() { // Passing false as last argument to super constructor turns off background discovery - super(Collections.singleton(new ThingTypeUID(BINDING_ID, "-")), DISCOVERY_TIMEOUT_SECONDS, false); + super(Set.of(new ThingTypeUID(BINDING_ID, "-")), DISCOVERY_TIMEOUT_SECONDS, false); // We create the hub controller with default host and port. In the future we could let users create hubs // manually with custom host and port settings and then perform discovery here for those hubs. @@ -76,10 +76,9 @@ public class AdorneDiscoveryService extends AbstractDiscoveryService implements // Future enhancement: Need a timeout for each future execution to recover from bugs in the hub controller, but // Java8 doesn't yet offer that - adorneHubController.start().thenCompose(Void -> { - // We use the hub's MAC address as its unique identifier - return adorneHubController.getMACAddress(); - }).thenCompose(macAddress -> { + adorneHubController.start().thenCompose(Void -> + // We use the hub's MAC address as its unique identifier + adorneHubController.getMACAddress()).thenCompose(macAddress -> { String macAddressNoColon = macAddress.replace(':', '-'); // Colons are not allowed in ThingUIDs bridgeUID[0] = new ThingUID(THING_TYPE_HUB, macAddressNoColon); // We have fully discovered the hub diff --git a/bundles/org.openhab.binding.adorne/src/main/java/org/openhab/binding/adorne/internal/handler/AdorneDimmerHandler.java b/bundles/org.openhab.binding.adorne/src/main/java/org/openhab/binding/adorne/internal/handler/AdorneDimmerHandler.java index 7ca99db1e..e8ca0c636 100644 --- a/bundles/org.openhab.binding.adorne/src/main/java/org/openhab/binding/adorne/internal/handler/AdorneDimmerHandler.java +++ b/bundles/org.openhab.binding.adorne/src/main/java/org/openhab/binding/adorne/internal/handler/AdorneDimmerHandler.java @@ -50,10 +50,10 @@ public class AdorneDimmerHandler extends AdorneSwitchHandler { if (channelUID.getId().equals(CHANNEL_BRIGHTNESS)) { if (command instanceof RefreshType) { refreshBrightness(); - } else if (command instanceof PercentType) { + } else if (command instanceof PercentType percentCommand) { // Change the brightness through the hub controller AdorneHubController adorneHubController = getAdorneHubController(); - int level = ((PercentType) command).intValue(); + int level = percentCommand.intValue(); if (level >= 1 && level <= 100) { // Ignore commands outside of the supported 1-100 range adorneHubController.setBrightness(zoneId, level); } else { diff --git a/bundles/org.openhab.binding.adorne/src/main/java/org/openhab/binding/adorne/internal/hub/AdorneHubConnection.java b/bundles/org.openhab.binding.adorne/src/main/java/org/openhab/binding/adorne/internal/hub/AdorneHubConnection.java index b911b8992..011319754 100644 --- a/bundles/org.openhab.binding.adorne/src/main/java/org/openhab/binding/adorne/internal/hub/AdorneHubConnection.java +++ b/bundles/org.openhab.binding.adorne/src/main/java/org/openhab/binding/adorne/internal/hub/AdorneHubConnection.java @@ -86,8 +86,8 @@ public class AdorneHubConnection { return null; // Eat empty messages } logger.debug("Received message {}", msg); - if (msg instanceof JsonObject) { - msgJsonObject = (JsonObject) msg; + if (msg instanceof JsonObject object) { + msgJsonObject = object; } return msgJsonObject; } diff --git a/bundles/org.openhab.binding.ahawastecollection/src/main/java/org/openhab/binding/ahawastecollection/internal/AhaCollectionScheduleImpl.java b/bundles/org.openhab.binding.ahawastecollection/src/main/java/org/openhab/binding/ahawastecollection/internal/AhaCollectionScheduleImpl.java index 6e888a3d5..10ec2fadb 100644 --- a/bundles/org.openhab.binding.ahawastecollection/src/main/java/org/openhab/binding/ahawastecollection/internal/AhaCollectionScheduleImpl.java +++ b/bundles/org.openhab.binding.ahawastecollection/src/main/java/org/openhab/binding/ahawastecollection/internal/AhaCollectionScheduleImpl.java @@ -81,7 +81,7 @@ final class AhaCollectionScheduleImpl implements AhaCollectionSchedule { final Elements table = doc.select("table"); - if (table.size() == 0) { + if (table.isEmpty()) { logger.warn("No result table found."); return Collections.emptyMap(); } @@ -91,7 +91,7 @@ final class AhaCollectionScheduleImpl implements AhaCollectionSchedule { while (rowIt.hasNext()) { final Element currentRow = rowIt.next(); - if (!currentRow.tagName().equals("tr")) { + if (!"tr".equals(currentRow.tagName())) { continue; } // Skip header, empty and download button rows. diff --git a/bundles/org.openhab.binding.airq/src/main/java/org/openhab/binding/airq/internal/AirqHandlerFactory.java b/bundles/org.openhab.binding.airq/src/main/java/org/openhab/binding/airq/internal/AirqHandlerFactory.java index 2e6adbeae..d9c2bd2dd 100644 --- a/bundles/org.openhab.binding.airq/src/main/java/org/openhab/binding/airq/internal/AirqHandlerFactory.java +++ b/bundles/org.openhab.binding.airq/src/main/java/org/openhab/binding/airq/internal/AirqHandlerFactory.java @@ -14,7 +14,6 @@ package org.openhab.binding.airq.internal; import static org.openhab.binding.airq.internal.AirqBindingConstants.THING_TYPE_AIRQ; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -38,7 +37,7 @@ import org.osgi.service.component.annotations.Reference; @Component(configurationPid = "binding.airq", service = ThingHandlerFactory.class) public class AirqHandlerFactory extends BaseThingHandlerFactory { - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_AIRQ); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_AIRQ); private final HttpClientFactory httpClientFactory; @Activate diff --git a/bundles/org.openhab.binding.airquality/src/main/java/org/openhab/binding/airquality/internal/api/Pollutant.java b/bundles/org.openhab.binding.airquality/src/main/java/org/openhab/binding/airquality/internal/api/Pollutant.java index 2957b6729..f5c5c6ebd 100644 --- a/bundles/org.openhab.binding.airquality/src/main/java/org/openhab/binding/airquality/internal/api/Pollutant.java +++ b/bundles/org.openhab.binding.airquality/src/main/java/org/openhab/binding/airquality/internal/api/Pollutant.java @@ -64,12 +64,12 @@ public enum Pollutant { new ConcentrationRange(205, 404, TWO_HUNDRED), new ConcentrationRange(405, 504, THREE_HUNDRED), new ConcentrationRange(505, 604, FOUR_HUNDRED)); - public static enum SensitiveGroup { + public enum SensitiveGroup { RESPIRATORY, HEART, ELDERLY, CHILDREN, - ASTHMA; + ASTHMA } public final Set sensitiveGroups; diff --git a/bundles/org.openhab.binding.airquality/src/main/java/org/openhab/binding/airquality/internal/api/dto/ResponseRoot.java b/bundles/org.openhab.binding.airquality/src/main/java/org/openhab/binding/airquality/internal/api/dto/ResponseRoot.java index 09c665f7e..3dbcb1828 100644 --- a/bundles/org.openhab.binding.airquality/src/main/java/org/openhab/binding/airquality/internal/api/dto/ResponseRoot.java +++ b/bundles/org.openhab.binding.airquality/src/main/java/org/openhab/binding/airquality/internal/api/dto/ResponseRoot.java @@ -22,11 +22,11 @@ import com.google.gson.annotations.SerializedName; * @author GaĆ«l L'hopital - Initial contribution */ public class ResponseRoot { - public static enum ResponseStatus { + public enum ResponseStatus { @SerializedName("error") ERROR, @SerializedName("ok") - OK; + OK } protected ResponseStatus status = ResponseStatus.OK; diff --git a/bundles/org.openhab.binding.airquality/src/main/java/org/openhab/binding/airquality/internal/config/SensitiveGroupConfiguration.java b/bundles/org.openhab.binding.airquality/src/main/java/org/openhab/binding/airquality/internal/config/SensitiveGroupConfiguration.java index 47afa4fec..1df1e9d59 100644 --- a/bundles/org.openhab.binding.airquality/src/main/java/org/openhab/binding/airquality/internal/config/SensitiveGroupConfiguration.java +++ b/bundles/org.openhab.binding.airquality/src/main/java/org/openhab/binding/airquality/internal/config/SensitiveGroupConfiguration.java @@ -28,8 +28,7 @@ public class SensitiveGroupConfiguration { public @Nullable SensitiveGroup asSensitiveGroup() { try { - SensitiveGroup value = SensitiveGroup.valueOf(group); - return value; + return SensitiveGroup.valueOf(group); } catch (IllegalArgumentException e) { return null; } diff --git a/bundles/org.openhab.binding.airquality/src/main/java/org/openhab/binding/airquality/internal/discovery/AirQualityDiscoveryService.java b/bundles/org.openhab.binding.airquality/src/main/java/org/openhab/binding/airquality/internal/discovery/AirQualityDiscoveryService.java index 0edc187dd..f30c05b2d 100644 --- a/bundles/org.openhab.binding.airquality/src/main/java/org/openhab/binding/airquality/internal/discovery/AirQualityDiscoveryService.java +++ b/bundles/org.openhab.binding.airquality/src/main/java/org/openhab/binding/airquality/internal/discovery/AirQualityDiscoveryService.java @@ -15,7 +15,6 @@ package org.openhab.binding.airquality.internal.discovery; import static org.openhab.binding.airquality.internal.AirQualityBindingConstants.*; import static org.openhab.binding.airquality.internal.config.AirQualityConfiguration.LOCATION; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -43,7 +42,7 @@ import org.slf4j.LoggerFactory; @NonNullByDefault public class AirQualityDiscoveryService extends AbstractDiscoveryService implements ThingHandlerService { private static final int DISCOVER_TIMEOUT_SECONDS = 2; - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_STATION); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_STATION); private final Logger logger = LoggerFactory.getLogger(AirQualityDiscoveryService.class); @@ -59,9 +58,8 @@ public class AirQualityDiscoveryService extends AbstractDiscoveryService impleme @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof AirQualityBridgeHandler) { - final AirQualityBridgeHandler bridgeHandler = (AirQualityBridgeHandler) handler; - this.bridgeHandler = bridgeHandler; + if (handler instanceof AirQualityBridgeHandler bridgeHandlerInstance) { + this.bridgeHandler = bridgeHandlerInstance; this.locationProvider = bridgeHandler.getLocationProvider(); } } diff --git a/bundles/org.openhab.binding.airvisualnode/src/main/java/org/openhab/binding/airvisualnode/internal/AirVisualNodeBindingConstants.java b/bundles/org.openhab.binding.airvisualnode/src/main/java/org/openhab/binding/airvisualnode/internal/AirVisualNodeBindingConstants.java index 72c3d3ab8..1924e2ebe 100644 --- a/bundles/org.openhab.binding.airvisualnode/src/main/java/org/openhab/binding/airvisualnode/internal/AirVisualNodeBindingConstants.java +++ b/bundles/org.openhab.binding.airvisualnode/src/main/java/org/openhab/binding/airvisualnode/internal/AirVisualNodeBindingConstants.java @@ -12,9 +12,6 @@ */ package org.openhab.binding.airvisualnode.internal; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -51,12 +48,10 @@ public class AirVisualNodeBindingConstants { .getUID().getId(); // List of all supported Thing UIDs - public static final Set SUPPORTED_THING_TYPES_UIDS = Collections - .unmodifiableSet(new HashSet<>(Arrays.asList(THING_TYPE_AVNODE))); + public static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_AVNODE); // List of all supported Channel ids - public static final Set SUPPORTED_CHANNEL_IDS = Collections - .unmodifiableSet(new HashSet<>(Arrays.asList(CHANNEL_CO2, CHANNEL_HUMIDITY, CHANNEL_AQI_US, CHANNEL_PM_25, - CHANNEL_PM_10, CHANNEL_PM_01, CHANNEL_TEMP_CELSIUS, CHANNEL_BATTERY_LEVEL, CHANNEL_WIFI_STRENGTH, - CHANNEL_TIMESTAMP, CHANNEL_USED_MEMORY))); + public static final Set SUPPORTED_CHANNEL_IDS = Set.of(CHANNEL_CO2, CHANNEL_HUMIDITY, CHANNEL_AQI_US, + CHANNEL_PM_25, CHANNEL_PM_10, CHANNEL_PM_01, CHANNEL_TEMP_CELSIUS, CHANNEL_BATTERY_LEVEL, + CHANNEL_WIFI_STRENGTH, CHANNEL_TIMESTAMP, CHANNEL_USED_MEMORY); } diff --git a/bundles/org.openhab.binding.airvisualnode/src/main/java/org/openhab/binding/airvisualnode/internal/discovery/AirVisualNodeDiscoveryService.java b/bundles/org.openhab.binding.airvisualnode/src/main/java/org/openhab/binding/airvisualnode/internal/discovery/AirVisualNodeDiscoveryService.java index 850049dfc..ce6ebbd51 100644 --- a/bundles/org.openhab.binding.airvisualnode/src/main/java/org/openhab/binding/airvisualnode/internal/discovery/AirVisualNodeDiscoveryService.java +++ b/bundles/org.openhab.binding.airvisualnode/src/main/java/org/openhab/binding/airvisualnode/internal/discovery/AirVisualNodeDiscoveryService.java @@ -14,7 +14,7 @@ package org.openhab.binding.airvisualnode.internal.discovery; import java.io.IOException; import java.net.UnknownHostException; -import java.util.Collections; +import java.util.Set; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; @@ -55,7 +55,7 @@ public class AirVisualNodeDiscoveryService extends AbstractDiscoveryService { private @Nullable ScheduledFuture backgroundDiscoveryFuture; public AirVisualNodeDiscoveryService() { - super(Collections.singleton(AirVisualNodeBindingConstants.THING_TYPE_AVNODE), 600, true); + super(Set.of(AirVisualNodeBindingConstants.THING_TYPE_AVNODE), 600, true); } @Override diff --git a/bundles/org.openhab.binding.airvisualnode/src/main/java/org/openhab/binding/airvisualnode/internal/dto/airvisual/Measurements.java b/bundles/org.openhab.binding.airvisualnode/src/main/java/org/openhab/binding/airvisualnode/internal/dto/airvisual/Measurements.java index cbdcb73ae..6d316c61b 100644 --- a/bundles/org.openhab.binding.airvisualnode/src/main/java/org/openhab/binding/airvisualnode/internal/dto/airvisual/Measurements.java +++ b/bundles/org.openhab.binding.airvisualnode/src/main/java/org/openhab/binding/airvisualnode/internal/dto/airvisual/Measurements.java @@ -49,6 +49,7 @@ public class Measurements implements MeasurementsInterface { this.vocPpb = vocPpb; } + @Override public int getCo2Ppm() { return co2Ppm; } @@ -57,6 +58,7 @@ public class Measurements implements MeasurementsInterface { this.co2Ppm = co2Ppm; } + @Override public int getHumidityRH() { return humidityRH; } @@ -65,6 +67,7 @@ public class Measurements implements MeasurementsInterface { this.humidityRH = humidityRH; } + @Override public int getPm25AQICN() { return pm25AQICN; } @@ -73,6 +76,7 @@ public class Measurements implements MeasurementsInterface { this.pm25AQICN = pm25AQICN; } + @Override public int getPm25AQIUS() { return pm25AQIUS; } @@ -91,6 +95,7 @@ public class Measurements implements MeasurementsInterface { return 0; } + @Override public float getPm25Ugm3() { return pm25Ugm3; } @@ -99,6 +104,7 @@ public class Measurements implements MeasurementsInterface { this.pm25Ugm3 = pm25Ugm3; } + @Override public float getTemperatureC() { return temperatureC; } @@ -107,6 +113,7 @@ public class Measurements implements MeasurementsInterface { this.temperatureC = temperatureC; } + @Override public float getTemperatureF() { return temperatureF; } @@ -115,6 +122,7 @@ public class Measurements implements MeasurementsInterface { this.temperatureF = temperatureF; } + @Override public int getVocPpb() { return vocPpb; } diff --git a/bundles/org.openhab.binding.airvisualnode/src/main/java/org/openhab/binding/airvisualnode/internal/dto/airvisual/NodeData.java b/bundles/org.openhab.binding.airvisualnode/src/main/java/org/openhab/binding/airvisualnode/internal/dto/airvisual/NodeData.java index 4694d44cb..8a7f055fa 100644 --- a/bundles/org.openhab.binding.airvisualnode/src/main/java/org/openhab/binding/airvisualnode/internal/dto/airvisual/NodeData.java +++ b/bundles/org.openhab.binding.airvisualnode/src/main/java/org/openhab/binding/airvisualnode/internal/dto/airvisual/NodeData.java @@ -40,6 +40,7 @@ public class NodeData implements NodeDataInterface { this.status = status; } + @Override public DateAndTime getDateAndTime() { return dateAndTime; } @@ -48,6 +49,7 @@ public class NodeData implements NodeDataInterface { this.dateAndTime = dateAndTime; } + @Override public MeasurementsInterface getMeasurements() { return measurements; } @@ -56,6 +58,7 @@ public class NodeData implements NodeDataInterface { this.measurements = measurements; } + @Override public String getSerialNumber() { return serialNumber; } @@ -64,6 +67,7 @@ public class NodeData implements NodeDataInterface { this.serialNumber = serialNumber; } + @Override public Settings getSettings() { return settings; } @@ -72,6 +76,7 @@ public class NodeData implements NodeDataInterface { this.settings = settings; } + @Override public Status getStatus() { return status; } diff --git a/bundles/org.openhab.binding.airvisualnode/src/main/java/org/openhab/binding/airvisualnode/internal/dto/airvisualpro/Measurements.java b/bundles/org.openhab.binding.airvisualnode/src/main/java/org/openhab/binding/airvisualnode/internal/dto/airvisualpro/Measurements.java index 481843e41..ffcfe87a1 100644 --- a/bundles/org.openhab.binding.airvisualnode/src/main/java/org/openhab/binding/airvisualnode/internal/dto/airvisualpro/Measurements.java +++ b/bundles/org.openhab.binding.airvisualnode/src/main/java/org/openhab/binding/airvisualnode/internal/dto/airvisualpro/Measurements.java @@ -66,6 +66,7 @@ public class Measurements implements MeasurementsInterface { this.vocPpb = vocPpb; } + @Override public int getCo2Ppm() { return co2Ppm; } @@ -74,6 +75,7 @@ public class Measurements implements MeasurementsInterface { this.co2Ppm = co2Ppm; } + @Override public int getHumidityRH() { return humidityRH; } @@ -82,6 +84,7 @@ public class Measurements implements MeasurementsInterface { this.humidityRH = humidityRH; } + @Override public int getPm25AQICN() { return pm25AQICN; } @@ -90,6 +93,7 @@ public class Measurements implements MeasurementsInterface { this.pm25AQICN = pm25AQICN; } + @Override public int getPm25AQIUS() { return pm25AQIUS; } @@ -98,6 +102,7 @@ public class Measurements implements MeasurementsInterface { this.pm25AQIUS = pm25AQIUS; } + @Override public float getPm01Ugm3() { return pm01Ugm3; } @@ -106,6 +111,7 @@ public class Measurements implements MeasurementsInterface { this.pm01Ugm3 = pm01Ugm3; } + @Override public float getPm10Ugm3() { return pm10Ugm3; } @@ -114,6 +120,7 @@ public class Measurements implements MeasurementsInterface { this.pm10Ugm3 = pm10Ugm3; } + @Override public float getPm25Ugm3() { return pm25Ugm3; } @@ -122,6 +129,7 @@ public class Measurements implements MeasurementsInterface { this.pm25Ugm3 = pm25Ugm3; } + @Override public float getTemperatureC() { return temperatureC; } @@ -130,6 +138,7 @@ public class Measurements implements MeasurementsInterface { this.temperatureC = temperatureC; } + @Override public float getTemperatureF() { return temperatureF; } @@ -138,6 +147,7 @@ public class Measurements implements MeasurementsInterface { this.temperatureF = temperatureF; } + @Override public int getVocPpb() { return vocPpb; } diff --git a/bundles/org.openhab.binding.airvisualnode/src/main/java/org/openhab/binding/airvisualnode/internal/dto/airvisualpro/ProNodeData.java b/bundles/org.openhab.binding.airvisualnode/src/main/java/org/openhab/binding/airvisualnode/internal/dto/airvisualpro/ProNodeData.java index b5162b715..2082a2f9f 100644 --- a/bundles/org.openhab.binding.airvisualnode/src/main/java/org/openhab/binding/airvisualnode/internal/dto/airvisualpro/ProNodeData.java +++ b/bundles/org.openhab.binding.airvisualnode/src/main/java/org/openhab/binding/airvisualnode/internal/dto/airvisualpro/ProNodeData.java @@ -44,6 +44,7 @@ public class ProNodeData implements NodeDataInterface { this.status = status; } + @Override public DateAndTime getDateAndTime() { return dateAndTime; } @@ -52,6 +53,7 @@ public class ProNodeData implements NodeDataInterface { this.dateAndTime = dateAndTime; } + @Override public MeasurementsInterface getMeasurements() { return measurements.get(0); } @@ -60,6 +62,7 @@ public class ProNodeData implements NodeDataInterface { this.measurements = measurements; } + @Override public String getSerialNumber() { return serialNumber; } @@ -68,6 +71,7 @@ public class ProNodeData implements NodeDataInterface { this.serialNumber = serialNumber; } + @Override public Settings getSettings() { return settings; } @@ -76,6 +80,7 @@ public class ProNodeData implements NodeDataInterface { this.settings = settings; } + @Override public Status getStatus() { return status; } diff --git a/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/actions/BridgeActions.java b/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/actions/BridgeActions.java index b21d41a83..33114c893 100644 --- a/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/actions/BridgeActions.java +++ b/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/actions/BridgeActions.java @@ -42,8 +42,8 @@ public class BridgeActions implements ThingActions { @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof ADBridgeHandler) { - this.bridge = (ADBridgeHandler) handler; + if (handler instanceof ADBridgeHandler bridgeHandler) { + this.bridge = bridgeHandler; } } diff --git a/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/handler/ADBridgeHandler.java b/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/handler/ADBridgeHandler.java index e5b7a49d6..453beb1f9 100644 --- a/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/handler/ADBridgeHandler.java +++ b/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/handler/ADBridgeHandler.java @@ -20,8 +20,8 @@ import java.io.IOException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.Collection; -import java.util.Collections; import java.util.Date; +import java.util.List; import java.util.Map; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -87,7 +87,7 @@ public abstract class ADBridgeHandler extends BaseBridgeHandler { @Override public Collection> getServices() { - return Collections.singletonList(BridgeActions.class); + return List.of(BridgeActions.class); } public void setDiscoveryService(AlarmDecoderDiscoveryService discoveryService) { diff --git a/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/handler/KeypadHandler.java b/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/handler/KeypadHandler.java index 34740a64a..fb255805e 100644 --- a/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/handler/KeypadHandler.java +++ b/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/handler/KeypadHandler.java @@ -113,13 +113,13 @@ public class KeypadHandler extends ADThingHandler { IntCommandMap intCommandMap = this.intCommandMap; if (channelUID.getId().equals(CHANNEL_KP_COMMAND)) { - if (command instanceof StringType) { - String cmd = ((StringType) command).toString(); + if (command instanceof StringType commandString) { + String cmd = commandString.toString(); handleKeypadCommand(cmd); } } else if (channelUID.getId().equals(CHANNEL_KP_INTCOMMAND)) { - if (command instanceof Number) { - int icmd = ((Number) command).intValue(); + if (command instanceof Number numberCommand) { + int icmd = numberCommand.intValue(); if (intCommandMap != null) { String cmd = intCommandMap.getCommand(icmd); if (cmd != null) { diff --git a/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/handler/VZoneHandler.java b/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/handler/VZoneHandler.java index 5e7e4822d..b6827d0b3 100644 --- a/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/handler/VZoneHandler.java +++ b/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/handler/VZoneHandler.java @@ -78,8 +78,8 @@ public class VZoneHandler extends ADThingHandler { @Override public void handleCommand(ChannelUID channelUID, Command command) { if (channelUID.getId().equals(CHANNEL_COMMAND)) { - if (command instanceof StringType) { - String cmd = ((StringType) command).toString(); + if (command instanceof StringType stringCommand) { + String cmd = stringCommand.toString(); if (CMD_OPEN.equalsIgnoreCase(cmd)) { sendCommand(ADCommand.setZone(config.address, ADCommand.ZONE_OPEN)); setChannelState(OnOffType.OFF); diff --git a/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/handler/ZoneHandler.java b/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/handler/ZoneHandler.java index 9154f719f..952f40fa1 100644 --- a/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/handler/ZoneHandler.java +++ b/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/handler/ZoneHandler.java @@ -46,7 +46,7 @@ public class ZoneHandler extends ADThingHandler { } /** Construct zone id from address and channel */ - public static final String zoneID(int address, int channel) { + public static String zoneID(int address, int channel) { return String.format("%d-%d", address, channel); } diff --git a/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/protocol/EXPMessage.java b/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/protocol/EXPMessage.java index b320f7c42..c0d5c582b 100644 --- a/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/protocol/EXPMessage.java +++ b/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/protocol/EXPMessage.java @@ -40,7 +40,7 @@ public class EXPMessage extends ADMessage { public EXPMessage(String message) throws IllegalArgumentException { super(message); - String topLevel[] = message.split(":"); + String[] topLevel = message.split(":"); if (topLevel.length != 2) { throw new IllegalArgumentException("Multiple colons found in EXP message"); } diff --git a/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/protocol/KeypadMessage.java b/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/protocol/KeypadMessage.java index cb9cad16e..ce9891b31 100644 --- a/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/protocol/KeypadMessage.java +++ b/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/protocol/KeypadMessage.java @@ -143,8 +143,7 @@ public class KeypadMessage extends ADMessage { return false; } else if (this == obj) { return true; - } else if (obj instanceof KeypadMessage) { - KeypadMessage other = (KeypadMessage) obj; + } else if (obj instanceof KeypadMessage other) { return this.message.equals(other.message); } else { return false; diff --git a/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/protocol/LRRMessage.java b/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/protocol/LRRMessage.java index 3857b9e82..c39ae7f74 100644 --- a/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/protocol/LRRMessage.java +++ b/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/protocol/LRRMessage.java @@ -43,7 +43,7 @@ public class LRRMessage extends ADMessage { public LRRMessage(String message) throws IllegalArgumentException { super(message); - String topLevel[] = message.split(":"); + String[] topLevel = message.split(":"); if (topLevel.length != 2) { throw new IllegalArgumentException("multiple colons in LRR message"); } diff --git a/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/protocol/RFXMessage.java b/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/protocol/RFXMessage.java index 0dc687fae..5175c4599 100644 --- a/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/protocol/RFXMessage.java +++ b/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/protocol/RFXMessage.java @@ -43,7 +43,7 @@ public class RFXMessage extends ADMessage { public RFXMessage(String message) throws IllegalArgumentException { super(message); - String topLevel[] = message.split(":"); + String[] topLevel = message.split(":"); if (topLevel.length != 2) { throw new IllegalArgumentException("Multiple colons found in RFX message"); } diff --git a/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/protocol/VersionMessage.java b/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/protocol/VersionMessage.java index 3819ee896..2cd570ca5 100644 --- a/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/protocol/VersionMessage.java +++ b/bundles/org.openhab.binding.alarmdecoder/src/main/java/org/openhab/binding/alarmdecoder/internal/protocol/VersionMessage.java @@ -38,7 +38,7 @@ public class VersionMessage extends ADMessage { public VersionMessage(String message) throws IllegalArgumentException { super(message); - String topLevel[] = message.split(":"); + String[] topLevel = message.split(":"); if (topLevel.length != 2) { throw new IllegalArgumentException("Multiple colons found in VER message"); } diff --git a/bundles/org.openhab.binding.allplay/src/main/java/org/openhab/binding/allplay/internal/AllPlayBindingProperties.java b/bundles/org.openhab.binding.allplay/src/main/java/org/openhab/binding/allplay/internal/AllPlayBindingProperties.java index 823b02229..2f208918a 100644 --- a/bundles/org.openhab.binding.allplay/src/main/java/org/openhab/binding/allplay/internal/AllPlayBindingProperties.java +++ b/bundles/org.openhab.binding.allplay/src/main/java/org/openhab/binding/allplay/internal/AllPlayBindingProperties.java @@ -63,9 +63,9 @@ public class AllPlayBindingProperties { private int getIntegerProperty(Dictionary properties, String propertyKey, int defaultValue) { Object configValue = properties.get(propertyKey); int value = defaultValue; - if (configValue instanceof String) { + if (configValue instanceof String stringValue) { try { - value = Integer.parseInt((String) configValue); + value = Integer.parseInt(stringValue); } catch (NumberFormatException e) { logger.warn("Unable to convert value {} for config property {} to integer. Using default value.", configValue, propertyKey); diff --git a/bundles/org.openhab.binding.allplay/src/main/java/org/openhab/binding/allplay/internal/AllPlayHandlerFactory.java b/bundles/org.openhab.binding.allplay/src/main/java/org/openhab/binding/allplay/internal/AllPlayHandlerFactory.java index e7615d79b..8d3a43f55 100644 --- a/bundles/org.openhab.binding.allplay/src/main/java/org/openhab/binding/allplay/internal/AllPlayHandlerFactory.java +++ b/bundles/org.openhab.binding.allplay/src/main/java/org/openhab/binding/allplay/internal/AllPlayHandlerFactory.java @@ -14,7 +14,6 @@ package org.openhab.binding.allplay.internal; import static org.openhab.binding.allplay.internal.AllPlayBindingConstants.SPEAKER_THING_TYPE; -import java.util.Collections; import java.util.Dictionary; import java.util.Hashtable; import java.util.Map; @@ -54,7 +53,7 @@ public class AllPlayHandlerFactory extends BaseThingHandlerFactory { private final Logger logger = LoggerFactory.getLogger(AllPlayHandlerFactory.class); - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(SPEAKER_THING_TYPE); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(SPEAKER_THING_TYPE); private final Map> audioSinkRegistrations = new ConcurrentHashMap<>(); private AllPlay allPlay; diff --git a/bundles/org.openhab.binding.allplay/src/main/java/org/openhab/binding/allplay/internal/discovery/AllPlaySpeakerDiscoveryService.java b/bundles/org.openhab.binding.allplay/src/main/java/org/openhab/binding/allplay/internal/discovery/AllPlaySpeakerDiscoveryService.java index f42baef7b..54fa0fb47 100644 --- a/bundles/org.openhab.binding.allplay/src/main/java/org/openhab/binding/allplay/internal/discovery/AllPlaySpeakerDiscoveryService.java +++ b/bundles/org.openhab.binding.allplay/src/main/java/org/openhab/binding/allplay/internal/discovery/AllPlaySpeakerDiscoveryService.java @@ -14,7 +14,6 @@ package org.openhab.binding.allplay.internal.discovery; import static org.openhab.binding.allplay.internal.AllPlayBindingConstants.SPEAKER_THING_TYPE; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -46,7 +45,7 @@ public class AllPlaySpeakerDiscoveryService extends AbstractDiscoveryService imp private final Logger logger = LoggerFactory.getLogger(AllPlaySpeakerDiscoveryService.class); private static final int DISCOVERY_TIMEOUT = 30; - private static final Set DISCOVERABLE_THING_TYPES_UIDS = Collections.singleton(SPEAKER_THING_TYPE); + private static final Set DISCOVERABLE_THING_TYPES_UIDS = Set.of(SPEAKER_THING_TYPE); private AllPlay allPlay; public AllPlaySpeakerDiscoveryService() { diff --git a/bundles/org.openhab.binding.allplay/src/main/java/org/openhab/binding/allplay/internal/handler/AllPlayHandler.java b/bundles/org.openhab.binding.allplay/src/main/java/org/openhab/binding/allplay/internal/handler/AllPlayHandler.java index 495c11a17..49c2d6a70 100644 --- a/bundles/org.openhab.binding.allplay/src/main/java/org/openhab/binding/allplay/internal/handler/AllPlayHandler.java +++ b/bundles/org.openhab.binding.allplay/src/main/java/org/openhab/binding/allplay/internal/handler/AllPlayHandler.java @@ -343,8 +343,8 @@ public class AllPlayHandler extends BaseThingHandler * @throws SpeakerException Exception if the volume change failed */ public void handleVolumeCommand(Command command) throws SpeakerException { - if (command instanceof PercentType) { - speaker.volume().setVolume(convertPercentToAbsoluteVolume((PercentType) command)); + if (command instanceof PercentType percentCommand) { + speaker.volume().setVolume(convertPercentToAbsoluteVolume(percentCommand)); } else if (command instanceof IncreaseDecreaseType) { int stepSize = (command == IncreaseDecreaseType.DECREASE ? -getVolumeStepSize() : getVolumeStepSize()); speaker.volume().adjustVolume(stepSize); diff --git a/bundles/org.openhab.binding.amazondashbutton/src/main/java/org/openhab/binding/amazondashbutton/internal/AmazonDashButtonHandlerFactory.java b/bundles/org.openhab.binding.amazondashbutton/src/main/java/org/openhab/binding/amazondashbutton/internal/AmazonDashButtonHandlerFactory.java index 135c05222..c8f952799 100644 --- a/bundles/org.openhab.binding.amazondashbutton/src/main/java/org/openhab/binding/amazondashbutton/internal/AmazonDashButtonHandlerFactory.java +++ b/bundles/org.openhab.binding.amazondashbutton/src/main/java/org/openhab/binding/amazondashbutton/internal/AmazonDashButtonHandlerFactory.java @@ -14,7 +14,6 @@ package org.openhab.binding.amazondashbutton.internal; import static org.openhab.binding.amazondashbutton.internal.AmazonDashButtonBindingConstants.DASH_BUTTON_THING_TYPE; -import java.util.Collections; import java.util.Set; import org.openhab.binding.amazondashbutton.internal.handler.AmazonDashButtonHandler; @@ -34,7 +33,7 @@ import org.osgi.service.component.annotations.Component; @Component(service = ThingHandlerFactory.class, configurationPid = "binding.amazondashbutton") public class AmazonDashButtonHandlerFactory extends BaseThingHandlerFactory { - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(DASH_BUTTON_THING_TYPE); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(DASH_BUTTON_THING_TYPE); @Override public boolean supportsThingType(ThingTypeUID thingTypeUID) { diff --git a/bundles/org.openhab.binding.amazondashbutton/src/main/java/org/openhab/binding/amazondashbutton/internal/discovery/AmazonDashButtonDiscoveryService.java b/bundles/org.openhab.binding.amazondashbutton/src/main/java/org/openhab/binding/amazondashbutton/internal/discovery/AmazonDashButtonDiscoveryService.java index 626e5fca1..e6782b3c4 100644 --- a/bundles/org.openhab.binding.amazondashbutton/src/main/java/org/openhab/binding/amazondashbutton/internal/discovery/AmazonDashButtonDiscoveryService.java +++ b/bundles/org.openhab.binding.amazondashbutton/src/main/java/org/openhab/binding/amazondashbutton/internal/discovery/AmazonDashButtonDiscoveryService.java @@ -15,7 +15,6 @@ package org.openhab.binding.amazondashbutton.internal.discovery; import static org.openhab.binding.amazondashbutton.internal.AmazonDashButtonBindingConstants.*; import java.math.BigDecimal; -import java.util.Collections; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -108,7 +107,7 @@ public class AmazonDashButtonDiscoveryService extends AbstractDiscoveryService i private boolean backgroundScanning = false; public AmazonDashButtonDiscoveryService() { - super(Collections.singleton(DASH_BUTTON_THING_TYPE), DISCOVER_TIMEOUT_SECONDS, false); + super(Set.of(DASH_BUTTON_THING_TYPE), DISCOVER_TIMEOUT_SECONDS, false); } @Override diff --git a/bundles/org.openhab.binding.amazondashbutton/src/main/java/org/openhab/binding/amazondashbutton/internal/pcap/PcapUtil.java b/bundles/org.openhab.binding.amazondashbutton/src/main/java/org/openhab/binding/amazondashbutton/internal/pcap/PcapUtil.java index 1b272ac31..d15fde52c 100644 --- a/bundles/org.openhab.binding.amazondashbutton/src/main/java/org/openhab/binding/amazondashbutton/internal/pcap/PcapUtil.java +++ b/bundles/org.openhab.binding.amazondashbutton/src/main/java/org/openhab/binding/amazondashbutton/internal/pcap/PcapUtil.java @@ -36,9 +36,8 @@ public class PcapUtil { */ public static Set getAllNetworkInterfaces() { try { - final Set allNetworkInterfaces = Collections.unmodifiableSet(Pcaps - .findAllDevs().stream().map(PcapNetworkInterfaceWrapper.TRANSFORMER).collect(Collectors.toSet())); - return allNetworkInterfaces; + return Collections.unmodifiableSet(Pcaps.findAllDevs().stream().map(PcapNetworkInterfaceWrapper.TRANSFORMER) + .collect(Collectors.toSet())); } catch (PcapNativeException e) { throw new RuntimeException(e); } diff --git a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/AmazonEchoControlHandlerFactory.java b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/AmazonEchoControlHandlerFactory.java index 85f4bf3dc..86dde679b 100644 --- a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/AmazonEchoControlHandlerFactory.java +++ b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/AmazonEchoControlHandlerFactory.java @@ -146,10 +146,10 @@ public class AmazonEchoControlHandlerFactory extends BaseThingHandlerFactory { .getService(serviceReg.getReference()); serviceReg.unregister(); if (service != null) { - if (service instanceof AmazonEchoDiscovery) { - ((AmazonEchoDiscovery) service).deactivate(); - } else if (service instanceof SmartHomeDevicesDiscovery) { - ((SmartHomeDevicesDiscovery) service).deactivate(); + if (service instanceof AmazonEchoDiscovery discovery) { + discovery.deactivate(); + } else if (service instanceof SmartHomeDevicesDiscovery discovery) { + discovery.deactivate(); } else { logger.warn("Found unknown discovery-service instance: {}", service); } diff --git a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/channelhandler/ChannelHandlerAnnouncement.java b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/channelhandler/ChannelHandlerAnnouncement.java index 9b7c1295e..860784bf6 100644 --- a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/channelhandler/ChannelHandlerAnnouncement.java +++ b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/channelhandler/ChannelHandlerAnnouncement.java @@ -49,8 +49,8 @@ public class ChannelHandlerAnnouncement extends ChannelHandler { public boolean tryHandleCommand(Device device, Connection connection, String channelId, Command command) throws IOException, URISyntaxException { if (channelId.equals(CHANNEL_NAME)) { - if (command instanceof StringType) { - String commandValue = ((StringType) command).toFullString(); + if (command instanceof StringType stringCommand) { + String commandValue = stringCommand.toFullString(); String body = commandValue; String title = null; String speak = commandValue; diff --git a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/channelhandler/IEchoThingHandler.java b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/channelhandler/IEchoThingHandler.java index d7afb03d0..2020bdd1e 100644 --- a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/channelhandler/IEchoThingHandler.java +++ b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/channelhandler/IEchoThingHandler.java @@ -26,6 +26,7 @@ import org.openhab.binding.amazonechocontrol.internal.jsons.JsonDevices.Device; */ @NonNullByDefault public interface IEchoThingHandler extends IAmazonThingHandler { + @Override void startAnnouncement(Device device, String speak, String bodyText, @Nullable String title, @Nullable Integer volume) throws IOException, URISyntaxException; } diff --git a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/discovery/SmartHomeDevicesDiscovery.java b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/discovery/SmartHomeDevicesDiscovery.java index 2cb40b640..41cccfe16 100644 --- a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/discovery/SmartHomeDevicesDiscovery.java +++ b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/discovery/SmartHomeDevicesDiscovery.java @@ -143,8 +143,7 @@ public class SmartHomeDevicesDiscovery extends AbstractDiscoveryService { String deviceName = null; Map props = new HashMap<>(); - if (smartHomeDevice instanceof SmartHomeDevice) { - SmartHomeDevice shd = (SmartHomeDevice) smartHomeDevice; + if (smartHomeDevice instanceof SmartHomeDevice shd) { logger.trace("Found SmartHome device: {}", shd); String entityId = shd.entityId; @@ -165,7 +164,7 @@ public class SmartHomeDevicesDiscovery extends AbstractDiscoveryService { // Connected through skill continue; } - if (!(smartHomeDeviceDiscoveryMode == 2) && "openHAB".equalsIgnoreCase(shd.manufacturerName)) { + if (smartHomeDeviceDiscoveryMode != 2 && "openHAB".equalsIgnoreCase(shd.manufacturerName)) { // OpenHAB device continue; } @@ -203,8 +202,7 @@ public class SmartHomeDevicesDiscovery extends AbstractDiscoveryService { deviceName = shd.friendlyName; } props.put(DEVICE_PROPERTY_ID, id); - } else if (smartHomeDevice instanceof SmartHomeGroup) { - SmartHomeGroup shg = (SmartHomeGroup) smartHomeDevice; + } else if (smartHomeDevice instanceof SmartHomeGroup shg) { logger.trace("Found SmartHome device: {}", shg); String id = shg.findId(); diff --git a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/handler/AccountHandler.java b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/handler/AccountHandler.java index 9c773ac4c..1eb78b4d3 100644 --- a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/handler/AccountHandler.java +++ b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/handler/AccountHandler.java @@ -821,8 +821,7 @@ public class AccountHandler extends BaseBridgeHandler implements IWebSocketComma // create new id map Map newJsonIdSmartHomeDeviceMapping = new HashMap<>(); for (Object smartHomeDevice : smartHomeDevices) { - if (smartHomeDevice instanceof SmartHomeBaseDevice) { - SmartHomeBaseDevice smartHomeBaseDevice = (SmartHomeBaseDevice) smartHomeDevice; + if (smartHomeDevice instanceof SmartHomeBaseDevice smartHomeBaseDevice) { String id = smartHomeBaseDevice.findId(); if (id != null) { newJsonIdSmartHomeDeviceMapping.put(id, smartHomeBaseDevice); diff --git a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/handler/EchoHandler.java b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/handler/EchoHandler.java index 367667db4..13fa2b3e8 100644 --- a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/handler/EchoHandler.java +++ b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/handler/EchoHandler.java @@ -293,8 +293,8 @@ public class EchoHandler extends BaseThingHandler implements IEchoThingHandler { } // Notification commands if (channelId.equals(CHANNEL_NOTIFICATION_VOLUME)) { - if (command instanceof PercentType) { - int volume = ((PercentType) command).intValue(); + if (command instanceof PercentType percentCommand) { + int volume = percentCommand.intValue(); connection.notificationVolume(device, volume); this.notificationVolumeLevel = volume; waitForUpdate = -1; @@ -318,21 +318,18 @@ public class EchoHandler extends BaseThingHandler implements IEchoThingHandler { // Media progress commands Long mediaPosition = null; if (channelId.equals(CHANNEL_MEDIA_PROGRESS)) { - if (command instanceof PercentType) { - PercentType value = (PercentType) command; - int percent = value.intValue(); + if (command instanceof PercentType percentCommand) { + int percent = percentCommand.intValue(); mediaPosition = Math.round((mediaLengthMs / 1000d) * (percent / 100d)); } } if (channelId.equals(CHANNEL_MEDIA_PROGRESS_TIME)) { - if (command instanceof DecimalType) { - DecimalType value = (DecimalType) command; - mediaPosition = value.longValue(); + if (command instanceof DecimalType decimalCommand) { + mediaPosition = decimalCommand.longValue(); } - if (command instanceof QuantityType) { - QuantityType value = (QuantityType) command; + if (command instanceof QuantityType quantityCommand) { @Nullable - QuantityType seconds = value.toUnit(Units.SECOND); + QuantityType seconds = quantityCommand.toUnit(Units.SECOND); if (seconds != null) { mediaPosition = seconds.longValue(); } @@ -353,9 +350,8 @@ public class EchoHandler extends BaseThingHandler implements IEchoThingHandler { // Volume commands if (channelId.equals(CHANNEL_VOLUME)) { Integer volume = null; - if (command instanceof PercentType) { - PercentType value = (PercentType) command; - volume = value.intValue(); + if (command instanceof PercentType percentCommand) { + volume = percentCommand.intValue(); } else if (command == OnOffType.OFF) { volume = 0; } else if (command == OnOffType.ON) { @@ -393,8 +389,7 @@ public class EchoHandler extends BaseThingHandler implements IEchoThingHandler { // shuffle command if (channelId.equals(CHANNEL_SHUFFLE)) { - if (command instanceof OnOffType) { - OnOffType value = (OnOffType) command; + if (command instanceof OnOffType value) { connection.command(device, "{\"type\":\"ShuffleCommand\",\"shuffle\":\"" + (value == OnOffType.ON ? "true" : "false") + "\"}"); @@ -429,8 +424,8 @@ public class EchoHandler extends BaseThingHandler implements IEchoThingHandler { // bluetooth commands if (channelId.equals(CHANNEL_BLUETOOTH_MAC)) { needBluetoothRefresh = true; - if (command instanceof StringType) { - String address = ((StringType) command).toFullString(); + if (command instanceof StringType stringCommand) { + String address = stringCommand.toFullString(); if (!address.isEmpty()) { waitForUpdate = 4000; } @@ -566,9 +561,8 @@ public class EchoHandler extends BaseThingHandler implements IEchoThingHandler { } } if (channelId.equals(CHANNEL_TEXT_TO_SPEECH_VOLUME)) { - if (command instanceof PercentType) { - PercentType value = (PercentType) command; - textToSpeechVolume = value.intValue(); + if (command instanceof PercentType percentCommand) { + textToSpeechVolume = percentCommand.intValue(); } else if (command == OnOffType.OFF) { textToSpeechVolume = 0; } else if (command == OnOffType.ON) { @@ -680,8 +674,7 @@ public class EchoHandler extends BaseThingHandler implements IEchoThingHandler { if (command instanceof RefreshType) { this.lastKnownEqualizer = null; } - if (command instanceof DecimalType) { - DecimalType value = (DecimalType) command; + if (command instanceof DecimalType decimalCommand) { if (this.lastKnownEqualizer == null) { updateEqualizerState(); } @@ -689,13 +682,13 @@ public class EchoHandler extends BaseThingHandler implements IEchoThingHandler { if (lastKnownEqualizer != null) { JsonEqualizer newEqualizerSetting = lastKnownEqualizer.createClone(); if (channelId.equals(CHANNEL_EQUALIZER_BASS)) { - newEqualizerSetting.bass = value.intValue(); + newEqualizerSetting.bass = decimalCommand.intValue(); } if (channelId.equals(CHANNEL_EQUALIZER_MIDRANGE)) { - newEqualizerSetting.mid = value.intValue(); + newEqualizerSetting.mid = decimalCommand.intValue(); } if (channelId.equals(CHANNEL_EQUALIZER_TREBLE)) { - newEqualizerSetting.treble = value.intValue(); + newEqualizerSetting.treble = decimalCommand.intValue(); } try { connection.setEqualizer(device, newEqualizerSetting); diff --git a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/handler/SmartHomeDeviceHandler.java b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/handler/SmartHomeDeviceHandler.java index 756661aa7..d37f4de76 100644 --- a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/handler/SmartHomeDeviceHandler.java +++ b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/handler/SmartHomeDeviceHandler.java @@ -191,8 +191,8 @@ public class SmartHomeDeviceHandler extends BaseThingHandler { boolean stateFound = false; Map> mapInterfaceToStates = new HashMap<>(); SmartHomeDevice firstDevice = null; - for (SmartHomeDevice shd : getSupportedSmartHomeDevices(smartHomeBaseDevice, allDevices)) { - String applianceId = shd.applianceId; + for (SmartHomeDevice smartHomeDevice : getSupportedSmartHomeDevices(smartHomeBaseDevice, allDevices)) { + String applianceId = smartHomeDevice.applianceId; if (applianceId == null) { continue; } @@ -210,7 +210,7 @@ public class SmartHomeDeviceHandler extends BaseThingHandler { } } if (firstDevice == null) { - firstDevice = shd; + firstDevice = smartHomeDevice; } for (JsonElement stateElement : states) { String stateJson = stateElement.getAsString(); @@ -240,9 +240,9 @@ public class SmartHomeDeviceHandler extends BaseThingHandler { } } - if (result.needSingleUpdate && smartHomeBaseDevice instanceof SmartHomeDevice && accountHandler != null) { - SmartHomeDevice shd = (SmartHomeDevice) smartHomeBaseDevice; - accountHandler.forceDelayedSmartHomeStateUpdate(shd.findId()); + if (result.needSingleUpdate && smartHomeBaseDevice instanceof SmartHomeDevice smartHomeDevice + && accountHandler != null) { + accountHandler.forceDelayedSmartHomeStateUpdate(smartHomeDevice.findId()); } } @@ -257,8 +257,8 @@ public class SmartHomeDeviceHandler extends BaseThingHandler { Bridge bridge = getBridge(); if (bridge != null) { BridgeHandler bridgeHandler = bridge.getHandler(); - if (bridgeHandler instanceof AccountHandler) { - return (AccountHandler) bridgeHandler; + if (bridgeHandler instanceof AccountHandler accountHandler) { + return accountHandler; } } @@ -297,17 +297,17 @@ public class SmartHomeDeviceHandler extends BaseThingHandler { if (handlerBase == null || !handlerBase.hasChannel(channelId)) { continue; } - for (SmartHomeDevice shd : devices) { - String entityId = shd.entityId; + for (SmartHomeDevice smartHomeDevice : devices) { + String entityId = smartHomeDevice.entityId; if (entityId == null) { continue; } accountHandler.forceDelayedSmartHomeStateUpdate(getId()); // block updates - if (handlerBase.handleCommand(connection, shd, entityId, shd.getCapabilities(), channelUID.getId(), - command)) { + if (handlerBase.handleCommand(connection, smartHomeDevice, entityId, + smartHomeDevice.getCapabilities(), channelUID.getId(), command)) { accountHandler.forceDelayedSmartHomeStateUpdate(getId()); // force update again to restart // update timer - logger.debug("Command {} sent to {}", command, shd.findId()); + logger.debug("Command {} sent to {}", command, smartHomeDevice.findId()); } } } @@ -318,9 +318,8 @@ public class SmartHomeDeviceHandler extends BaseThingHandler { private static void getCapabilities(Map> result, AccountHandler accountHandler, SmartHomeBaseDevice device) { - if (device instanceof SmartHomeDevice) { - SmartHomeDevice shd = (SmartHomeDevice) device; - for (SmartHomeCapability capability : shd.getCapabilities()) { + if (device instanceof SmartHomeDevice smartHomeDevice) { + for (SmartHomeCapability capability : smartHomeDevice.getCapabilities()) { String interfaceName = capability.interfaceName; if (interfaceName != null) { Objects.requireNonNull(result.computeIfAbsent(interfaceName, name -> new ArrayList<>())) @@ -329,9 +328,9 @@ public class SmartHomeDeviceHandler extends BaseThingHandler { } } if (device instanceof SmartHomeGroup) { - for (SmartHomeDevice shd : getSupportedSmartHomeDevices(device, + for (SmartHomeDevice smartHomeDevice : getSupportedSmartHomeDevices(device, accountHandler.getLastKnownSmartHomeDevices())) { - getCapabilities(result, accountHandler, shd); + getCapabilities(result, accountHandler, smartHomeDevice); } } } @@ -342,29 +341,28 @@ public class SmartHomeDeviceHandler extends BaseThingHandler { return Collections.emptySet(); } Set result = new HashSet<>(); - if (baseDevice instanceof SmartHomeDevice) { - SmartHomeDevice shd = (SmartHomeDevice) baseDevice; - if (shd.getCapabilities().stream().map(capability -> capability.interfaceName) + if (baseDevice instanceof SmartHomeDevice smartHomeDevice) { + if (smartHomeDevice.getCapabilities().stream().map(capability -> capability.interfaceName) .anyMatch(SUPPORTED_INTERFACES::contains)) { - result.add(shd); + result.add(smartHomeDevice); } } else { - SmartHomeGroup shg = (SmartHomeGroup) baseDevice; + SmartHomeGroup smartHomeGroup = (SmartHomeGroup) baseDevice; for (SmartHomeBaseDevice device : allDevices) { - if (device instanceof SmartHomeDevice) { - SmartHomeDevice shd = (SmartHomeDevice) device; - JsonSmartHomeTags.JsonSmartHomeTag tags = shd.tags; + if (device instanceof SmartHomeDevice smartHomeDevice) { + JsonSmartHomeTags.JsonSmartHomeTag tags = smartHomeDevice.tags; if (tags != null) { JsonSmartHomeGroupIdentity.SmartHomeGroupIdentity tagNameToValueSetMap = tags.tagNameToValueSetMap; - JsonSmartHomeGroupIdentifiers.SmartHomeGroupIdentifier applianceGroupIdentifier = shg.applianceGroupIdentifier; + JsonSmartHomeGroupIdentifiers.SmartHomeGroupIdentifier applianceGroupIdentifier = smartHomeGroup.applianceGroupIdentifier; if (tagNameToValueSetMap != null) { List groupIdentity = Objects.requireNonNullElse(tagNameToValueSetMap.groupIdentity, List.of()); if (applianceGroupIdentifier != null && applianceGroupIdentifier.value != null && groupIdentity.contains(applianceGroupIdentifier.value)) { - if (shd.getCapabilities().stream().map(capability -> capability.interfaceName) + if (smartHomeDevice.getCapabilities().stream() + .map(capability -> capability.interfaceName) .anyMatch(SUPPORTED_INTERFACES::contains)) { - result.add(shd); + result.add(smartHomeDevice); } } } diff --git a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/smarthome/DynamicStateDescriptionSmartHome.java b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/smarthome/DynamicStateDescriptionSmartHome.java index 07d1bee09..098da95b4 100644 --- a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/smarthome/DynamicStateDescriptionSmartHome.java +++ b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/smarthome/DynamicStateDescriptionSmartHome.java @@ -55,11 +55,10 @@ public class DynamicStateDescriptionSmartHome implements DynamicStateDescription return null; } ThingHandler handler = thing.getHandler(); - if (!(handler instanceof SmartHomeDeviceHandler)) { - return null; + if (handler instanceof SmartHomeDeviceHandler smartHomeHandler) { + return smartHomeHandler; } - SmartHomeDeviceHandler smartHomeHandler = (SmartHomeDeviceHandler) handler; - return smartHomeHandler; + return null; } @Override diff --git a/bundles/org.openhab.binding.ambientweather/src/main/java/org/openhab/binding/ambientweather/internal/handler/AmbientWeatherEventListener.java b/bundles/org.openhab.binding.ambientweather/src/main/java/org/openhab/binding/ambientweather/internal/handler/AmbientWeatherEventListener.java index 08f31998a..16a46e454 100644 --- a/bundles/org.openhab.binding.ambientweather/src/main/java/org/openhab/binding/ambientweather/internal/handler/AmbientWeatherEventListener.java +++ b/bundles/org.openhab.binding.ambientweather/src/main/java/org/openhab/binding/ambientweather/internal/handler/AmbientWeatherEventListener.java @@ -263,11 +263,10 @@ public class AmbientWeatherEventListener { private void handleError(String event, Object... args) { String reason = "Unknown"; if (args.length > 0) { - if (args[0] instanceof String) { - reason = (String) args[0]; - } else if (args[0] instanceof Exception) { - reason = String.format("Exception=%s Message=%s", args[0].getClass(), - ((Exception) args[0]).getMessage()); + if (args[0] instanceof String stringArg) { + reason = stringArg; + } else if (args[0] instanceof Exception exception) { + reason = String.format("Exception=%s Message=%s", args[0].getClass(), exception.getMessage()); } } logger.debug("Listener: Received socket event: {}, Reason: {}", event, reason); diff --git a/bundles/org.openhab.binding.amplipi/src/gen/java/org/openhab/binding/amplipi/internal/model/StreamCommand.java b/bundles/org.openhab.binding.amplipi/src/gen/java/org/openhab/binding/amplipi/internal/model/StreamCommand.java index 4f3849ec4..d0ffccd65 100644 --- a/bundles/org.openhab.binding.amplipi/src/gen/java/org/openhab/binding/amplipi/internal/model/StreamCommand.java +++ b/bundles/org.openhab.binding.amplipi/src/gen/java/org/openhab/binding/amplipi/internal/model/StreamCommand.java @@ -39,7 +39,7 @@ public enum StreamCommand { @Override public String toString() { - return String.valueOf(value); + return value; } public static StreamCommand fromValue(String value) { diff --git a/bundles/org.openhab.binding.amplipi/src/main/java/org/openhab/binding/amplipi/internal/AmpliPiGroupHandler.java b/bundles/org.openhab.binding.amplipi/src/main/java/org/openhab/binding/amplipi/internal/AmpliPiGroupHandler.java index 732381272..6c5f863a3 100644 --- a/bundles/org.openhab.binding.amplipi/src/main/java/org/openhab/binding/amplipi/internal/AmpliPiGroupHandler.java +++ b/bundles/org.openhab.binding.amplipi/src/main/java/org/openhab/binding/amplipi/internal/AmpliPiGroupHandler.java @@ -109,8 +109,8 @@ public class AmpliPiGroupHandler extends BaseThingHandler implements AmpliPiStat } break; case AmpliPiBindingConstants.CHANNEL_VOLUME: - if (command instanceof PercentType) { - update.setVolDelta(AmpliPiUtils.percentTypeToVolume((PercentType) command)); + if (command instanceof PercentType percentCommand) { + update.setVolDelta(AmpliPiUtils.percentTypeToVolume(percentCommand)); } else if (command instanceof IncreaseDecreaseType) { if (groupState != null) { if (IncreaseDecreaseType.INCREASE.equals(command)) { @@ -125,14 +125,13 @@ public class AmpliPiGroupHandler extends BaseThingHandler implements AmpliPiStat } break; case AmpliPiBindingConstants.CHANNEL_SOURCE: - if (command instanceof DecimalType) { - update.setSourceId(((DecimalType) command).intValue()); + if (command instanceof DecimalType decimalCommand) { + update.setSourceId(decimalCommand.intValue()); } break; } if (bridgeHandler != null) { String url = bridgeHandler.getUrl() + "/api/groups/" + getId(thing); - ; StringContentProvider contentProvider = new StringContentProvider(gson.toJson(update)); try { ContentResponse response = httpClient.newRequest(url).method(HttpMethod.PATCH) diff --git a/bundles/org.openhab.binding.amplipi/src/main/java/org/openhab/binding/amplipi/internal/AmpliPiHandler.java b/bundles/org.openhab.binding.amplipi/src/main/java/org/openhab/binding/amplipi/internal/AmpliPiHandler.java index 8064bed11..f5236a766 100644 --- a/bundles/org.openhab.binding.amplipi/src/main/java/org/openhab/binding/amplipi/internal/AmpliPiHandler.java +++ b/bundles/org.openhab.binding.amplipi/src/main/java/org/openhab/binding/amplipi/internal/AmpliPiHandler.java @@ -99,12 +99,11 @@ public class AmpliPiHandler extends BaseBridgeHandler { if (CHANNEL_PRESET.equals(channelUID.getId())) { if (command instanceof RefreshType) { updateState(channelUID, UnDefType.NULL); - } else if (command instanceof DecimalType) { - DecimalType preset = (DecimalType) command; + } else if (command instanceof DecimalType decimalCommand) { try { ContentResponse response = this.httpClient - .newRequest(url + "/api/presets/" + preset.intValue() + "/load").method(HttpMethod.POST) - .timeout(REQUEST_TIMEOUT, TimeUnit.MILLISECONDS).send(); + .newRequest(url + "/api/presets/" + decimalCommand.intValue() + "/load") + .method(HttpMethod.POST).timeout(REQUEST_TIMEOUT, TimeUnit.MILLISECONDS).send(); if (response.getStatus() != HttpStatus.OK_200) { logger.error("AmpliPi API returned HTTP status {}.", response.getStatus()); logger.debug("Content: {}", response.getContentAsString()); @@ -115,11 +114,10 @@ public class AmpliPiHandler extends BaseBridgeHandler { } } } else if (channelUID.getId().startsWith(CHANNEL_INPUT)) { - if (command instanceof StringType) { - StringType input = (StringType) command; + if (command instanceof StringType stringCommand) { int source = Integer.valueOf(channelUID.getId().substring(CHANNEL_INPUT.length())) - 1; SourceUpdate update = new SourceUpdate(); - update.setInput(input.toString()); + update.setInput(stringCommand.toString()); try { StringContentProvider contentProvider = new StringContentProvider(gson.toJson(update)); ContentResponse response = this.httpClient.newRequest(url + "/api/sources/" + source) diff --git a/bundles/org.openhab.binding.amplipi/src/main/java/org/openhab/binding/amplipi/internal/AmpliPiZoneHandler.java b/bundles/org.openhab.binding.amplipi/src/main/java/org/openhab/binding/amplipi/internal/AmpliPiZoneHandler.java index 78ed933bc..1cba6138e 100644 --- a/bundles/org.openhab.binding.amplipi/src/main/java/org/openhab/binding/amplipi/internal/AmpliPiZoneHandler.java +++ b/bundles/org.openhab.binding.amplipi/src/main/java/org/openhab/binding/amplipi/internal/AmpliPiZoneHandler.java @@ -109,8 +109,8 @@ public class AmpliPiZoneHandler extends BaseThingHandler implements AmpliPiStatu } break; case AmpliPiBindingConstants.CHANNEL_VOLUME: - if (command instanceof PercentType) { - update.setVol(AmpliPiUtils.percentTypeToVolume((PercentType) command)); + if (command instanceof PercentType percentCommand) { + update.setVol(AmpliPiUtils.percentTypeToVolume(percentCommand)); } else if (command instanceof IncreaseDecreaseType) { if (zoneState != null) { if (IncreaseDecreaseType.INCREASE.equals(command)) { @@ -125,8 +125,8 @@ public class AmpliPiZoneHandler extends BaseThingHandler implements AmpliPiStatu } break; case AmpliPiBindingConstants.CHANNEL_SOURCE: - if (command instanceof DecimalType) { - update.setSourceId(((DecimalType) command).intValue()); + if (command instanceof DecimalType decimalCommand) { + update.setSourceId(decimalCommand.intValue()); } break; } diff --git a/bundles/org.openhab.binding.amplipi/src/main/java/org/openhab/binding/amplipi/internal/InputStateOptionProvider.java b/bundles/org.openhab.binding.amplipi/src/main/java/org/openhab/binding/amplipi/internal/InputStateOptionProvider.java index 0edd7d912..b17396604 100644 --- a/bundles/org.openhab.binding.amplipi/src/main/java/org/openhab/binding/amplipi/internal/InputStateOptionProvider.java +++ b/bundles/org.openhab.binding.amplipi/src/main/java/org/openhab/binding/amplipi/internal/InputStateOptionProvider.java @@ -65,7 +65,7 @@ public class InputStateOptionProvider extends BaseDynamicStateDescriptionProvide } private @Nullable String getLabel(Stream stream) { - if (stream.getType().equals("internetradio")) { + if ("internetradio".equals(stream.getType())) { return stream.getName(); } else { return stream.getType().substring(0, 1).toUpperCase() + stream.getType().substring(1); diff --git a/bundles/org.openhab.binding.amplipi/src/main/java/org/openhab/binding/amplipi/internal/discovery/AmpliPiMDNSDiscoveryParticipant.java b/bundles/org.openhab.binding.amplipi/src/main/java/org/openhab/binding/amplipi/internal/discovery/AmpliPiMDNSDiscoveryParticipant.java index 9131a3f8a..6dff237e1 100644 --- a/bundles/org.openhab.binding.amplipi/src/main/java/org/openhab/binding/amplipi/internal/discovery/AmpliPiMDNSDiscoveryParticipant.java +++ b/bundles/org.openhab.binding.amplipi/src/main/java/org/openhab/binding/amplipi/internal/discovery/AmpliPiMDNSDiscoveryParticipant.java @@ -54,10 +54,9 @@ public class AmpliPiMDNSDiscoveryParticipant implements MDNSDiscoveryParticipant public @Nullable DiscoveryResult createResult(ServiceInfo service) { ThingUID uid = getThingUID(service); if (uid != null) { - DiscoveryResult result = DiscoveryResultBuilder.create(uid).withLabel("AmpliPi Controller") + return DiscoveryResultBuilder.create(uid).withLabel("AmpliPi Controller") .withProperty(AmpliPiBindingConstants.CFG_PARAM_HOSTNAME, getIpAddress(service).getHostAddress()) .withRepresentationProperty(AmpliPiBindingConstants.CFG_PARAM_HOSTNAME).build(); - return result; } else { return null; } @@ -68,7 +67,7 @@ public class AmpliPiMDNSDiscoveryParticipant implements MDNSDiscoveryParticipant if (service.getName().equals(AMPLIPI_API)) { InetAddress ip = getIpAddress(service); if (ip != null) { - String id = ip.toString().substring(1).replaceAll("\\.", ""); + String id = ip.toString().substring(1).replace(".", ""); return new ThingUID(AmpliPiBindingConstants.THING_TYPE_CONTROLLER, id); } } diff --git a/bundles/org.openhab.binding.androiddebugbridge/src/main/java/org/openhab/binding/androiddebugbridge/internal/AndroidDebugBridgeDevice.java b/bundles/org.openhab.binding.androiddebugbridge/src/main/java/org/openhab/binding/androiddebugbridge/internal/AndroidDebugBridgeDevice.java index a35897f9a..8765072b5 100644 --- a/bundles/org.openhab.binding.androiddebugbridge/src/main/java/org/openhab/binding/androiddebugbridge/internal/AndroidDebugBridgeDevice.java +++ b/bundles/org.openhab.binding.androiddebugbridge/src/main/java/org/openhab/binding/androiddebugbridge/internal/AndroidDebugBridgeDevice.java @@ -246,13 +246,13 @@ public class AndroidDebugBridgeDevice { AndroidDebugBridgeDeviceReadException, TimeoutException, ExecutionException { if (isAtLeastVersion(12)) { String devicesResp = runAdbShell("getprop", "debug.tracing.screen_state"); - return devicesResp.replace("\n", "").equals("2"); + return "2".equals(devicesResp.replace("\n", "")); } String devicesResp = runAdbShell("dumpsys", "power", "|", "grep", "'Display Power'"); if (devicesResp.contains("=")) { try { var state = devicesResp.split("=")[1].trim(); - return state.equals("ON"); + return "ON".equals(state); } catch (NumberFormatException e) { logger.debug("Unable to parse device screen state: {}", e.getMessage()); } diff --git a/bundles/org.openhab.binding.androiddebugbridge/src/main/java/org/openhab/binding/androiddebugbridge/internal/discovery/AndroidDebugBridgeDiscoveryService.java b/bundles/org.openhab.binding.androiddebugbridge/src/main/java/org/openhab/binding/androiddebugbridge/internal/discovery/AndroidDebugBridgeDiscoveryService.java index be66cb309..a4ff9e13d 100644 --- a/bundles/org.openhab.binding.androiddebugbridge/src/main/java/org/openhab/binding/androiddebugbridge/internal/discovery/AndroidDebugBridgeDiscoveryService.java +++ b/bundles/org.openhab.binding.androiddebugbridge/src/main/java/org/openhab/binding/androiddebugbridge/internal/discovery/AndroidDebugBridgeDiscoveryService.java @@ -161,7 +161,7 @@ public class AndroidDebugBridgeDiscoveryService extends AbstractDiscoveryService String brand, String macAddress) { String friendlyName = String.format("%s (%s)", model, ip); thingDiscovered( - DiscoveryResultBuilder.create(new ThingUID(THING_TYPE_ANDROID_DEVICE, macAddress.replaceAll(":", ""))) // + DiscoveryResultBuilder.create(new ThingUID(THING_TYPE_ANDROID_DEVICE, macAddress.replace(":", ""))) // .withProperties(Map.of( // PARAMETER_IP, ip, // PARAMETER_PORT, port, // diff --git a/bundles/org.openhab.binding.androiddebugbridge/src/main/java/org/openhab/binding/androiddebugbridge/internal/discovery/AndroidTVMDNSDiscoveryParticipant.java b/bundles/org.openhab.binding.androiddebugbridge/src/main/java/org/openhab/binding/androiddebugbridge/internal/discovery/AndroidTVMDNSDiscoveryParticipant.java index 9a252504e..6b7a9d97a 100644 --- a/bundles/org.openhab.binding.androiddebugbridge/src/main/java/org/openhab/binding/androiddebugbridge/internal/discovery/AndroidTVMDNSDiscoveryParticipant.java +++ b/bundles/org.openhab.binding.androiddebugbridge/src/main/java/org/openhab/binding/androiddebugbridge/internal/discovery/AndroidTVMDNSDiscoveryParticipant.java @@ -104,7 +104,7 @@ public class AndroidTVMDNSDiscoveryParticipant implements MDNSDiscoveryParticipa public @Nullable ThingUID getThingUID(ServiceInfo service) { String macAddress = service.getPropertyString(MDNS_PROPERTY_MAC_ADDRESS); if (macAddress != null && !macAddress.isBlank()) { - return new ThingUID(THING_TYPE_ANDROID_DEVICE, macAddress.replaceAll(":", "").toLowerCase()); + return new ThingUID(THING_TYPE_ANDROID_DEVICE, macAddress.replace(":", "").toLowerCase()); } return null; } diff --git a/bundles/org.openhab.binding.androiddebugbridge/src/main/java/org/openhab/binding/androiddebugbridge/internal/discovery/FireTVStickMDNSDiscoveryParticipant.java b/bundles/org.openhab.binding.androiddebugbridge/src/main/java/org/openhab/binding/androiddebugbridge/internal/discovery/FireTVStickMDNSDiscoveryParticipant.java index a0c21c3d0..8d768dd06 100644 --- a/bundles/org.openhab.binding.androiddebugbridge/src/main/java/org/openhab/binding/androiddebugbridge/internal/discovery/FireTVStickMDNSDiscoveryParticipant.java +++ b/bundles/org.openhab.binding.androiddebugbridge/src/main/java/org/openhab/binding/androiddebugbridge/internal/discovery/FireTVStickMDNSDiscoveryParticipant.java @@ -104,7 +104,7 @@ public class FireTVStickMDNSDiscoveryParticipant implements MDNSDiscoveryPartici public @Nullable ThingUID getThingUID(ServiceInfo service) { String macAddress = service.getPropertyString(MDNS_PROPERTY_MAC_ADDRESS); if (macAddress != null && !macAddress.isBlank()) { - return new ThingUID(THING_TYPE_ANDROID_DEVICE, macAddress.replaceAll(":", "").toLowerCase()); + return new ThingUID(THING_TYPE_ANDROID_DEVICE, macAddress.replace(":", "").toLowerCase()); } return null; } diff --git a/bundles/org.openhab.binding.anel/src/test/java/org/openhab/binding/anel/internal/AnelStateUpdaterTest.java b/bundles/org.openhab.binding.anel/src/test/java/org/openhab/binding/anel/internal/AnelStateUpdaterTest.java index 50876df94..6ccf993e0 100644 --- a/bundles/org.openhab.binding.anel/src/test/java/org/openhab/binding/anel/internal/AnelStateUpdaterTest.java +++ b/bundles/org.openhab.binding.anel/src/test/java/org/openhab/binding/anel/internal/AnelStateUpdaterTest.java @@ -135,8 +135,8 @@ public class AnelStateUpdaterTest implements IAnelTestStatus, IAnelConstants { private void assertTemperature(@Nullable State state, double value) { assertThat(state, isA(QuantityType.class)); - if (state instanceof QuantityType) { - assertThat(((QuantityType) state).doubleValue(), closeTo(value, 0.0001d)); + if (state instanceof QuantityType temperature) { + assertThat(temperature.doubleValue(), closeTo(value, 0.0001d)); } } } diff --git a/bundles/org.openhab.binding.anel/src/test/java/org/openhab/binding/anel/internal/AnelUdpConnectorTest.java b/bundles/org.openhab.binding.anel/src/test/java/org/openhab/binding/anel/internal/AnelUdpConnectorTest.java index 1c7a9e60c..727dd7056 100644 --- a/bundles/org.openhab.binding.anel/src/test/java/org/openhab/binding/anel/internal/AnelUdpConnectorTest.java +++ b/bundles/org.openhab.binding.anel/src/test/java/org/openhab/binding/anel/internal/AnelUdpConnectorTest.java @@ -144,7 +144,7 @@ public class AnelUdpConnectorTest { // toggle state of switch 1 final String auth = AnelAuthentication.getUserPasswordString(USER, PASSWORD, AuthMethod.of(status)); - final String command = "Sw_" + (switch1state ? "off" : "on") + String.valueOf(switchNr) + auth; + final String command = "Sw_" + (switch1state ? "off" : "on") + switchNr + auth; final String status2 = sendAndReceiveSingle(command); // assert new state of switch 1 diff --git a/bundles/org.openhab.binding.anel/src/test/java/org/openhab/binding/anel/internal/IAnelTestStatus.java b/bundles/org.openhab.binding.anel/src/test/java/org/openhab/binding/anel/internal/IAnelTestStatus.java index 8daef5081..c91b70ff4 100644 --- a/bundles/org.openhab.binding.anel/src/test/java/org/openhab/binding/anel/internal/IAnelTestStatus.java +++ b/bundles/org.openhab.binding.anel/src/test/java/org/openhab/binding/anel/internal/IAnelTestStatus.java @@ -22,26 +22,40 @@ import org.eclipse.jdt.annotation.NonNullByDefault; @NonNullByDefault public interface IAnelTestStatus { - String STATUS_INVALID_NAME = "NET-PwrCtrl:NET-CONTROL :192.168.6.63:255.255.255.0:192.168.6.1:0.4.163.21.4.71:" - + "Nr. 1,0:Nr. 2,1:Nr: 3,1:Nr. 4,0:Nr. 5,0:Nr. 6,0:Nr. 7,0:Nr. 8,0:248:80:NET-PWRCTRL_04.6:H:xor:"; - String STATUS_HUT_V61_POW = "NET-PwrCtrl:NET-CONTROL :192.168.178.148:255.255.255.0:192.168.178.1:0.4.163.10.9.107:" - + "Nr. 1,1:Nr. 2,1:Nr. 3,1:Nr. 4,0:Nr. 5,0:Nr. 6,0:Nr. 7,1:Nr. 8,1:0:80:" - + "IO-1,0,0:IO-2,0,0:IO-3,0,0:IO-4,0,0:IO-5,0,0:IO-6,0,0:IO-7,0,0:IO-8,0,0:27.7Ā°C:NET-PWRCTRL_06.1:h:" - + "p:225.9:0.0004:50.056:0.04:0.00:0.0:1.0000:xor:"; - String STATUS_HUT_V61_SENSOR = "NET-PwrCtrl:NET-CONTROL :192.168.178.148:255.255.255.0:192.168.178.1:0.4.163.10.9.107:" - + "Nr. 1,1:Nr. 2,1:Nr. 3,1:Nr. 4,0:Nr. 5,0:Nr. 6,0:Nr. 7,1:Nr. 8,1:0:80:" - + "IO-1,0,0:IO-2,0,0:IO-3,0,0:IO-4,0,0:IO-5,0,0:IO-6,0,0:IO-7,0,0:IO-8,0,0:27.7Ā°C:NET-PWRCTRL_06.1:h:" - + "n:s:20.61:40.7:7.0:xor:"; - String STATUS_HUT_V61_POW_SENSOR = "NET-PwrCtrl:NET-CONTROL :192.168.178.148:255.255.255.0:192.168.178.1:0.4.163.10.9.107:" - + "Nr. 1,1:Nr. 2,1:Nr. 3,1:Nr. 4,0:Nr. 5,0:Nr. 6,0:Nr. 7,1:Nr. 8,1:0:80:" - + "IO-1,0,0:IO-2,0,0:IO-3,0,0:IO-4,0,0:IO-5,0,0:IO-6,0,0:IO-7,0,0:IO-8,0,0:27.7Ā°C:NET-PWRCTRL_06.1:h:" - + "p:225.9:0.0004:50.056:0.04:0.00:0.0:1.0000:s:20.61:40.7:7.0:xor"; - String STATUS_HUT_V5 = "NET-PwrCtrl:ANEL1 :192.168.0.244:255.255.255.0:192.168.0.1:0.5.163.14.7.91:" - + "hoch,0:links hoch,0:runter,0:rechts run,0:runter,0:hoch,0:links runt,0:rechts hoc,0:0:80:" - + "WHN_UP,1,1:LI_DOWN,1,1:RE_DOWN,1,1:LI_UP,1,1:RE_UP,1,1:DOWN,1,1:DOWN,1,1:UP,1,1:27.3Ā°C:NET-PWRCTRL_05.0"; - String STATUS_HUT_V65 = "NET-PwrCtrl:NET-CONTROL :192.168.0.64:255.255.255.0:192.168.6.1:0.5.163.17.9.116:" - + "Nr.1,0:Nr.2,1:Nr.3,0:Nr.4,1:Nr.5,0:Nr.6,1:Nr.7,0:Nr.8,1:248:80:" - + "IO-1,0,0:IO-2,0,0:IO-3,0,0:IO-4,0,0:IO-5,1,0:IO-6,1,0:IO-7,1,0:IO-8,1,0:27.0ļæ½C:NET-PWRCTRL_06.5:h:n:xor:"; - String STATUS_HOME_V46 = "NET-PwrCtrl:NET-CONTROL :192.168.0.63:255.255.255.0:192.168.6.1:0.5.163.21.4.71:" - + "Nr. 1,1:Nr. 2,0:Nr. 3,1:Nr. 4,0:Nr. 5,1:Nr. 6,0:Nr. 7,1:Nr. 8,0:248:80:NET-PWRCTRL_04.6:H:xor:"; + String STATUS_INVALID_NAME = """ + NET-PwrCtrl:NET-CONTROL :192.168.6.63:255.255.255.0:192.168.6.1:0.4.163.21.4.71:\ + Nr. 1,0:Nr. 2,1:Nr: 3,1:Nr. 4,0:Nr. 5,0:Nr. 6,0:Nr. 7,0:Nr. 8,0:248:80:NET-PWRCTRL_04.6:H:xor:\ + """; + String STATUS_HUT_V61_POW = """ + NET-PwrCtrl:NET-CONTROL :192.168.178.148:255.255.255.0:192.168.178.1:0.4.163.10.9.107:\ + Nr. 1,1:Nr. 2,1:Nr. 3,1:Nr. 4,0:Nr. 5,0:Nr. 6,0:Nr. 7,1:Nr. 8,1:0:80:\ + IO-1,0,0:IO-2,0,0:IO-3,0,0:IO-4,0,0:IO-5,0,0:IO-6,0,0:IO-7,0,0:IO-8,0,0:27.7Ā°C:NET-PWRCTRL_06.1:h:\ + p:225.9:0.0004:50.056:0.04:0.00:0.0:1.0000:xor:\ + """; + String STATUS_HUT_V61_SENSOR = """ + NET-PwrCtrl:NET-CONTROL :192.168.178.148:255.255.255.0:192.168.178.1:0.4.163.10.9.107:\ + Nr. 1,1:Nr. 2,1:Nr. 3,1:Nr. 4,0:Nr. 5,0:Nr. 6,0:Nr. 7,1:Nr. 8,1:0:80:\ + IO-1,0,0:IO-2,0,0:IO-3,0,0:IO-4,0,0:IO-5,0,0:IO-6,0,0:IO-7,0,0:IO-8,0,0:27.7Ā°C:NET-PWRCTRL_06.1:h:\ + n:s:20.61:40.7:7.0:xor:\ + """; + String STATUS_HUT_V61_POW_SENSOR = """ + NET-PwrCtrl:NET-CONTROL :192.168.178.148:255.255.255.0:192.168.178.1:0.4.163.10.9.107:\ + Nr. 1,1:Nr. 2,1:Nr. 3,1:Nr. 4,0:Nr. 5,0:Nr. 6,0:Nr. 7,1:Nr. 8,1:0:80:\ + IO-1,0,0:IO-2,0,0:IO-3,0,0:IO-4,0,0:IO-5,0,0:IO-6,0,0:IO-7,0,0:IO-8,0,0:27.7Ā°C:NET-PWRCTRL_06.1:h:\ + p:225.9:0.0004:50.056:0.04:0.00:0.0:1.0000:s:20.61:40.7:7.0:xor\ + """; + String STATUS_HUT_V5 = """ + NET-PwrCtrl:ANEL1 :192.168.0.244:255.255.255.0:192.168.0.1:0.5.163.14.7.91:\ + hoch,0:links hoch,0:runter,0:rechts run,0:runter,0:hoch,0:links runt,0:rechts hoc,0:0:80:\ + WHN_UP,1,1:LI_DOWN,1,1:RE_DOWN,1,1:LI_UP,1,1:RE_UP,1,1:DOWN,1,1:DOWN,1,1:UP,1,1:27.3Ā°C:NET-PWRCTRL_05.0\ + """; + String STATUS_HUT_V65 = """ + NET-PwrCtrl:NET-CONTROL :192.168.0.64:255.255.255.0:192.168.6.1:0.5.163.17.9.116:\ + Nr.1,0:Nr.2,1:Nr.3,0:Nr.4,1:Nr.5,0:Nr.6,1:Nr.7,0:Nr.8,1:248:80:\ + IO-1,0,0:IO-2,0,0:IO-3,0,0:IO-4,0,0:IO-5,1,0:IO-6,1,0:IO-7,1,0:IO-8,1,0:27.0ļæ½C:NET-PWRCTRL_06.5:h:n:xor:\ + """; + String STATUS_HOME_V46 = """ + NET-PwrCtrl:NET-CONTROL :192.168.0.63:255.255.255.0:192.168.6.1:0.5.163.21.4.71:\ + Nr. 1,1:Nr. 2,0:Nr. 3,1:Nr. 4,0:Nr. 5,1:Nr. 6,0:Nr. 7,1:Nr. 8,0:248:80:NET-PWRCTRL_04.6:H:xor:\ + """; } diff --git a/bundles/org.openhab.binding.anthem/src/main/java/org/openhab/binding/anthem/internal/handler/AnthemHandler.java b/bundles/org.openhab.binding.anthem/src/main/java/org/openhab/binding/anthem/internal/handler/AnthemHandler.java index 2e7448c93..dc987e50e 100644 --- a/bundles/org.openhab.binding.anthem/src/main/java/org/openhab/binding/anthem/internal/handler/AnthemHandler.java +++ b/bundles/org.openhab.binding.anthem/src/main/java/org/openhab/binding/anthem/internal/handler/AnthemHandler.java @@ -116,7 +116,7 @@ public class AnthemHandler extends BaseThingHandler { @Override public void handleCommand(ChannelUID channelUID, Command command) { - logger.trace("Command {} received for channel {}", command, channelUID.getId().toString()); + logger.trace("Command {} received for channel {}", command, channelUID.getId()); String groupId = channelUID.getGroupId(); if (groupId == null) { return; @@ -166,8 +166,8 @@ public class AnthemHandler extends BaseThingHandler { } break; case CHANNEL_VOLUME_DB: - if (command instanceof DecimalType) { - sendCommand(AnthemCommand.volume(zone, ((DecimalType) command).intValue())); + if (command instanceof DecimalType decimalCommand) { + sendCommand(AnthemCommand.volume(zone, decimalCommand.intValue())); } break; case CHANNEL_MUTE: @@ -180,8 +180,8 @@ public class AnthemHandler extends BaseThingHandler { } break; case CHANNEL_ACTIVE_INPUT: - if (command instanceof DecimalType) { - sendCommand(AnthemCommand.activeInput(zone, ((DecimalType) command).intValue())); + if (command instanceof DecimalType decimalCommand) { + sendCommand(AnthemCommand.activeInput(zone, decimalCommand.intValue())); } break; default: diff --git a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/action/AstroActions.java b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/action/AstroActions.java index ed6b007ab..c4af735d7 100644 --- a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/action/AstroActions.java +++ b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/action/AstroActions.java @@ -52,8 +52,8 @@ public class AstroActions implements ThingActions { @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof AstroThingHandler) { - this.handler = (AstroThingHandler) handler; + if (handler instanceof AstroThingHandler thingHandler) { + this.handler = thingHandler; } } @@ -115,10 +115,9 @@ public class AstroActions implements ThingActions { try { AstroThingHandler theHandler = this.handler; if (theHandler != null) { - if (theHandler instanceof SunHandler) { - SunHandler handler = (SunHandler) theHandler; + if (theHandler instanceof SunHandler sunHandler) { SunPhaseName phase = SunPhaseName.valueOf(phaseName.toUpperCase()); - return handler.getEventTime(phase, date != null ? date : ZonedDateTime.now(), + return sunHandler.getEventTime(phase, date != null ? date : ZonedDateTime.now(), moment == null || AstroBindingConstants.EVENT_START.equalsIgnoreCase(moment)); } else { logger.info("Astro Action service ThingHandler is not a SunHandler!"); diff --git a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/calc/MoonCalc.java b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/calc/MoonCalc.java index f6c5b00f4..ad0a06fed 100644 --- a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/calc/MoonCalc.java +++ b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/calc/MoonCalc.java @@ -490,8 +490,7 @@ public class MoonCalc { double m1 = 134.9634114 + 477198.8676313 * t + .008997 * t * t + t * t * t / 69699 - t * t * t * t / 14712000; double f = 93.27209929999999 + 483202.0175273 * t - .0034029 * t * t - t * t * t / 3526000 + t * t * t * t / 863310000; - double sr = 385000.56 + getCoefficient(d, m, m1, f) / 1000; - return sr; + return 385000.56 + getCoefficient(d, m, m1, f) / 1000; } private double[] calcMoon(double t) { @@ -540,7 +539,7 @@ public class MoonCalc { private double SINALT(double moonJd, int hour, double lambda, double cphi, double sphi) { double jdo = moonJd + hour / 24.0; double t = (jdo - 51544.5) / 36525.0; - double decra[] = calcMoon(t); + double[] decra = calcMoon(t); double tau = 15.0 * (LMST(jdo, lambda) - decra[1]); return sphi * SN(decra[0]) + cphi * CS(decra[0]) * CS(tau); } @@ -688,12 +687,12 @@ public class MoonCalc { double moonLon = mod2Pi(n2 + Math.atan2(Math.sin(l3 - n2) * Math.cos(i), Math.cos(l3 - n2))); double moonLat = Math.asin(Math.sin(l3 - n2) * Math.sin(i)); - double raDec[] = ecl2Equ(moonLat, moonLon, julianDate); + double[] raDec = ecl2Equ(moonLat, moonLon, julianDate); double distance = (1 - 0.00301401) / (1 + 0.054900 * Math.cos(mMoon2 + ec)) * 384401; - double raDecTopo[] = geoEqu2TopoEqu(raDec, distance, lat, lmst); - double azAlt[] = equ2AzAlt(raDecTopo[0], raDecTopo[1], lat, lmst); + double[] raDecTopo = geoEqu2TopoEqu(raDec, distance, lat, lmst); + double[] azAlt = equ2AzAlt(raDecTopo[0], raDecTopo[1], lat, lmst); Position position = moon.getPosition(); position.setAzimuth(azAlt[0] * SunCalc.RAD2DEG); diff --git a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/handler/AstroThingHandler.java b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/handler/AstroThingHandler.java index 767bf1112..718e7339f 100644 --- a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/handler/AstroThingHandler.java +++ b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/handler/AstroThingHandler.java @@ -22,7 +22,6 @@ import java.time.ZonedDateTime; import java.util.Arrays; import java.util.Calendar; import java.util.Collection; -import java.util.Collections; import java.util.Date; import java.util.HashSet; import java.util.Iterator; @@ -366,6 +365,6 @@ public abstract class AstroThingHandler extends BaseThingHandler { @Override public Collection> getServices() { - return Collections.singletonList(AstroActions.class); + return List.of(AstroActions.class); } } diff --git a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/job/Job.java b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/job/Job.java index 19d47153a..051f8886b 100644 --- a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/job/Job.java +++ b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/job/Job.java @@ -12,7 +12,6 @@ */ package org.openhab.binding.astro.internal.job; -import static java.util.Collections.singletonList; import static java.util.stream.Collectors.toList; import static org.openhab.binding.astro.internal.AstroBindingConstants.*; import static org.openhab.binding.astro.internal.util.DateTimeUtils.*; @@ -72,7 +71,7 @@ public interface Job extends SchedulerRunnable, Runnable { */ static void scheduleEvent(String thingUID, AstroThingHandler astroHandler, Calendar eventAt, String event, String channelId, boolean configAlreadyApplied) { - scheduleEvent(thingUID, astroHandler, eventAt, singletonList(event), channelId, configAlreadyApplied); + scheduleEvent(thingUID, astroHandler, eventAt, List.of(event), channelId, configAlreadyApplied); } /** diff --git a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/job/SunPhaseJob.java b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/job/SunPhaseJob.java index 78336bde5..096772b27 100644 --- a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/job/SunPhaseJob.java +++ b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/job/SunPhaseJob.java @@ -53,9 +53,8 @@ public final class SunPhaseJob extends AbstractJob { Channel phaseNameChannel = astroHandler.getThing().getChannel(CHANNEL_ID_SUN_PHASE_NAME); if (phaseNameChannel != null) { Planet planet = astroHandler.getPlanet(); - if (planet != null && planet instanceof Sun) { - final Sun typedSun = (Sun) planet; - typedSun.getPhase().setName(sunPhaseName); + if (planet instanceof Sun theSun) { + theSun.getPhase().setName(sunPhaseName); astroHandler.publishChannelIfLinked(phaseNameChannel.getUID()); } } else { diff --git a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/model/EclipseKind.java b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/model/EclipseKind.java index 8b7c99469..78c6130d8 100644 --- a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/model/EclipseKind.java +++ b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/model/EclipseKind.java @@ -23,5 +23,5 @@ import org.eclipse.jdt.annotation.NonNullByDefault; public enum EclipseKind { PARTIAL, TOTAL, - RING; + RING } diff --git a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/model/EclipseType.java b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/model/EclipseType.java index c5b8302ac..b63826d57 100644 --- a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/model/EclipseType.java +++ b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/model/EclipseType.java @@ -22,5 +22,5 @@ import org.eclipse.jdt.annotation.NonNullByDefault; @NonNullByDefault public enum EclipseType { SUN, - MOON; + MOON } diff --git a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/util/PropertyUtils.java b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/util/PropertyUtils.java index 7cccf4269..05b962f88 100644 --- a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/util/PropertyUtils.java +++ b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/util/PropertyUtils.java @@ -57,10 +57,9 @@ public class PropertyUtils { Object value = getPropertyValue(channelUID, instance); if (value == null) { return UnDefType.UNDEF; - } else if (value instanceof State) { - return (State) value; - } else if (value instanceof Calendar) { - Calendar cal = (Calendar) value; + } else if (value instanceof State state) { + return state; + } else if (value instanceof Calendar cal) { GregorianCalendar gregorianCal = (GregorianCalendar) DateTimeUtils.applyConfig(cal, config); cal.setTimeZone(TimeZone.getTimeZone(zoneId)); ZonedDateTime zoned = gregorianCal.toZonedDateTime().withFixedOffsetZone(); diff --git a/bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/AtlonaHandlerFactory.java b/bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/AtlonaHandlerFactory.java index 585de5350..739f4dbb6 100644 --- a/bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/AtlonaHandlerFactory.java +++ b/bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/AtlonaHandlerFactory.java @@ -14,7 +14,6 @@ package org.openhab.binding.atlona.internal; import static org.openhab.binding.atlona.internal.AtlonaBindingConstants.*; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -69,7 +68,7 @@ public class AtlonaHandlerFactory extends BaseThingHandlerFactory { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); if (thingTypeUID.equals(THING_TYPE_PRO3_44M)) { - return new AtlonaPro3Handler(thing, new AtlonaPro3Capabilities(5, 3, Collections.singleton(5), true)); + return new AtlonaPro3Handler(thing, new AtlonaPro3Capabilities(5, 3, Set.of(5), true)); } if (thingTypeUID.equals(THING_TYPE_PRO3_66M)) { diff --git a/bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/discovery/AtlonaDiscovery.java b/bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/discovery/AtlonaDiscovery.java index e7f5d6e64..d7ff33424 100644 --- a/bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/discovery/AtlonaDiscovery.java +++ b/bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/discovery/AtlonaDiscovery.java @@ -197,17 +197,17 @@ public class AtlonaDiscovery extends AbstractDiscoveryService { String name = msg.substring(0, idx); if ("Host".equalsIgnoreCase(name)) { - host = msg.substring(idx + 1).trim().replaceAll("\"", ""); + host = msg.substring(idx + 1).trim().replace("\"", ""); int sep = host.indexOf('_'); if (sep >= 0) { host = host.substring(sep + 1); } } else if ("Model".equalsIgnoreCase(name)) { - model = msg.substring(idx + 1).trim().replaceAll("\"", ""); + model = msg.substring(idx + 1).trim().replace("\"", ""); } else if ("Manufacturer".equalsIgnoreCase(name)) { - manufacturer = msg.substring(idx + 1).trim().replaceAll("\"", ""); + manufacturer = msg.substring(idx + 1).trim().replace("\"", ""); } else if ("From".equalsIgnoreCase(name)) { - from = msg.substring(idx + 1).trim().replaceAll("\"", ""); + from = msg.substring(idx + 1).trim().replace("\"", ""); int sep = from.indexOf(':'); if (sep >= 0) { from = from.substring(0, sep); diff --git a/bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/net/SocketChannelSession.java b/bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/net/SocketChannelSession.java index 36324b026..1dea1c8a8 100644 --- a/bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/net/SocketChannelSession.java +++ b/bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/net/SocketChannelSession.java @@ -349,23 +349,23 @@ public class SocketChannelSession implements SocketSession { final Object response = responses.poll(1, TimeUnit.SECONDS); if (response != null) { - if (response instanceof String) { + if (response instanceof String stringResponse) { try { logger.debug("Dispatching response: {}", response); final SocketSessionListener[] listeners = SocketChannelSession.this.listeners .toArray(new SocketSessionListener[0]); for (SocketSessionListener listener : listeners) { - listener.responseReceived((String) response); + listener.responseReceived(stringResponse); } } catch (Exception e) { logger.warn("Exception occurred processing the response '{}': ", response, e); } - } else if (response instanceof Exception) { + } else if (response instanceof Exception exceptionResponse) { logger.debug("Dispatching exception: {}", response); final SocketSessionListener[] listeners = SocketChannelSession.this.listeners .toArray(new SocketSessionListener[0]); for (SocketSessionListener listener : listeners) { - listener.responseException((Exception) response); + listener.responseException(exceptionResponse); } } else { logger.warn("Unknown response class: {}", response); diff --git a/bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/pro3/AtlonaPro3Handler.java b/bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/pro3/AtlonaPro3Handler.java index ffbeb04f0..8dcc8b5ba 100644 --- a/bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/pro3/AtlonaPro3Handler.java +++ b/bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/pro3/AtlonaPro3Handler.java @@ -133,8 +133,8 @@ public class AtlonaPro3Handler extends AtlonaHandler { if ((m = GROUP_PRIMARY_PATTERN.matcher(group)).matches()) { switch (id) { case AtlonaPro3Constants.CHANNEL_POWER: - if (command instanceof OnOffType) { - final boolean makeOn = ((OnOffType) command) == OnOffType.ON; + if (command instanceof OnOffType onOffCommand) { + final boolean makeOn = onOffCommand == OnOffType.ON; atlonaHandler.setPower(makeOn); } else { logger.debug("Received a POWER channel command with a non OnOffType: {}", command); @@ -143,8 +143,8 @@ public class AtlonaPro3Handler extends AtlonaHandler { break; case AtlonaPro3Constants.CHANNEL_PANELLOCK: - if (command instanceof OnOffType) { - final boolean makeOn = ((OnOffType) command) == OnOffType.ON; + if (command instanceof OnOffType onOffCommand) { + final boolean makeOn = onOffCommand == OnOffType.ON; atlonaHandler.setPanelLock(makeOn); } else { logger.debug("Received a PANELLOCK channel command with a non OnOffType: {}", command); @@ -152,8 +152,8 @@ public class AtlonaPro3Handler extends AtlonaHandler { break; case AtlonaPro3Constants.CHANNEL_IRENABLE: - if (command instanceof OnOffType) { - final boolean makeOn = ((OnOffType) command) == OnOffType.ON; + if (command instanceof OnOffType onOffCommand) { + final boolean makeOn = onOffCommand == OnOffType.ON; atlonaHandler.setIrOn(makeOn); } else { logger.debug("Received an IRLOCK channel command with a non OnOffType: {}", command); @@ -232,8 +232,8 @@ public class AtlonaPro3Handler extends AtlonaHandler { switch (id) { case AtlonaPro3Constants.CHANNEL_PORTOUTPUT: - if (command instanceof DecimalType) { - final int inpNbr = ((DecimalType) command).intValue(); + if (command instanceof DecimalType decimalCommand) { + final int inpNbr = decimalCommand.intValue(); atlonaHandler.setPortSwitch(inpNbr, portNbr); } else { logger.debug("Received a PORTOUTPUT channel command with a non DecimalType: {}", @@ -243,8 +243,8 @@ public class AtlonaPro3Handler extends AtlonaHandler { break; case AtlonaPro3Constants.CHANNEL_PORTPOWER: - if (command instanceof OnOffType) { - final boolean makeOn = ((OnOffType) command) == OnOffType.ON; + if (command instanceof OnOffType onOffCommand) { + final boolean makeOn = onOffCommand == OnOffType.ON; atlonaHandler.setPortPower(portNbr, makeOn); } else { logger.debug("Received a PORTPOWER channel command with a non OnOffType: {}", command); @@ -265,8 +265,8 @@ public class AtlonaPro3Handler extends AtlonaHandler { switch (id) { case AtlonaPro3Constants.CHANNEL_PORTMIRROR: - if (command instanceof DecimalType) { - final int outPortNbr = ((DecimalType) command).intValue(); + if (command instanceof DecimalType decimalCommand) { + final int outPortNbr = decimalCommand.intValue(); if (outPortNbr <= 0) { atlonaHandler.removePortMirror(hdmiPortNbr); } else { @@ -285,8 +285,8 @@ public class AtlonaPro3Handler extends AtlonaHandler { .getCallback(); final State state = callback.getState(AtlonaPro3Constants.CHANNEL_PORTMIRROR); int outPortNbr = 1; - if (state != null && state instanceof DecimalType) { - outPortNbr = ((DecimalType) state).intValue(); + if (state instanceof DecimalType decimalCommand) { + outPortNbr = decimalCommand.intValue(); } atlonaHandler.setPortMirror(hdmiPortNbr, outPortNbr); } else { @@ -313,8 +313,8 @@ public class AtlonaPro3Handler extends AtlonaHandler { switch (id) { case AtlonaPro3Constants.CHANNEL_VOLUME_MUTE: - if (command instanceof OnOffType) { - atlonaHandler.setVolumeMute(portNbr, ((OnOffType) command) == OnOffType.ON); + if (command instanceof OnOffType onOffCommand) { + atlonaHandler.setVolumeMute(portNbr, onOffCommand == OnOffType.ON); } else { logger.debug("Received a VOLUME MUTE channel command with a non OnOffType: {}", command); @@ -322,8 +322,8 @@ public class AtlonaPro3Handler extends AtlonaHandler { break; case AtlonaPro3Constants.CHANNEL_VOLUME: - if (command instanceof DecimalType) { - final int level = ((DecimalType) command).intValue(); + if (command instanceof DecimalType decimalCommand) { + final int level = decimalCommand.intValue(); atlonaHandler.setVolume(portNbr, level); } else { logger.debug("Received a VOLUME channel command with a non DecimalType: {}", command); diff --git a/bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/pro3/AtlonaPro3PortocolHandler.java b/bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/pro3/AtlonaPro3PortocolHandler.java index c8182ed45..dda1a52b8 100644 --- a/bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/pro3/AtlonaPro3PortocolHandler.java +++ b/bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/pro3/AtlonaPro3PortocolHandler.java @@ -1253,10 +1253,10 @@ class AtlonaPro3PortocolHandler { */ String getResponse() throws Exception { final Object lastResponse = responses.poll(5, TimeUnit.SECONDS); - if (lastResponse instanceof String) { - return (String) lastResponse; - } else if (lastResponse instanceof Exception) { - throw (Exception) lastResponse; + if (lastResponse instanceof String stringResponse) { + return stringResponse; + } else if (lastResponse instanceof Exception exceptionResponse) { + throw exceptionResponse; } else if (lastResponse == null) { throw new Exception("Didn't receive response in time"); } else { diff --git a/bundles/org.openhab.binding.autelis/src/main/java/org/openhab/binding/autelis/internal/discovery/AutelisDiscoveryParticipant.java b/bundles/org.openhab.binding.autelis/src/main/java/org/openhab/binding/autelis/internal/discovery/AutelisDiscoveryParticipant.java index 624c3623d..f05f46b8b 100644 --- a/bundles/org.openhab.binding.autelis/src/main/java/org/openhab/binding/autelis/internal/discovery/AutelisDiscoveryParticipant.java +++ b/bundles/org.openhab.binding.autelis/src/main/java/org/openhab/binding/autelis/internal/discovery/AutelisDiscoveryParticipant.java @@ -86,7 +86,7 @@ public class AutelisDiscoveryParticipant implements UpnpDiscoveryParticipant { device.getDetails().getModelDetails().getModelNumber()); if (device.getDetails().getManufacturerDetails().getManufacturer().toLowerCase().startsWith(MANUFACTURER)) { logger.debug("Autelis Pool Control Found at {}", device.getDetails().getBaseURL()); - String id = device.getIdentity().getUdn().getIdentifierString().replaceAll(":", "").toUpperCase(); + String id = device.getIdentity().getUdn().getIdentifierString().replace(":", "").toUpperCase(); if (device.getDetails().getModelDetails().getModelNumber().toLowerCase().startsWith(MODEL_PENTAIR)) { return new ThingUID(AutelisBindingConstants.PENTAIR_THING_TYPE_UID, id); } diff --git a/bundles/org.openhab.binding.automower/src/main/java/org/openhab/binding/automower/internal/bridge/AutomowerBridgeHandler.java b/bundles/org.openhab.binding.automower/src/main/java/org/openhab/binding/automower/internal/bridge/AutomowerBridgeHandler.java index 414c2847e..c964e473a 100644 --- a/bundles/org.openhab.binding.automower/src/main/java/org/openhab/binding/automower/internal/bridge/AutomowerBridgeHandler.java +++ b/bundles/org.openhab.binding.automower/src/main/java/org/openhab/binding/automower/internal/bridge/AutomowerBridgeHandler.java @@ -14,7 +14,6 @@ package org.openhab.binding.automower.internal.bridge; import static org.openhab.binding.automower.internal.AutomowerBindingConstants.THING_TYPE_BRIDGE; -import java.util.Collections; import java.util.Optional; import java.util.Set; import java.util.concurrent.ScheduledFuture; @@ -49,7 +48,7 @@ public class AutomowerBridgeHandler extends BaseBridgeHandler { private static final String HUSQVARNA_API_TOKEN_URL = "https://api.authentication.husqvarnagroup.dev/v1/oauth2/token"; - 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 long DEFAULT_POLLING_INTERVAL_S = TimeUnit.HOURS.toSeconds(1); private final OAuthFactory oAuthFactory; diff --git a/bundles/org.openhab.binding.automower/src/main/java/org/openhab/binding/automower/internal/discovery/AutomowerDiscoveryService.java b/bundles/org.openhab.binding.automower/src/main/java/org/openhab/binding/automower/internal/discovery/AutomowerDiscoveryService.java index 9842d29f3..4f3c13d13 100644 --- a/bundles/org.openhab.binding.automower/src/main/java/org/openhab/binding/automower/internal/discovery/AutomowerDiscoveryService.java +++ b/bundles/org.openhab.binding.automower/src/main/java/org/openhab/binding/automower/internal/discovery/AutomowerDiscoveryService.java @@ -14,10 +14,10 @@ package org.openhab.binding.automower.internal.discovery; import static org.openhab.binding.automower.internal.AutomowerBindingConstants.THING_TYPE_AUTOMOWER; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Optional; +import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.automower.internal.AutomowerBindingConstants; @@ -42,7 +42,7 @@ public class AutomowerDiscoveryService extends AbstractDiscoveryService { private final AutomowerBridgeHandler bridgeHandler; public AutomowerDiscoveryService(AutomowerBridgeHandler bridgeHandler) { - super(Collections.singleton(THING_TYPE_AUTOMOWER), 10, false); + super(Set.of(THING_TYPE_AUTOMOWER), 10, false); this.bridgeHandler = bridgeHandler; } diff --git a/bundles/org.openhab.binding.automower/src/main/java/org/openhab/binding/automower/internal/things/AutomowerHandler.java b/bundles/org.openhab.binding.automower/src/main/java/org/openhab/binding/automower/internal/things/AutomowerHandler.java index e38c32733..2c8f32f2c 100644 --- a/bundles/org.openhab.binding.automower/src/main/java/org/openhab/binding/automower/internal/things/AutomowerHandler.java +++ b/bundles/org.openhab.binding.automower/src/main/java/org/openhab/binding/automower/internal/things/AutomowerHandler.java @@ -18,7 +18,6 @@ import java.time.Instant; import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.Map; import java.util.Optional; import java.util.Set; @@ -73,7 +72,7 @@ import com.google.gson.Gson; */ @NonNullByDefault public class AutomowerHandler extends BaseThingHandler { - public static final Set SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_AUTOMOWER); + public static final Set SUPPORTED_THING_TYPES = Set.of(THING_TYPE_AUTOMOWER); private static final String NO_ID = "NO_ID"; private static final long DEFAULT_COMMAND_DURATION_MIN = 60; private static final long DEFAULT_POLLING_INTERVAL_S = TimeUnit.MINUTES.toSeconds(10); @@ -120,8 +119,8 @@ public class AutomowerHandler extends BaseThingHandler { } private Optional getCommandValue(Type type) { - if (type instanceof DecimalType) { - return Optional.of(((DecimalType) type).intValue()); + if (type instanceof DecimalType command) { + return Optional.of(command.intValue()); } return Optional.empty(); } @@ -132,7 +131,7 @@ public class AutomowerHandler extends BaseThingHandler { @Override public Collection> getServices() { - return Collections.singleton(AutomowerActions.class); + return Set.of(AutomowerActions.class); } @Override @@ -163,8 +162,7 @@ public class AutomowerHandler extends BaseThingHandler { Bridge bridge = getBridge(); if (bridge != null) { ThingHandler handler = bridge.getHandler(); - if (handler instanceof AutomowerBridgeHandler) { - AutomowerBridgeHandler bridgeHandler = (AutomowerBridgeHandler) handler; + if (handler instanceof AutomowerBridgeHandler bridgeHandler) { return bridgeHandler.getAutomowerBridge(); } } diff --git a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/discovery/AVMFritzDiscoveryService.java b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/discovery/AVMFritzDiscoveryService.java index f1b8020b8..9d62c5746 100644 --- a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/discovery/AVMFritzDiscoveryService.java +++ b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/discovery/AVMFritzDiscoveryService.java @@ -87,8 +87,8 @@ public class AVMFritzDiscoveryService extends AbstractDiscoveryService @Override public void setThingHandler(@NonNullByDefault({}) ThingHandler handler) { - if (handler instanceof AVMFritzBaseBridgeHandler) { - bridgeHandler = (AVMFritzBaseBridgeHandler) handler; + if (handler instanceof AVMFritzBaseBridgeHandler baseBridgeHandler) { + bridgeHandler = baseBridgeHandler; } } @@ -128,9 +128,9 @@ public class AVMFritzDiscoveryService extends AbstractDiscoveryService properties.put(PRODUCT_NAME, device.getProductName()); properties.put(PROPERTY_SERIAL_NUMBER, device.getIdentifier()); properties.put(PROPERTY_FIRMWARE_VERSION, device.getFirmwareVersion()); - if (device instanceof GroupModel && ((GroupModel) device).getGroupinfo() != null) { - properties.put(PROPERTY_MASTER, ((GroupModel) device).getGroupinfo().getMasterdeviceid()); - properties.put(PROPERTY_MEMBERS, ((GroupModel) device).getGroupinfo().getMembers()); + if (device instanceof GroupModel model && model.getGroupinfo() != null) { + properties.put(PROPERTY_MASTER, model.getGroupinfo().getMasterdeviceid()); + properties.put(PROPERTY_MEMBERS, model.getGroupinfo().getMembers()); } DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withProperties(properties) diff --git a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzBaseBridgeHandler.java b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzBaseBridgeHandler.java index 82e27925a..56aaaef57 100644 --- a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzBaseBridgeHandler.java +++ b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzBaseBridgeHandler.java @@ -17,9 +17,9 @@ import static org.openhab.binding.avmfritz.internal.dto.DeviceModel.ETSUnitInfoM import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -172,21 +172,21 @@ public abstract class AVMFritzBaseBridgeHandler extends BaseBridgeHandler { @Override public void childHandlerInitialized(ThingHandler childHandler, Thing childThing) { - if (childHandler instanceof FritzAhaStatusListener) { - registerStatusListener((FritzAhaStatusListener) childHandler); + if (childHandler instanceof FritzAhaStatusListener listener) { + registerStatusListener(listener); } } @Override public void childHandlerDisposed(ThingHandler childHandler, Thing childThing) { - if (childHandler instanceof FritzAhaStatusListener) { - unregisterStatusListener((FritzAhaStatusListener) childHandler); + if (childHandler instanceof FritzAhaStatusListener listener) { + unregisterStatusListener(listener); } } @Override public Collection> getServices() { - return Collections.singleton(AVMFritzDiscoveryService.class); + return Set.of(AVMFritzDiscoveryService.class); } public boolean registerStatusListener(FritzAhaStatusListener listener) { @@ -327,7 +327,7 @@ public abstract class AVMFritzBaseBridgeHandler extends BaseBridgeHandler { } else if (device.isSwitchableOutlet()) { return GROUP_SWITCH; } - } else if (device instanceof DeviceModel && device.isHANFUNUnit()) { + } else if (device instanceof DeviceModel deviceModel && device.isHANFUNUnit()) { if (device.isHANFUNBlinds()) { return DEVICE_HAN_FUN_BLINDS; } else if (device.isColorLight()) { @@ -335,8 +335,7 @@ public abstract class AVMFritzBaseBridgeHandler extends BaseBridgeHandler { } else if (device.isDimmableLight()) { return DEVICE_HAN_FUN_DIMMABLE_BULB; } - List interfaces = Arrays - .asList(((DeviceModel) device).getEtsiunitinfo().getInterfaces().split(",")); + List interfaces = Arrays.asList(deviceModel.getEtsiunitinfo().getInterfaces().split(",")); if (interfaces.contains(HAN_FUN_INTERFACE_ALERT)) { return DEVICE_HAN_FUN_CONTACT; } else if (interfaces.contains(HAN_FUN_INTERFACE_SIMPLE_BUTTON)) { diff --git a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzBaseThingHandler.java b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzBaseThingHandler.java index 81baa1da7..38666b54d 100644 --- a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzBaseThingHandler.java +++ b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzBaseThingHandler.java @@ -187,8 +187,7 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen if (device.isHeatingThermostat()) { updateHeatingThermostat(device.getHkr()); } - if (device instanceof DeviceModel) { - DeviceModel deviceModel = (DeviceModel) device; + if (device instanceof DeviceModel deviceModel) { if (deviceModel.isTemperatureSensor()) { updateTemperatureSensor(deviceModel.getTemperature()); } @@ -497,13 +496,12 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen case CHANNEL_COLOR: case CHANNEL_BRIGHTNESS: BigDecimal brightness = null; - if (command instanceof HSBType) { - HSBType hsbType = (HSBType) command; - brightness = hsbType.getBrightness().toBigDecimal(); - fritzBox.setUnmappedHueAndSaturation(ain, hsbType.getHue().intValue(), - ColorControlModel.fromPercent(hsbType.getSaturation()), 0); - } else if (command instanceof PercentType) { - brightness = ((PercentType) command).toBigDecimal(); + if (command instanceof HSBType hsbCommand) { + brightness = hsbCommand.getBrightness().toBigDecimal(); + fritzBox.setUnmappedHueAndSaturation(ain, hsbCommand.getHue().intValue(), + ColorControlModel.fromPercent(hsbCommand.getSaturation()), 0); + } else if (command instanceof PercentType brightnessPercent) { + brightness = brightnessPercent.toBigDecimal(); } else if (command instanceof OnOffType) { fritzBox.setSwitch(ain, OnOffType.ON.equals(command)); } else if (command instanceof IncreaseDecreaseType) { @@ -525,8 +523,8 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen break; case CHANNEL_COLORTEMPERATURE: BigDecimal colorTemperaturePct = null; - if (command instanceof PercentType) { - colorTemperaturePct = ((PercentType) command).toBigDecimal(); + if (command instanceof PercentType percentCommand) { + colorTemperaturePct = percentCommand.toBigDecimal(); } if (colorTemperaturePct != null) { int pct = colorTemperaturePct.intValue(); @@ -540,13 +538,13 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen break; case CHANNEL_COLORTEMPERATURE_ABS: BigDecimal colorTemperature = null; - if (command instanceof QuantityType) { - QuantityType convertedCommand = ((QuantityType) command).toInvertibleUnit(Units.KELVIN); + if (command instanceof QuantityType quantityCommand) { + QuantityType convertedCommand = quantityCommand.toInvertibleUnit(Units.KELVIN); if (convertedCommand != null) { colorTemperature = convertedCommand.toBigDecimal(); } - } else if (command instanceof DecimalType) { - colorTemperature = ((DecimalType) command).toBigDecimal(); + } else if (command instanceof DecimalType decimalCommand) { + colorTemperature = decimalCommand.toBigDecimal(); } if (colorTemperature != null) { fritzBox.setColorTemperature(ain, colorTemperature.intValue(), 0); @@ -554,9 +552,9 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen break; case CHANNEL_SETTEMP: BigDecimal temperature = null; - if (command instanceof DecimalType) { - temperature = normalizeCelsius(((DecimalType) command).toBigDecimal()); - } else if (command instanceof QuantityType) { + if (command instanceof DecimalType decimalCommand) { + temperature = normalizeCelsius(decimalCommand.toBigDecimal()); + } else if (command instanceof QuantityType quantityCommand) { @SuppressWarnings("unchecked") QuantityType convertedCommand = ((QuantityType) command) .toUnit(SIUnits.CELSIUS); @@ -564,7 +562,7 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen temperature = normalizeCelsius(convertedCommand.toBigDecimal()); } else { logger.warn("Unable to convert unit from '{}' to '{}'. Skipping command.", - ((QuantityType) command).getUnit(), SIUnits.CELSIUS); + quantityCommand.getUnit(), SIUnits.CELSIUS); } } else if (command instanceof IncreaseDecreaseType) { temperature = currentDevice.getHkr().getTsoll(); @@ -615,22 +613,20 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen } break; case CHANNEL_ROLLERSHUTTER: - if (command instanceof StopMoveType) { - StopMoveType rollershutterCommand = (StopMoveType) command; + if (command instanceof StopMoveType rollershutterCommand) { if (StopMoveType.STOP.equals(rollershutterCommand)) { fritzBox.setBlind(ain, BlindCommand.STOP); } else { logger.debug("Received unknown rollershutter StopMove command MOVE"); } - } else if (command instanceof UpDownType) { - UpDownType rollershutterCommand = (UpDownType) command; + } else if (command instanceof UpDownType rollershutterCommand) { if (UpDownType.UP.equals(rollershutterCommand)) { fritzBox.setBlind(ain, BlindCommand.OPEN); } else { fritzBox.setBlind(ain, BlindCommand.CLOSE); } - } else if (command instanceof PercentType) { - BigDecimal levelPercentage = ((PercentType) command).toBigDecimal(); + } else if (command instanceof PercentType percentCommand) { + BigDecimal levelPercentage = percentCommand.toBigDecimal(); fritzBox.setLevelPercentage(ain, levelPercentage); } else { logger.debug("Received unknown rollershutter command type '{}'", command.toString()); @@ -686,8 +682,8 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen Bridge bridge = getBridge(); if (bridge != null) { BridgeHandler handler = bridge.getHandler(); - if (handler instanceof AVMFritzBaseBridgeHandler) { - return ((AVMFritzBaseBridgeHandler) handler).getWebInterface(); + if (handler instanceof AVMFritzBaseBridgeHandler bridgeHandler) { + return bridgeHandler.getWebInterface(); } } return null; @@ -700,8 +696,8 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen Bridge bridge = getBridge(); if (bridge != null) { BridgeHandler handler = bridge.getHandler(); - if (handler instanceof AVMFritzBaseBridgeHandler) { - ((AVMFritzBaseBridgeHandler) handler).handleRefreshCommand(); + if (handler instanceof AVMFritzBaseBridgeHandler bridgeHandler) { + bridgeHandler.handleRefreshCommand(); } } } diff --git a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzButtonHandler.java b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzButtonHandler.java index 678411b52..1b2d5f6f3 100644 --- a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzButtonHandler.java +++ b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzButtonHandler.java @@ -78,8 +78,7 @@ public class AVMFritzButtonHandler extends DeviceHandler { if (thing.getUID().equals(thingUID)) { super.onDeviceUpdated(thingUID, device); - if (device instanceof DeviceModel) { - DeviceModel deviceModel = (DeviceModel) device; + if (device instanceof DeviceModel deviceModel) { if (deviceModel.isHANFUNButton()) { updateHANFUNButton(deviceModel.getButtons()); } diff --git a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzHeatingActionsHandler.java b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzHeatingActionsHandler.java index 62715d834..9a9ac2af0 100644 --- a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzHeatingActionsHandler.java +++ b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzHeatingActionsHandler.java @@ -13,7 +13,7 @@ package org.openhab.binding.avmfritz.internal.handler; import java.util.Collection; -import java.util.Collections; +import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.avmfritz.internal.actions.AVMFritzHeatingActions; @@ -30,7 +30,7 @@ public interface AVMFritzHeatingActionsHandler extends ThingHandler { @Override default Collection> getServices() { - return Collections.singleton(AVMFritzHeatingActions.class); + return Set.of(AVMFritzHeatingActions.class); } /** diff --git a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/GroupHandler.java b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/GroupHandler.java index bbb77dd6a..84abfe35a 100644 --- a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/GroupHandler.java +++ b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/GroupHandler.java @@ -35,8 +35,7 @@ public class GroupHandler extends AVMFritzBaseThingHandler { @Override protected void updateProperties(AVMFritzBaseModel device, Map editProperties) { - if (device instanceof GroupModel) { - GroupModel groupModel = (GroupModel) device; + if (device instanceof GroupModel groupModel) { if (groupModel.getGroupinfo() != null) { editProperties.put(PROPERTY_MASTER, groupModel.getGroupinfo().getMasterdeviceid()); editProperties.put(PROPERTY_MEMBERS, groupModel.getGroupinfo().getMembers()); diff --git a/bundles/org.openhab.binding.avmfritz/src/test/java/org/openhab/binding/avmfritz/internal/dto/AVMFritzDeviceListModelTest.java b/bundles/org.openhab.binding.avmfritz/src/test/java/org/openhab/binding/avmfritz/internal/dto/AVMFritzDeviceListModelTest.java index 1ab4db6a2..254be38b9 100644 --- a/bundles/org.openhab.binding.avmfritz/src/test/java/org/openhab/binding/avmfritz/internal/dto/AVMFritzDeviceListModelTest.java +++ b/bundles/org.openhab.binding.avmfritz/src/test/java/org/openhab/binding/avmfritz/internal/dto/AVMFritzDeviceListModelTest.java @@ -45,72 +45,74 @@ public class AVMFritzDeviceListModelTest { public void setUp() throws JAXBException, XMLStreamException { //@formatter:off final String xml = - "" - + "1Schlafzimmer1manuell00230051020871717,18" - + "1Schlafzimmer220-104442284211000000100148434120028020,21,22" - + "1FRITZ!DECT 200 #11manuell00230051020872550" - + "1FRITZ!DECT 210 #81manuell00230051020872550" - + "0FRITZ!DECT 300 #1220-104442284211000000100148434120028" - + "0FRITZ!DECT 301 #1220-104442284211000000100148434120028" - + "0Comet DECT #1220-104442284211000000100148434120028" - + "1FRITZ!Powerline 546E #10manuell0123005102087" - + "1FRITZ!DECT Repeater 100 #52300" - + "0HAN-FUN #2: Unit #24065142561" - + "0HAN-FUN #2: Unit #2412273772" - + "1FRITZ!DECT 400 #141000" - + "1FRITZ!DECT 440 #152300431000" - + "10Rollotron 1213 #11manuell2610406281256,513,516,5170" - + "\n" - + " 1\n" - + " 0\n" - + " Steckdose innen\n" - + " \n" - + " 0\n" - + " \n" - + " \n" - + " 408\n" - + " 263\n" - + " 512,768\n" - + " \n" - + "" - + "\n" - + " 1\n" - + " 0\n" - + " Steckdose auƟen\n" - + " \n" - + " 0\n" - + " \n" - + " \n" - + " 407\n" - + " 262\n" - + " 512\n" - + " \n" - + "" - + "\n" - + " 0\n" - + " 0\n" - + " SmartHome LED-Lampe #1\n" - + " \n" - + " 0\n" - + " \n" - + " \n" - + " 26\n" - + " 10\n" - + " \n" - + " \n" - + " 254\n" - + " 100\n" - + " \n" - + " \n" - + " 2700\n" - + " \n" - + " \n" - + " 407\n" - + " 278\n" - + " 512,514,513\n" - + " \n" - + "" + - ""; + """ + \ + 1Schlafzimmer1manuell00230051020871717,18\ + 1Schlafzimmer220-104442284211000000100148434120028020,21,22\ + 1FRITZ!DECT 200 #11manuell00230051020872550\ + 1FRITZ!DECT 210 #81manuell00230051020872550\ + 0FRITZ!DECT 300 #1220-104442284211000000100148434120028\ + 0FRITZ!DECT 301 #1220-104442284211000000100148434120028\ + 0Comet DECT #1220-104442284211000000100148434120028\ + 1FRITZ!Powerline 546E #10manuell0123005102087\ + 1FRITZ!DECT Repeater 100 #52300\ + 0HAN-FUN #2: Unit #24065142561\ + 0HAN-FUN #2: Unit #2412273772\ + 1FRITZ!DECT 400 #141000\ + 1FRITZ!DECT 440 #152300431000\ + 10Rollotron 1213 #11manuell2610406281256,513,516,5170\ + + 1 + 0 + Steckdose innen + + 0 + + + 408 + 263 + 512,768 + + \ + + 1 + 0 + Steckdose auƟen + + 0 + + + 407 + 262 + 512 + + \ + + 0 + 0 + SmartHome LED-Lampe #1 + + 0 + + + 26 + 10 + + + 254 + 100 + + + 2700 + + + 407 + 278 + 512,514,513 + + \ + \ + """; //@formatter:on XMLStreamReader xsr = JAXBUtils.XMLINPUTFACTORY.createXMLStreamReader(new StringReader(xml)); Unmarshaller u = JAXBUtils.JAXBCONTEXT_DEVICES.createUnmarshaller(); diff --git a/bundles/org.openhab.binding.avmfritz/src/test/java/org/openhab/binding/avmfritz/internal/dto/AVMFritzTemplateListModelTest.java b/bundles/org.openhab.binding.avmfritz/src/test/java/org/openhab/binding/avmfritz/internal/dto/AVMFritzTemplateListModelTest.java index a8d0252e3..d6d23363c 100644 --- a/bundles/org.openhab.binding.avmfritz/src/test/java/org/openhab/binding/avmfritz/internal/dto/AVMFritzTemplateListModelTest.java +++ b/bundles/org.openhab.binding.avmfritz/src/test/java/org/openhab/binding/avmfritz/internal/dto/AVMFritzTemplateListModelTest.java @@ -44,10 +44,12 @@ public class AVMFritzTemplateListModelTest { public void setUp() throws JAXBException, XMLStreamException { //@formatter:off String xml = - "" + - "" + - "" + - ""; + """ + \ + \ + \ + \ + """; //@formatter:on XMLStreamReader xsr = JAXBUtils.XMLINPUTFACTORY.createXMLStreamReader(new StringReader(xml)); Unmarshaller u = JAXBUtils.JAXBCONTEXT_TEMPLATES.createUnmarshaller(); diff --git a/bundles/org.openhab.binding.awattar/src/main/java/org/openhab/binding/awattar/internal/AwattarBestpriceConfiguration.java b/bundles/org.openhab.binding.awattar/src/main/java/org/openhab/binding/awattar/internal/AwattarBestpriceConfiguration.java index 083919b92..ebc3937cb 100644 --- a/bundles/org.openhab.binding.awattar/src/main/java/org/openhab/binding/awattar/internal/AwattarBestpriceConfiguration.java +++ b/bundles/org.openhab.binding.awattar/src/main/java/org/openhab/binding/awattar/internal/AwattarBestpriceConfiguration.java @@ -27,6 +27,7 @@ public class AwattarBestpriceConfiguration { public int length; public boolean consecutive; + @Override public String toString() { return String.format("{ s: %d, d: %d, l: %d, c: %b )", rangeStart, rangeDuration, length, consecutive); } diff --git a/bundles/org.openhab.binding.awattar/src/main/java/org/openhab/binding/awattar/internal/AwattarConsecutiveBestPriceResult.java b/bundles/org.openhab.binding.awattar/src/main/java/org/openhab/binding/awattar/internal/AwattarConsecutiveBestPriceResult.java index 65a4c706d..49cb3eb28 100644 --- a/bundles/org.openhab.binding.awattar/src/main/java/org/openhab/binding/awattar/internal/AwattarConsecutiveBestPriceResult.java +++ b/bundles/org.openhab.binding.awattar/src/main/java/org/openhab/binding/awattar/internal/AwattarConsecutiveBestPriceResult.java @@ -66,11 +66,13 @@ public class AwattarConsecutiveBestPriceResult extends AwattarBestPriceResult { return priceSum; } + @Override public String toString() { return String.format("{%s, %s, %.2f}", formatDate(getStart(), zoneId), formatDate(getEnd(), zoneId), priceSum / length); } + @Override public String getHours() { return hours; } diff --git a/bundles/org.openhab.binding.awattar/src/main/java/org/openhab/binding/awattar/internal/AwattarNonConsecutiveBestPriceResult.java b/bundles/org.openhab.binding.awattar/src/main/java/org/openhab/binding/awattar/internal/AwattarNonConsecutiveBestPriceResult.java index 7db7fddd1..ecffe1431 100644 --- a/bundles/org.openhab.binding.awattar/src/main/java/org/openhab/binding/awattar/internal/AwattarNonConsecutiveBestPriceResult.java +++ b/bundles/org.openhab.binding.awattar/src/main/java/org/openhab/binding/awattar/internal/AwattarNonConsecutiveBestPriceResult.java @@ -52,6 +52,7 @@ public class AwattarNonConsecutiveBestPriceResult extends AwattarBestPriceResult return members.stream().anyMatch(x -> x.contains(Instant.now().toEpochMilli())); } + @Override public String toString() { return String.format("NonConsecutiveBestpriceResult with %s", members.toString()); } @@ -67,6 +68,7 @@ public class AwattarNonConsecutiveBestPriceResult extends AwattarBestPriceResult } } + @Override public String getHours() { boolean second = false; sort(); diff --git a/bundles/org.openhab.binding.awattar/src/main/java/org/openhab/binding/awattar/internal/AwattarPrice.java b/bundles/org.openhab.binding.awattar/src/main/java/org/openhab/binding/awattar/internal/AwattarPrice.java index 9d3609a04..635d1cac1 100644 --- a/bundles/org.openhab.binding.awattar/src/main/java/org/openhab/binding/awattar/internal/AwattarPrice.java +++ b/bundles/org.openhab.binding.awattar/src/main/java/org/openhab/binding/awattar/internal/AwattarPrice.java @@ -50,6 +50,7 @@ public class AwattarPrice implements Comparable { return price; } + @Override public String toString() { return String.format("(%1$tF %1$tR - %2$tR: %3$.3f)", startTimestamp, endTimestamp, getPrice()); } diff --git a/bundles/org.openhab.binding.awattar/src/main/java/org/openhab/binding/awattar/internal/AwattarUtil.java b/bundles/org.openhab.binding.awattar/src/main/java/org/openhab/binding/awattar/internal/AwattarUtil.java index b1b09ed6b..4ba5bf1ad 100644 --- a/bundles/org.openhab.binding.awattar/src/main/java/org/openhab/binding/awattar/internal/AwattarUtil.java +++ b/bundles/org.openhab.binding.awattar/src/main/java/org/openhab/binding/awattar/internal/AwattarUtil.java @@ -40,9 +40,7 @@ public class AwattarUtil { int offset = min % mod; offset = offset == 0 ? mod : offset; dt = dt.plusMinutes(offset); - long result = dt.toInstant().toEpochMilli() - now; - - return result; + return dt.toInstant().toEpochMilli() - now; } public static ZonedDateTime getCalendarForHour(int hour, ZoneId zone) { diff --git a/bundles/org.openhab.binding.awattar/src/main/java/org/openhab/binding/awattar/internal/handler/AwattarPriceHandler.java b/bundles/org.openhab.binding.awattar/src/main/java/org/openhab/binding/awattar/internal/handler/AwattarPriceHandler.java index 92d1f9e0a..81d22bf28 100644 --- a/bundles/org.openhab.binding.awattar/src/main/java/org/openhab/binding/awattar/internal/handler/AwattarPriceHandler.java +++ b/bundles/org.openhab.binding.awattar/src/main/java/org/openhab/binding/awattar/internal/handler/AwattarPriceHandler.java @@ -97,6 +97,7 @@ public class AwattarPriceHandler extends BaseThingHandler { updateStatus(ThingStatus.UNKNOWN); } + @Override public void dispose() { ScheduledFuture localRefresher = thingRefresher; if (localRefresher != null) { diff --git a/bundles/org.openhab.binding.benqprojector/src/main/java/org/openhab/binding/benqprojector/internal/enums/Switch.java b/bundles/org.openhab.binding.benqprojector/src/main/java/org/openhab/binding/benqprojector/internal/enums/Switch.java index 46cd9ba0f..ec7213a0a 100644 --- a/bundles/org.openhab.binding.benqprojector/src/main/java/org/openhab/binding/benqprojector/internal/enums/Switch.java +++ b/bundles/org.openhab.binding.benqprojector/src/main/java/org/openhab/binding/benqprojector/internal/enums/Switch.java @@ -22,5 +22,5 @@ import org.eclipse.jdt.annotation.NonNullByDefault; @NonNullByDefault public enum Switch { ON, - OFF; + OFF } diff --git a/bundles/org.openhab.binding.bigassfan/src/main/java/org/openhab/binding/bigassfan/internal/handler/BigAssFanHandler.java b/bundles/org.openhab.binding.bigassfan/src/main/java/org/openhab/binding/bigassfan/internal/handler/BigAssFanHandler.java index 1430b3410..3b6dc9e19 100644 --- a/bundles/org.openhab.binding.bigassfan/src/main/java/org/openhab/binding/bigassfan/internal/handler/BigAssFanHandler.java +++ b/bundles/org.openhab.binding.bigassfan/src/main/java/org/openhab/binding/bigassfan/internal/handler/BigAssFanHandler.java @@ -187,8 +187,8 @@ public class BigAssFanHandler extends BaseThingHandler { logger.debug("Handling fan speed command for {}: {}", thing.getUID(), command); // - if (command instanceof PercentType) { - sendCommand(macAddress, ";FAN;SPD;SET;".concat(BigAssFanConverter.percentToSpeed((PercentType) command))); + if (command instanceof PercentType percentCommand) { + sendCommand(macAddress, ";FAN;SPD;SET;".concat(BigAssFanConverter.percentToSpeed(percentCommand))); } } @@ -238,52 +238,48 @@ public class BigAssFanHandler extends BaseThingHandler { private void handleFanLearnSpeedMin(Command command) { logger.debug("Handling fan learn speed minimum command {}", command); // - if (command instanceof PercentType) { + if (command instanceof PercentType percentCommand) { // Send min speed set command - sendCommand(macAddress, - ";LEARN;MINSPEED;SET;".concat(BigAssFanConverter.percentToSpeed((PercentType) command))); - fanStateMap.put(CHANNEL_FAN_LEARN_MINSPEED, (PercentType) command); + sendCommand(macAddress, ";LEARN;MINSPEED;SET;".concat(BigAssFanConverter.percentToSpeed(percentCommand))); + fanStateMap.put(CHANNEL_FAN_LEARN_MINSPEED, percentCommand); // Don't let max be less than min - adjustMaxSpeed((PercentType) command, CHANNEL_FAN_LEARN_MAXSPEED, ";LEARN;MAXSPEED;"); + adjustMaxSpeed(percentCommand, CHANNEL_FAN_LEARN_MAXSPEED, ";LEARN;MAXSPEED;"); } } private void handleFanLearnSpeedMax(Command command) { logger.debug("Handling fan learn speed maximum command {}", command); // - if (command instanceof PercentType) { + if (command instanceof PercentType percentCommand) { // Send max speed set command - sendCommand(macAddress, - ";LEARN;MAXSPEED;SET;;".concat(BigAssFanConverter.percentToSpeed((PercentType) command))); - fanStateMap.put(CHANNEL_FAN_LEARN_MAXSPEED, (PercentType) command); + sendCommand(macAddress, ";LEARN;MAXSPEED;SET;;".concat(BigAssFanConverter.percentToSpeed(percentCommand))); + fanStateMap.put(CHANNEL_FAN_LEARN_MAXSPEED, percentCommand); // Don't let min be greater than max - adjustMinSpeed((PercentType) command, CHANNEL_FAN_LEARN_MINSPEED, ";LEARN;MINSPEED;"); + adjustMinSpeed(percentCommand, CHANNEL_FAN_LEARN_MINSPEED, ";LEARN;MINSPEED;"); } } private void handleFanSpeedMin(Command command) { logger.debug("Handling fan speed minimum command {}", command); // - if (command instanceof PercentType) { + if (command instanceof PercentType percentCommand) { // Send min speed set command - sendCommand(macAddress, - ";FAN;SPD;SET;MIN;".concat(BigAssFanConverter.percentToSpeed((PercentType) command))); - fanStateMap.put(CHANNEL_FAN_SPEED_MIN, (PercentType) command); + sendCommand(macAddress, ";FAN;SPD;SET;MIN;".concat(BigAssFanConverter.percentToSpeed(percentCommand))); + fanStateMap.put(CHANNEL_FAN_SPEED_MIN, percentCommand); // Don't let max be less than min - adjustMaxSpeed((PercentType) command, CHANNEL_FAN_SPEED_MAX, ";FAN;SPD;SET;MAX;"); + adjustMaxSpeed(percentCommand, CHANNEL_FAN_SPEED_MAX, ";FAN;SPD;SET;MAX;"); } } private void handleFanSpeedMax(Command command) { logger.debug("Handling fan speed maximum command {}", command); // - if (command instanceof PercentType) { + if (command instanceof PercentType percentCommand) { // Send max speed set command - sendCommand(macAddress, - ";FAN;SPD;SET;MAX;".concat(BigAssFanConverter.percentToSpeed((PercentType) command))); - fanStateMap.put(CHANNEL_FAN_SPEED_MAX, (PercentType) command); + sendCommand(macAddress, ";FAN;SPD;SET;MAX;".concat(BigAssFanConverter.percentToSpeed(percentCommand))); + fanStateMap.put(CHANNEL_FAN_SPEED_MAX, percentCommand); // Don't let min be greater than max - adjustMinSpeed((PercentType) command, CHANNEL_FAN_SPEED_MIN, ";FAN;SPD;SET;MIN;"); + adjustMinSpeed(percentCommand, CHANNEL_FAN_SPEED_MIN, ";FAN;SPD;SET;MIN;"); } } @@ -364,9 +360,8 @@ public class BigAssFanHandler extends BaseThingHandler { logger.debug("Handling light level command {}", command); // - if (command instanceof PercentType) { - sendCommand(macAddress, - ";LIGHT;LEVEL;SET;".concat(BigAssFanConverter.percentToLevel((PercentType) command))); + if (command instanceof PercentType percentCommand) { + sendCommand(macAddress, ";LIGHT;LEVEL;SET;".concat(BigAssFanConverter.percentToLevel(percentCommand))); } } @@ -378,9 +373,9 @@ public class BigAssFanHandler extends BaseThingHandler { logger.debug("Handling light hue command {}", command); // - if (command instanceof PercentType) { + if (command instanceof PercentType percentCommand) { sendCommand(macAddress, - ";LIGHT;COLOR;TEMP;VALUE;SET;".concat(BigAssFanConverter.percentToHue((PercentType) command))); + ";LIGHT;COLOR;TEMP;VALUE;SET;".concat(BigAssFanConverter.percentToHue(percentCommand))); } } @@ -426,12 +421,11 @@ public class BigAssFanHandler extends BaseThingHandler { logger.debug("Handling light level minimum command {}", command); // - if (command instanceof PercentType) { + if (command instanceof PercentType percentCommand) { // Send min light level set command - sendCommand(macAddress, - ";LIGHT;LEVEL;MIN;".concat(BigAssFanConverter.percentToLevel((PercentType) command))); + sendCommand(macAddress, ";LIGHT;LEVEL;MIN;".concat(BigAssFanConverter.percentToLevel(percentCommand))); // Don't let max be less than min - adjustMaxLevel((PercentType) command); + adjustMaxLevel(percentCommand); } } @@ -443,12 +437,11 @@ public class BigAssFanHandler extends BaseThingHandler { logger.debug("Handling light level maximum command {}", command); // - if (command instanceof PercentType) { + if (command instanceof PercentType percentCommand) { // Send max light level set command - sendCommand(macAddress, - ";LIGHT;LEVEL;MAX;".concat(BigAssFanConverter.percentToLevel((PercentType) command))); + sendCommand(macAddress, ";LIGHT;LEVEL;MAX;".concat(BigAssFanConverter.percentToLevel(percentCommand))); // Don't let min be greater than max - adjustMinLevel((PercentType) command); + adjustMinLevel(percentCommand); } } diff --git a/bundles/org.openhab.binding.bluetooth.am43/src/main/java/org/openhab/binding/bluetooth/am43/internal/AM43DiscoveryParticipant.java b/bundles/org.openhab.binding.bluetooth.am43/src/main/java/org/openhab/binding/bluetooth/am43/internal/AM43DiscoveryParticipant.java index bbedbc866..450bd7885 100644 --- a/bundles/org.openhab.binding.bluetooth.am43/src/main/java/org/openhab/binding/bluetooth/am43/internal/AM43DiscoveryParticipant.java +++ b/bundles/org.openhab.binding.bluetooth.am43/src/main/java/org/openhab/binding/bluetooth/am43/internal/AM43DiscoveryParticipant.java @@ -12,7 +12,6 @@ */ package org.openhab.binding.bluetooth.am43.internal; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -42,7 +41,7 @@ public class AM43DiscoveryParticipant implements BluetoothDiscoveryParticipant { @Override public Set getSupportedThingTypeUIDs() { - return Collections.singleton(AM43BindingConstants.THING_TYPE_AM43); + return Set.of(AM43BindingConstants.THING_TYPE_AM43); } @Override diff --git a/bundles/org.openhab.binding.bluetooth.am43/src/main/java/org/openhab/binding/bluetooth/am43/internal/AM43Handler.java b/bundles/org.openhab.binding.bluetooth.am43/src/main/java/org/openhab/binding/bluetooth/am43/internal/AM43Handler.java index 1bdcc7db6..c6bf4f42e 100644 --- a/bundles/org.openhab.binding.bluetooth.am43/src/main/java/org/openhab/binding/bluetooth/am43/internal/AM43Handler.java +++ b/bundles/org.openhab.binding.bluetooth.am43/src/main/java/org/openhab/binding/bluetooth/am43/internal/AM43Handler.java @@ -235,27 +235,28 @@ public class AM43Handler extends ConnectedBluetoothHandler implements ResponseLi } switch (channelUID.getId()) { case AM43BindingConstants.CHANNEL_ID_POSITION: - if (command instanceof PercentType) { + if (command instanceof PercentType percentCommand) { MotorSettings settings = motorSettings; if (settings == null) { logger.warn("Cannot set position before settings have been received."); return; } if (!settings.isTopLimitSet() || !settings.isBottomLimitSet()) { - logger.warn("Cannot set position of blinds. Top or bottom limits have not been set. " - + "Please configure manually."); + logger.warn(""" + Cannot set position of blinds. Top or bottom limits have not been set. \ + Please configure manually.\ + """); return; } - PercentType percent = (PercentType) command; - int value = percent.intValue(); + int value = percentCommand.intValue(); if (getAM43Config().invertPosition) { value = 100 - value; } submitCommand(new SetPositionCommand(value)); return; } - if (command instanceof StopMoveType) { - switch ((StopMoveType) command) { + if (command instanceof StopMoveType stopMoveCommand) { + switch (stopMoveCommand) { case STOP: submitCommand(new ControlCommand(ControlAction.STOP)); return; @@ -264,8 +265,8 @@ public class AM43Handler extends ConnectedBluetoothHandler implements ResponseLi return; } } - if (command instanceof UpDownType) { - switch ((UpDownType) command) { + if (command instanceof UpDownType upDownCommand) { + switch (upDownCommand) { case UP: submitCommand(new ControlCommand(ControlAction.OPEN)); return; @@ -276,11 +277,10 @@ public class AM43Handler extends ConnectedBluetoothHandler implements ResponseLi } return; case AM43BindingConstants.CHANNEL_ID_SPEED: - if (command instanceof DecimalType) { + if (command instanceof DecimalType decimalCommand) { MotorSettings settings = motorSettings; if (settings != null) { - DecimalType speedType = (DecimalType) command; - settings.setSpeed(speedType.intValue()); + settings.setSpeed(decimalCommand.intValue()); submitCommand(new SetSettingsCommand(settings)); } else { logger.warn("Cannot set Speed before setting have been received"); diff --git a/bundles/org.openhab.binding.bluetooth.am43/src/main/java/org/openhab/binding/bluetooth/am43/internal/AM43HandlerFactory.java b/bundles/org.openhab.binding.bluetooth.am43/src/main/java/org/openhab/binding/bluetooth/am43/internal/AM43HandlerFactory.java index 490771613..29ed381c5 100644 --- a/bundles/org.openhab.binding.bluetooth.am43/src/main/java/org/openhab/binding/bluetooth/am43/internal/AM43HandlerFactory.java +++ b/bundles/org.openhab.binding.bluetooth.am43/src/main/java/org/openhab/binding/bluetooth/am43/internal/AM43HandlerFactory.java @@ -12,7 +12,6 @@ */ package org.openhab.binding.bluetooth.am43.internal; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -33,8 +32,7 @@ import org.osgi.service.component.annotations.Component; @Component(service = ThingHandlerFactory.class, configurationPid = "binding.am43") public class AM43HandlerFactory extends BaseThingHandlerFactory { - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections - .singleton(AM43BindingConstants.THING_TYPE_AM43); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(AM43BindingConstants.THING_TYPE_AM43); @Override public boolean supportsThingType(ThingTypeUID thingTypeUID) { diff --git a/bundles/org.openhab.binding.bluetooth.bluegiga/src/main/java/org/openhab/binding/bluetooth/bluegiga/BlueGigaBluetoothCharacteristic.java b/bundles/org.openhab.binding.bluetooth.bluegiga/src/main/java/org/openhab/binding/bluetooth/bluegiga/BlueGigaBluetoothCharacteristic.java index e520daf1b..8a3937638 100644 --- a/bundles/org.openhab.binding.bluetooth.bluegiga/src/main/java/org/openhab/binding/bluetooth/bluegiga/BlueGigaBluetoothCharacteristic.java +++ b/bundles/org.openhab.binding.bluetooth.bluegiga/src/main/java/org/openhab/binding/bluetooth/bluegiga/BlueGigaBluetoothCharacteristic.java @@ -35,6 +35,7 @@ public class BlueGigaBluetoothCharacteristic extends BluetoothCharacteristic { super(null, handle); } + @Override public void setProperties(int properties) { this.properties = properties; } diff --git a/bundles/org.openhab.binding.bluetooth.bluegiga/src/main/java/org/openhab/binding/bluetooth/bluegiga/BlueGigaBluetoothDevice.java b/bundles/org.openhab.binding.bluetooth.bluegiga/src/main/java/org/openhab/binding/bluetooth/bluegiga/BlueGigaBluetoothDevice.java index 7938f3802..0aa8377b0 100644 --- a/bundles/org.openhab.binding.bluetooth.bluegiga/src/main/java/org/openhab/binding/bluetooth/bluegiga/BlueGigaBluetoothDevice.java +++ b/bundles/org.openhab.binding.bluetooth.bluegiga/src/main/java/org/openhab/binding/bluetooth/bluegiga/BlueGigaBluetoothDevice.java @@ -356,33 +356,33 @@ public class BlueGigaBluetoothDevice extends BaseBluetoothDevice implements Blue @Override public void bluegigaEventReceived(BlueGigaResponse event) { - if (event instanceof BlueGigaScanResponseEvent) { - handleScanEvent((BlueGigaScanResponseEvent) event); + if (event instanceof BlueGigaScanResponseEvent responseEvent) { + handleScanEvent(responseEvent); } - else if (event instanceof BlueGigaGroupFoundEvent) { - handleGroupFoundEvent((BlueGigaGroupFoundEvent) event); + else if (event instanceof BlueGigaGroupFoundEvent foundEvent) { + handleGroupFoundEvent(foundEvent); } - else if (event instanceof BlueGigaFindInformationFoundEvent) { + else if (event instanceof BlueGigaFindInformationFoundEvent foundEvent) { // A Characteristic has been discovered - handleFindInformationFoundEvent((BlueGigaFindInformationFoundEvent) event); + handleFindInformationFoundEvent(foundEvent); } - else if (event instanceof BlueGigaProcedureCompletedEvent) { - handleProcedureCompletedEvent((BlueGigaProcedureCompletedEvent) event); + else if (event instanceof BlueGigaProcedureCompletedEvent completedEvent) { + handleProcedureCompletedEvent(completedEvent); } - else if (event instanceof BlueGigaConnectionStatusEvent) { - handleConnectionStatusEvent((BlueGigaConnectionStatusEvent) event); + else if (event instanceof BlueGigaConnectionStatusEvent statusEvent) { + handleConnectionStatusEvent(statusEvent); } - else if (event instanceof BlueGigaDisconnectedEvent) { - handleDisconnectedEvent((BlueGigaDisconnectedEvent) event); + else if (event instanceof BlueGigaDisconnectedEvent disconnectedEvent) { + handleDisconnectedEvent(disconnectedEvent); } - else if (event instanceof BlueGigaAttributeValueEvent) { - handleAttributeValueEvent((BlueGigaAttributeValueEvent) event); + else if (event instanceof BlueGigaAttributeValueEvent valueEvent) { + handleAttributeValueEvent(valueEvent); } } diff --git a/bundles/org.openhab.binding.bluetooth.bluegiga/src/main/java/org/openhab/binding/bluetooth/bluegiga/handler/BlueGigaBridgeHandler.java b/bundles/org.openhab.binding.bluetooth.bluegiga/src/main/java/org/openhab/binding/bluetooth/bluegiga/handler/BlueGigaBridgeHandler.java index 8443d9d2a..27e244ae9 100644 --- a/bundles/org.openhab.binding.bluetooth.bluegiga/src/main/java/org/openhab/binding/bluetooth/bluegiga/handler/BlueGigaBridgeHandler.java +++ b/bundles/org.openhab.binding.bluetooth.bluegiga/src/main/java/org/openhab/binding/bluetooth/bluegiga/handler/BlueGigaBridgeHandler.java @@ -779,9 +779,8 @@ public class BlueGigaBridgeHandler extends AbstractBluetoothBridgeHandler SUPPORTED_THING_TYPES_UIDS = Collections - .singleton(BlueGigaAdapterConstants.THING_TYPE_BLUEGIGA); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set + .of(BlueGigaAdapterConstants.THING_TYPE_BLUEGIGA); private final Map> serviceRegs = new HashMap<>(); @@ -90,8 +89,8 @@ public class BlueGigaHandlerFactory extends BaseThingHandlerFactory { @Override protected synchronized void removeHandler(ThingHandler thingHandler) { - if (thingHandler instanceof BluetoothAdapter) { - UID uid = ((BluetoothAdapter) thingHandler).getUID(); + if (thingHandler instanceof BluetoothAdapter bluetoothAdapter) { + UID uid = bluetoothAdapter.getUID(); ServiceRegistration serviceReg = this.serviceRegs.remove(uid); if (serviceReg != null) { serviceReg.unregister(); diff --git a/bundles/org.openhab.binding.bluetooth.bluez/src/main/java/org/openhab/binding/bluetooth/bluez/internal/BlueZBridgeHandler.java b/bundles/org.openhab.binding.bluetooth.bluez/src/main/java/org/openhab/binding/bluetooth/bluez/internal/BlueZBridgeHandler.java index 32889928e..6903f2d5a 100644 --- a/bundles/org.openhab.binding.bluetooth.bluez/src/main/java/org/openhab/binding/bluetooth/bluez/internal/BlueZBridgeHandler.java +++ b/bundles/org.openhab.binding.bluetooth.bluez/src/main/java/org/openhab/binding/bluetooth/bluez/internal/BlueZBridgeHandler.java @@ -194,8 +194,7 @@ public class BlueZBridgeHandler extends AbstractBluetoothBridgeHandler SUPPORTED_THING_TYPES_UIDS = Collections - .singleton(BlueZAdapterConstants.THING_TYPE_BLUEZ); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(BlueZAdapterConstants.THING_TYPE_BLUEZ); private final Map> serviceRegs = new HashMap<>(); @@ -82,8 +80,8 @@ public class BlueZHandlerFactory extends BaseThingHandlerFactory { @Override protected synchronized void removeHandler(ThingHandler thingHandler) { - if (thingHandler instanceof BluetoothAdapter) { - UID uid = ((BluetoothAdapter) thingHandler).getUID(); + if (thingHandler instanceof BluetoothAdapter bluetoothAdapter) { + UID uid = bluetoothAdapter.getUID(); ServiceRegistration serviceReg = this.serviceRegs.remove(uid); if (serviceReg != null) { serviceReg.unregister(); diff --git a/bundles/org.openhab.binding.bluetooth.blukii/src/main/java/org/openhab/binding/bluetooth/blukii/internal/BlukiiDiscoveryParticipant.java b/bundles/org.openhab.binding.bluetooth.blukii/src/main/java/org/openhab/binding/bluetooth/blukii/internal/BlukiiDiscoveryParticipant.java index 35c1c2a68..a8844f0bb 100644 --- a/bundles/org.openhab.binding.bluetooth.blukii/src/main/java/org/openhab/binding/bluetooth/blukii/internal/BlukiiDiscoveryParticipant.java +++ b/bundles/org.openhab.binding.bluetooth.blukii/src/main/java/org/openhab/binding/bluetooth/blukii/internal/BlukiiDiscoveryParticipant.java @@ -12,7 +12,6 @@ */ package org.openhab.binding.bluetooth.blukii.internal; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -42,7 +41,7 @@ public class BlukiiDiscoveryParticipant implements BluetoothDiscoveryParticipant @Override public Set getSupportedThingTypeUIDs() { - return Collections.singleton(BlukiiBindingConstants.THING_TYPE_BEACON); + return Set.of(BlukiiBindingConstants.THING_TYPE_BEACON); } @Override diff --git a/bundles/org.openhab.binding.bluetooth.blukii/src/main/java/org/openhab/binding/bluetooth/blukii/internal/BlukiiHandlerFactory.java b/bundles/org.openhab.binding.bluetooth.blukii/src/main/java/org/openhab/binding/bluetooth/blukii/internal/BlukiiHandlerFactory.java index e3bd9790f..5eed6b011 100644 --- a/bundles/org.openhab.binding.bluetooth.blukii/src/main/java/org/openhab/binding/bluetooth/blukii/internal/BlukiiHandlerFactory.java +++ b/bundles/org.openhab.binding.bluetooth.blukii/src/main/java/org/openhab/binding/bluetooth/blukii/internal/BlukiiHandlerFactory.java @@ -12,7 +12,6 @@ */ package org.openhab.binding.bluetooth.blukii.internal; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -35,8 +34,8 @@ import org.osgi.service.component.annotations.Component; @Component(service = ThingHandlerFactory.class, configurationPid = "binding.blukii") public class BlukiiHandlerFactory extends BaseThingHandlerFactory { - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections - .singleton(BlukiiBindingConstants.THING_TYPE_BEACON); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set + .of(BlukiiBindingConstants.THING_TYPE_BEACON); @Override public boolean supportsThingType(ThingTypeUID thingTypeUID) { diff --git a/bundles/org.openhab.binding.bluetooth.daikinmadoka/src/main/java/org/openhab/binding/bluetooth/daikinmadoka/internal/DaikinMadokaHandlerFactory.java b/bundles/org.openhab.binding.bluetooth.daikinmadoka/src/main/java/org/openhab/binding/bluetooth/daikinmadoka/internal/DaikinMadokaHandlerFactory.java index 47a61b34a..4f80d140d 100644 --- a/bundles/org.openhab.binding.bluetooth.daikinmadoka/src/main/java/org/openhab/binding/bluetooth/daikinmadoka/internal/DaikinMadokaHandlerFactory.java +++ b/bundles/org.openhab.binding.bluetooth.daikinmadoka/src/main/java/org/openhab/binding/bluetooth/daikinmadoka/internal/DaikinMadokaHandlerFactory.java @@ -14,7 +14,6 @@ package org.openhab.binding.bluetooth.daikinmadoka.internal; import static org.openhab.binding.bluetooth.daikinmadoka.DaikinMadokaBindingConstants.THING_TYPE_BRC1H; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -39,7 +38,7 @@ import org.slf4j.LoggerFactory; @Component(configurationPid = "binding.bluetooth.daikinmadoka", service = ThingHandlerFactory.class) public class DaikinMadokaHandlerFactory extends BaseThingHandlerFactory { - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_BRC1H); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_BRC1H); private final Logger logger = LoggerFactory.getLogger(DaikinMadokaHandlerFactory.class); diff --git a/bundles/org.openhab.binding.bluetooth.enoceanble/src/main/java/org/openhab/binding/bluetooth/enoceanble/internal/EnoceanBleDiscoveryParticipant.java b/bundles/org.openhab.binding.bluetooth.enoceanble/src/main/java/org/openhab/binding/bluetooth/enoceanble/internal/EnoceanBleDiscoveryParticipant.java index 7eb0d2699..de627b349 100644 --- a/bundles/org.openhab.binding.bluetooth.enoceanble/src/main/java/org/openhab/binding/bluetooth/enoceanble/internal/EnoceanBleDiscoveryParticipant.java +++ b/bundles/org.openhab.binding.bluetooth.enoceanble/src/main/java/org/openhab/binding/bluetooth/enoceanble/internal/EnoceanBleDiscoveryParticipant.java @@ -12,7 +12,6 @@ */ package org.openhab.binding.bluetooth.enoceanble.internal; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -46,7 +45,7 @@ public class EnoceanBleDiscoveryParticipant implements BluetoothDiscoveryPartici @Override public Set getSupportedThingTypeUIDs() { - return Collections.singleton(EnoceanBleBindingConstants.THING_TYPE_PTM215B); + return Set.of(EnoceanBleBindingConstants.THING_TYPE_PTM215B); } @Override diff --git a/bundles/org.openhab.binding.bluetooth.enoceanble/src/main/java/org/openhab/binding/bluetooth/enoceanble/internal/EnoceanBleHandlerFactory.java b/bundles/org.openhab.binding.bluetooth.enoceanble/src/main/java/org/openhab/binding/bluetooth/enoceanble/internal/EnoceanBleHandlerFactory.java index 292c83646..dcbf0dd16 100644 --- a/bundles/org.openhab.binding.bluetooth.enoceanble/src/main/java/org/openhab/binding/bluetooth/enoceanble/internal/EnoceanBleHandlerFactory.java +++ b/bundles/org.openhab.binding.bluetooth.enoceanble/src/main/java/org/openhab/binding/bluetooth/enoceanble/internal/EnoceanBleHandlerFactory.java @@ -12,7 +12,6 @@ */ package org.openhab.binding.bluetooth.enoceanble.internal; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -33,8 +32,8 @@ import org.osgi.service.component.annotations.Component; @Component(service = ThingHandlerFactory.class, configurationPid = "binding.enoceanble") public class EnoceanBleHandlerFactory extends BaseThingHandlerFactory { - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections - .singleton(EnoceanBleBindingConstants.THING_TYPE_PTM215B); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set + .of(EnoceanBleBindingConstants.THING_TYPE_PTM215B); @Override public boolean supportsThingType(ThingTypeUID thingTypeUID) { diff --git a/bundles/org.openhab.binding.bluetooth.generic/src/main/java/org/openhab/binding/bluetooth/generic/internal/CharacteristicChannelTypeProvider.java b/bundles/org.openhab.binding.bluetooth.generic/src/main/java/org/openhab/binding/bluetooth/generic/internal/CharacteristicChannelTypeProvider.java index e3743123a..e6f176670 100644 --- a/bundles/org.openhab.binding.bluetooth.generic/src/main/java/org/openhab/binding/bluetooth/generic/internal/CharacteristicChannelTypeProvider.java +++ b/bundles/org.openhab.binding.bluetooth.generic/src/main/java/org/openhab/binding/bluetooth/generic/internal/CharacteristicChannelTypeProvider.java @@ -108,7 +108,7 @@ public class CharacteristicChannelTypeProvider implements ChannelTypeProvider { if (channelID.charAt(30) != '-') { return false; } - return !(channelID.charAt(67) != '-'); + return channelID.charAt(67) == '-'; } public ChannelTypeUID registerChannelType(String characteristicUUID, boolean advanced, boolean readOnly, diff --git a/bundles/org.openhab.binding.bluetooth.roaming/src/main/java/org/openhab/binding/bluetooth/roaming/internal/RoamingBindingConstants.java b/bundles/org.openhab.binding.bluetooth.roaming/src/main/java/org/openhab/binding/bluetooth/roaming/internal/RoamingBindingConstants.java index a42bdfe01..abde93890 100644 --- a/bundles/org.openhab.binding.bluetooth.roaming/src/main/java/org/openhab/binding/bluetooth/roaming/internal/RoamingBindingConstants.java +++ b/bundles/org.openhab.binding.bluetooth.roaming/src/main/java/org/openhab/binding/bluetooth/roaming/internal/RoamingBindingConstants.java @@ -12,7 +12,6 @@ */ package org.openhab.binding.bluetooth.roaming.internal; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -32,7 +31,7 @@ public class RoamingBindingConstants { public static final ThingTypeUID THING_TYPE_ROAMING = new ThingTypeUID(BluetoothBindingConstants.BINDING_ID, "roaming"); - public static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_ROAMING); + public static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_ROAMING); public static final String CONFIGURATION_GROUP_ADAPTER_UIDS = "groupUIDs"; } diff --git a/bundles/org.openhab.binding.bluetooth.roaming/src/main/java/org/openhab/binding/bluetooth/roaming/internal/RoamingBridgeHandler.java b/bundles/org.openhab.binding.bluetooth.roaming/src/main/java/org/openhab/binding/bluetooth/roaming/internal/RoamingBridgeHandler.java index 50b3fd5a1..e0122ac08 100644 --- a/bundles/org.openhab.binding.bluetooth.roaming/src/main/java/org/openhab/binding/bluetooth/roaming/internal/RoamingBridgeHandler.java +++ b/bundles/org.openhab.binding.bluetooth.roaming/src/main/java/org/openhab/binding/bluetooth/roaming/internal/RoamingBridgeHandler.java @@ -136,7 +136,7 @@ public class RoamingBridgeHandler extends BaseBridgeHandler implements RoamingBl return false; } Object discovery = getConfig().get(BluetoothBindingConstants.CONFIGURATION_DISCOVERY); - return !(discovery != null && discovery.toString().equalsIgnoreCase("false")); + return !(discovery != null && "false".equalsIgnoreCase(discovery.toString())); } @Override diff --git a/bundles/org.openhab.binding.bluetooth.roaming/src/main/java/org/openhab/binding/bluetooth/roaming/internal/RoamingHandlerFactory.java b/bundles/org.openhab.binding.bluetooth.roaming/src/main/java/org/openhab/binding/bluetooth/roaming/internal/RoamingHandlerFactory.java index c49693f62..2681ed1ae 100644 --- a/bundles/org.openhab.binding.bluetooth.roaming/src/main/java/org/openhab/binding/bluetooth/roaming/internal/RoamingHandlerFactory.java +++ b/bundles/org.openhab.binding.bluetooth.roaming/src/main/java/org/openhab/binding/bluetooth/roaming/internal/RoamingHandlerFactory.java @@ -20,7 +20,6 @@ import java.util.Map; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.openhab.binding.bluetooth.BluetoothAdapter; import org.openhab.core.thing.Bridge; import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingTypeUID; @@ -69,8 +68,8 @@ public class RoamingHandlerFactory extends BaseThingHandlerFactory { @Override protected synchronized void removeHandler(ThingHandler thingHandler) { - if (thingHandler instanceof RoamingBluetoothAdapter) { - UID uid = ((BluetoothAdapter) thingHandler).getUID(); + if (thingHandler instanceof RoamingBluetoothAdapter bluetoothAdapter) { + UID uid = bluetoothAdapter.getUID(); ServiceRegistration serviceReg = this.serviceRegs.remove(uid); if (serviceReg != null) { serviceReg.unregister(); diff --git a/bundles/org.openhab.binding.bluetooth.ruuvitag/src/main/java/org/openhab/binding/bluetooth/ruuvitag/internal/RuuviTagDiscoveryParticipant.java b/bundles/org.openhab.binding.bluetooth.ruuvitag/src/main/java/org/openhab/binding/bluetooth/ruuvitag/internal/RuuviTagDiscoveryParticipant.java index 8532714fc..15d1ab5e4 100644 --- a/bundles/org.openhab.binding.bluetooth.ruuvitag/src/main/java/org/openhab/binding/bluetooth/ruuvitag/internal/RuuviTagDiscoveryParticipant.java +++ b/bundles/org.openhab.binding.bluetooth.ruuvitag/src/main/java/org/openhab/binding/bluetooth/ruuvitag/internal/RuuviTagDiscoveryParticipant.java @@ -12,7 +12,6 @@ */ package org.openhab.binding.bluetooth.ruuvitag.internal; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -43,7 +42,7 @@ public class RuuviTagDiscoveryParticipant implements BluetoothDiscoveryParticipa @Override public Set getSupportedThingTypeUIDs() { - return Collections.singleton(RuuviTagBindingConstants.THING_TYPE_BEACON); + return Set.of(RuuviTagBindingConstants.THING_TYPE_BEACON); } @Override diff --git a/bundles/org.openhab.binding.bluetooth.ruuvitag/src/main/java/org/openhab/binding/bluetooth/ruuvitag/internal/RuuviTagHandlerFactory.java b/bundles/org.openhab.binding.bluetooth.ruuvitag/src/main/java/org/openhab/binding/bluetooth/ruuvitag/internal/RuuviTagHandlerFactory.java index bfaae59f7..46acaaa7c 100644 --- a/bundles/org.openhab.binding.bluetooth.ruuvitag/src/main/java/org/openhab/binding/bluetooth/ruuvitag/internal/RuuviTagHandlerFactory.java +++ b/bundles/org.openhab.binding.bluetooth.ruuvitag/src/main/java/org/openhab/binding/bluetooth/ruuvitag/internal/RuuviTagHandlerFactory.java @@ -12,7 +12,6 @@ */ package org.openhab.binding.bluetooth.ruuvitag.internal; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -33,8 +32,8 @@ import org.osgi.service.component.annotations.Component; @Component(service = ThingHandlerFactory.class, configurationPid = "binding.ruuvitag") public class RuuviTagHandlerFactory extends BaseThingHandlerFactory { - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections - .singleton(RuuviTagBindingConstants.THING_TYPE_BEACON); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set + .of(RuuviTagBindingConstants.THING_TYPE_BEACON); @Override public boolean supportsThingType(ThingTypeUID thingTypeUID) { diff --git a/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/ConnectedBluetoothHandler.java b/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/ConnectedBluetoothHandler.java index 4ca5dc455..6bd553448 100644 --- a/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/ConnectedBluetoothHandler.java +++ b/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/ConnectedBluetoothHandler.java @@ -80,8 +80,8 @@ public class ConnectedBluetoothHandler extends BeaconBluetoothHandler { Object idleDisconnectDelayRaw = getConfig().get(BluetoothBindingConstants.CONFIGURATION_IDLE_DISCONNECT_DELAY); idleDisconnectDelay = 1000; - if (idleDisconnectDelayRaw instanceof Number) { - idleDisconnectDelay = ((Number) idleDisconnectDelayRaw).intValue(); + if (idleDisconnectDelayRaw instanceof Number numberCommand) { + idleDisconnectDelay = numberCommand.intValue(); } // Start the recurrent job if the device is always connected @@ -202,11 +202,11 @@ public class ConnectedBluetoothHandler extends BeaconBluetoothHandler { return CompletableFuture.failedFuture(new IllegalStateException("connectionTaskExecutor is shut down")); } // we use a RetryFuture because it supports running Callable instances - return RetryFuture.callWithRetry(() -> { - // we block for completion here so that we keep the lock on the connectionTaskExecutor active. - return callable.apply(connectAndGetCharacteristic(serviceUUID, characteristicUUID)).get(); - }, connectionTaskExecutor)// we make this completion async so that operations chained off the returned future - // will not run on the connectionTaskExecutor + return RetryFuture.callWithRetry(() -> + // we block for completion here so that we keep the lock on the connectionTaskExecutor active. + callable.apply(connectAndGetCharacteristic(serviceUUID, characteristicUUID)).get(), connectionTaskExecutor) + // we make this completion async so that operations chained off the returned future + // will not run on the connectionTaskExecutor .whenCompleteAsync((r, th) -> { // we us a while loop here in case the exceptions get nested while (th instanceof CompletionException || th instanceof ExecutionException) { diff --git a/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/util/RetryFuture.java b/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/util/RetryFuture.java index 7058bb386..18e370367 100644 --- a/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/util/RetryFuture.java +++ b/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/util/RetryFuture.java @@ -94,8 +94,7 @@ public class RetryFuture extends HeritableFuture { if (th instanceof CompletionException) { th = th.getCause(); } - if (th instanceof RetryException) { - RetryException e = (RetryException) th; + if (th instanceof RetryException e) { setParentFuture(() -> { if (!isDone()) { return scheduler.schedule(this, e.delay, e.unit); diff --git a/bundles/org.openhab.binding.bluetooth/src/test/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDiscoveryServiceTest.java b/bundles/org.openhab.binding.bluetooth/src/test/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDiscoveryServiceTest.java index 9b362883c..aae70b1e8 100644 --- a/bundles/org.openhab.binding.bluetooth/src/test/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDiscoveryServiceTest.java +++ b/bundles/org.openhab.binding.bluetooth/src/test/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDiscoveryServiceTest.java @@ -539,7 +539,7 @@ public class BluetoothDiscoveryServiceTest { @Override public Set getSupportedThingTypeUIDs() { - return Collections.singleton(typeUID); + return Set.of(typeUID); } @Override diff --git a/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/BondHomeHandlerFactory.java b/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/BondHomeHandlerFactory.java index 315874728..0eb0b5297 100644 --- a/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/BondHomeHandlerFactory.java +++ b/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/BondHomeHandlerFactory.java @@ -64,8 +64,7 @@ public class BondHomeHandlerFactory extends BaseThingHandlerFactory { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); if (THING_TYPE_BOND_BRIDGE.equals(thingTypeUID)) { - final BondBridgeHandler handler = new BondBridgeHandler((Bridge) thing, httpClientFactory); - return handler; + return new BondBridgeHandler((Bridge) thing, httpClientFactory); } else if (SUPPORTED_THING_TYPES.contains(thingTypeUID)) { return new BondDeviceHandler(thing); } diff --git a/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/api/BondHttpApi.java b/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/api/BondHttpApi.java index 0fcf8256b..97b9ec888 100644 --- a/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/api/BondHttpApi.java +++ b/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/api/BondHttpApi.java @@ -219,7 +219,7 @@ public class BondHttpApi { bridgeHandler.getBridgeToken()); ContentResponse response; response = request.send(); - String encoding = response.getEncoding() != null ? response.getEncoding().replaceAll("\"", "").trim() + String encoding = response.getEncoding() != null ? response.getEncoding().replace("\"", "").trim() : StandardCharsets.UTF_8.name(); try { httpResponse = new String(response.getContent(), encoding); diff --git a/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/discovery/BondDiscoveryService.java b/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/discovery/BondDiscoveryService.java index 6d3ce30c6..c32697ef3 100644 --- a/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/discovery/BondDiscoveryService.java +++ b/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/discovery/BondDiscoveryService.java @@ -58,9 +58,7 @@ public class BondDiscoveryService extends AbstractDiscoveryService implements Th @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof BondBridgeHandler) { - @Nullable - BondBridgeHandler localHandler = (BondBridgeHandler) handler; + if (handler instanceof BondBridgeHandler localHandler) { bridgeHandler = localHandler; localHandler.setDiscoveryService(this); api = localHandler.getBridgeAPI(); diff --git a/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/handler/BondBridgeHandler.java b/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/handler/BondBridgeHandler.java index 7c28cf341..ed779d454 100644 --- a/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/handler/BondBridgeHandler.java +++ b/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/handler/BondBridgeHandler.java @@ -170,8 +170,7 @@ public class BondBridgeHandler extends BaseBridgeHandler { @Override public void childHandlerInitialized(ThingHandler childHandler, Thing childThing) { super.childHandlerInitialized(childHandler, childThing); - if (childHandler instanceof BondDeviceHandler) { - BondDeviceHandler handler = (BondDeviceHandler) childHandler; + if (childHandler instanceof BondDeviceHandler handler) { synchronized (handlers) { // Start the BPUP update service after the first child device is added startUDPListenerJob(); @@ -184,8 +183,7 @@ public class BondBridgeHandler extends BaseBridgeHandler { @Override public void childHandlerDisposed(ThingHandler childHandler, Thing childThing) { - if (childHandler instanceof BondDeviceHandler) { - BondDeviceHandler handler = (BondDeviceHandler) childHandler; + if (childHandler instanceof BondDeviceHandler handler) { synchronized (handlers) { handlers.remove(handler); if (handlers.isEmpty()) { @@ -210,7 +208,7 @@ public class BondBridgeHandler extends BaseBridgeHandler { String deviceId = null; String topicType = null; if (topic != null) { - String parts[] = topic.split("/"); + String[] parts = topic.split("/"); deviceId = parts[1]; topicType = parts[2]; } @@ -332,7 +330,7 @@ public class BondBridgeHandler extends BaseBridgeHandler { @Override public Collection> getServices() { - return Collections.singleton(BondDiscoveryService.class); + return Set.of(BondDiscoveryService.class); } public void setDiscoveryService(BondDiscoveryService discoveryService) { diff --git a/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/handler/BondDeviceHandler.java b/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/handler/BondDeviceHandler.java index 89c7571b8..d0846decb 100644 --- a/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/handler/BondDeviceHandler.java +++ b/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/handler/BondDeviceHandler.java @@ -156,9 +156,9 @@ public class BondDeviceHandler extends BaseThingHandler { case CHANNEL_FAN_SPEED: logger.trace("Fan speed command"); - if (command instanceof PercentType) { + if (command instanceof PercentType percentCommand) { if (devInfo.actions.contains(BondDeviceAction.SET_FP_FAN)) { - value = ((PercentType) command).intValue(); + value = percentCommand.intValue(); if (value == 0) { action = BondDeviceAction.TURN_FP_FAN_OFF; value = null; @@ -169,7 +169,7 @@ public class BondDeviceHandler extends BaseThingHandler { BondDeviceProperties devProperties = this.deviceProperties; if (devProperties != null) { int maxSpeed = devProperties.maxSpeed; - value = (int) Math.ceil(((PercentType) command).intValue() * maxSpeed / 100); + value = (int) Math.ceil(percentCommand.intValue() * maxSpeed / 100); } else { value = 1; } @@ -182,11 +182,10 @@ public class BondDeviceHandler extends BaseThingHandler { } logger.trace("Fan speed command with speed set as {}", value); api.executeDeviceAction(deviceId, action, value); - } else if (command instanceof IncreaseDecreaseType) { + } else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) { logger.trace("Fan increase/decrease speed command"); api.executeDeviceAction(deviceId, - ((IncreaseDecreaseType) command == IncreaseDecreaseType.INCREASE - ? BondDeviceAction.INCREASE_SPEED + (increaseDecreaseCommand == IncreaseDecreaseType.INCREASE ? BondDeviceAction.INCREASE_SPEED : BondDeviceAction.DECREASE_SPEED), null); } else if (command instanceof OnOffType) { @@ -206,8 +205,8 @@ public class BondDeviceHandler extends BaseThingHandler { break; case CHANNEL_RAW_FAN_SPEED: - if (command instanceof DecimalType) { - value = ((DecimalType) command).intValue(); + if (command instanceof DecimalType decimalCommand) { + value = decimalCommand.intValue(); BondDeviceProperties devProperties = this.deviceProperties; if (devProperties != null) { if (value < 1) { @@ -246,7 +245,7 @@ public class BondDeviceHandler extends BaseThingHandler { logger.trace("Fan direction command {}", command.toString()); if (command instanceof StringType) { api.executeDeviceAction(deviceId, BondDeviceAction.SET_DIRECTION, - command.toString().equals("winter") ? -1 : 1); + "winter".equals(command.toString()) ? -1 : 1); } break; @@ -258,9 +257,8 @@ public class BondDeviceHandler extends BaseThingHandler { break; case CHANNEL_LIGHT_BRIGHTNESS: - if (command instanceof PercentType) { - PercentType pctCommand = (PercentType) command; - value = pctCommand.intValue(); + if (command instanceof PercentType percentCommand) { + value = percentCommand.intValue(); if (value == 0) { action = BondDeviceAction.TURN_LIGHT_OFF; value = null; @@ -269,10 +267,10 @@ public class BondDeviceHandler extends BaseThingHandler { } logger.trace("Fan light brightness command with value of {}", value); api.executeDeviceAction(deviceId, action, value); - } else if (command instanceof IncreaseDecreaseType) { + } else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) { logger.trace("Fan light brightness increase/decrease command {}", command); api.executeDeviceAction(deviceId, - ((IncreaseDecreaseType) command == IncreaseDecreaseType.INCREASE + (increaseDecreaseCommand == IncreaseDecreaseType.INCREASE ? BondDeviceAction.INCREASE_BRIGHTNESS : BondDeviceAction.DECREASE_BRIGHTNESS), null); @@ -301,9 +299,8 @@ public class BondDeviceHandler extends BaseThingHandler { case CHANNEL_UP_LIGHT_BRIGHTNESS: enableUpLight(); - if (command instanceof PercentType) { - PercentType pctCommand = (PercentType) command; - value = pctCommand.intValue(); + if (command instanceof PercentType percentCommand) { + value = percentCommand.intValue(); if (value == 0) { action = BondDeviceAction.TURN_LIGHT_OFF; value = null; @@ -312,10 +309,10 @@ public class BondDeviceHandler extends BaseThingHandler { } logger.trace("Fan up light brightness command with value of {}", value); api.executeDeviceAction(deviceId, action, value); - } else if (command instanceof IncreaseDecreaseType) { + } else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) { logger.trace("Fan uplight brightness increase/decrease command {}", command); api.executeDeviceAction(deviceId, - ((IncreaseDecreaseType) command == IncreaseDecreaseType.INCREASE + (increaseDecreaseCommand == IncreaseDecreaseType.INCREASE ? BondDeviceAction.INCREASE_UP_LIGHT_BRIGHTNESS : BondDeviceAction.DECREASE_UP_LIGHT_BRIGHTNESS), null); @@ -344,9 +341,8 @@ public class BondDeviceHandler extends BaseThingHandler { case CHANNEL_DOWN_LIGHT_BRIGHTNESS: enableDownLight(); - if (command instanceof PercentType) { - PercentType pctCommand = (PercentType) command; - value = pctCommand.intValue(); + if (command instanceof PercentType percentCommand) { + value = percentCommand.intValue(); if (value == 0) { action = BondDeviceAction.TURN_LIGHT_OFF; value = null; @@ -355,10 +351,10 @@ public class BondDeviceHandler extends BaseThingHandler { } logger.trace("Fan down light brightness command with value of {}", value); api.executeDeviceAction(deviceId, action, value); - } else if (command instanceof IncreaseDecreaseType) { + } else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) { logger.trace("Fan down light brightness increase/decrease command"); api.executeDeviceAction(deviceId, - ((IncreaseDecreaseType) command == IncreaseDecreaseType.INCREASE + (increaseDecreaseCommand == IncreaseDecreaseType.INCREASE ? BondDeviceAction.INCREASE_DOWN_LIGHT_BRIGHTNESS : BondDeviceAction.DECREASE_DOWN_LIGHT_BRIGHTNESS), null); @@ -373,9 +369,8 @@ public class BondDeviceHandler extends BaseThingHandler { break; case CHANNEL_FLAME: - if (command instanceof PercentType) { - PercentType pctCommand = (PercentType) command; - value = pctCommand.intValue(); + if (command instanceof PercentType percentCommand) { + value = percentCommand.intValue(); if (value == 0) { action = BondDeviceAction.TURN_OFF; value = null; @@ -384,11 +379,10 @@ public class BondDeviceHandler extends BaseThingHandler { } logger.trace("Fireplace flame command with value of {}", value); api.executeDeviceAction(deviceId, action, value); - } else if (command instanceof IncreaseDecreaseType) { + } else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) { logger.trace("Fireplace flame increase/decrease command"); api.executeDeviceAction(deviceId, - ((IncreaseDecreaseType) command == IncreaseDecreaseType.INCREASE - ? BondDeviceAction.INCREASE_FLAME + (increaseDecreaseCommand == IncreaseDecreaseType.INCREASE ? BondDeviceAction.INCREASE_FLAME : BondDeviceAction.DECREASE_FLAME), null); } else if (command instanceof OnOffType) { @@ -540,7 +534,7 @@ public class BondDeviceHandler extends BaseThingHandler { updateProperty(thingProperties, PROPERTIES_TEMPLATE_NAME, devInfo.template); thingProperties.put(PROPERTIES_MAX_SPEED, String.valueOf(devProperties.maxSpeed)); thingProperties.put(PROPERTIES_TRUST_STATE, String.valueOf(devProperties.trustState)); - thingProperties.put(PROPERTIES_ADDRESS, String.valueOf(devProperties.addr)); + thingProperties.put(PROPERTIES_ADDRESS, devProperties.addr); thingProperties.put(PROPERTIES_RF_FREQUENCY, String.valueOf(devProperties.freq)); logger.trace("Saving properties for {} ({})", config.deviceId, this.getThing().getLabel()); updateProperties(thingProperties); diff --git a/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/AuthorizationController.java b/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/AuthorizationController.java index 0482e3e1e..06d701918 100644 --- a/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/AuthorizationController.java +++ b/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/AuthorizationController.java @@ -47,6 +47,7 @@ public class AuthorizationController implements AuthorizationProvider { this.oAuthClientService = oAuthClientService; } + @Override public String getAuthorizationHeader() throws IndegoAuthenticationException { final AccessTokenResponse accessTokenResponse; try { diff --git a/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/IndegoController.java b/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/IndegoController.java index 22c734d74..2cf326001 100644 --- a/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/IndegoController.java +++ b/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/IndegoController.java @@ -158,8 +158,8 @@ public class IndegoController { throw new IndegoException(e); } catch (ExecutionException e) { Throwable cause = e.getCause(); - if (cause != null && cause instanceof HttpResponseException) { - Response response = ((HttpResponseException) cause).getResponse(); + if (cause != null && cause instanceof HttpResponseException httpResponseException) { + Response response = httpResponseException.getResponse(); if (response.getStatus() == HttpStatus.UNAUTHORIZED_401) { /* * The service may respond with HTTP code 401 without any "WWW-Authenticate" @@ -218,8 +218,8 @@ public class IndegoController { throw new IndegoException(e); } catch (ExecutionException e) { Throwable cause = e.getCause(); - if (cause != null && cause instanceof HttpResponseException) { - Response response = ((HttpResponseException) cause).getResponse(); + if (cause != null && cause instanceof HttpResponseException httpResponseException) { + Response response = httpResponseException.getResponse(); if (response.getStatus() == HttpStatus.UNAUTHORIZED_401) { /* * When contextId is not valid, the service will respond with HTTP code 401 without @@ -316,8 +316,8 @@ public class IndegoController { throw new IndegoException(e); } catch (ExecutionException e) { Throwable cause = e.getCause(); - if (cause != null && cause instanceof HttpResponseException) { - Response response = ((HttpResponseException) cause).getResponse(); + if (cause != null && cause instanceof HttpResponseException httpResponseException) { + Response response = httpResponseException.getResponse(); if (response.getStatus() == HttpStatus.UNAUTHORIZED_401) { /* * When contextId is not valid, the service will respond with HTTP code 401 without diff --git a/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/IndegoDeviceController.java b/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/IndegoDeviceController.java index 72bff9f46..18afdf0e4 100644 --- a/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/IndegoDeviceController.java +++ b/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/IndegoDeviceController.java @@ -141,9 +141,7 @@ public class IndegoDeviceController extends IndegoController { * @throws IndegoException if any communication or parsing error occurred */ public DeviceCalendarResponse getCalendar() throws IndegoAuthenticationException, IndegoException { - DeviceCalendarResponse calendar = getRequest(SERIAL_NUMBER_SUBPATH + serialNumber + "/calendar", - DeviceCalendarResponse.class); - return calendar; + return getRequest(SERIAL_NUMBER_SUBPATH + serialNumber + "/calendar", DeviceCalendarResponse.class); } /** diff --git a/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/handler/BoschAccountHandler.java b/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/handler/BoschAccountHandler.java index cb8624915..0329c0dfd 100644 --- a/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/handler/BoschAccountHandler.java +++ b/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/handler/BoschAccountHandler.java @@ -130,10 +130,12 @@ public class BoschAccountHandler extends BaseBridgeHandler implements Authorizat } } + @Override public void onSuccessfulAuthorization() { updateStatus(ThingStatus.ONLINE); } + @Override public void onFailedAuthorization(Throwable throwable) { logger.debug("Authorization failure", throwable); if (throwable instanceof IndegoAuthenticationException) { @@ -144,6 +146,7 @@ public class BoschAccountHandler extends BaseBridgeHandler implements Authorizat } } + @Override public void onAuthorizationFlowCompleted() { // Ignore } diff --git a/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/handler/BoschIndegoHandler.java b/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/handler/BoschIndegoHandler.java index 9cf3fdd9e..e7f2b9768 100644 --- a/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/handler/BoschIndegoHandler.java +++ b/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/handler/BoschIndegoHandler.java @@ -161,14 +161,17 @@ public class BoschIndegoHandler extends BaseThingHandler implements Authorizatio } } + @Override public void onSuccessfulAuthorization() { // Ignore } + @Override public void onFailedAuthorization(Throwable throwable) { // Ignore } + @Override public void onAuthorizationFlowCompleted() { // Trigger immediate state refresh upon authorization success. rescheduleStatePoll(0, stateInactiveRefreshIntervalSeconds, true); @@ -226,8 +229,8 @@ public class BoschIndegoHandler extends BaseThingHandler implements Authorizatio handleRefreshCommand(channelUID.getId()); return; } - if (command instanceof DecimalType && channelUID.getId().equals(STATE)) { - sendCommand(((DecimalType) command).intValue()); + if (command instanceof DecimalType decimalCommand && channelUID.getId().equals(STATE)) { + sendCommand(decimalCommand.intValue()); } } catch (IndegoAuthenticationException e) { // Ignore, will be handled by bridge diff --git a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/bridge/BridgeHandler.java b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/bridge/BridgeHandler.java index 926c45063..54e14d749 100644 --- a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/bridge/BridgeHandler.java +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/bridge/BridgeHandler.java @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -106,7 +107,7 @@ public class BridgeHandler extends BaseBridgeHandler { @Override public Collection> getServices() { - return Collections.singleton(ThingDiscoveryService.class); + return Set.of(ThingDiscoveryService.class); } @Override diff --git a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/climatecontrol/ClimateControlHandler.java b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/climatecontrol/ClimateControlHandler.java index af55dc182..79a2a7a76 100644 --- a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/climatecontrol/ClimateControlHandler.java +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/climatecontrol/ClimateControlHandler.java @@ -65,8 +65,8 @@ public final class ClimateControlHandler extends BoschSHCDeviceHandler { super.handleCommand(channelUID, command); switch (channelUID.getId()) { case CHANNEL_SETPOINT_TEMPERATURE: - if (command instanceof QuantityType) { - updateSetpointTemperature((QuantityType) command); + if (command instanceof QuantityType temperature) { + updateSetpointTemperature(temperature); } break; } diff --git a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/intrusion/IntrusionDetectionHandler.java b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/intrusion/IntrusionDetectionHandler.java index d8b61aea1..8941c8db1 100644 --- a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/intrusion/IntrusionDetectionHandler.java +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/intrusion/IntrusionDetectionHandler.java @@ -122,18 +122,18 @@ public class IntrusionDetectionHandler extends BoschSHCHandler { switch (channelUID.getId()) { case CHANNEL_ARM_ACTION: - if (command instanceof StringType) { - armIntrusionDetectionSystem((StringType) command); + if (command instanceof StringType stringCommand) { + armIntrusionDetectionSystem(stringCommand); } break; case CHANNEL_DISARM_ACTION: - if (command instanceof OnOffType) { - disarmIntrusionDetectionSystem((OnOffType) command); + if (command instanceof OnOffType onOffCommand) { + disarmIntrusionDetectionSystem(onOffCommand); } break; case CHANNEL_MUTE_ACTION: - if (command instanceof OnOffType) { - muteIntrusionDetectionSystem((OnOffType) command); + if (command instanceof OnOffType onOffCommand) { + muteIntrusionDetectionSystem(onOffCommand); } break; } diff --git a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/intrusion/dto/AlarmState.java b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/intrusion/dto/AlarmState.java index cba0a0839..0c00e1a70 100644 --- a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/intrusion/dto/AlarmState.java +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/intrusion/dto/AlarmState.java @@ -26,5 +26,5 @@ public enum AlarmState { PRE_ALARM, ALARM_ON, ALARM_MUTED, - UNKNOWN; + UNKNOWN } diff --git a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/intrusion/dto/ArmingState.java b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/intrusion/dto/ArmingState.java index ddbc37619..b224f3e15 100644 --- a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/intrusion/dto/ArmingState.java +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/intrusion/dto/ArmingState.java @@ -24,5 +24,5 @@ import org.eclipse.jdt.annotation.NonNullByDefault; public enum ArmingState { SYSTEM_ARMED, SYSTEM_ARMING, - SYSTEM_DISARMED; + SYSTEM_DISARMED } diff --git a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/shuttercontact/ShutterContactState.java b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/shuttercontact/ShutterContactState.java index b2b731330..d97dfb409 100644 --- a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/shuttercontact/ShutterContactState.java +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/shuttercontact/ShutterContactState.java @@ -22,5 +22,5 @@ import org.eclipse.jdt.annotation.NonNullByDefault; @NonNullByDefault public enum ShutterContactState { OPEN, - CLOSED; + CLOSED } diff --git a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/shuttercontrol/OperationState.java b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/shuttercontrol/OperationState.java index 8a138dbaa..ec34a91a8 100644 --- a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/shuttercontrol/OperationState.java +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/shuttercontrol/OperationState.java @@ -22,5 +22,5 @@ import org.eclipse.jdt.annotation.NonNullByDefault; @NonNullByDefault public enum OperationState { MOVING, - STOPPED; + STOPPED } diff --git a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/smokedetectorcheck/SmokeDetectorCheckService.java b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/smokedetectorcheck/SmokeDetectorCheckService.java index c0f7828b0..49942f88c 100644 --- a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/smokedetectorcheck/SmokeDetectorCheckService.java +++ b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/services/smokedetectorcheck/SmokeDetectorCheckService.java @@ -34,15 +34,13 @@ public class SmokeDetectorCheckService extends BoschSHCService fields = ReflectionSupport.findFields(BoschHttpClient.class, - f -> f.getName().equalsIgnoreCase("logger"), HierarchyTraversalMode.TOP_DOWN); + f -> "logger".equalsIgnoreCase(f.getName()), HierarchyTraversalMode.TOP_DOWN); Field field = fields.iterator().next(); field.setAccessible(true); field.set(mockedHttpClient, mockedLogger); @@ -137,7 +137,7 @@ class BoschHttpClientTest { // mock a logger using reflection to avoid NPEs during logger calls Logger mockedLogger = mock(Logger.class); List fields = ReflectionSupport.findFields(BoschHttpClient.class, - f -> f.getName().equalsIgnoreCase("logger"), HierarchyTraversalMode.TOP_DOWN); + f -> "logger".equalsIgnoreCase(f.getName()), HierarchyTraversalMode.TOP_DOWN); Field field = fields.iterator().next(); field.setAccessible(true); field.set(mockedHttpClient, mockedLogger); @@ -210,9 +210,7 @@ class BoschHttpClientTest { "{\"@type\": \"JsonRestExceptionResponseEntity\", \"errorCode\": \"500\", \"statusCode\": \"500\"}"); BoschSHCException e = assertThrows(BoschSHCException.class, () -> httpClient.sendRequest(request, Device.class, - Device::isValid, (Integer statusCode, String content) -> { - return new BoschSHCException("test exception"); - })); + Device::isValid, (Integer statusCode, String content) -> new BoschSHCException("test exception"))); assertEquals("test exception", e.getMessage()); } @@ -240,9 +238,7 @@ class BoschHttpClientTest { when(response.getContentAsString()).thenReturn( "{\"@type\": \"JsonRestExceptionResponseEntity\", \"errorCode\": \"500\", \"statusCode\": \"500\"}"); ExecutionException e = assertThrows(ExecutionException.class, - () -> httpClient.sendRequest(request, SubscribeResult.class, sr -> { - return false; - }, null)); + () -> httpClient.sendRequest(request, SubscribeResult.class, sr -> false, null)); String actualMessage = e.getMessage(); assertTrue(actualMessage.contains( "Received invalid content for type org.openhab.binding.boschshc.internal.devices.bridge.dto.SubscribeResult:")); @@ -257,9 +253,7 @@ class BoschHttpClientTest { when(response.getStatus()).thenReturn(200); when(response.getContentAsString()).thenReturn("{\"@type\": \"JsonRestExceptionResponseEntity}"); ExecutionException e = assertThrows(ExecutionException.class, - () -> httpClient.sendRequest(request, SubscribeResult.class, sr -> { - return false; - }, null)); + () -> httpClient.sendRequest(request, SubscribeResult.class, sr -> false, null)); assertEquals( "Received invalid content in response, expected type org.openhab.binding.boschshc.internal.devices.bridge.dto.SubscribeResult: com.google.gson.stream.MalformedJsonException: Unterminated string at line 1 column 44 path $.@type", e.getMessage()); diff --git a/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/devices/bridge/BridgeHandlerTest.java b/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/devices/bridge/BridgeHandlerTest.java index a6be12174..bd71f83b3 100644 --- a/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/devices/bridge/BridgeHandlerTest.java +++ b/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/devices/bridge/BridgeHandlerTest.java @@ -159,14 +159,21 @@ class BridgeHandlerTest { Request devicesRequest = mock(Request.class); ContentResponse devicesResponse = mock(ContentResponse.class); when(devicesResponse.getStatus()).thenReturn(200); - when(devicesResponse.getContentAsString()).thenReturn("[{\"@type\":\"device\",\r\n" - + " \"rootDeviceId\":\"64-da-a0-02-14-9b\",\r\n" - + " \"id\":\"hdm:HomeMaticIP:3014F711A00004953859F31B\",\r\n" - + " \"deviceServiceIds\":[\"PowerMeter\",\"PowerSwitch\",\"PowerSwitchProgram\",\"Routing\"],\r\n" - + " \"manufacturer\":\"BOSCH\",\r\n" + " \"roomId\":\"hz_3\",\r\n" + " \"deviceModel\":\"PSM\",\r\n" - + " \"serial\":\"3014F711A00004953859F31B\",\r\n" + " \"profile\":\"GENERIC\",\r\n" - + " \"name\":\"Coffee Machine\",\r\n" + " \"status\":\"AVAILABLE\",\r\n" + " \"childDeviceIds\":[]\r\n" - + " }]"); + when(devicesResponse.getContentAsString()).thenReturn(""" + [{"@type":"device", + "rootDeviceId":"64-da-a0-02-14-9b", + "id":"hdm:HomeMaticIP:3014F711A00004953859F31B", + "deviceServiceIds":["PowerMeter","PowerSwitch","PowerSwitchProgram","Routing"], + "manufacturer":"BOSCH", + "roomId":"hz_3", + "deviceModel":"PSM", + "serial":"3014F711A00004953859F31B", + "profile":"GENERIC", + "name":"Coffee Machine", + "status":"AVAILABLE", + "childDeviceIds":[] + }]\ + """); when(devicesRequest.send()).thenReturn(devicesResponse); when(httpClient.createRequest(contains("/devices"), same(HttpMethod.GET))).thenReturn(devicesRequest); @@ -175,7 +182,7 @@ class BridgeHandlerTest { Request longPollRequest = mock(Request.class); when(httpClient.createRequest(anyString(), same(HttpMethod.POST), - argThat((JsonRpcRequest r) -> r.method.equals("RE/longPoll")))).thenReturn(longPollRequest); + argThat((JsonRpcRequest r) -> "RE/longPoll".equals(r.method)))).thenReturn(longPollRequest); fixture.initialAccess(httpClient); verify(thingHandlerCallback).statusUpdated(any(), @@ -190,18 +197,37 @@ class BridgeHandlerTest { when(request.header(anyString(), anyString())).thenReturn(request); ContentResponse response = mock(ContentResponse.class); when(response.getStatus()).thenReturn(200); - when(response.getContentAsString()).thenReturn("{\r\n" + " \"@type\": \"systemState\",\r\n" - + " \"systemAvailability\": {\r\n" + " \"@type\": \"systemAvailabilityState\",\r\n" - + " \"available\": true,\r\n" + " \"deleted\": false\r\n" + " },\r\n" - + " \"armingState\": {\r\n" + " \"@type\": \"armingState\",\r\n" - + " \"state\": \"SYSTEM_DISARMED\",\r\n" + " \"deleted\": false\r\n" + " },\r\n" - + " \"alarmState\": {\r\n" + " \"@type\": \"alarmState\",\r\n" - + " \"value\": \"ALARM_OFF\",\r\n" + " \"incidents\": [],\r\n" - + " \"deleted\": false\r\n" + " },\r\n" + " \"activeConfigurationProfile\": {\r\n" - + " \"@type\": \"activeConfigurationProfile\",\r\n" + " \"deleted\": false\r\n" - + " },\r\n" + " \"securityGapState\": {\r\n" + " \"@type\": \"securityGapState\",\r\n" - + " \"securityGaps\": [],\r\n" + " \"deleted\": false\r\n" + " },\r\n" - + " \"deleted\": false\r\n" + " }"); + when(response.getContentAsString()).thenReturn(""" + { + "@type": "systemState", + "systemAvailability": { + "@type": "systemAvailabilityState", + "available": true, + "deleted": false + }, + "armingState": { + "@type": "armingState", + "state": "SYSTEM_DISARMED", + "deleted": false + }, + "alarmState": { + "@type": "alarmState", + "value": "ALARM_OFF", + "incidents": [], + "deleted": false + }, + "activeConfigurationProfile": { + "@type": "activeConfigurationProfile", + "deleted": false + }, + "securityGapState": { + "@type": "securityGapState", + "securityGaps": [], + "deleted": false + }, + "deleted": false + }\ + """); when(request.send()).thenReturn(response); when(httpClient.createRequest(anyString(), same(HttpMethod.GET))).thenReturn(request); @@ -302,12 +328,22 @@ class BridgeHandlerTest { when(request.header(anyString(), anyString())).thenReturn(request); ContentResponse response = mock(ContentResponse.class); when(response.getStatus()).thenReturn(200); - when(response.getContentAsString()).thenReturn("{ \n" + " \"@type\":\"DeviceServiceData\",\n" - + " \"path\":\"/devices/hdm:ZigBee:000d6f0004b93361/services/BatteryLevel\",\n" - + " \"id\":\"BatteryLevel\",\n" + " \"deviceId\":\"hdm:ZigBee:000d6f0004b93361\",\n" - + " \"faults\":{ \n" + " \"entries\":[\n" + " {\n" - + " \"type\":\"LOW_BATTERY\",\n" + " \"category\":\"WARNING\"\n" + " }\n" - + " ]\n" + " }\n" + "}"); + when(response.getContentAsString()).thenReturn(""" + { + "@type":"DeviceServiceData", + "path":"/devices/hdm:ZigBee:000d6f0004b93361/services/BatteryLevel", + "id":"BatteryLevel", + "deviceId":"hdm:ZigBee:000d6f0004b93361", + "faults":{\s + "entries":[ + { + "type":"LOW_BATTERY", + "category":"WARNING" + } + ] + } + }\ + """); when(request.send()).thenReturn(response); when(httpClient.createRequest(anyString(), same(HttpMethod.GET))).thenReturn(request); diff --git a/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/devices/bridge/LongPollingTest.java b/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/devices/bridge/LongPollingTest.java index b6c2dc837..33035a95b 100644 --- a/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/devices/bridge/LongPollingTest.java +++ b/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/devices/bridge/LongPollingTest.java @@ -210,13 +210,13 @@ class LongPollingTest { Request subscribeRequest = mock(Request.class); when(httpClient.createRequest(anyString(), same(HttpMethod.POST), - argThat((JsonRpcRequest r) -> r.method.equals("RE/subscribe")))).thenReturn(subscribeRequest); + argThat((JsonRpcRequest r) -> "RE/subscribe".equals(r.method)))).thenReturn(subscribeRequest); SubscribeResult subscribeResult = new SubscribeResult(); when(httpClient.sendRequest(any(), same(SubscribeResult.class), any(), any())).thenReturn(subscribeResult); Request longPollRequest = mock(Request.class); when(httpClient.createRequest(anyString(), same(HttpMethod.POST), - argThat((JsonRpcRequest r) -> r.method.equals("RE/longPoll")))).thenReturn(longPollRequest); + argThat((JsonRpcRequest r) -> "RE/longPoll".equals(r.method)))).thenReturn(longPollRequest); fixture.start(httpClient); @@ -268,7 +268,7 @@ class LongPollingTest { Request longPollRequest = mock(Request.class); when(httpClient.createRequest(anyString(), same(HttpMethod.POST), - argThat((JsonRpcRequest r) -> r.method.equals("RE/longPoll")))).thenReturn(longPollRequest); + argThat((JsonRpcRequest r) -> "RE/longPoll".equals(r.method)))).thenReturn(longPollRequest); fixture.start(httpClient); @@ -296,13 +296,13 @@ class LongPollingTest { Request subscribeRequest = mock(Request.class); when(httpClient.createRequest(anyString(), same(HttpMethod.POST), - argThat((JsonRpcRequest r) -> r.method.equals("RE/subscribe")))).thenReturn(subscribeRequest); + argThat((JsonRpcRequest r) -> "RE/subscribe".equals(r.method)))).thenReturn(subscribeRequest); SubscribeResult subscribeResult = new SubscribeResult(); when(httpClient.sendRequest(any(), same(SubscribeResult.class), any(), any())).thenReturn(subscribeResult); Request longPollRequest = mock(Request.class); when(httpClient.createRequest(anyString(), same(HttpMethod.POST), - argThat((JsonRpcRequest r) -> r.method.equals("RE/longPoll")))).thenReturn(longPollRequest); + argThat((JsonRpcRequest r) -> "RE/longPoll".equals(r.method)))).thenReturn(longPollRequest); fixture.start(httpClient); diff --git a/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/devices/climatecontrol/ClimateControlHandlerTest.java b/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/devices/climatecontrol/ClimateControlHandlerTest.java index c8ced460d..05911dd53 100644 --- a/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/devices/climatecontrol/ClimateControlHandlerTest.java +++ b/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/devices/climatecontrol/ClimateControlHandlerTest.java @@ -78,8 +78,12 @@ class ClimateControlHandlerTest extends AbstractBoschSHCDeviceHandlerTest", ">"); - xml = xml.replaceAll("\"", """); - xml = xml.replaceAll("'", "'"); + xml = xml.replace("&", "&"); + xml = xml.replace("<", "<"); + xml = xml.replace(">", ">"); + xml = xml.replace("\"", """); + xml = xml.replace("'", "'"); return xml; } @@ -251,7 +250,7 @@ public class ContentItem { } public StateOption toStateOption() { - String stateOptionLabel = String.valueOf(presetID) + ": " + itemName; + String stateOptionLabel = presetID + ": " + itemName; return new StateOption(String.valueOf(presetID), stateOptionLabel); } diff --git a/bundles/org.openhab.binding.broadlinkthermostat/src/main/java/org/openhab/binding/broadlinkthermostat/internal/discovery/BroadlinkDiscoveryService.java b/bundles/org.openhab.binding.broadlinkthermostat/src/main/java/org/openhab/binding/broadlinkthermostat/internal/discovery/BroadlinkDiscoveryService.java index cf8b69fe5..714003afc 100644 --- a/bundles/org.openhab.binding.broadlinkthermostat/src/main/java/org/openhab/binding/broadlinkthermostat/internal/discovery/BroadlinkDiscoveryService.java +++ b/bundles/org.openhab.binding.broadlinkthermostat/src/main/java/org/openhab/binding/broadlinkthermostat/internal/discovery/BroadlinkDiscoveryService.java @@ -90,7 +90,7 @@ public class BroadlinkDiscoveryService extends AbstractDiscoveryService { Integer.toHexString(dev.getDeviceType()), dev.getHost(), dev.getMac()); ThingUID thingUID; - String id = dev.getHost().replaceAll("\\.", "-"); + String id = dev.getHost().replace(".", "-"); logger.debug("Device ID with IP address replacement: {}", id); try { id = getHostnameWithoutDomain(InetAddress.getByName(dev.getHost()).getHostName()); @@ -187,11 +187,11 @@ public class BroadlinkDiscoveryService extends AbstractDiscoveryService { if (hostname.matches(broadlinkRegex)) { String[] dotSeparatedString = hostname.split("\\."); logger.debug("Found original broadlink DNS name {}, removing domain", hostname); - return dotSeparatedString[0].replaceAll("\\.", "-"); + return dotSeparatedString[0].replace(".", "-"); } else { logger.debug("DNS name does not match original broadlink name: {}, using it without modification. ", hostname); - return hostname.replaceAll("\\.", "-"); + return hostname.replace(".", "-"); } } } diff --git a/bundles/org.openhab.binding.broadlinkthermostat/src/main/java/org/openhab/binding/broadlinkthermostat/internal/handler/FloureonThermostatHandler.java b/bundles/org.openhab.binding.broadlinkthermostat/src/main/java/org/openhab/binding/broadlinkthermostat/internal/handler/FloureonThermostatHandler.java index 26e261ec5..644395b0a 100644 --- a/bundles/org.openhab.binding.broadlinkthermostat/src/main/java/org/openhab/binding/broadlinkthermostat/internal/handler/FloureonThermostatHandler.java +++ b/bundles/org.openhab.binding.broadlinkthermostat/src/main/java/org/openhab/binding/broadlinkthermostat/internal/handler/FloureonThermostatHandler.java @@ -159,9 +159,9 @@ public class FloureonThermostatHandler extends BroadlinkBaseHandler { private void handleSetpointCommand(ChannelUID channelUID, Command command) { FloureonDevice floureonDevice = this.floureonDevice; - if (command instanceof QuantityType && floureonDevice != null) { + if (command instanceof QuantityType quantityCommand && floureonDevice != null) { try { - QuantityType temperatureQuantityType = ((QuantityType) command).toUnit(SIUnits.CELSIUS); + QuantityType temperatureQuantityType = quantityCommand.toUnit(SIUnits.CELSIUS); if (temperatureQuantityType != null) { floureonDevice.setThermostatTemp(temperatureQuantityType.doubleValue()); } else { @@ -211,8 +211,8 @@ public class FloureonThermostatHandler extends BroadlinkBaseHandler { } private void handleSetTimeCommand(ChannelUID channelUID, Command command) { - if (command instanceof DateTimeType) { - ZonedDateTime zonedDateTime = ((DateTimeType) command).getZonedDateTime(); + if (command instanceof DateTimeType dateTimeCommand) { + ZonedDateTime zonedDateTime = dateTimeCommand.getZonedDateTime(); try { new SetTimeCommand(tob(zonedDateTime.getHour()), tob(zonedDateTime.getMinute()), tob(zonedDateTime.getSecond()), tob(zonedDateTime.getDayOfWeek().getValue())) diff --git a/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/handler/BsbLanBaseThingHandler.java b/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/handler/BsbLanBaseThingHandler.java index c54280b80..f4dcbfd0f 100644 --- a/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/handler/BsbLanBaseThingHandler.java +++ b/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/handler/BsbLanBaseThingHandler.java @@ -71,8 +71,8 @@ public abstract class BsbLanBaseThingHandler extends BaseThingHandler { return null; } ThingHandler handler = bridge.getHandler(); - if (handler instanceof BsbLanBridgeHandler) { - this.bridgeHandler = (BsbLanBridgeHandler) handler; + if (handler instanceof BsbLanBridgeHandler lanBridgeHandler) { + this.bridgeHandler = lanBridgeHandler; } } return this.bridgeHandler; diff --git a/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/helper/BsbLanParameterConverter.java b/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/helper/BsbLanParameterConverter.java index fa48aa7c8..c1bd31c32 100644 --- a/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/helper/BsbLanParameterConverter.java +++ b/bundles/org.openhab.binding.bsblan/src/main/java/org/openhab/binding/bsblan/internal/helper/BsbLanParameterConverter.java @@ -106,7 +106,7 @@ public class BsbLanParameterConverter { private static State getStateForSwitchValueChannel(BsbLanApiParameterDTO parameter) { // treat "0" as OFF and everything else as ON - return parameter.value.equals("0") ? OnOffType.OFF : OnOffType.ON; + return "0".equals(parameter.value) ? OnOffType.OFF : OnOffType.ON; } /** @@ -134,9 +134,7 @@ public class BsbLanParameterConverter { } private static @Nullable String getValueForNumberValueChannel(Command command) { - if (command instanceof QuantityType) { - // the target unit is yet unknown, so just use the value as is (without converting based on the unit) - QuantityType quantity = (QuantityType) command; + if (command instanceof QuantityType quantity) { return String.valueOf(quantity.doubleValue()); } // check if numeric diff --git a/bundles/org.openhab.binding.bsblan/src/test/java/org/openhab/binding/bsblan/internal/api/BsbLanApiContentConverterTests.java b/bundles/org.openhab.binding.bsblan/src/test/java/org/openhab/binding/bsblan/internal/api/BsbLanApiContentConverterTests.java index ab0eaeb96..49afff39f 100644 --- a/bundles/org.openhab.binding.bsblan/src/test/java/org/openhab/binding/bsblan/internal/api/BsbLanApiContentConverterTests.java +++ b/bundles/org.openhab.binding.bsblan/src/test/java/org/openhab/binding/bsblan/internal/api/BsbLanApiContentConverterTests.java @@ -35,8 +35,17 @@ public class BsbLanApiContentConverterTests { @Test public void parseBsbLanApiParameterQueryResponse() { - String content = "{\r\n" + "\"700\": {\r\n" + "\"name\": \"Betriebsart\",\r\n" + "\"value\": \"0\",\r\n" - + "\"unit\": \"\",\r\n" + "\"desc\": \"Schutzbetrieb\",\r\n" + "\"dataType\": 1\r\n" + "}\r\n" + "}"; + String content = """ + { + "700": { + "name": "Betriebsart", + "value": "0", + "unit": "", + "desc": "Schutzbetrieb", + "dataType": 1 + } + }\ + """; BsbLanApiParameterQueryResponseDTO r = BsbLanApiContentConverter.fromJson(content, BsbLanApiParameterQueryResponseDTO.class); diff --git a/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/api/SmartherApiConnector.java b/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/api/SmartherApiConnector.java index 479051f7b..6532aee7b 100644 --- a/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/api/SmartherApiConnector.java +++ b/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/api/SmartherApiConnector.java @@ -128,8 +128,8 @@ public class SmartherApiConnector { } catch (ExecutionException e) { final Throwable cause = e.getCause(); - if (cause instanceof SmartherGatewayException) { - throw (SmartherGatewayException) cause; + if (cause instanceof SmartherGatewayException gatewayException) { + throw gatewayException; } else { throw new SmartherGatewayException(e.getMessage(), e); } diff --git a/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/api/dto/Location.java b/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/api/dto/Location.java index b8a9ac89e..fb9c1e2bb 100644 --- a/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/api/dto/Location.java +++ b/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/api/dto/Location.java @@ -173,7 +173,7 @@ public class Location { if (locations == null || locations.isEmpty()) { return null; } - return locations.stream().map(a -> String.valueOf(a.getName())).collect(Collectors.joining(NAME_SEPARATOR)); + return locations.stream().map(a -> a.getName()).collect(Collectors.joining(NAME_SEPARATOR)); } @Override diff --git a/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/api/dto/Modules.java b/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/api/dto/Modules.java index 1d6d57554..20448e04a 100644 --- a/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/api/dto/Modules.java +++ b/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/api/dto/Modules.java @@ -50,6 +50,6 @@ public class Modules { if (modules == null || modules.isEmpty()) { return null; } - return modules.stream().map(a -> String.valueOf(a.getName())).collect(Collectors.joining(NAME_SEPARATOR)); + return modules.stream().map(a -> a.getName()).collect(Collectors.joining(NAME_SEPARATOR)); } } diff --git a/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/discovery/SmartherModuleDiscoveryService.java b/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/discovery/SmartherModuleDiscoveryService.java index 9bde70ba1..87bbc52ab 100644 --- a/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/discovery/SmartherModuleDiscoveryService.java +++ b/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/discovery/SmartherModuleDiscoveryService.java @@ -14,7 +14,6 @@ package org.openhab.binding.bticinosmarther.internal.discovery; import static org.openhab.binding.bticinosmarther.internal.SmartherBindingConstants.*; -import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -47,7 +46,7 @@ public class SmartherModuleDiscoveryService extends AbstractDiscoveryService implements DiscoveryService, ThingHandlerService { // Only modules can be discovered. A bridge must be manually added. - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_MODULE); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_MODULE); private static final int DISCOVERY_TIME_SECONDS = 30; @@ -86,8 +85,7 @@ public class SmartherModuleDiscoveryService extends AbstractDiscoveryService @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof SmartherAccountHandler) { - final SmartherAccountHandler localBridgeHandler = (SmartherAccountHandler) handler; + if (handler instanceof SmartherAccountHandler localBridgeHandler) { this.bridgeHandler = localBridgeHandler; this.bridgeUID = localBridgeHandler.getUID(); } diff --git a/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/factory/SmartherHandlerFactory.java b/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/factory/SmartherHandlerFactory.java index ab88c78fd..cf1971e4d 100644 --- a/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/factory/SmartherHandlerFactory.java +++ b/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/factory/SmartherHandlerFactory.java @@ -90,8 +90,8 @@ public class SmartherHandlerFactory extends BaseThingHandlerFactory { @Override protected synchronized void removeHandler(ThingHandler thingHandler) { - if (thingHandler instanceof SmartherBridgeHandler) { - authService.removeSmartherAccountHandler((SmartherBridgeHandler) thingHandler); + if (thingHandler instanceof SmartherBridgeHandler bridgeHandler) { + authService.removeSmartherAccountHandler(bridgeHandler); } } } diff --git a/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/handler/SmartherBridgeHandler.java b/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/handler/SmartherBridgeHandler.java index 884f90ac1..75952397e 100644 --- a/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/handler/SmartherBridgeHandler.java +++ b/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/handler/SmartherBridgeHandler.java @@ -25,6 +25,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Optional; +import java.util.Set; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -121,7 +122,7 @@ public class SmartherBridgeHandler extends BaseBridgeHandler @Override public Collection> getServices() { - return Collections.singleton(SmartherModuleDiscoveryService.class); + return Set.of(SmartherModuleDiscoveryService.class); } // =========================================================================== diff --git a/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/handler/SmartherModuleHandler.java b/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/handler/SmartherModuleHandler.java index 0ae5cd4c0..13ae557b6 100644 --- a/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/handler/SmartherModuleHandler.java +++ b/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/handler/SmartherModuleHandler.java @@ -222,14 +222,14 @@ public class SmartherModuleHandler extends BaseThingHandler { } break; case CHANNEL_SETTINGS_PROGRAM: - if (command instanceof DecimalType) { - localModuleSettings.setProgram(((DecimalType) command).intValue()); + if (command instanceof DecimalType decimalCommand) { + localModuleSettings.setProgram(decimalCommand.intValue()); return; } break; case CHANNEL_SETTINGS_BOOSTTIME: - if (command instanceof DecimalType) { - localModuleSettings.setBoostTime(BoostTime.fromValue(((DecimalType) command).intValue())); + if (command instanceof DecimalType decimalCommand) { + localModuleSettings.setBoostTime(BoostTime.fromValue(decimalCommand.intValue())); return; } break; @@ -324,8 +324,8 @@ public class SmartherModuleHandler extends BaseThingHandler { * @return {@code true} if the change succeeded, {@code false} otherwise */ private boolean changeTimeHour(Command command, final ModuleSettings settings) { - if (command instanceof DecimalType) { - int endHour = ((DecimalType) command).intValue(); + if (command instanceof DecimalType decimalCommand) { + int endHour = decimalCommand.intValue(); if (endHour >= 0 && endHour <= 23) { settings.setEndHour(endHour); return true; @@ -344,8 +344,8 @@ public class SmartherModuleHandler extends BaseThingHandler { * @return {@code true} if the change succeeded, {@code false} otherwise */ private boolean changeTimeMinute(Command command, final ModuleSettings settings) { - if (command instanceof DecimalType) { - int endMinute = ((DecimalType) command).intValue(); + if (command instanceof DecimalType decimalCommand) { + int endMinute = decimalCommand.intValue(); if (endMinute >= 0 && endMinute <= 59) { // Only 15 min increments are allowed endMinute = Math.round(endMinute / 15) * 15; diff --git a/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/util/StringUtil.java b/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/util/StringUtil.java index 320b674d2..64c1929b0 100644 --- a/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/util/StringUtil.java +++ b/bundles/org.openhab.binding.bticinosmarther/src/main/java/org/openhab/binding/bticinosmarther/internal/util/StringUtil.java @@ -55,7 +55,7 @@ public final class StringUtil { * @return the passed in string, or the empty string if it was {@code null} * */ - public static final String defaultString(@Nullable String str) { + public static String defaultString(@Nullable String str) { return (str == null) ? "" : str; } diff --git a/bundles/org.openhab.binding.buienradar/src/main/java/org/openhab/binding/buienradar/internal/BuienradarHandler.java b/bundles/org.openhab.binding.buienradar/src/main/java/org/openhab/binding/buienradar/internal/BuienradarHandler.java index 02a689e2a..740a994c7 100644 --- a/bundles/org.openhab.binding.buienradar/src/main/java/org/openhab/binding/buienradar/internal/BuienradarHandler.java +++ b/bundles/org.openhab.binding.buienradar/src/main/java/org/openhab/binding/buienradar/internal/BuienradarHandler.java @@ -126,7 +126,7 @@ public class BuienradarHandler extends BaseThingHandler { } try { final Optional> predictionsOpt = client.getPredictions(location); - if (!predictionsOpt.isPresent()) { + if (predictionsOpt.isEmpty()) { // Did not get a result, retry the retrieval. // Buienradar is not a very stable source and returns nothing quite regular if (tries <= 2) { diff --git a/bundles/org.openhab.binding.buienradar/src/main/java/org/openhab/binding/buienradar/internal/BuienradarHandlerFactory.java b/bundles/org.openhab.binding.buienradar/src/main/java/org/openhab/binding/buienradar/internal/BuienradarHandlerFactory.java index 8db4e35df..52522568e 100644 --- a/bundles/org.openhab.binding.buienradar/src/main/java/org/openhab/binding/buienradar/internal/BuienradarHandlerFactory.java +++ b/bundles/org.openhab.binding.buienradar/src/main/java/org/openhab/binding/buienradar/internal/BuienradarHandlerFactory.java @@ -14,7 +14,6 @@ package org.openhab.binding.buienradar.internal; import static org.openhab.binding.buienradar.internal.BuienradarBindingConstants.THING_TYPE_RAIN_FORECAST; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -36,7 +35,7 @@ import org.osgi.service.component.annotations.Component; @Component(configurationPid = "binding.buienradar", service = ThingHandlerFactory.class) public class BuienradarHandlerFactory extends BaseThingHandlerFactory { - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_RAIN_FORECAST); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_RAIN_FORECAST); @Override public boolean supportsThingType(ThingTypeUID thingTypeUID) { diff --git a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/CaddxMessageContext.java b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/CaddxMessageContext.java index a406fc1c8..44eb5f2c4 100644 --- a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/CaddxMessageContext.java +++ b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/CaddxMessageContext.java @@ -23,5 +23,5 @@ import org.eclipse.jdt.annotation.NonNullByDefault; public enum CaddxMessageContext { NONE, DISCOVERY, - COMMAND; + COMMAND } diff --git a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/action/CaddxBridgeActions.java b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/action/CaddxBridgeActions.java index 83715bdf6..8571a178f 100644 --- a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/action/CaddxBridgeActions.java +++ b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/action/CaddxBridgeActions.java @@ -38,8 +38,8 @@ public class CaddxBridgeActions implements ThingActions { @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof CaddxBridgeHandler) { - this.handler = (CaddxBridgeHandler) handler; + if (handler instanceof CaddxBridgeHandler bridgeHandler) { + this.handler = bridgeHandler; } } diff --git a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/action/CaddxKeypadActions.java b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/action/CaddxKeypadActions.java index 071514876..38d3fd8e9 100644 --- a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/action/CaddxKeypadActions.java +++ b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/action/CaddxKeypadActions.java @@ -43,8 +43,8 @@ public class CaddxKeypadActions implements ThingActions { @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof ThingHandlerKeypad) { - this.handler = (ThingHandlerKeypad) handler; + if (handler instanceof ThingHandlerKeypad keypadHandler) { + this.handler = keypadHandler; } } diff --git a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/action/CaddxPanelActions.java b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/action/CaddxPanelActions.java index c377d2f6f..1e447e8f0 100644 --- a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/action/CaddxPanelActions.java +++ b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/action/CaddxPanelActions.java @@ -42,8 +42,8 @@ public class CaddxPanelActions implements ThingActions { @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof ThingHandlerPanel) { - this.handler = (ThingHandlerPanel) handler; + if (handler instanceof ThingHandlerPanel panelHandler) { + this.handler = panelHandler; } } diff --git a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/action/CaddxPartitionActions.java b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/action/CaddxPartitionActions.java index d8d4ba780..fb1c48d96 100644 --- a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/action/CaddxPartitionActions.java +++ b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/action/CaddxPartitionActions.java @@ -40,8 +40,8 @@ public class CaddxPartitionActions implements ThingActions { @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof ThingHandlerPartition) { - this.handler = (ThingHandlerPartition) handler; + if (handler instanceof ThingHandlerPartition partitionHandler) { + this.handler = partitionHandler; } } diff --git a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/action/CaddxZoneActions.java b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/action/CaddxZoneActions.java index cae2d06cb..3dfef2632 100644 --- a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/action/CaddxZoneActions.java +++ b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/action/CaddxZoneActions.java @@ -39,8 +39,8 @@ public class CaddxZoneActions implements ThingActions { @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof ThingHandlerZone) { - this.handler = (ThingHandlerZone) handler; + if (handler instanceof ThingHandlerZone zoneHandler) { + this.handler = zoneHandler; } } diff --git a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/discovery/CaddxDiscoveryService.java b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/discovery/CaddxDiscoveryService.java index 709c4bdf0..cbc83a009 100644 --- a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/discovery/CaddxDiscoveryService.java +++ b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/discovery/CaddxDiscoveryService.java @@ -12,7 +12,6 @@ */ package org.openhab.binding.caddx.internal.discovery; -import java.util.Collections; import java.util.Map; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -85,7 +84,7 @@ public class CaddxDiscoveryService extends AbstractDiscoveryService implements T thingUID = new ThingUID(CaddxBindingConstants.PARTITION_THING_TYPE, bridge.getUID(), thingID); if (partition != null) { - properties = Collections.singletonMap(CaddxPartitionConfiguration.PARTITION_NUMBER, partition); + properties = Map.of(CaddxPartitionConfiguration.PARTITION_NUMBER, partition); representationProperty = CaddxPartitionConfiguration.PARTITION_NUMBER; } @@ -96,7 +95,7 @@ public class CaddxDiscoveryService extends AbstractDiscoveryService implements T thingUID = new ThingUID(CaddxBindingConstants.ZONE_THING_TYPE, bridge.getUID(), thingID); if (zone != null) { - properties = Collections.singletonMap(CaddxZoneConfiguration.ZONE_NUMBER, zone); + properties = Map.of(CaddxZoneConfiguration.ZONE_NUMBER, zone); representationProperty = CaddxZoneConfiguration.ZONE_NUMBER; } break; @@ -106,7 +105,7 @@ public class CaddxDiscoveryService extends AbstractDiscoveryService implements T thingUID = new ThingUID(CaddxBindingConstants.KEYPAD_THING_TYPE, bridge.getUID(), thingID); if (keypad != null) { - properties = Collections.singletonMap(CaddxKeypadConfiguration.KEYPAD_ADDRESS, keypad); + properties = Map.of(CaddxKeypadConfiguration.KEYPAD_ADDRESS, keypad); representationProperty = CaddxKeypadConfiguration.KEYPAD_ADDRESS; } break; @@ -154,8 +153,8 @@ public class CaddxDiscoveryService extends AbstractDiscoveryService implements T @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof CaddxBridgeHandler) { - caddxBridgeHandler = (CaddxBridgeHandler) handler; + if (handler instanceof CaddxBridgeHandler bridgeHandler) { + caddxBridgeHandler = bridgeHandler; } } diff --git a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/CaddxBaseThingHandler.java b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/CaddxBaseThingHandler.java index 380c8cdb4..ec4963c01 100644 --- a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/CaddxBaseThingHandler.java +++ b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/CaddxBaseThingHandler.java @@ -88,8 +88,8 @@ public abstract class CaddxBaseThingHandler extends BaseThingHandler { ThingHandler handler = bridge.getHandler(); - if (handler instanceof CaddxBridgeHandler) { - this.caddxBridgeHandler = (CaddxBridgeHandler) handler; + if (handler instanceof CaddxBridgeHandler bridgeHandler) { + this.caddxBridgeHandler = bridgeHandler; } else { logger.debug("getCaddxBridgeHandler(): Unable to get bridge handler!"); } diff --git a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/CaddxBridgeHandler.java b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/CaddxBridgeHandler.java index e00ef4aca..f6c2c63dd 100644 --- a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/CaddxBridgeHandler.java +++ b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/CaddxBridgeHandler.java @@ -375,7 +375,7 @@ public class CaddxBridgeHandler extends BaseBridgeHandler implements CaddxPanelL switch (caddxMessage.getCaddxMessageType()) { case PARTITIONS_SNAPSHOT_MESSAGE: for (int i = 1; i <= 8; i++) { - if (caddxMessage.getPropertyById("partition_" + i + "_valid").equals("true")) { + if ("true".equals(caddxMessage.getPropertyById("partition_" + i + "_valid"))) { thing = findThing(CaddxThingType.PARTITION, i, null, null); if (thing != null) { continue; diff --git a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/CaddxThingType.java b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/CaddxThingType.java index 96682c205..352889127 100644 --- a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/CaddxThingType.java +++ b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/CaddxThingType.java @@ -24,5 +24,5 @@ public enum CaddxThingType { PANEL, PARTITION, ZONE, - KEYPAD; + KEYPAD } diff --git a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/ThingHandlerKeypad.java b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/ThingHandlerKeypad.java index 3fc33882f..ef8d5b501 100644 --- a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/ThingHandlerKeypad.java +++ b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/ThingHandlerKeypad.java @@ -13,7 +13,7 @@ package org.openhab.binding.caddx.internal.handler; import java.util.Collection; -import java.util.Collections; +import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.caddx.internal.CaddxBindingConstants; @@ -99,7 +99,7 @@ public class ThingHandlerKeypad extends CaddxBaseThingHandler { @Override public Collection> getServices() { - return Collections.singleton(CaddxKeypadActions.class); + return Set.of(CaddxKeypadActions.class); } public void enterTerminalMode() { diff --git a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/ThingHandlerPanel.java b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/ThingHandlerPanel.java index 778ac9c93..d6165848b 100644 --- a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/ThingHandlerPanel.java +++ b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/ThingHandlerPanel.java @@ -13,8 +13,8 @@ package org.openhab.binding.caddx.internal.handler; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; +import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -258,7 +258,7 @@ public class ThingHandlerPanel extends CaddxBaseThingHandler { @Override public Collection> getServices() { - return Collections.singleton(CaddxPanelActions.class); + return Set.of(CaddxPanelActions.class); } private void sendPrimaryCommand(String pin, String function) { diff --git a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/ThingHandlerPartition.java b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/ThingHandlerPartition.java index 285f01469..ea041e097 100644 --- a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/ThingHandlerPartition.java +++ b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/ThingHandlerPartition.java @@ -13,7 +13,7 @@ package org.openhab.binding.caddx.internal.handler; import java.util.Collection; -import java.util.Collections; +import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.caddx.internal.CaddxBindingConstants; @@ -135,7 +135,7 @@ public class ThingHandlerPartition extends CaddxBaseThingHandler { @Override public Collection> getServices() { - return Collections.singleton(CaddxPartitionActions.class); + return Set.of(CaddxPartitionActions.class); } private void sendPrimaryCommand(String pin, String function) { diff --git a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/ThingHandlerZone.java b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/ThingHandlerZone.java index eeee553e1..079ec8145 100644 --- a/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/ThingHandlerZone.java +++ b/bundles/org.openhab.binding.caddx/src/main/java/org/openhab/binding/caddx/internal/handler/ThingHandlerZone.java @@ -13,7 +13,7 @@ package org.openhab.binding.caddx.internal.handler; import java.util.Collection; -import java.util.Collections; +import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.caddx.internal.CaddxBindingConstants; @@ -147,7 +147,7 @@ public class ThingHandlerZone extends CaddxBaseThingHandler { @Override public Collection> getServices() { - return Collections.singleton(CaddxZoneActions.class); + return Set.of(CaddxZoneActions.class); } public void bypass() { diff --git a/bundles/org.openhab.binding.caddx/src/test/java/org/openhab/binding/caddx/internal/message/CaddxMessageParseTest.java b/bundles/org.openhab.binding.caddx/src/test/java/org/openhab/binding/caddx/internal/message/CaddxMessageParseTest.java index 008bf6afb..ab9cd8e37 100644 --- a/bundles/org.openhab.binding.caddx/src/test/java/org/openhab/binding/caddx/internal/message/CaddxMessageParseTest.java +++ b/bundles/org.openhab.binding.caddx/src/test/java/org/openhab/binding/caddx/internal/message/CaddxMessageParseTest.java @@ -32,7 +32,7 @@ import org.openhab.binding.caddx.internal.CaddxMessageReaderUtil; public class CaddxMessageParseTest { // @formatter:off - public static final List data() { + public static List data() { return Arrays.asList(new Object[][] { { "interface_configuration_message", "panel_firmware_version", "5.37", }, { "interface_configuration_message", "panel_interface_configuration_message", "true", }, diff --git a/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusCGateHandler.java b/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusCGateHandler.java index d644a7c24..d983bc9f0 100644 --- a/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusCGateHandler.java +++ b/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusCGateHandler.java @@ -152,8 +152,8 @@ public class CBusCGateHandler extends BaseBridgeHandler { // now also re-initialize all network handlers for (Thing thing : getThing().getThings()) { ThingHandler handler = thing.getHandler(); - if (handler instanceof CBusNetworkHandler) { - ((CBusNetworkHandler) handler).cgateStateChanged(isOnline); + if (handler instanceof CBusNetworkHandler networkHandler) { + networkHandler.cgateStateChanged(isOnline); } } }); @@ -194,8 +194,8 @@ public class CBusCGateHandler extends BaseBridgeHandler { continue; } - if (thingThingHandler instanceof CBusGroupHandler) { - ((CBusGroupHandler) thingThingHandler).updateGroup(application, group, value); + if (thingThingHandler instanceof CBusGroupHandler groupHandler) { + groupHandler.updateGroup(application, group, value); } } } diff --git a/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusDaliHandler.java b/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusDaliHandler.java index 01a48e3ac..08270e709 100644 --- a/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusDaliHandler.java +++ b/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusDaliHandler.java @@ -72,9 +72,8 @@ public class CBusDaliHandler extends CBusGroupHandler { } else if (command == OnOffType.OFF) { group.off(); } - } else if (command instanceof PercentType) { - PercentType value = (PercentType) command; - group.ramp((int) Math.round(value.doubleValue() / 100 * 255), 0); + } else if (command instanceof PercentType percentCommand) { + group.ramp((int) Math.round(percentCommand.doubleValue() / 100 * 255), 0); } else if (command instanceof IncreaseDecreaseType) { int level = group.getLevel(); if (command == IncreaseDecreaseType.DECREASE) { @@ -93,6 +92,7 @@ public class CBusDaliHandler extends CBusGroupHandler { } } + @Override public void updateGroup(int updateApplicationId, int updateGroupId, String value) { if (updateGroupId == groupId && updateApplicationId == applicationId) { Thing thing = getThing(); diff --git a/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusGroupHandler.java b/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusGroupHandler.java index ed4c9bfd6..c64ddf93a 100644 --- a/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusGroupHandler.java +++ b/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusGroupHandler.java @@ -151,8 +151,8 @@ public abstract class CBusGroupHandler extends BaseThingHandler { return null; } ThingHandler handler = bridge.getHandler(); - if (handler instanceof CBusNetworkHandler) { - return (CBusNetworkHandler) handler; + if (handler instanceof CBusNetworkHandler networkHandler) { + return networkHandler; } logger.debug("No available bridge handler found for bridge: {}", bridge.getUID()); return null; diff --git a/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusLightHandler.java b/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusLightHandler.java index bbed50cbe..745812169 100644 --- a/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusLightHandler.java +++ b/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusLightHandler.java @@ -88,9 +88,8 @@ public class CBusLightHandler extends CBusGroupHandler { } else if (command == OnOffType.OFF) { group.off(); } - } else if (command instanceof PercentType) { - PercentType value = (PercentType) command; - group.ramp((int) Math.round(value.doubleValue() / 100 * 255), 0); + } else if (command instanceof PercentType percentCommand) { + group.ramp((int) Math.round(percentCommand.doubleValue() / 100 * 255), 0); } else if (command instanceof IncreaseDecreaseType) { int level = group.getLevel(); if (command == IncreaseDecreaseType.DECREASE) { @@ -109,6 +108,7 @@ public class CBusLightHandler extends CBusGroupHandler { } } + @Override public void updateGroup(int updateApplicationId, int updateGroupId, String value) { if (updateGroupId == groupId && updateApplicationId == applicationId) { Thing thing = getThing(); diff --git a/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusNetworkHandler.java b/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusNetworkHandler.java index 8ebeae849..8100c857a 100644 --- a/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusNetworkHandler.java +++ b/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusNetworkHandler.java @@ -235,8 +235,8 @@ public class CBusNetworkHandler extends BaseBridgeHandler { } for (Thing thing : getThing().getThings()) { ThingHandler handler = thing.getHandler(); - if (handler instanceof CBusGroupHandler) { - ((CBusGroupHandler) handler).updateStatus(); + if (handler instanceof CBusGroupHandler groupHandler) { + groupHandler.updateStatus(); } } } @@ -262,8 +262,8 @@ public class CBusNetworkHandler extends BaseBridgeHandler { return null; } ThingHandler handler = bridge.getHandler(); - if (handler instanceof CBusCGateHandler) { - return (CBusCGateHandler) handler; + if (handler instanceof CBusCGateHandler gateHandler) { + return gateHandler; } else { logger.debug("No available bridge handler found for bridge: {}.", bridge.getUID()); return null; diff --git a/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusTemperatureHandler.java b/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusTemperatureHandler.java index 9c5af8ec1..21e97f01f 100644 --- a/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusTemperatureHandler.java +++ b/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusTemperatureHandler.java @@ -66,6 +66,7 @@ public class CBusTemperatureHandler extends CBusGroupHandler { } } + @Override public void updateGroup(int updateApplicationId, int updateGroupId, String value) { if (updateGroupId == groupId && updateApplicationId == applicationId) { Thing thing = getThing(); diff --git a/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusTriggerHandler.java b/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusTriggerHandler.java index 05188d4e0..31060fefc 100644 --- a/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusTriggerHandler.java +++ b/bundles/org.openhab.binding.cbus/src/main/java/org/openhab/binding/cbus/handler/CBusTriggerHandler.java @@ -58,8 +58,8 @@ public class CBusTriggerHandler extends CBusGroupHandler { if (channelUID.getId().equals(CBusBindingConstants.CHANNEL_VALUE)) { logger.debug("Channel Value command for {}: {}", channelUID, command); try { - if (command instanceof DecimalType) { - group.TriggerEvent(((DecimalType) command).intValue()); + if (command instanceof DecimalType decimalCommand) { + group.TriggerEvent(decimalCommand.intValue()); } } catch (CGateException e) { logger.debug("Failed to send trigger command {} to {}", command, group, e); @@ -69,6 +69,7 @@ public class CBusTriggerHandler extends CBusGroupHandler { } } + @Override public void updateGroup(int updateApplicationId, int updateGroupId, String value) { if (updateGroupId == groupId && updateApplicationId == applicationId) { Thing thing = getThing(); diff --git a/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/ChromecastAudioSink.java b/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/ChromecastAudioSink.java index 80a6ab3c3..04decc606 100644 --- a/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/ChromecastAudioSink.java +++ b/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/ChromecastAudioSink.java @@ -78,9 +78,8 @@ public class ChromecastAudioSink extends AudioSinkAsync { handler.stop(); } else { final String url; - if (audioStream instanceof URLAudioStream) { - // it is an external URL, the speaker can access it itself and play it. - URLAudioStream urlAudioStream = (URLAudioStream) audioStream; + if (audioStream instanceof URLAudioStream urlAudioStream) { + // it is an external URL, the speaker can access it itself and play it url = urlAudioStream.getURL(); tryClose(audioStream); } else { diff --git a/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/ChromecastCommander.java b/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/ChromecastCommander.java index 649726109..411e8e953 100644 --- a/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/ChromecastCommander.java +++ b/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/ChromecastCommander.java @@ -158,18 +158,16 @@ public class ChromecastCommander { return; } - if (command instanceof PlayPauseType) { + if (command instanceof PlayPauseType playPauseCommand) { MediaStatus mediaStatus = chromeCast.getMediaStatus(); logger.debug("mediaStatus {}", mediaStatus); if (mediaStatus == null || mediaStatus.playerState == MediaStatus.PlayerState.IDLE) { logger.debug("{} command ignored because media is not loaded", command); return; } - - final PlayPauseType playPause = (PlayPauseType) command; - if (playPause == PlayPauseType.PLAY) { + if (playPauseCommand == PlayPauseType.PLAY) { chromeCast.play(); - } else if (playPause == PlayPauseType.PAUSE + } else if (playPauseCommand == PlayPauseType.PAUSE && ((mediaStatus.supportedMediaCommands & 0x00000001) == 0x1)) { chromeCast.pause(); } else { @@ -199,8 +197,8 @@ public class ChromecastCommander { } public void handleVolume(final Command command) { - if (command instanceof PercentType) { - setVolumeInternal((PercentType) command); + if (command instanceof PercentType percentCommand) { + setVolumeInternal(percentCommand); } else if (command == IncreaseDecreaseType.INCREASE) { setVolumeInternal(new PercentType( Math.min(statusUpdater.getVolume().intValue() + VOLUMESTEP, PercentType.HUNDRED.intValue()))); diff --git a/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/ChromecastStatusUpdater.java b/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/ChromecastStatusUpdater.java index ea8a7cf0a..e03bd86c3 100644 --- a/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/ChromecastStatusUpdater.java +++ b/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/ChromecastStatusUpdater.java @@ -318,8 +318,8 @@ public class ChromecastStatusUpdater { state = new DecimalType(((Integer) value).longValue()); } else if (value instanceof String) { state = new StringType(value.toString()); - } else if (value instanceof ZonedDateTime) { - state = new DateTimeType((ZonedDateTime) value); + } else if (value instanceof ZonedDateTime datetime) { + state = new DateTimeType(datetime); } else { state = UnDefType.UNDEF; logger.warn("Update channel {}: Unsupported value type {}", channelUID, value.getClass().getSimpleName()); diff --git a/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/action/ChromecastActions.java b/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/action/ChromecastActions.java index d06d4e1e7..0354e579d 100644 --- a/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/action/ChromecastActions.java +++ b/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/action/ChromecastActions.java @@ -82,8 +82,8 @@ public class ChromecastActions implements ThingActions { @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof ChromecastHandler) { - this.handler = (ChromecastHandler) handler; + if (handler instanceof ChromecastHandler chromecastHandler) { + this.handler = chromecastHandler; } } diff --git a/bundles/org.openhab.binding.cm11a/src/main/java/org/openhab/binding/cm11a/internal/Cm11aHandlerFactory.java b/bundles/org.openhab.binding.cm11a/src/main/java/org/openhab/binding/cm11a/internal/Cm11aHandlerFactory.java index 3860827e9..d3ea931dd 100644 --- a/bundles/org.openhab.binding.cm11a/src/main/java/org/openhab/binding/cm11a/internal/Cm11aHandlerFactory.java +++ b/bundles/org.openhab.binding.cm11a/src/main/java/org/openhab/binding/cm11a/internal/Cm11aHandlerFactory.java @@ -14,9 +14,6 @@ package org.openhab.binding.cm11a.internal; import static org.openhab.binding.cm11a.internal.CM11ABindingConstants.*; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; import java.util.Set; import org.openhab.binding.cm11a.internal.handler.Cm11aApplianceHandler; @@ -43,8 +40,7 @@ public class Cm11aHandlerFactory extends BaseThingHandlerFactory { private final Logger logger = LoggerFactory.getLogger(Cm11aHandlerFactory.class); - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections - .unmodifiableSet(new HashSet<>(Arrays.asList(THING_TYPE_SWITCH, THING_TYPE_DIMMER))); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_SWITCH, THING_TYPE_DIMMER); @Override public boolean supportsThingType(ThingTypeUID thingTypeUID) { diff --git a/bundles/org.openhab.binding.cm11a/src/main/java/org/openhab/binding/cm11a/internal/X10ReceivedData.java b/bundles/org.openhab.binding.cm11a/src/main/java/org/openhab/binding/cm11a/internal/X10ReceivedData.java index 40fcf4fc7..226385ca5 100644 --- a/bundles/org.openhab.binding.cm11a/src/main/java/org/openhab/binding/cm11a/internal/X10ReceivedData.java +++ b/bundles/org.openhab.binding.cm11a/src/main/java/org/openhab/binding/cm11a/internal/X10ReceivedData.java @@ -79,13 +79,13 @@ public class X10ReceivedData { /** * Lookup table to convert House code received from the cm11a into an X10 house code */ - public static final char HOUSE_CODE[] = new char[] { 'M', 'E', 'C', 'K', 'O', 'G', 'A', 'I', 'N', 'F', 'D', 'L', + public static final char[] HOUSE_CODE = new char[] { 'M', 'E', 'C', 'K', 'O', 'G', 'A', 'I', 'N', 'F', 'D', 'L', 'P', 'H', 'B', 'J' }; /** * Lookup table to convert Unit code received from the cm11a into an X10 unit code */ - public static final byte UNIT_CODE[] = new byte[] { 13, 5, 3, 11, 15, 7, 1, 9, 14, 6, 4, 12, 16, 8, 2, 10 }; + public static final byte[] UNIT_CODE = new byte[] { 13, 5, 3, 11, 15, 7, 1, 9, 14, 6, 4, 12, 16, 8, 2, 10 }; private String[] addr; private X10COMMAND cmd; diff --git a/bundles/org.openhab.binding.cm11a/src/main/java/org/openhab/binding/cm11a/internal/handler/Cm11aLampHandler.java b/bundles/org.openhab.binding.cm11a/src/main/java/org/openhab/binding/cm11a/internal/handler/Cm11aLampHandler.java index 7bcb4ba3b..d6a997f5a 100644 --- a/bundles/org.openhab.binding.cm11a/src/main/java/org/openhab/binding/cm11a/internal/handler/Cm11aLampHandler.java +++ b/bundles/org.openhab.binding.cm11a/src/main/java/org/openhab/binding/cm11a/internal/handler/Cm11aLampHandler.java @@ -71,8 +71,8 @@ public class Cm11aLampHandler extends Cm11aAbstractHandler { desiredState = OnOffType.ON; } else if (OnOffType.OFF.equals(command)) { desiredState = OnOffType.OFF; - } else if (command instanceof PercentType) { - desiredState = (PercentType) command; + } else if (command instanceof PercentType percentCommand) { + desiredState = percentCommand; } else if (command instanceof RefreshType) { // Refresh is triggered by framework during startup. // Force the lamp off by indicating it is currently on and we want it off @@ -105,10 +105,10 @@ public class Cm11aLampHandler extends Cm11aAbstractHandler { x10Status = x10Interface.sendFunction(houseUnitCode, X10Interface.FUNC_ON); } else if (desiredState.equals(OnOffType.OFF)) { x10Status = x10Interface.sendFunction(houseUnitCode, X10Interface.FUNC_OFF); - } else if (desiredState instanceof PercentType) { + } else if (desiredState instanceof PercentType desiredStatePercent) { // desiredState must be a PercentType if we got here. // Calc how many bright increments we need to send (0 to 22) - int desiredPercentFullBright = ((PercentType) desiredState).intValue(); + int desiredPercentFullBright = desiredStatePercent.intValue(); int dims = (desiredPercentFullBright * X10_DIM_INCREMENTS) / 100; if (currentState.equals(OnOffType.ON)) { // The current level isn't known because it would have gone to @@ -120,11 +120,11 @@ public class Cm11aLampHandler extends Cm11aAbstractHandler { // desiredState must be a PercentType if we got here. And, the light should be off // We should just be able to send the appropriate number if dims x10Status = x10Interface.sendFunction(houseUnitCode, X10Interface.FUNC_BRIGHT, dims); - } else if (currentState instanceof PercentType) { + } else if (currentState instanceof PercentType currentStatePercent) { // This is the expected case // Now currentState and desiredState are both PercentType's // Need to calc how much to dim or brighten - int currentPercentFullBright = ((PercentType) currentState).intValue(); + int currentPercentFullBright = currentStatePercent.intValue(); int percentToBrighten = desiredPercentFullBright - currentPercentFullBright; int brightens = (percentToBrighten * X10_DIM_INCREMENTS) / 100; if (brightens > 0) { diff --git a/bundles/org.openhab.binding.coolmasternet/src/main/java/org/openhab/binding/coolmasternet/internal/handler/HVACHandler.java b/bundles/org.openhab.binding.coolmasternet/src/main/java/org/openhab/binding/coolmasternet/internal/handler/HVACHandler.java index 7bbb845bd..9b52212ac 100644 --- a/bundles/org.openhab.binding.coolmasternet/src/main/java/org/openhab/binding/coolmasternet/internal/handler/HVACHandler.java +++ b/bundles/org.openhab.binding.coolmasternet/src/main/java/org/openhab/binding/coolmasternet/internal/handler/HVACHandler.java @@ -148,9 +148,9 @@ public class HVACHandler extends BaseThingHandler { if (on != null) { updateState(ON, "1".equals(on) ? OnOffType.ON : OnOffType.OFF); } - } else if (command instanceof OnOffType) { - final OnOffType onoff = (OnOffType) command; - controller.sendCommand(String.format("%s %s", onoff == OnOffType.ON ? "on" : "off", uid)); + } else if (command instanceof OnOffType onOffCommand) { + controller + .sendCommand(String.format("%s %s", onOffCommand == OnOffType.ON ? "on" : "off", uid)); } break; case SET_TEMP: @@ -161,9 +161,8 @@ public class HVACHandler extends BaseThingHandler { final QuantityType value = new QuantityType<>(temp, controller.getUnit()); updateState(SET_TEMP, value); } - } else if (command instanceof QuantityType) { - final QuantityType temp = (QuantityType) command; - final QuantityType converted = temp.toUnit(controller.getUnit()); + } else if (command instanceof QuantityType quantityCommand) { + final QuantityType converted = quantityCommand.toUnit(controller.getUnit()); final String formatted = converted.format("%.1f"); controller.sendCommand(String.format("temp %s %s", uid, formatted)); } @@ -174,8 +173,8 @@ public class HVACHandler extends BaseThingHandler { if (mode != null) { updateState(MODE, new StringType(mode)); } - } else if (command instanceof StringType) { - final String mode = ((StringType) command).toString(); + } else if (command instanceof StringType stringCommand) { + final String mode = stringCommand.toString(); controller.sendCommand(String.format("%s %s", mode, uid)); } break; @@ -185,8 +184,8 @@ public class HVACHandler extends BaseThingHandler { if (fan != null) { updateState(FAN_SPEED, new StringType(fan)); } - } else if (command instanceof StringType) { - final String fan = ((StringType) command).toString(); + } else if (command instanceof StringType stringCommand) { + final String fan = stringCommand.toString(); controller.sendCommand(String.format("fspeed %s %s", uid, fan)); } break; @@ -196,8 +195,8 @@ public class HVACHandler extends BaseThingHandler { if (louvre != null) { updateState(LOUVRE, new StringType(louvre)); } - } else if (command instanceof StringType) { - final String louvre = ((StringType) command).toString(); + } else if (command instanceof StringType stringCommand) { + final String louvre = stringCommand.toString(); controller.sendCommand(String.format("swing %s %s", uid, louvre)); } break; diff --git a/bundles/org.openhab.binding.coronastats/src/main/java/org/openhab/binding/coronastats/internal/handler/CoronaStatsCountryHandler.java b/bundles/org.openhab.binding.coronastats/src/main/java/org/openhab/binding/coronastats/internal/handler/CoronaStatsCountryHandler.java index 0a062aa62..10496a49e 100644 --- a/bundles/org.openhab.binding.coronastats/src/main/java/org/openhab/binding/coronastats/internal/handler/CoronaStatsCountryHandler.java +++ b/bundles/org.openhab.binding.coronastats/src/main/java/org/openhab/binding/coronastats/internal/handler/CoronaStatsCountryHandler.java @@ -87,8 +87,8 @@ public class CoronaStatsCountryHandler extends BaseThingHandler { Bridge bridge = getBridge(); if (bridge != null) { ThingHandler handler = bridge.getHandler(); - if (handler instanceof CoronaStatsWorldHandler) { - return (CoronaStatsWorldHandler) handler; + if (handler instanceof CoronaStatsWorldHandler worldHandler) { + return worldHandler; } } diff --git a/bundles/org.openhab.binding.coronastats/src/main/java/org/openhab/binding/coronastats/internal/handler/CoronaStatsWorldHandler.java b/bundles/org.openhab.binding.coronastats/src/main/java/org/openhab/binding/coronastats/internal/handler/CoronaStatsWorldHandler.java index 41f509f00..8beb81320 100644 --- a/bundles/org.openhab.binding.coronastats/src/main/java/org/openhab/binding/coronastats/internal/handler/CoronaStatsWorldHandler.java +++ b/bundles/org.openhab.binding.coronastats/src/main/java/org/openhab/binding/coronastats/internal/handler/CoronaStatsWorldHandler.java @@ -172,9 +172,8 @@ public class CoronaStatsWorldHandler extends BaseBridgeHandler { @Override public void childHandlerInitialized(ThingHandler childHandler, Thing childThing) { - if (childHandler instanceof CoronaStatsCountryHandler) { + if (childHandler instanceof CoronaStatsCountryHandler listener) { logger.debug("Register thing listener."); - final CoronaStatsCountryHandler listener = (CoronaStatsCountryHandler) childHandler; if (countryListeners.add(listener)) { final CoronaStats localCoronaStats = coronaStats; if (localCoronaStats != null) { @@ -189,9 +188,9 @@ public class CoronaStatsWorldHandler extends BaseBridgeHandler { @Override public void childHandlerDisposed(ThingHandler childHandler, Thing childThing) { - if (childHandler instanceof CoronaStatsCountryHandler) { + if (childHandler instanceof CoronaStatsCountryHandler countryHandler) { logger.debug("Unregister thing listener."); - if (!countryListeners.remove((CoronaStatsCountryHandler) childHandler)) { + if (!countryListeners.remove(countryHandler)) { logger.warn("Tried to remove listener {} but it was not registered. This is probably an error.", childHandler); } diff --git a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/airbase/AirbaseZoneInfo.java b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/airbase/AirbaseZoneInfo.java index 473a85a69..7f043596f 100644 --- a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/airbase/AirbaseZoneInfo.java +++ b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/api/airbase/AirbaseZoneInfo.java @@ -35,7 +35,7 @@ public class AirbaseZoneInfo { private static final Logger LOGGER = LoggerFactory.getLogger(AirbaseZoneInfo.class); public String zonenames = ""; - public boolean zone[] = new boolean[8]; + public boolean[] zone = new boolean[8]; private AirbaseZoneInfo() { } diff --git a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/discovery/DaikinACUnitDiscoveryService.java b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/discovery/DaikinACUnitDiscoveryService.java index d1b26f0a5..1554cf3b8 100644 --- a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/discovery/DaikinACUnitDiscoveryService.java +++ b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/discovery/DaikinACUnitDiscoveryService.java @@ -18,10 +18,10 @@ import java.net.InetAddress; import java.net.UnknownHostException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; import java.util.UUID; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -65,7 +65,7 @@ public class DaikinACUnitDiscoveryService extends AbstractDiscoveryService { private @Nullable ScheduledFuture backgroundFuture; public DaikinACUnitDiscoveryService() { - super(Collections.singleton(DaikinBindingConstants.THING_TYPE_AC_UNIT), 600, true); + super(Set.of(DaikinBindingConstants.THING_TYPE_AC_UNIT), 600, true); } @Override diff --git a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/handler/DaikinAcUnitHandler.java b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/handler/DaikinAcUnitHandler.java index 4f3f66437..ed23fbfdd 100644 --- a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/handler/DaikinAcUnitHandler.java +++ b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/handler/DaikinAcUnitHandler.java @@ -159,20 +159,20 @@ public class DaikinAcUnitHandler extends DaikinBaseHandler { throws DaikinCommunicationException { switch (channelUID.getId()) { case DaikinBindingConstants.CHANNEL_AC_FAN_DIR: - if (command instanceof StringType) { - changeFanDir(((StringType) command).toString()); + if (command instanceof StringType stringCommand) { + changeFanDir(stringCommand.toString()); return true; } break; case DaikinBindingConstants.CHANNEL_AC_SPECIALMODE: - if (command instanceof StringType) { - changeSpecialMode(((StringType) command).toString()); + if (command instanceof StringType stringCommand) { + changeSpecialMode(stringCommand.toString()); return true; } break; case DaikinBindingConstants.CHANNEL_AC_STREAMER: - if (command instanceof OnOffType) { - changeStreamer(((OnOffType) command).equals(OnOffType.ON)); + if (command instanceof OnOffType onOffCommand) { + changeStreamer(onOffCommand.equals(OnOffType.ON)); return true; } break; diff --git a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/handler/DaikinBaseHandler.java b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/handler/DaikinBaseHandler.java index 456794b80..7ebc6050f 100644 --- a/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/handler/DaikinBaseHandler.java +++ b/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/handler/DaikinBaseHandler.java @@ -102,8 +102,8 @@ public abstract class DaikinBaseHandler extends BaseThingHandler { } switch (channelUID.getId()) { case DaikinBindingConstants.CHANNEL_AC_POWER: - if (command instanceof OnOffType) { - changePower(((OnOffType) command).equals(OnOffType.ON)); + if (command instanceof OnOffType onOffCommand) { + changePower(onOffCommand.equals(OnOffType.ON)); return; } break; @@ -114,8 +114,8 @@ public abstract class DaikinBaseHandler extends BaseThingHandler { break; case DaikinBindingConstants.CHANNEL_AIRBASE_AC_FAN_SPEED: case DaikinBindingConstants.CHANNEL_AC_FAN_SPEED: - if (command instanceof StringType) { - changeFanSpeed(((StringType) command).toString()); + if (command instanceof StringType stringCommand) { + changeFanSpeed(stringCommand.toString()); return; } break; @@ -126,8 +126,8 @@ public abstract class DaikinBaseHandler extends BaseThingHandler { } break; case DaikinBindingConstants.CHANNEL_AC_MODE: - if (command instanceof StringType) { - changeMode(((StringType) command).toString()); + if (command instanceof StringType stringCommand) { + changeMode(stringCommand.toString()); return; } break; @@ -214,8 +214,8 @@ public abstract class DaikinBaseHandler extends BaseThingHandler { */ private boolean changeSetPoint(Command command) throws DaikinCommunicationException { double newTemperature; - if (command instanceof DecimalType) { - newTemperature = ((DecimalType) command).doubleValue(); + if (command instanceof DecimalType decimalCommand) { + newTemperature = decimalCommand.doubleValue(); } else if (command instanceof QuantityType) { newTemperature = ((QuantityType) command).toUnit(SIUnits.CELSIUS).doubleValue(); } else { diff --git a/bundles/org.openhab.binding.dali/src/main/java/org/openhab/binding/dali/internal/handler/DaliDeviceHandler.java b/bundles/org.openhab.binding.dali/src/main/java/org/openhab/binding/dali/internal/handler/DaliDeviceHandler.java index 5c4b02693..45b3bd701 100644 --- a/bundles/org.openhab.binding.dali/src/main/java/org/openhab/binding/dali/internal/handler/DaliDeviceHandler.java +++ b/bundles/org.openhab.binding.dali/src/main/java/org/openhab/binding/dali/internal/handler/DaliDeviceHandler.java @@ -93,25 +93,25 @@ public class DaliDeviceHandler extends BaseThingHandler { boolean queryDeviceState = false; - if (command instanceof PercentType) { - byte dimmValue = (byte) ((((PercentType) command).floatValue() * DALI_SWITCH_100_PERCENT) / 100); + if (command instanceof PercentType percentCommand) { + byte dimmValue = (byte) ((percentCommand.floatValue() * DALI_SWITCH_100_PERCENT) / 100); // A dimm value of zero is handled correctly by DALI devices, i.e. they are turned off getBridgeHandler().sendCommand(new DaliDAPCCommand(address, dimmValue)); - } else if (command instanceof OnOffType) { - if ((OnOffType) command == OnOffType.ON) { + } else if (command instanceof OnOffType onOffCommand) { + if (onOffCommand == OnOffType.ON) { getBridgeHandler().sendCommand(new DaliDAPCCommand(address, (byte) DALI_SWITCH_100_PERCENT)); } else { getBridgeHandler().sendCommand(DaliStandardCommand.createOffCommand(address)); } - } else if (command instanceof IncreaseDecreaseType) { + } else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) { if (CHANNEL_DIM_AT_FADE_RATE.equals(channelUID.getId())) { - if ((IncreaseDecreaseType) command == IncreaseDecreaseType.INCREASE) { + if (increaseDecreaseCommand == IncreaseDecreaseType.INCREASE) { getBridgeHandler().sendCommand(DaliStandardCommand.createUpCommand(address)); } else { getBridgeHandler().sendCommand(DaliStandardCommand.createDownCommand(address)); } } else { - if ((IncreaseDecreaseType) command == IncreaseDecreaseType.INCREASE) { + if (increaseDecreaseCommand == IncreaseDecreaseType.INCREASE) { getBridgeHandler().sendCommand(DaliStandardCommand.createStepUpCommand(address)); } else { getBridgeHandler().sendCommand(DaliStandardCommand.createStepDownCommand(address)); diff --git a/bundles/org.openhab.binding.dali/src/main/java/org/openhab/binding/dali/internal/handler/DaliDt8DeviceHandler.java b/bundles/org.openhab.binding.dali/src/main/java/org/openhab/binding/dali/internal/handler/DaliDt8DeviceHandler.java index 00c2fe9d0..7b6df1616 100644 --- a/bundles/org.openhab.binding.dali/src/main/java/org/openhab/binding/dali/internal/handler/DaliDt8DeviceHandler.java +++ b/bundles/org.openhab.binding.dali/src/main/java/org/openhab/binding/dali/internal/handler/DaliDt8DeviceHandler.java @@ -65,13 +65,13 @@ public class DaliDt8DeviceHandler extends DaliDeviceHandler { throw new DaliException("unknown device type"); } int mirek; - if (command instanceof DecimalType) { + if (command instanceof DecimalType decimalCommand) { // Color temperature in DALI is represented in mirek ("reciprocal megakelvin") // It is one million times the reciprocal of the color temperature (in Kelvin) - mirek = (int) (1E6f / (Math.min(Math.max(((DecimalType) command).intValue(), 1000), 20000))); - } else if (command instanceof QuantityType) { + mirek = (int) (1E6f / (Math.min(Math.max(decimalCommand.intValue(), 1000), 20000))); + } else if (command instanceof QuantityType quantityCommand) { // ensure it's in the correct units - QuantityType commandQuantity = ((QuantityType) command).toInvertibleUnit(Units.MIRED); + QuantityType commandQuantity = quantityCommand.toInvertibleUnit(Units.MIRED); if (commandQuantity == null) { logger.warn("Unable to convert command {} to mireks", command); return; @@ -134,8 +134,8 @@ public class DaliDt8DeviceHandler extends DaliDeviceHandler { } else { throw new DaliException("unknown device type"); } - if (command instanceof HSBType) { - PercentType[] rgb = ((HSBType) command).toRGB(); + if (command instanceof HSBType hsbCommand) { + PercentType[] rgb = hsbCommand.toRGB(); final int r = (int) (254 * (rgb[0].floatValue() / 100)); final int g = (int) (254 * (rgb[1].floatValue() / 100)); final int b = (int) (254 * (rgb[2].floatValue() / 100)); diff --git a/bundles/org.openhab.binding.dali/src/main/java/org/openhab/binding/dali/internal/handler/DaliRgbHandler.java b/bundles/org.openhab.binding.dali/src/main/java/org/openhab/binding/dali/internal/handler/DaliRgbHandler.java index 83dccadfc..c39631046 100644 --- a/bundles/org.openhab.binding.dali/src/main/java/org/openhab/binding/dali/internal/handler/DaliRgbHandler.java +++ b/bundles/org.openhab.binding.dali/src/main/java/org/openhab/binding/dali/internal/handler/DaliRgbHandler.java @@ -76,16 +76,16 @@ public class DaliRgbHandler extends BaseThingHandler { if (CHANNEL_COLOR.equals(channelUID.getId())) { boolean queryDeviceState = false; - if (command instanceof HSBType) { - PercentType[] rgb = ((HSBType) command).toRGB(); + if (command instanceof HSBType hsbCommand) { + PercentType[] rgb = hsbCommand.toRGB(); for (int i = 0; i < 3; i++) { byte dimmValue = (byte) ((rgb[i].floatValue() * DALI_SWITCH_100_PERCENT) / 100); getBridgeHandler().sendCommand( new DaliDAPCCommand(DaliAddress.createShortAddress(outputs.get(i)), dimmValue)); } - } else if (command instanceof OnOffType) { - if ((OnOffType) command == OnOffType.ON) { + } else if (command instanceof OnOffType onOffCommand) { + if (onOffCommand == OnOffType.ON) { for (Integer output : outputs) { getBridgeHandler().sendCommand(new DaliDAPCCommand(DaliAddress.createShortAddress(output), (byte) DALI_SWITCH_100_PERCENT)); @@ -96,8 +96,8 @@ public class DaliRgbHandler extends BaseThingHandler { DaliStandardCommand.createOffCommand(DaliAddress.createShortAddress(output))); } } - } else if (command instanceof IncreaseDecreaseType) { - if ((IncreaseDecreaseType) command == IncreaseDecreaseType.INCREASE) { + } else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) { + if (increaseDecreaseCommand == IncreaseDecreaseType.INCREASE) { for (Integer output : outputs) { getBridgeHandler().sendCommand( DaliStandardCommand.createUpCommand(DaliAddress.createShortAddress(output))); diff --git a/bundles/org.openhab.binding.dali/src/main/java/org/openhab/binding/dali/internal/handler/DaliserverBridgeHandler.java b/bundles/org.openhab.binding.dali/src/main/java/org/openhab/binding/dali/internal/handler/DaliserverBridgeHandler.java index 78370c149..6985628d8 100644 --- a/bundles/org.openhab.binding.dali/src/main/java/org/openhab/binding/dali/internal/handler/DaliserverBridgeHandler.java +++ b/bundles/org.openhab.binding.dali/src/main/java/org/openhab/binding/dali/internal/handler/DaliserverBridgeHandler.java @@ -20,7 +20,6 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.net.Socket; import java.net.SocketTimeoutException; -import java.util.Collections; import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; @@ -50,7 +49,7 @@ import org.slf4j.LoggerFactory; */ @NonNullByDefault public class DaliserverBridgeHandler extends BaseBridgeHandler { - public static final Set SUPPORTED_THING_TYPES = Collections.singleton(BRIDGE_TYPE); + public static final Set SUPPORTED_THING_TYPES = Set.of(BRIDGE_TYPE); private final Logger logger = LoggerFactory.getLogger(DaliserverBridgeHandler.class); private static final int DALI_DEFAULT_TIMEOUT = 5000; diff --git a/bundles/org.openhab.binding.danfossairunit/src/main/java/org/openhab/binding/danfossairunit/internal/DanfossAirUnit.java b/bundles/org.openhab.binding.danfossairunit/src/main/java/org/openhab/binding/danfossairunit/internal/DanfossAirUnit.java index 576130bd5..91d5a97b2 100644 --- a/bundles/org.openhab.binding.danfossairunit/src/main/java/org/openhab/binding/danfossairunit/internal/DanfossAirUnit.java +++ b/bundles/org.openhab.binding.danfossairunit/src/main/java/org/openhab/binding/danfossairunit/internal/DanfossAirUnit.java @@ -236,16 +236,16 @@ public class DanfossAirUnit { } private DecimalType setNumberTypeRegister(Command cmd, byte[] register) throws IOException { - if (cmd instanceof DecimalType) { - byte value = (byte) ((DecimalType) cmd).intValue(); + if (cmd instanceof DecimalType decimalCommand) { + byte value = (byte) decimalCommand.intValue(); set(REGISTER_1_WRITE, register, value); } return new DecimalType(BigDecimal.valueOf(getByte(REGISTER_1_READ, register))); } private PercentType setPercentTypeRegister(Command cmd, byte[] register) throws IOException { - if (cmd instanceof PercentType) { - byte value = (byte) ((((PercentType) cmd).intValue() + 5) / 10); + if (cmd instanceof PercentType percentCommand) { + byte value = (byte) ((percentCommand.intValue() + 5) / 10); set(REGISTER_1_WRITE, register, value); } return new PercentType(BigDecimal.valueOf(getByte(REGISTER_1_READ, register) * 10)); diff --git a/bundles/org.openhab.binding.danfossairunit/src/main/java/org/openhab/binding/danfossairunit/internal/DanfossAirUnitCommunicationController.java b/bundles/org.openhab.binding.danfossairunit/src/main/java/org/openhab/binding/danfossairunit/internal/DanfossAirUnitCommunicationController.java index e7c51a175..7b397141f 100644 --- a/bundles/org.openhab.binding.danfossairunit/src/main/java/org/openhab/binding/danfossairunit/internal/DanfossAirUnitCommunicationController.java +++ b/bundles/org.openhab.binding.danfossairunit/src/main/java/org/openhab/binding/danfossairunit/internal/DanfossAirUnitCommunicationController.java @@ -52,6 +52,7 @@ public class DanfossAirUnitCommunicationController implements CommunicationContr this.port = port; } + @Override public synchronized void connect() throws IOException { if (connected) { return; @@ -64,6 +65,7 @@ public class DanfossAirUnitCommunicationController implements CommunicationContr connected = true; } + @Override public synchronized void disconnect() { if (!connected) { return; @@ -83,10 +85,12 @@ public class DanfossAirUnitCommunicationController implements CommunicationContr connected = false; } + @Override public byte[] sendRobustRequest(byte[] operation, byte[] register) throws IOException { return sendRobustRequest(operation, register, EMPTY); } + @Override public synchronized byte[] sendRobustRequest(byte[] operation, byte[] register, byte[] value) throws IOException { connect(); byte[] request = new byte[4 + value.length]; diff --git a/bundles/org.openhab.binding.danfossairunit/src/main/java/org/openhab/binding/danfossairunit/internal/DanfossAirUnitHandlerFactory.java b/bundles/org.openhab.binding.danfossairunit/src/main/java/org/openhab/binding/danfossairunit/internal/DanfossAirUnitHandlerFactory.java index 0196cf15a..155cb28d5 100644 --- a/bundles/org.openhab.binding.danfossairunit/src/main/java/org/openhab/binding/danfossairunit/internal/DanfossAirUnitHandlerFactory.java +++ b/bundles/org.openhab.binding.danfossairunit/src/main/java/org/openhab/binding/danfossairunit/internal/DanfossAirUnitHandlerFactory.java @@ -14,7 +14,6 @@ package org.openhab.binding.danfossairunit.internal; import static org.openhab.binding.danfossairunit.internal.DanfossAirUnitBindingConstants.THING_TYPE_AIRUNIT; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -38,7 +37,7 @@ import org.osgi.service.component.annotations.Component; @Component(configurationPid = "binding.danfossairunit", service = ThingHandlerFactory.class) public class DanfossAirUnitHandlerFactory extends BaseThingHandlerFactory { - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_AIRUNIT); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_AIRUNIT); @Override public boolean supportsThingType(ThingTypeUID thingTypeUID) { diff --git a/bundles/org.openhab.binding.dbquery/src/main/java/org/openhab/binding/dbquery/action/DBQueryActions.java b/bundles/org.openhab.binding.dbquery/src/main/java/org/openhab/binding/dbquery/action/DBQueryActions.java index 3a390a298..618eaf959 100644 --- a/bundles/org.openhab.binding.dbquery/src/main/java/org/openhab/binding/dbquery/action/DBQueryActions.java +++ b/bundles/org.openhab.binding.dbquery/src/main/java/org/openhab/binding/dbquery/action/DBQueryActions.java @@ -78,9 +78,9 @@ public class DBQueryActions implements IDBQueryActions, ThingActions { @RuleAction(label = "Set query parameters", description = "Set query parameters for a query") public void setQueryParameters(@ActionInput(name = "parameters") Map parameters) { logger.debug("setQueryParameters {}", parameters); - var queryHandler = getThingHandler(); - if (queryHandler instanceof QueryHandler) { - ((QueryHandler) queryHandler).setParameters(parameters); + var thingHandler = getThingHandler(); + if (thingHandler instanceof QueryHandler queryHandler) { + queryHandler.setParameters(parameters); } else { logger.warn("setQueryParameters called on wrong Thing, it must be a Query Thing"); } @@ -100,10 +100,10 @@ public class DBQueryActions implements IDBQueryActions, ThingActions { @Override public void setThingHandler(ThingHandler thingHandler) { - if (thingHandler instanceof QueryHandler) { - this.queryHandler = ((QueryHandler) thingHandler); - } else if (thingHandler instanceof DatabaseBridgeHandler) { - this.databaseBridgeHandler = ((DatabaseBridgeHandler) thingHandler); + if (thingHandler instanceof QueryHandler queryHandler) { + this.queryHandler = queryHandler; + } else if (thingHandler instanceof DatabaseBridgeHandler databaseBridgeHandler) { + this.databaseBridgeHandler = databaseBridgeHandler; } else { throw new UnnexpectedCondition("Not expected thing handler " + thingHandler); } diff --git a/bundles/org.openhab.binding.dbquery/src/main/java/org/openhab/binding/dbquery/internal/QueryHandler.java b/bundles/org.openhab.binding.dbquery/src/main/java/org/openhab/binding/dbquery/internal/QueryHandler.java index fa2a89604..6e6762f7e 100644 --- a/bundles/org.openhab.binding.dbquery/src/main/java/org/openhab/binding/dbquery/internal/QueryHandler.java +++ b/bundles/org.openhab.binding.dbquery/src/main/java/org/openhab/binding/dbquery/internal/QueryHandler.java @@ -193,13 +193,11 @@ public class QueryHandler extends BaseThingHandler { private void updateStateWithParentBridgeStatus() { final @Nullable Bridge bridge = getBridge(); - DatabaseBridgeHandler databaseBridgeHandler; if (bridge != null) { @Nullable BridgeHandler bridgeHandler = bridge.getHandler(); - if (bridgeHandler instanceof DatabaseBridgeHandler) { - databaseBridgeHandler = (DatabaseBridgeHandler) bridgeHandler; + if (bridgeHandler instanceof DatabaseBridgeHandler databaseBridgeHandler) { database = databaseBridgeHandler.getDatabase(); if (bridge.getStatus() == ThingStatus.ONLINE) { updateStatus(ThingStatus.ONLINE); diff --git a/bundles/org.openhab.binding.dbquery/src/main/java/org/openhab/binding/dbquery/internal/Value2StateConverter.java b/bundles/org.openhab.binding.dbquery/src/main/java/org/openhab/binding/dbquery/internal/Value2StateConverter.java index dcfc5f318..ae01166b0 100644 --- a/bundles/org.openhab.binding.dbquery/src/main/java/org/openhab/binding/dbquery/internal/Value2StateConverter.java +++ b/bundles/org.openhab.binding.dbquery/src/main/java/org/openhab/binding/dbquery/internal/Value2StateConverter.java @@ -75,12 +75,12 @@ public class Value2StateConverter { } private State convert2DateTime(Object value) { - if (value instanceof Instant) { - return new DateTimeType(ZonedDateTime.ofInstant((Instant) value, ZoneId.systemDefault())); - } else if (value instanceof Date) { - return new DateTimeType(ZonedDateTime.ofInstant(((Date) value).toInstant(), ZoneId.systemDefault())); - } else if (value instanceof String) { - return new DateTimeType((String) value); + if (value instanceof Instant instant) { + return new DateTimeType(ZonedDateTime.ofInstant(instant, ZoneId.systemDefault())); + } else if (value instanceof Date date) { + return new DateTimeType(ZonedDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault())); + } else if (value instanceof String string) { + return new DateTimeType(string); } else { logger.warn("Can't convert {} to DateTimeType", value); return UnDefType.NULL; @@ -96,16 +96,16 @@ public class Value2StateConverter { return new DecimalType((Float) value); } else if (value instanceof Double) { return new DecimalType((Double) value); - } else if (value instanceof BigDecimal) { - return new DecimalType((BigDecimal) value); - } else if (value instanceof BigInteger) { - return new DecimalType(new BigDecimal((BigInteger) value)); - } else if (value instanceof Number) { - return new DecimalType(((Number) value).longValue()); - } else if (value instanceof String) { - return DecimalType.valueOf((String) value); - } else if (value instanceof Duration) { - return new DecimalType(((Duration) value).toMillis()); + } else if (value instanceof BigDecimal decimal) { + return new DecimalType(decimal); + } else if (value instanceof BigInteger integer) { + return new DecimalType(new BigDecimal(integer)); + } else if (value instanceof Number number) { + return new DecimalType(number.longValue()); + } else if (value instanceof String string) { + return DecimalType.valueOf(string); + } else if (value instanceof Duration duration) { + return new DecimalType(duration.toMillis()); } else { logger.warn("Can't convert {} to DecimalType", value); return UnDefType.NULL; @@ -113,25 +113,24 @@ public class Value2StateConverter { } private State convert2String(Object value) { - if (value instanceof String) { - return new StringType((String) value); - } else if (value instanceof byte[]) { - return new StringType(Base64.getEncoder().encodeToString((byte[]) value)); - } else if (value instanceof QueryResult) { - return new StringType(jsonEncoder.encode((QueryResult) value)); + if (value instanceof String string) { + return new StringType(string); + } else if (value instanceof byte[] bytes) { + return new StringType(Base64.getEncoder().encodeToString(bytes)); + } else if (value instanceof QueryResult result) { + return new StringType(jsonEncoder.encode(result)); } else { return new StringType(String.valueOf(value)); } } private @Nullable Boolean convert2Boolean(Object value) { - if (value instanceof Boolean) { - return (Boolean) value; - } else if (value instanceof Number) { - return ((Number) value).doubleValue() != 0d; - } else if (value instanceof String) { - var svalue = (String) value; - return Boolean.parseBoolean(svalue) || (svalue.equalsIgnoreCase("on")) || svalue.equals("1"); + if (value instanceof Boolean boolean1) { + return boolean1; + } else if (value instanceof Number number) { + return number.doubleValue() != 0d; + } else if (value instanceof String svalue) { + return Boolean.parseBoolean(svalue) || ("on".equalsIgnoreCase(svalue)) || "1".equals(svalue); } else { logger.warn("Can't convert {} to OnOffType or OpenClosedType", value); return null; diff --git a/bundles/org.openhab.binding.dbquery/src/main/java/org/openhab/binding/dbquery/internal/dbimpl/influx2/Influx2Database.java b/bundles/org.openhab.binding.dbquery/src/main/java/org/openhab/binding/dbquery/internal/dbimpl/influx2/Influx2Database.java index f84927515..b9cfa6157 100644 --- a/bundles/org.openhab.binding.dbquery/src/main/java/org/openhab/binding/dbquery/internal/dbimpl/influx2/Influx2Database.java +++ b/bundles/org.openhab.binding.dbquery/src/main/java/org/openhab/binding/dbquery/internal/dbimpl/influx2/Influx2Database.java @@ -81,8 +81,7 @@ public class Influx2Database implements Database { @Override public CompletableFuture executeQuery(Query query) { try { - if (query instanceof Influx2QueryFactory.Influx2Query) { - Influx2QueryFactory.Influx2Query influxQuery = (Influx2QueryFactory.Influx2Query) query; + if (query instanceof Influx2QueryFactory.Influx2Query influxQuery) { CompletableFuture asyncResult = new CompletableFuture<>(); List records = new ArrayList<>(); diff --git a/bundles/org.openhab.binding.dbquery/src/main/java/org/openhab/binding/dbquery/internal/domain/DBQueryJSONEncoder.java b/bundles/org.openhab.binding.dbquery/src/main/java/org/openhab/binding/dbquery/internal/domain/DBQueryJSONEncoder.java index 135b0e767..59fa462fa 100644 --- a/bundles/org.openhab.binding.dbquery/src/main/java/org/openhab/binding/dbquery/internal/domain/DBQueryJSONEncoder.java +++ b/bundles/org.openhab.binding.dbquery/src/main/java/org/openhab/binding/dbquery/internal/domain/DBQueryJSONEncoder.java @@ -90,16 +90,16 @@ public class DBQueryJSONEncoder { } private static JsonElement convertValueToJsonPrimitive(@Nullable Object value) { - if (value instanceof Number) { - return new JsonPrimitive((Number) value); - } else if (value instanceof Boolean) { - return new JsonPrimitive((Boolean) value); + if (value instanceof Number number) { + return new JsonPrimitive(number); + } else if (value instanceof Boolean boolean1) { + return new JsonPrimitive(boolean1); } else if (value instanceof Character) { return new JsonPrimitive((Character) value); - } else if (value instanceof Date) { - return new JsonPrimitive(DateTimeFormatter.ISO_INSTANT.format(((Date) value).toInstant())); - } else if (value instanceof Instant) { - return new JsonPrimitive(DateTimeFormatter.ISO_INSTANT.format((Instant) value)); + } else if (value instanceof Date date) { + return new JsonPrimitive(DateTimeFormatter.ISO_INSTANT.format(date.toInstant())); + } else if (value instanceof Instant instant) { + return new JsonPrimitive(DateTimeFormatter.ISO_INSTANT.format(instant)); } else if (value != null) { return new JsonPrimitive(value.toString()); } else { diff --git a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/action/BridgeActions.java b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/action/BridgeActions.java index ec8a1fd3a..358adc0df 100644 --- a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/action/BridgeActions.java +++ b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/action/BridgeActions.java @@ -75,8 +75,8 @@ public class BridgeActions implements ThingActions { @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof DeconzBridgeHandler) { - this.handler = (DeconzBridgeHandler) handler; + if (handler instanceof DeconzBridgeHandler bridgeHandler) { + this.handler = bridgeHandler; } } diff --git a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/action/GroupActions.java b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/action/GroupActions.java index 79f005781..7e767d840 100644 --- a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/action/GroupActions.java +++ b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/action/GroupActions.java @@ -144,8 +144,8 @@ public class GroupActions implements ThingActions { @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof GroupThingHandler) { - this.handler = (GroupThingHandler) handler; + if (handler instanceof GroupThingHandler thingHandler) { + this.handler = thingHandler; } } diff --git a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/discovery/BridgeDiscoveryParticipant.java b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/discovery/BridgeDiscoveryParticipant.java index 74894aafa..caeb2e400 100644 --- a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/discovery/BridgeDiscoveryParticipant.java +++ b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/discovery/BridgeDiscoveryParticipant.java @@ -16,7 +16,6 @@ import static org.openhab.binding.deconz.internal.BindingConstants.*; import java.net.URI; import java.net.URL; -import java.util.Collections; import java.util.Map; import java.util.Set; import java.util.TreeMap; @@ -48,7 +47,7 @@ public class BridgeDiscoveryParticipant implements UpnpDiscoveryParticipant { @Override public Set getSupportedThingTypeUIDs() { - return Collections.singleton(BRIDGE_TYPE); + return Set.of(BRIDGE_TYPE); } @Override diff --git a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/discovery/ThingDiscoveryService.java b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/discovery/ThingDiscoveryService.java index 0c391c44f..653b80641 100644 --- a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/discovery/ThingDiscoveryService.java +++ b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/discovery/ThingDiscoveryService.java @@ -291,8 +291,8 @@ public class ThingDiscoveryService extends AbstractDiscoveryService implements D @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof DeconzBridgeHandler) { - this.handler = (DeconzBridgeHandler) handler; + if (handler instanceof DeconzBridgeHandler bridgeHandler) { + this.handler = bridgeHandler; this.bridgeUID = handler.getThing().getUID(); } } diff --git a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/GroupThingHandler.java b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/GroupThingHandler.java index 04a8144d5..1e0985c5b 100644 --- a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/GroupThingHandler.java +++ b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/GroupThingHandler.java @@ -119,10 +119,10 @@ public class GroupThingHandler extends DeconzBaseThingHandler { newGroupAction.xy = new double[] { xy[0], xy[1] }; newGroupAction.bri = (int) (xy[2] * BRIGHTNESS_MAX); } - } else if (command instanceof PercentType) { - newGroupAction.bri = Util.fromPercentType((PercentType) command); - } else if (command instanceof DecimalType) { - newGroupAction.bri = ((DecimalType) command).intValue(); + } else if (command instanceof PercentType percentCommand) { + newGroupAction.bri = Util.fromPercentType(percentCommand); + } else if (command instanceof DecimalType decimalCommand) { + newGroupAction.bri = decimalCommand.intValue(); } else { return; } diff --git a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/SensorThermostatThingHandler.java b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/SensorThermostatThingHandler.java index e0f4b455f..7249119a4 100644 --- a/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/SensorThermostatThingHandler.java +++ b/bundles/org.openhab.binding.deconz/src/main/java/org/openhab/binding/deconz/internal/handler/SensorThermostatThingHandler.java @@ -17,7 +17,6 @@ import static org.openhab.core.library.unit.SIUnits.CELSIUS; import static org.openhab.core.library.unit.Units.PERCENT; import java.math.BigDecimal; -import java.util.Collections; import java.util.List; import java.util.Set; @@ -63,7 +62,7 @@ import com.google.gson.Gson; */ @NonNullByDefault public class SensorThermostatThingHandler extends SensorBaseThingHandler { - public static final Set SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_THERMOSTAT); + public static final Set SUPPORTED_THING_TYPES = Set.of(THING_TYPE_THERMOSTAT); private static final List CONFIG_CHANNELS = List.of(CHANNEL_EXTERNAL_WINDOW_OPEN, CHANNEL_BATTERY_LEVEL, CHANNEL_BATTERY_LOW, CHANNEL_HEATSETPOINT, CHANNEL_TEMPERATURE_OFFSET, CHANNEL_THERMOSTAT_MODE, @@ -102,8 +101,8 @@ public class SensorThermostatThingHandler extends SensorBaseThingHandler { newConfig.offset = newOffset; } case CHANNEL_THERMOSTAT_MODE -> { - if (command instanceof StringType) { - String thermostatMode = ((StringType) command).toString(); + if (command instanceof StringType stringCommand) { + String thermostatMode = stringCommand.toString(); try { newConfig.mode = ThermostatMode.valueOf(thermostatMode); } catch (IllegalArgumentException ex) { @@ -205,8 +204,8 @@ public class SensorThermostatThingHandler extends SensorBaseThingHandler { private @Nullable Integer getTemperatureFromCommand(Command command) { BigDecimal newTemperature; - if (command instanceof DecimalType) { - newTemperature = ((DecimalType) command).toBigDecimal(); + if (command instanceof DecimalType decimalCommand) { + newTemperature = decimalCommand.toBigDecimal(); } else if (command instanceof QuantityType) { @SuppressWarnings("unchecked") QuantityType temperatureCelsius = ((QuantityType) command).toUnit(CELSIUS); diff --git a/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/DenonMarantzHandlerFactory.java b/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/DenonMarantzHandlerFactory.java index 14f41ca82..3c952d85e 100644 --- a/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/DenonMarantzHandlerFactory.java +++ b/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/DenonMarantzHandlerFactory.java @@ -14,7 +14,6 @@ package org.openhab.binding.denonmarantz.internal; import static org.openhab.binding.denonmarantz.internal.DenonMarantzBindingConstants.THING_TYPE_AVR; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -41,7 +40,7 @@ import org.osgi.service.component.annotations.Reference; @NonNullByDefault public class DenonMarantzHandlerFactory extends BaseThingHandlerFactory { - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_AVR); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_AVR); private final HttpClient httpClient; diff --git a/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/connector/DenonMarantzConnector.java b/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/connector/DenonMarantzConnector.java index effb5018c..cc9b91617 100644 --- a/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/connector/DenonMarantzConnector.java +++ b/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/connector/DenonMarantzConnector.java @@ -165,10 +165,10 @@ public abstract class DenonMarantzConnector { cmd += "UP"; } else if (command == IncreaseDecreaseType.DECREASE) { cmd += "DOWN"; - } else if (command instanceof DecimalType) { - cmd += toDenonValue(((DecimalType) command)); - } else if (command instanceof PercentType) { - cmd += percentToDenonValue(((PercentType) command).toBigDecimal()); + } else if (command instanceof DecimalType decimalCommand) { + cmd += toDenonValue(decimalCommand); + } else if (command instanceof PercentType percentCommand) { + cmd += percentToDenonValue(percentCommand.toBigDecimal()); } else { throw new UnsupportedCommandTypeException(); } diff --git a/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/connector/telnet/DenonMarantzTelnetConnector.java b/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/connector/telnet/DenonMarantzTelnetConnector.java index 2e9c73a83..f92c5746a 100644 --- a/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/connector/telnet/DenonMarantzTelnetConnector.java +++ b/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/connector/telnet/DenonMarantzTelnetConnector.java @@ -274,7 +274,7 @@ public class DenonMarantzTelnetConnector extends DenonMarantzConnector implement * Display info could contain some garbled text, attempt to clean it up. */ private String cleanupDisplayInfo(String titleValue) { - byte firstByteRemoved[] = Arrays.copyOfRange(titleValue.getBytes(), 1, titleValue.getBytes().length); + byte[] firstByteRemoved = Arrays.copyOfRange(titleValue.getBytes(), 1, titleValue.getBytes().length); return new String(firstByteRemoved).replaceAll("[\u0000-\u001f]", ""); } } diff --git a/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/discovery/DenonMarantzDiscoveryParticipant.java b/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/discovery/DenonMarantzDiscoveryParticipant.java index 86756be82..fedf9f906 100644 --- a/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/discovery/DenonMarantzDiscoveryParticipant.java +++ b/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/discovery/DenonMarantzDiscoveryParticipant.java @@ -14,7 +14,6 @@ package org.openhab.binding.denonmarantz.internal.discovery; import static org.openhab.binding.denonmarantz.internal.DenonMarantzBindingConstants.*; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -66,7 +65,7 @@ public class DenonMarantzDiscoveryParticipant implements MDNSDiscoveryParticipan @Override public Set getSupportedThingTypeUIDs() { - return Collections.singleton(THING_TYPE_AVR); + return Set.of(THING_TYPE_AVR); } @Override @@ -115,9 +114,8 @@ public class DenonMarantzDiscoveryParticipant implements MDNSDiscoveryParticipan properties.put(Thing.PROPERTY_MODEL_ID, model); String label = friendlyName + " (" + vendor + ' ' + model + ")"; - DiscoveryResult result = DiscoveryResultBuilder.create(thingUID).withProperties(properties).withLabel(label) + return DiscoveryResultBuilder.create(thingUID).withProperties(properties).withLabel(label) .withRepresentationProperty(Thing.PROPERTY_SERIAL_NUMBER).build(); - return result; } else { return null; diff --git a/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/xml/adapters/OnOffAdapter.java b/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/xml/adapters/OnOffAdapter.java index a0a694d5d..6fff78d81 100644 --- a/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/xml/adapters/OnOffAdapter.java +++ b/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/xml/adapters/OnOffAdapter.java @@ -24,7 +24,7 @@ public class OnOffAdapter extends XmlAdapter { @Override public Boolean unmarshal(String v) throws Exception { if (v != null) { - return Boolean.valueOf(v.toLowerCase().equals("on")); + return Boolean.valueOf("on".equals(v.toLowerCase())); } return Boolean.FALSE; diff --git a/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/xml/adapters/VolumeAdapter.java b/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/xml/adapters/VolumeAdapter.java index a46aca2a1..9ca8db11d 100644 --- a/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/xml/adapters/VolumeAdapter.java +++ b/bundles/org.openhab.binding.denonmarantz/src/main/java/org/openhab/binding/denonmarantz/internal/xml/adapters/VolumeAdapter.java @@ -27,7 +27,7 @@ public class VolumeAdapter extends XmlAdapter { @Override public BigDecimal unmarshal(String v) throws Exception { - if (v != null && !v.trim().equals("--")) { + if (v != null && !"--".equals(v.trim())) { return new BigDecimal(v.trim()).add(DB_OFFSET); } diff --git a/bundles/org.openhab.binding.deutschebahn/src/main/java/org/openhab/binding/deutschebahn/internal/EventAttribute.java b/bundles/org.openhab.binding.deutschebahn/src/main/java/org/openhab/binding/deutschebahn/internal/EventAttribute.java index 894d3aae0..9171d49ed 100644 --- a/bundles/org.openhab.binding.deutschebahn/src/main/java/org/openhab/binding/deutschebahn/internal/EventAttribute.java +++ b/bundles/org.openhab.binding.deutschebahn/src/main/java/org/openhab/binding/deutschebahn/internal/EventAttribute.java @@ -17,7 +17,6 @@ import java.text.SimpleDateFormat; import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.Arrays; -import java.util.Collections; import java.util.Date; import java.util.List; import java.util.function.BiConsumer; @@ -236,9 +235,9 @@ public final class EventAttribute private static List listFromEventStatus(final @Nullable EventStatus value) { if (value == null) { - return Collections.emptyList(); + return List.of(); } else { - return Collections.singletonList(value.value()); + return List.of(value.value()); } } @@ -247,14 +246,14 @@ public final class EventAttribute } private static List nullToEmptyList(@Nullable final List value) { - return value == null ? Collections.emptyList() : value; + return value == null ? List.of() : value; } /** * Returns a list containing only the given value or empty list if value is null. */ private static List singletonList(@Nullable String value) { - return value == null ? Collections.emptyList() : Collections.singletonList(value); + return value == null ? List.of() : List.of(value); } private static OnOffType parseHidden(@Nullable Integer value) { @@ -262,9 +261,7 @@ public final class EventAttribute } private static Function getDate(final Function getValue) { - return (final Event event) -> { - return parseDate(getValue.apply(event)); - }; + return (final Event event) -> parseDate(getValue.apply(event)); } private static BiConsumer setDate(final BiConsumer setter) { @@ -331,7 +328,7 @@ public final class EventAttribute */ private static List mapMessagesToList(final @Nullable List messages) { if (messages == null || messages.isEmpty()) { - return Collections.emptyList(); + return List.of(); } else { return messages // .stream()// @@ -360,18 +357,18 @@ public final class EventAttribute private static List mapIntegerToStringList(@Nullable Integer value) { if (value == null) { - return Collections.emptyList(); + return List.of(); } else { - return Collections.singletonList(String.valueOf(value)); + return List.of(String.valueOf(value)); } } private static List mapDateToStringList(@Nullable Date value) { if (value == null) { - return Collections.emptyList(); + return List.of(); } else { synchronized (DATETIME_FORMAT) { - return Collections.singletonList(DATETIME_FORMAT.format(value)); + return List.of(DATETIME_FORMAT.format(value)); } } } diff --git a/bundles/org.openhab.binding.deutschebahn/src/main/java/org/openhab/binding/deutschebahn/internal/TripLabelAttribute.java b/bundles/org.openhab.binding.deutschebahn/src/main/java/org/openhab/binding/deutschebahn/internal/TripLabelAttribute.java index 059c73777..a444995f4 100644 --- a/bundles/org.openhab.binding.deutschebahn/src/main/java/org/openhab/binding/deutschebahn/internal/TripLabelAttribute.java +++ b/bundles/org.openhab.binding.deutschebahn/src/main/java/org/openhab/binding/deutschebahn/internal/TripLabelAttribute.java @@ -121,7 +121,7 @@ public final class TripLabelAttribute exte if (value == null) { return Collections.emptyList(); } else { - return Collections.singletonList(value.value()); + return List.of(value.value()); } } @@ -129,7 +129,7 @@ public final class TripLabelAttribute exte * Returns a list containing only the given value or empty list if value is null. */ private static List singletonList(@Nullable String value) { - return value == null ? Collections.emptyList() : Collections.singletonList(value); + return value == null ? Collections.emptyList() : List.of(value); } /** diff --git a/bundles/org.openhab.binding.digiplex/src/main/java/org/openhab/binding/digiplex/internal/communication/events/TroubleStatus.java b/bundles/org.openhab.binding.digiplex/src/main/java/org/openhab/binding/digiplex/internal/communication/events/TroubleStatus.java index 1b3675dbe..b010be4f7 100644 --- a/bundles/org.openhab.binding.digiplex/src/main/java/org/openhab/binding/digiplex/internal/communication/events/TroubleStatus.java +++ b/bundles/org.openhab.binding.digiplex/src/main/java/org/openhab/binding/digiplex/internal/communication/events/TroubleStatus.java @@ -23,5 +23,5 @@ import org.eclipse.jdt.annotation.NonNullByDefault; @NonNullByDefault public enum TroubleStatus { TROUBLE_STARTED, - TROUBLE_RESTORED; + TROUBLE_RESTORED } diff --git a/bundles/org.openhab.binding.digiplex/src/main/java/org/openhab/binding/digiplex/internal/discovery/DigiplexDiscoveryService.java b/bundles/org.openhab.binding.digiplex/src/main/java/org/openhab/binding/digiplex/internal/discovery/DigiplexDiscoveryService.java index f28e6d3e5..7bb0c2a9e 100644 --- a/bundles/org.openhab.binding.digiplex/src/main/java/org/openhab/binding/digiplex/internal/discovery/DigiplexDiscoveryService.java +++ b/bundles/org.openhab.binding.digiplex/src/main/java/org/openhab/binding/digiplex/internal/discovery/DigiplexDiscoveryService.java @@ -14,9 +14,9 @@ package org.openhab.binding.digiplex.internal.discovery; import static org.openhab.binding.digiplex.internal.DigiplexBindingConstants.*; -import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -53,7 +53,7 @@ public class DigiplexDiscoveryService extends AbstractDiscoveryService private @Nullable DigiplexBridgeHandler bridgeHandler; public DigiplexDiscoveryService() { - super(Collections.singleton(THING_TYPE_ZONE), DISCOVERY_TIMEOUT, false); + super(Set.of(THING_TYPE_ZONE), DISCOVERY_TIMEOUT, false); } @Override @@ -100,9 +100,8 @@ public class DigiplexDiscoveryService extends AbstractDiscoveryService } private boolean isDefaultName(ZoneLabelResponse response) { - return ZONE_DEFAULT_NAMES.stream().anyMatch(format -> { - return String.format(format, response.zoneNo).equals(response.zoneName); - }); + return ZONE_DEFAULT_NAMES.stream() + .anyMatch(format -> String.format(format, response.zoneNo).equals(response.zoneName)); } @Override @@ -127,8 +126,8 @@ public class DigiplexDiscoveryService extends AbstractDiscoveryService @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof DigiplexBridgeHandler) { - bridgeHandler = (DigiplexBridgeHandler) handler; + if (handler instanceof DigiplexBridgeHandler digiplexBridgeHandler) { + bridgeHandler = digiplexBridgeHandler; bridgeHandler.registerMessageHandler(this); } } diff --git a/bundles/org.openhab.binding.digiplex/src/main/java/org/openhab/binding/digiplex/internal/handler/DigiplexAreaHandler.java b/bundles/org.openhab.binding.digiplex/src/main/java/org/openhab/binding/digiplex/internal/handler/DigiplexAreaHandler.java index 7fecd1091..4012f79fa 100644 --- a/bundles/org.openhab.binding.digiplex/src/main/java/org/openhab/binding/digiplex/internal/handler/DigiplexAreaHandler.java +++ b/bundles/org.openhab.binding.digiplex/src/main/java/org/openhab/binding/digiplex/internal/handler/DigiplexAreaHandler.java @@ -121,8 +121,8 @@ public class DigiplexAreaHandler extends BaseThingHandler { case AREA_CONTROL: if (command == RefreshType.REFRESH) { updateState(AREA_CONTROL, lastCommandResult); - } else if (command instanceof StringType) { - processControlCommand(((StringType) command).toString()); + } else if (command instanceof StringType stringCommand) { + processControlCommand(stringCommand.toString()); } break; } diff --git a/bundles/org.openhab.binding.digiplex/src/main/java/org/openhab/binding/digiplex/internal/handler/DigiplexBridgeHandler.java b/bundles/org.openhab.binding.digiplex/src/main/java/org/openhab/binding/digiplex/internal/handler/DigiplexBridgeHandler.java index 546ab0d62..76adaa170 100644 --- a/bundles/org.openhab.binding.digiplex/src/main/java/org/openhab/binding/digiplex/internal/handler/DigiplexBridgeHandler.java +++ b/bundles/org.openhab.binding.digiplex/src/main/java/org/openhab/binding/digiplex/internal/handler/DigiplexBridgeHandler.java @@ -18,7 +18,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Collection; -import java.util.Collections; +import java.util.List; import java.util.Optional; import java.util.Set; import java.util.TooManyListenersException; @@ -272,7 +272,7 @@ public class DigiplexBridgeHandler extends BaseBridgeHandler implements SerialPo @Override public Collection> getServices() { - return Collections.singletonList(DigiplexDiscoveryService.class); + return List.of(DigiplexDiscoveryService.class); } private class BridgeMessageHandler implements DigiplexMessageHandler { @@ -367,7 +367,7 @@ public class DigiplexBridgeHandler extends BaseBridgeHandler implements SerialPo stream.write(request.getSerialMessage().getBytes()); stream.flush(); updateState(BRIDGE_MESSAGES_SENT, new DecimalType(messagesSent.incrementAndGet())); - logger.debug("message sent: '{}'", request.getSerialMessage().replaceAll("\r", "")); + logger.debug("message sent: '{}'", request.getSerialMessage().replace("\r", "")); Thread.sleep(SLEEP_TIME); // do not flood PRT3 with messages as it creates unpredictable responses } catch (IOException e) { handleCommunicationError(); diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/DigitalSTROMHandlerFactory.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/DigitalSTROMHandlerFactory.java index a86f0497b..685952bf6 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/DigitalSTROMHandlerFactory.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/DigitalSTROMHandlerFactory.java @@ -71,10 +71,13 @@ public class DigitalSTROMHandlerFactory extends BaseThingHandlerFactory { if (dSSUID != null) { return super.createThing(thingTypeUID, configuration, dSSUID, null); } else { - logger.error("Can't generate thing UID for thing type {}" - + ", because digitalSTROM-Server is not reachable. Please check these points:\n" - + "Are the server address and portnumber correct?\n" + "Is the server turned on?\n" - + "Is the network configured correctly?", thingTypeUID); + logger.error(""" + Can't generate thing UID for thing type {}\ + , because digitalSTROM-Server is not reachable. Please check these points: + Are the server address and portnumber correct? + Is the server turned on? + Is the network configured correctly?\ + """, thingTypeUID); return null; } } diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/BridgeMDNSDiscoveryParticipant.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/BridgeMDNSDiscoveryParticipant.java index 52625faa1..425772bcd 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/BridgeMDNSDiscoveryParticipant.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/BridgeMDNSDiscoveryParticipant.java @@ -12,7 +12,6 @@ */ package org.openhab.binding.digitalstrom.internal.discovery; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -48,7 +47,7 @@ public class BridgeMDNSDiscoveryParticipant implements MDNSDiscoveryParticipant @Override public Set getSupportedThingTypeUIDs() { - return Collections.singleton(DigitalSTROMBindingConstants.THING_TYPE_DSS_BRIDGE); + return Set.of(DigitalSTROMBindingConstants.THING_TYPE_DSS_BRIDGE); } @Override diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/DeviceDiscoveryService.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/DeviceDiscoveryService.java index 762da5f00..b34efc2ae 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/DeviceDiscoveryService.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/DeviceDiscoveryService.java @@ -108,8 +108,7 @@ public class DeviceDiscoveryService extends AbstractDiscoveryService { private void onDeviceAddedInternal(GeneralDeviceInformation device) { boolean isSupported = false; - if (device instanceof Device) { - Device tempDevice = (Device) device; + if (device instanceof Device tempDevice) { if ((tempDevice.isSensorDevice() && deviceType.equals(tempDevice.getHWinfo().replaceAll("-", ""))) || (deviceType.equals(tempDevice.getHWinfo().substring(0, 2)) && (tempDevice.isDeviceWithOutput() || tempDevice.isBinaryInputDevice()) @@ -135,18 +134,17 @@ public class DeviceDiscoveryService extends AbstractDiscoveryService { thingDiscovered(discoveryResult); } else { - if (device instanceof Device) { - logger.debug("Discovered unsupported device hardware type '{}' with uid {}", - ((Device) device).getHWinfo(), device.getDSUID()); + if (device instanceof Device device1) { + logger.debug("Discovered unsupported device hardware type '{}' with uid {}", device1.getHWinfo(), + device.getDSUID()); } } } else { - if (device instanceof Device) { - logger.debug( - "Discovered device with disabled or no output mode. Device was not added to inbox. " - + "Device information: hardware info: {}, dSUID: {}, device-name: {}, output value: {}", - ((Device) device).getHWinfo(), device.getDSUID(), device.getName(), - ((Device) device).getOutputMode()); + if (device instanceof Device device1) { + logger.debug(""" + Discovered device with disabled or no output mode. Device was not added to inbox. \ + Device information: hardware info: {}, dSUID: {}, device-name: {}, output value: {}\ + """, device1.getHWinfo(), device.getDSUID(), device.getName(), device1.getOutputMode()); } } } @@ -154,8 +152,7 @@ public class DeviceDiscoveryService extends AbstractDiscoveryService { private ThingUID getThingUID(GeneralDeviceInformation device) { ThingUID bridgeUID = bridgeHandler.getThing().getUID(); ThingTypeUID thingTypeUID = null; - if (device instanceof Device) { - Device tempDevice = (Device) device; + if (device instanceof Device tempDevice) { thingTypeUID = new ThingTypeUID(BINDING_ID, tempDevice.getHWinfo().substring(0, 2)); if (tempDevice.isSensorDevice() && deviceType.equals(tempDevice.getHWinfo().replaceAll("-", ""))) { thingTypeUID = new ThingTypeUID(BINDING_ID, deviceType); @@ -166,8 +163,7 @@ public class DeviceDiscoveryService extends AbstractDiscoveryService { } if (getSupportedThingTypes().contains(thingTypeUID)) { String thingDeviceId = device.getDSID().toString(); - ThingUID thingUID = new ThingUID(thingTypeUID, bridgeUID, thingDeviceId); - return thingUID; + return new ThingUID(thingTypeUID, bridgeUID, thingDeviceId); } else { return null; } diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/DiscoveryServiceManager.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/DiscoveryServiceManager.java index 589313187..5f761457a 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/DiscoveryServiceManager.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/DiscoveryServiceManager.java @@ -96,22 +96,19 @@ public class DiscoveryServiceManager public void unregisterDiscoveryServices(BundleContext bundleContext) { if (discoveryServices != null) { for (AbstractDiscoveryService service : discoveryServices.values()) { - if (service instanceof SceneDiscoveryService) { - SceneDiscoveryService sceneDisServ = (SceneDiscoveryService) service; + if (service instanceof SceneDiscoveryService sceneDisServ) { ServiceRegistration serviceReg = this.discoveryServiceRegs.get(bridgeUID + sceneDisServ.getID()); sceneDisServ.deactivate(); serviceReg.unregister(); discoveryServiceRegs.remove(bridgeUID + sceneDisServ.getID()); } - if (service instanceof DeviceDiscoveryService) { - DeviceDiscoveryService devDisServ = (DeviceDiscoveryService) service; + if (service instanceof DeviceDiscoveryService devDisServ) { ServiceRegistration serviceReg = this.discoveryServiceRegs.get(bridgeUID + devDisServ.getID()); devDisServ.deactivate(); serviceReg.unregister(); discoveryServiceRegs.remove(bridgeUID + devDisServ.getID()); } - if (service instanceof ZoneTemperatureControlDiscoveryService) { - ZoneTemperatureControlDiscoveryService devDisServ = (ZoneTemperatureControlDiscoveryService) service; + if (service instanceof ZoneTemperatureControlDiscoveryService devDisServ) { ServiceRegistration serviceReg = this.discoveryServiceRegs.get(bridgeUID + devDisServ.getID()); devDisServ.deactivate(); serviceReg.unregister(); @@ -130,18 +127,17 @@ public class DiscoveryServiceManager public void registerDiscoveryServices(BundleContext bundleContext) { if (discoveryServices != null) { for (AbstractDiscoveryService service : discoveryServices.values()) { - if (service instanceof SceneDiscoveryService) { - this.discoveryServiceRegs.put(bridgeUID + ((SceneDiscoveryService) service).getID(), bundleContext + if (service instanceof SceneDiscoveryService discoveryService) { + this.discoveryServiceRegs.put(bridgeUID + discoveryService.getID(), bundleContext .registerService(DiscoveryService.class.getName(), service, new Hashtable<>())); } - if (service instanceof DeviceDiscoveryService) { - this.discoveryServiceRegs.put(bridgeUID + ((DeviceDiscoveryService) service).getID(), bundleContext + if (service instanceof DeviceDiscoveryService discoveryService) { + this.discoveryServiceRegs.put(bridgeUID + discoveryService.getID(), bundleContext .registerService(DiscoveryService.class.getName(), service, new Hashtable<>())); } - if (service instanceof ZoneTemperatureControlDiscoveryService) { - this.discoveryServiceRegs - .put(bridgeUID + ((ZoneTemperatureControlDiscoveryService) service).getID(), bundleContext - .registerService(DiscoveryService.class.getName(), service, new Hashtable<>())); + if (service instanceof ZoneTemperatureControlDiscoveryService discoveryService) { + this.discoveryServiceRegs.put(bridgeUID + discoveryService.getID(), bundleContext + .registerService(DiscoveryService.class.getName(), service, new Hashtable<>())); } } } @@ -178,10 +174,10 @@ public class DiscoveryServiceManager @Override public void onDeviceRemoved(GeneralDeviceInformation device) { - if (device instanceof Device) { - String id = ((Device) device).getHWinfo().substring(0, 2); - if (((Device) device).isSensorDevice()) { - id = ((Device) device).getHWinfo().replace("-", ""); + if (device instanceof Device dev) { + String id = dev.getHWinfo().substring(0, 2); + if (dev.isSensorDevice()) { + id = dev.getHWinfo().replace("-", ""); } if (discoveryServices.get(id) != null) { ((DeviceDiscoveryService) discoveryServices.get(id)).onDeviceRemoved(device); @@ -198,10 +194,10 @@ public class DiscoveryServiceManager @Override public void onDeviceAdded(GeneralDeviceInformation device) { try { - if (device instanceof Device) { - String id = ((Device) device).getHWinfo().substring(0, 2); - if (((Device) device).isSensorDevice()) { - id = ((Device) device).getHWinfo(); + if (device instanceof Device dev) { + String id = dev.getHWinfo().substring(0, 2); + if (dev.isSensorDevice()) { + id = dev.getHWinfo(); } if (discoveryServices.get(id) != null) { ((DeviceDiscoveryService) discoveryServices.get(id)).onDeviceAdded(device); diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/SceneDiscoveryService.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/SceneDiscoveryService.java index d275567a0..c4c4ddfd0 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/SceneDiscoveryService.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/SceneDiscoveryService.java @@ -173,8 +173,7 @@ public class SceneDiscoveryService extends AbstractDiscoveryService { if (getSupportedThingTypes().contains(thingTypeUID)) { String thingSceneId = scene.getID(); - ThingUID thingUID = new ThingUID(thingTypeUID, bridgeUID, thingSceneId); - return thingUID; + return new ThingUID(thingTypeUID, bridgeUID, thingSceneId); } else { return null; } diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/ZoneTemperatureControlDiscoveryService.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/ZoneTemperatureControlDiscoveryService.java index 7b57652b7..03b1472a3 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/ZoneTemperatureControlDiscoveryService.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/ZoneTemperatureControlDiscoveryService.java @@ -117,8 +117,7 @@ public class ZoneTemperatureControlDiscoveryService extends AbstractDiscoverySer ThingTypeUID thingTypeUID = new ThingTypeUID(BINDING_ID, thingTypeID); if (getSupportedThingTypes().contains(thingTypeUID)) { String thingID = tempControlStatus.getZoneID().toString(); - ThingUID thingUID = new ThingUID(thingTypeUID, bridgeUID, thingID); - return thingUID; + return new ThingUID(thingTypeUID, bridgeUID, thingID); } else { return null; } diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/handler/BridgeHandler.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/handler/BridgeHandler.java index 8d336eb02..20d1228f8 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/handler/BridgeHandler.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/handler/BridgeHandler.java @@ -17,7 +17,6 @@ import static org.openhab.binding.digitalstrom.internal.DigitalSTROMBindingConst import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -95,7 +94,7 @@ public class BridgeHandler extends BaseBridgeHandler /** * Contains all supported thing types of this handler */ - public static final Set SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_DSS_BRIDGE); + public static final Set SUPPORTED_THING_TYPES = Set.of(THING_TYPE_DSS_BRIDGE); private static final long RECONNECT_TRACKER_INTERVAL = 15; @@ -631,8 +630,10 @@ public class BridgeHandler extends BaseBridgeHandler switch (reason) { case WRONG_APP_TOKEN: updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - "User defined Application-Token is wrong. " - + "Please set user name and password to generate an Application-Token or set a valid Application-Token."); + """ + User defined Application-Token is wrong. \ + Please set user name and password to generate an Application-Token or set a valid Application-Token.\ + """); stopServices(); return; case WRONG_USER_OR_PASSWORD: @@ -655,10 +656,12 @@ public class BridgeHandler extends BaseBridgeHandler return; } case HOST_NOT_FOUND: - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Server not found! Please check these points:\n" + " - Is digitalSTROM-Server turned on?\n" - + " - Is the host address correct?\n" - + " - Is the ethernet cable connection established?"); + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, """ + Server not found! Please check these points: + - Is digitalSTROM-Server turned on? + - Is the host address correct? + - Is the ethernet cable connection established?\ + """); break; case UNKNOWN_HOST: updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/handler/CircuitHandler.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/handler/CircuitHandler.java index cd169663c..9f70548a6 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/handler/CircuitHandler.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/handler/CircuitHandler.java @@ -111,8 +111,8 @@ public class CircuitHandler extends BaseThingHandler implements DeviceStatusList } ThingHandler handler = bridge.getHandler(); - if (handler instanceof BridgeHandler) { - dssBridgeHandler = (BridgeHandler) handler; + if (handler instanceof BridgeHandler bridgeHandler) { + dssBridgeHandler = bridgeHandler; } else { return null; } @@ -179,8 +179,8 @@ public class CircuitHandler extends BaseThingHandler implements DeviceStatusList @Override public void onDeviceRemoved(GeneralDeviceInformation device) { - if (device instanceof Circuit) { - this.circuit = (Circuit) device; + if (device instanceof Circuit circ) { + this.circuit = circ; if (getThing().getStatus().equals(ThingStatus.ONLINE)) { if (!circuit.isPresent()) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, @@ -197,8 +197,8 @@ public class CircuitHandler extends BaseThingHandler implements DeviceStatusList @Override public void onDeviceAdded(GeneralDeviceInformation device) { - if (device instanceof Circuit) { - this.circuit = (Circuit) device; + if (device instanceof Circuit circ) { + this.circuit = circ; if (this.circuit.isPresent()) { ThingStatusInfo statusInfo = this.dssBridgeHandler.getThing().getStatusInfo(); updateStatus(statusInfo.getStatus(), statusInfo.getStatusDetail(), statusInfo.getDescription()); diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/handler/DeviceHandler.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/handler/DeviceHandler.java index f33f1bbc8..745a6915f 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/handler/DeviceHandler.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/handler/DeviceHandler.java @@ -204,9 +204,9 @@ public class DeviceHandler extends BaseThingHandler implements DeviceStatusListe } } else if (!device.isShade()) { if (DsChannelTypeProvider.isOutputChannel(channelUID.getId())) { - if (command instanceof PercentType) { + if (command instanceof PercentType percentCommand) { device.setOutputValue( - (short) fromPercentToValue(((PercentType) command).intValue(), device.getMaxOutputValue())); + (short) fromPercentToValue(percentCommand.intValue(), device.getMaxOutputValue())); } else if (command instanceof OnOffType) { if (OnOffType.ON.equals(command)) { device.setIsOn(true); @@ -219,17 +219,17 @@ public class DeviceHandler extends BaseThingHandler implements DeviceStatusListe } else { device.decrease(); } - } else if (command instanceof StringType) { - device.setOutputValue(Short.parseShort(((StringType) command).toString())); + } else if (command instanceof StringType stringCommand) { + device.setOutputValue(Short.parseShort(stringCommand.toString())); } } else { logger.debug("Command sent to an unknown channel id: {}", channelUID); } } else { if (channelUID.getId().contains(DsChannelTypeProvider.ANGLE)) { - if (command instanceof PercentType) { + if (command instanceof PercentType percentCommand) { device.setAnglePosition( - (short) fromPercentToValue(((PercentType) command).intValue(), device.getMaxSlatAngle())); + (short) fromPercentToValue(percentCommand.intValue(), device.getMaxSlatAngle())); } else if (command instanceof OnOffType) { if (OnOffType.ON.equals(command)) { device.setAnglePosition(device.getMaxSlatAngle()); @@ -244,9 +244,9 @@ public class DeviceHandler extends BaseThingHandler implements DeviceStatusListe } } } else if (channelUID.getId().contains(DsChannelTypeProvider.SHADE)) { - if (command instanceof PercentType) { - int percent = ((PercentType) command).intValue(); - if (!device.getHWinfo().equals("GR-KL200")) { + if (command instanceof PercentType percentCommand) { + int percent = percentCommand.intValue(); + if (!"GR-KL200".equals(device.getHWinfo())) { percent = 100 - percent; } device.setSlatPosition(fromPercentToValue(percent, device.getMaxSlatPosition())); @@ -291,8 +291,8 @@ public class DeviceHandler extends BaseThingHandler implements DeviceStatusListe } ThingHandler handler = bridge.getHandler(); - if (handler instanceof BridgeHandler) { - dssBridgeHandler = (BridgeHandler) handler; + if (handler instanceof BridgeHandler bridgeHandler) { + dssBridgeHandler = bridgeHandler; } else { return null; } @@ -398,7 +398,7 @@ public class DeviceHandler extends BaseThingHandler implements DeviceStatusListe default: return; } - if (!device.getHWinfo().equals("GR-KL210")) { + if (!"GR-KL210".equals(device.getHWinfo())) { percent = 100 - percent; } updateState(DsChannelTypeProvider.SHADE, new PercentType(percent)); @@ -418,10 +418,10 @@ public class DeviceHandler extends BaseThingHandler implements DeviceStatusListe @Override public synchronized void onDeviceRemoved(GeneralDeviceInformation device) { - if (device instanceof Device) { - this.device = (Device) device; + if (device instanceof Device dev) { + this.device = dev; if (this.getThing().getStatus().equals(ThingStatus.ONLINE)) { - if (!((Device) device).isPresent()) { + if (!dev.isPresent()) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "Device is not present in the digitalSTROM-System."); } else { @@ -436,8 +436,8 @@ public class DeviceHandler extends BaseThingHandler implements DeviceStatusListe @Override public synchronized void onDeviceAdded(GeneralDeviceInformation device) { - if (device instanceof Device) { - this.device = (Device) device; + if (device instanceof Device dev) { + this.device = dev; if (this.device.isPresent()) { ThingStatusInfo statusInfo = this.dssBridgeHandler.getThing().getStatusInfo(); updateStatus(statusInfo.getStatus(), statusInfo.getStatusDetail(), statusInfo.getDescription()); @@ -458,11 +458,11 @@ public class DeviceHandler extends BaseThingHandler implements DeviceStatusListe checkOutputChannel(); } else if (this.device.isBlind()) { // load channel for set the angle of jalousie devices - ApplicationGroup.Color color = ((Device) device).getFunctionalColorGroup() != null - ? ((Device) device).getFunctionalColorGroup().getColor() + ApplicationGroup.Color color = dev.getFunctionalColorGroup() != null + ? dev.getFunctionalColorGroup().getColor() : null; - String channelTypeID = DsChannelTypeProvider.getOutputChannelTypeID(color, - ((Device) device).getOutputMode(), ((Device) device).getOutputChannels()); + String channelTypeID = DsChannelTypeProvider.getOutputChannelTypeID(color, dev.getOutputMode(), + dev.getOutputChannels()); loadOutputChannel(new ChannelTypeUID(BINDING_ID, channelTypeID), DsChannelTypeProvider.getItemType(channelTypeID)); } @@ -595,8 +595,8 @@ public class DeviceHandler extends BaseThingHandler implements DeviceStatusListe if (loadedSensorChannels == null) { loadedSensorChannels = new LinkedList<>(); } - if (!loadedSensorChannels.contains(sensorChannelType.toString())) { - return loadedSensorChannels.add(sensorChannelType.toString()); + if (!loadedSensorChannels.contains(sensorChannelType)) { + return loadedSensorChannels.add(sensorChannelType); } return false; } diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/handler/SceneHandler.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/handler/SceneHandler.java index e632698e8..1b87feae7 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/handler/SceneHandler.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/handler/SceneHandler.java @@ -312,8 +312,8 @@ public class SceneHandler extends BaseThingHandler implements SceneStatusListene } ThingHandler handler = bridge.getHandler(); - if (handler instanceof BridgeHandler) { - this.bridgeHandler = (BridgeHandler) handler; + if (handler instanceof BridgeHandler bridgeHandler) { + this.bridgeHandler = bridgeHandler; } else { logger.debug("BridgeHandler cannot be found"); return null; diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/handler/ZoneTemperatureControlHandler.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/handler/ZoneTemperatureControlHandler.java index 3fbdf4310..417606d6b 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/handler/ZoneTemperatureControlHandler.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/handler/ZoneTemperatureControlHandler.java @@ -28,6 +28,7 @@ import org.openhab.binding.digitalstrom.internal.lib.climate.constants.ControlSt import org.openhab.binding.digitalstrom.internal.lib.climate.jsonresponsecontainer.impl.TemperatureControlStatus; import org.openhab.binding.digitalstrom.internal.lib.listener.TemperatureControlStatusListener; import org.openhab.binding.digitalstrom.internal.lib.manager.StructureManager; +import org.openhab.binding.digitalstrom.internal.lib.manager.impl.TemperatureControlManager; import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.ApplicationGroup; import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.OutputChannelEnum; import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.OutputModeEnum; @@ -257,8 +258,8 @@ public class ZoneTemperatureControlHandler extends BaseThingHandler implements T } ThingHandler handler = bridge.getHandler(); - if (handler instanceof BridgeHandler) { - dssBridgeHandler = (BridgeHandler) handler; + if (handler instanceof BridgeHandler bridgeHandler) { + dssBridgeHandler = bridgeHandler; } else { return null; } diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/manager/impl/DeviceStatusManagerImpl.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/manager/impl/DeviceStatusManagerImpl.java index 35f742d8d..5bdc50e7e 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/manager/impl/DeviceStatusManagerImpl.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/manager/impl/DeviceStatusManagerImpl.java @@ -610,9 +610,7 @@ public class DeviceStatusManagerImpl implements DeviceStatusManager { @Override public boolean equals(Object object) { - return object instanceof TrashDevice - ? this.device.getDSID().equals(((TrashDevice) object).getDevice().getDSID()) - : false; + return object instanceof TrashDevice td ? this.device.getDSID().equals(td.getDevice().getDSID()) : false; } } diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/manager/impl/SceneManagerImpl.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/manager/impl/SceneManagerImpl.java index 7f101e5df..15c9f8d56 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/manager/impl/SceneManagerImpl.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/manager/impl/SceneManagerImpl.java @@ -464,7 +464,7 @@ public class SceneManagerImpl implements SceneManager { @Override public void scenesGenerated(char[] scenesGenerated) { - if (String.valueOf(scenesGenerated).equals("1111")) { + if ("1111".equals(String.valueOf(scenesGenerated))) { this.scenesGenerated = true; stateChanged(ManagerStates.RUNNING); } diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/sensorjobexecutor/sensorjob/impl/DeviceConsumptionSensorJob.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/sensorjobexecutor/sensorjob/impl/DeviceConsumptionSensorJob.java index c3b12b2c4..59fb21bcf 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/sensorjobexecutor/sensorjob/impl/DeviceConsumptionSensorJob.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/sensorjobexecutor/sensorjob/impl/DeviceConsumptionSensorJob.java @@ -79,8 +79,7 @@ public class DeviceConsumptionSensorJob implements SensorJob { @Override public boolean equals(Object obj) { - if (obj instanceof DeviceConsumptionSensorJob) { - DeviceConsumptionSensorJob other = (DeviceConsumptionSensorJob) obj; + if (obj instanceof DeviceConsumptionSensorJob other) { String device = this.device.getDSID().getValue() + this.sensorType.getSensorType(); return device.equals(other.device.getDSID().getValue() + other.sensorType.getSensorType()); } diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/sensorjobexecutor/sensorjob/impl/DeviceOutputValueSensorJob.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/sensorjobexecutor/sensorjob/impl/DeviceOutputValueSensorJob.java index ffb7d4473..6f15b4f26 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/sensorjobexecutor/sensorjob/impl/DeviceOutputValueSensorJob.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/sensorjobexecutor/sensorjob/impl/DeviceOutputValueSensorJob.java @@ -85,8 +85,7 @@ public class DeviceOutputValueSensorJob implements SensorJob { @Override public boolean equals(Object obj) { - if (obj instanceof DeviceOutputValueSensorJob) { - DeviceOutputValueSensorJob other = (DeviceOutputValueSensorJob) obj; + if (obj instanceof DeviceOutputValueSensorJob other) { String key = this.device.getDSID().getValue() + this.index; return key.equals((other.device.getDSID().getValue() + other.index)); } diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/sensorjobexecutor/sensorjob/impl/SceneConfigReadingJob.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/sensorjobexecutor/sensorjob/impl/SceneConfigReadingJob.java index 984aa744a..b45d21a94 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/sensorjobexecutor/sensorjob/impl/SceneConfigReadingJob.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/sensorjobexecutor/sensorjob/impl/SceneConfigReadingJob.java @@ -62,8 +62,7 @@ public class SceneConfigReadingJob implements SensorJob { @Override public boolean equals(Object obj) { - if (obj instanceof SceneConfigReadingJob) { - SceneConfigReadingJob other = (SceneConfigReadingJob) obj; + if (obj instanceof SceneConfigReadingJob other) { String str = other.device.getDSID().getValue() + "-" + other.sceneID; return (this.device.getDSID().getValue() + "-" + this.sceneID).equals(str); } diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/sensorjobexecutor/sensorjob/impl/SceneOutputValueReadingJob.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/sensorjobexecutor/sensorjob/impl/SceneOutputValueReadingJob.java index d84e34783..de430978a 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/sensorjobexecutor/sensorjob/impl/SceneOutputValueReadingJob.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/sensorjobexecutor/sensorjob/impl/SceneOutputValueReadingJob.java @@ -65,8 +65,7 @@ public class SceneOutputValueReadingJob implements SensorJob { @Override public boolean equals(Object obj) { - if (obj instanceof SceneOutputValueReadingJob) { - SceneOutputValueReadingJob other = (SceneOutputValueReadingJob) obj; + if (obj instanceof SceneOutputValueReadingJob other) { String str = other.device.getDSID().getValue() + "-" + other.sceneID; return (this.device.getDSID().getValue() + "-" + this.sceneID).equals(str); } diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/serverconnection/impl/DsAPIImpl.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/serverconnection/impl/DsAPIImpl.java index 9bac10666..40840abdf 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/serverconnection/impl/DsAPIImpl.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/serverconnection/impl/DsAPIImpl.java @@ -931,8 +931,9 @@ public class DsAPIImpl implements DsAPI { .addRequestClass(ClassKeys.ZONE).addFunction(FunctionKeys.SET_TEMEPERATURE_CONTROL_VALUE) .addDefaultZoneParameter(sessionToken, zoneID, zoneName); for (Object[] objAry : controlValues) { - if (objAry.length == 2 && objAry[0] instanceof String && objAry[1] instanceof Integer) { - builder.addParameter((String) objAry[0], SimpleRequestBuilder.objectToString(objAry[1])); + if (objAry.length == 2 && objAry[0] instanceof String stringValue + && objAry[1] instanceof Integer) { + builder.addParameter(stringValue, SimpleRequestBuilder.objectToString(objAry[1])); } else { builder.buildRequestString(); throw new IllegalArgumentException( diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/serverconnection/impl/JSONResponseHandler.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/serverconnection/impl/JSONResponseHandler.java index 562d7d663..6e656dc63 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/serverconnection/impl/JSONResponseHandler.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/serverconnection/impl/JSONResponseHandler.java @@ -61,7 +61,7 @@ public class JSONResponseHandler { * @return jsonObject */ public static JsonObject toJsonObject(String jsonResponse) { - if (jsonResponse != null && !jsonResponse.trim().equals("")) { + if (jsonResponse != null && !"".equals(jsonResponse.trim())) { try { return (JsonObject) JsonParser.parseString(jsonResponse); } catch (JsonParseException e) { diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/serverconnection/simpledsrequestbuilder/SimpleRequestBuilder.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/serverconnection/simpledsrequestbuilder/SimpleRequestBuilder.java index 9eb712e1a..962868bba 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/serverconnection/simpledsrequestbuilder/SimpleRequestBuilder.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/serverconnection/simpledsrequestbuilder/SimpleRequestBuilder.java @@ -283,11 +283,11 @@ public class SimpleRequestBuilder { if (obj == null) { return null; } - if (obj instanceof DSID) { - return ((DSID) obj).getValue(); + if (obj instanceof DSID id) { + return id.getValue(); } - if (obj instanceof Number) { - return ((Number) obj).intValue() > -1 ? obj.toString() : null; + if (obj instanceof Number number) { + return number.intValue() > -1 ? obj.toString() : null; } return obj.toString(); } diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/devices/deviceparameters/impl/DSID.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/devices/deviceparameters/impl/DSID.java index afb279f52..1ad42098e 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/devices/deviceparameters/impl/DSID.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/devices/deviceparameters/impl/DSID.java @@ -54,8 +54,8 @@ public class DSID { @Override public boolean equals(Object obj) { - if (obj instanceof DSID) { - return ((DSID) obj).getValue().equals(this.getValue()); + if (obj instanceof DSID id) { + return id.getValue().equals(this.getValue()); } return false; } diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/devices/deviceparameters/impl/DSUID.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/devices/deviceparameters/impl/DSUID.java index 856cf4dc8..f33dfde7b 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/devices/deviceparameters/impl/DSUID.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/devices/deviceparameters/impl/DSUID.java @@ -47,8 +47,8 @@ public class DSUID { @Override public boolean equals(Object obj) { - if (obj instanceof DSUID) { - return ((DSUID) obj).getValue().equals(this.getValue()); + if (obj instanceof DSUID id) { + return id.getValue().equals(this.getValue()); } return false; } diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/devices/deviceparameters/impl/DeviceStateUpdateImpl.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/devices/deviceparameters/impl/DeviceStateUpdateImpl.java index 7db29e6bc..211512833 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/devices/deviceparameters/impl/DeviceStateUpdateImpl.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/devices/deviceparameters/impl/DeviceStateUpdateImpl.java @@ -85,8 +85,8 @@ public class DeviceStateUpdateImpl implements DeviceStateUpdate { if (value instanceof Short) { return ((Short) value).intValue(); } - if (value instanceof String) { - return Integer.parseInt((String) value); + if (value instanceof String string) { + return Integer.parseInt(string); } } catch (Exception e) { throw new ClassCastException(); @@ -105,8 +105,8 @@ public class DeviceStateUpdateImpl implements DeviceStateUpdate { if (value instanceof Short) { return ((Short) value).toString(); } - if (value instanceof String) { - return (String) value; + if (value instanceof String string) { + return string; } throw new ClassCastException(); } @@ -128,8 +128,8 @@ public class DeviceStateUpdateImpl implements DeviceStateUpdate { if (value instanceof Short) { return (Short) value; } - if (value instanceof String) { - return Short.parseShort((String) value); + if (value instanceof String string) { + return Short.parseShort(string); } } catch (Exception e) { throw new ClassCastException(); @@ -149,8 +149,8 @@ public class DeviceStateUpdateImpl implements DeviceStateUpdate { if (value instanceof Short) { return ((Short) value).floatValue(); } - if (value instanceof String) { - return Float.parseFloat((String) value); + if (value instanceof String string) { + return Float.parseFloat(string); } } catch (Exception e) { throw new ClassCastException(); diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/devices/impl/DeviceImpl.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/devices/impl/DeviceImpl.java index 0f83bf630..8b4588543 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/devices/impl/DeviceImpl.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/devices/impl/DeviceImpl.java @@ -952,8 +952,7 @@ public class DeviceImpl extends AbstractGeneralDeviceInformations implements Dev @Override public boolean equals(Object obj) { - if (obj instanceof Device) { - Device device = (Device) obj; + if (obj instanceof Device device) { return device.getDSID().equals(this.getDSID()); } return false; @@ -1781,7 +1780,7 @@ public class DeviceImpl extends AbstractGeneralDeviceInformations implements Dev String[] scenes = propertries.split("\n"); for (int i = 0; i < scenes.length; i++) { logger.debug("Find saved scene configuration for device with dSID {} and sceneID {}", dsid, i); - String[] sceneIdToConfig = scenes[i].replaceAll(" ", "").split("="); + String[] sceneIdToConfig = scenes[i].replace(" ", "").split("="); String[] sceneParm = sceneIdToConfig[1].split(","); JSONDeviceSceneSpecImpl sceneSpecNew = null; int sceneValue = -1; diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/impl/JSONDetailedGroupInfoImpl.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/impl/JSONDetailedGroupInfoImpl.java index 4b405667c..d55256811 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/impl/JSONDetailedGroupInfoImpl.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/impl/JSONDetailedGroupInfoImpl.java @@ -75,8 +75,7 @@ public class JSONDetailedGroupInfoImpl implements DetailedGroupInfo { @Override public boolean equals(Object obj) { - if (obj instanceof DetailedGroupInfo) { - DetailedGroupInfo group = (DetailedGroupInfo) obj; + if (obj instanceof DetailedGroupInfo group) { return group.getGroupID() == this.getGroupID(); } return false; diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/impl/JSONZoneImpl.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/impl/JSONZoneImpl.java index ebaff0b97..77aaf5f01 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/impl/JSONZoneImpl.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/impl/JSONZoneImpl.java @@ -129,8 +129,7 @@ public class JSONZoneImpl implements Zone { @Override public boolean equals(Object obj) { - if (obj instanceof Zone) { - Zone other = (Zone) obj; + if (obj instanceof Zone other) { return (other.getZoneId() == this.getZoneId()); } return false; diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/providers/DsDeviceThingTypeProvider.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/providers/DsDeviceThingTypeProvider.java index cf11f1ece..864bb4420 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/providers/DsDeviceThingTypeProvider.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/providers/DsDeviceThingTypeProvider.java @@ -62,7 +62,7 @@ public class DsDeviceThingTypeProvider extends BaseDsI18n implements ThingTypePr * @author Michael Ochel - Initial contribution * @author Matthias Siegele - Initial contribution */ - public static enum SupportedThingTypes { + public enum SupportedThingTypes { // ThingType, responsible ThingHanlder, Device config-description with power-sensors GE(DeviceHandler.class.getSimpleName(), true), GR(DeviceHandler.class.getSimpleName(), false), diff --git a/bundles/org.openhab.binding.dlinksmarthome/src/main/java/org/openhab/binding/dlinksmarthome/internal/DLinkSmartHomeBindingConstants.java b/bundles/org.openhab.binding.dlinksmarthome/src/main/java/org/openhab/binding/dlinksmarthome/internal/DLinkSmartHomeBindingConstants.java index f034752f9..929756ed2 100644 --- a/bundles/org.openhab.binding.dlinksmarthome/src/main/java/org/openhab/binding/dlinksmarthome/internal/DLinkSmartHomeBindingConstants.java +++ b/bundles/org.openhab.binding.dlinksmarthome/src/main/java/org/openhab/binding/dlinksmarthome/internal/DLinkSmartHomeBindingConstants.java @@ -12,7 +12,6 @@ */ package org.openhab.binding.dlinksmarthome.internal; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -32,7 +31,7 @@ public class DLinkSmartHomeBindingConstants { // List of all Thing Type UIDs public static final ThingTypeUID THING_TYPE_DCHS150 = new ThingTypeUID(BINDING_ID, "DCH-S150"); - public static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_DCHS150); + public static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_DCHS150); // Motion trigger channel public static final String MOTION = "motion"; diff --git a/bundles/org.openhab.binding.dlinksmarthome/src/main/java/org/openhab/binding/dlinksmarthome/internal/DLinkSmartHomeDiscoveryParticipant.java b/bundles/org.openhab.binding.dlinksmarthome/src/main/java/org/openhab/binding/dlinksmarthome/internal/DLinkSmartHomeDiscoveryParticipant.java index e87dc0890..144e402df 100644 --- a/bundles/org.openhab.binding.dlinksmarthome/src/main/java/org/openhab/binding/dlinksmarthome/internal/DLinkSmartHomeDiscoveryParticipant.java +++ b/bundles/org.openhab.binding.dlinksmarthome/src/main/java/org/openhab/binding/dlinksmarthome/internal/DLinkSmartHomeDiscoveryParticipant.java @@ -87,7 +87,7 @@ public class DLinkSmartHomeDiscoveryParticipant implements MDNSDiscoveryParticip if (model == null) { return null; - } else if (model.equals("DCH-S150")) { + } else if ("DCH-S150".equals(model)) { return THING_TYPE_DCHS150; } else { logger.debug("D-Link HNAP Type: {}", model); diff --git a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/DmxBindingConstants.java b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/DmxBindingConstants.java index 7b600ca40..30e255bd4 100644 --- a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/DmxBindingConstants.java +++ b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/DmxBindingConstants.java @@ -79,7 +79,7 @@ public class DmxBindingConstants { public static final ChannelTypeUID MUTE_CHANNEL_TYPEUID = new ChannelTypeUID(BINDING_ID, CHANNEL_MUTE); // Listener Type for channel updates - public static enum ListenerType { + public enum ListenerType { VALUE, ACTION } diff --git a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/DmxBridgeHandler.java b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/DmxBridgeHandler.java index dcbd8e466..c2727be21 100644 --- a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/DmxBridgeHandler.java +++ b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/DmxBridgeHandler.java @@ -16,7 +16,6 @@ import static org.openhab.binding.dmx.internal.DmxBindingConstants.CHANNEL_MUTE; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -275,6 +274,6 @@ public abstract class DmxBridgeHandler extends BaseBridgeHandler { @Override public Collection> getServices() { - return Collections.singletonList(DmxActions.class); + return List.of(DmxActions.class); } } diff --git a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/DmxHandlerFactory.java b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/DmxHandlerFactory.java index 2b8f258d8..0662cb640 100644 --- a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/DmxHandlerFactory.java +++ b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/DmxHandlerFactory.java @@ -60,26 +60,19 @@ public class DmxHandlerFactory extends BaseThingHandlerFactory { protected @Nullable ThingHandler createHandler(Thing thing) { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); if (thingTypeUID.equals(THING_TYPE_ARTNET_BRIDGE)) { - ArtnetBridgeHandler handler = new ArtnetBridgeHandler((Bridge) thing); - return handler; + return new ArtnetBridgeHandler((Bridge) thing); } else if (thingTypeUID.equals(THING_TYPE_LIB485_BRIDGE)) { - Lib485BridgeHandler handler = new Lib485BridgeHandler((Bridge) thing); - return handler; + return new Lib485BridgeHandler((Bridge) thing); } else if (thingTypeUID.equals(THING_TYPE_SACN_BRIDGE)) { - SacnBridgeHandler handler = new SacnBridgeHandler((Bridge) thing); - return handler; + return new SacnBridgeHandler((Bridge) thing); } else if (thingTypeUID.equals(THING_TYPE_DIMMER)) { - DimmerThingHandler handler = new DimmerThingHandler(thing); - return handler; + return new DimmerThingHandler(thing); } else if (thingTypeUID.equals(THING_TYPE_COLOR)) { - ColorThingHandler handler = new ColorThingHandler(thing); - return handler; + return new ColorThingHandler(thing); } else if (thingTypeUID.equals(THING_TYPE_TUNABLEWHITE)) { - TunableWhiteThingHandler handler = new TunableWhiteThingHandler(thing); - return handler; + return new TunableWhiteThingHandler(thing); } else if (thingTypeUID.equals(THING_TYPE_CHASER)) { - ChaserThingHandler handler = new ChaserThingHandler(thing); - return handler; + return new ChaserThingHandler(thing); } return null; } diff --git a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/action/DmxActions.java b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/action/DmxActions.java index 7acd49247..b94404dca 100644 --- a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/action/DmxActions.java +++ b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/action/DmxActions.java @@ -73,8 +73,8 @@ public class DmxActions implements ThingActions { @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof DmxBridgeHandler) { - this.handler = (DmxBridgeHandler) handler; + if (handler instanceof DmxBridgeHandler bridgeHandler) { + this.handler = bridgeHandler; } } diff --git a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/handler/ArtnetBridgeHandler.java b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/handler/ArtnetBridgeHandler.java index 024409660..dfa8df12b 100644 --- a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/handler/ArtnetBridgeHandler.java +++ b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/handler/ArtnetBridgeHandler.java @@ -82,7 +82,7 @@ public class ArtnetBridgeHandler extends DmxOverEthernetHandler { } logger.debug("originating address is {} for {}", senderNode, this.thing.getUID()); - refreshAlways = configuration.refreshmode.equals("always"); + refreshAlways = "always".equals(configuration.refreshmode); logger.debug("refresh mode set to always: {}", refreshAlways); diff --git a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/handler/ChaserThingHandler.java b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/handler/ChaserThingHandler.java index 347a41fe1..5a08a2864 100644 --- a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/handler/ChaserThingHandler.java +++ b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/handler/ChaserThingHandler.java @@ -68,8 +68,8 @@ public class ChaserThingHandler extends DmxThingHandler { public void handleCommand(ChannelUID channelUID, Command command) { switch (channelUID.getId()) { case CHANNEL_SWITCH: - if (command instanceof OnOffType) { - if (((OnOffType) command).equals(OnOffType.ON)) { + if (command instanceof OnOffType onOffCommand) { + if (onOffCommand.equals(OnOffType.ON)) { Integer channelCounter = 0; for (DmxChannel channel : channels) { if (resumeAfter) { @@ -104,8 +104,8 @@ public class ChaserThingHandler extends DmxThingHandler { } break; case CHANNEL_CONTROL: - if (command instanceof StringType) { - List newValues = ValueSet.parseChaseConfig(((StringType) command).toString()); + if (command instanceof StringType stringCommand) { + List newValues = ValueSet.parseChaseConfig(stringCommand.toString()); if (!newValues.isEmpty()) { values = newValues; logger.debug("updated chase config in {}", this.thing.getUID()); @@ -206,8 +206,8 @@ public class ChaserThingHandler extends DmxThingHandler { @Override public void updateSwitchState(ChannelUID channelUID, State state) { logger.trace("received {} for {}", state, channelUID); - if (channelUID.getId().equals(CHANNEL_SWITCH) && (state instanceof OnOffType)) { - this.isRunning = (OnOffType) state; + if (channelUID.getId().equals(CHANNEL_SWITCH) && (state instanceof OnOffType onOffState)) { + this.isRunning = onOffState; updateState(channelUID, state); } else { logger.debug("unknown state received: {} in channel {} thing {}", state, channelUID, this.thing.getUID()); diff --git a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/handler/ColorThingHandler.java b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/handler/ColorThingHandler.java index 1540a3f63..8bd90d81c 100644 --- a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/handler/ColorThingHandler.java +++ b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/handler/ColorThingHandler.java @@ -117,9 +117,9 @@ public class ColorThingHandler extends DmxThingHandler { return; } case CHANNEL_COLOR: { - if (command instanceof OnOffType) { + if (command instanceof OnOffType onOffCommand) { logger.trace("adding {} fade to channels in thing {}", command, this.thing.getUID()); - if (((OnOffType) command) == OnOffType.ON) { + if (onOffCommand == OnOffType.ON) { targetValueSet = turnOnValue; } else { if (dynamicTurnOnValue) { @@ -131,21 +131,21 @@ public class ColorThingHandler extends DmxThingHandler { } targetValueSet = turnOffValue; } - } else if (command instanceof HSBType) { + } else if (command instanceof HSBType hsbCommand) { logger.trace("adding color fade to channels in thing {}", this.thing.getUID()); - targetValueSet.addValue(((HSBType) command).getRed()); - targetValueSet.addValue(((HSBType) command).getGreen()); - targetValueSet.addValue(((HSBType) command).getBlue()); + targetValueSet.addValue(hsbCommand.getRed()); + targetValueSet.addValue(hsbCommand.getGreen()); + targetValueSet.addValue(hsbCommand.getBlue()); } else if ((command instanceof PercentType) || (command instanceof DecimalType)) { logger.trace("adding brightness fade to channels in thing {}", this.thing.getUID()); - PercentType brightness = (command instanceof PercentType) ? (PercentType) command + PercentType brightness = (command instanceof PercentType percentCommand) ? percentCommand : Util.toPercentValue(((DecimalType) command).intValue()); HSBType targetColor = new HSBType(currentColor.getHue(), currentColor.getSaturation(), brightness); targetValueSet.addValue(targetColor.getRed()); targetValueSet.addValue(targetColor.getGreen()); targetValueSet.addValue(targetColor.getBlue()); - } else if (command instanceof IncreaseDecreaseType) { - if (isDimming && ((IncreaseDecreaseType) command).equals(IncreaseDecreaseType.INCREASE)) { + } else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) { + if (isDimming && increaseDecreaseCommand.equals(IncreaseDecreaseType.INCREASE)) { logger.trace("stopping fade in thing {}", this.thing.getUID()); channels.forEach(DmxChannel::clearAction); isDimming = false; @@ -153,7 +153,7 @@ public class ColorThingHandler extends DmxThingHandler { } else { logger.trace("starting {} fade in thing {}", command, this.thing.getUID()); HSBType targetColor; - if (((IncreaseDecreaseType) command).equals(IncreaseDecreaseType.INCREASE)) { + if (increaseDecreaseCommand.equals(IncreaseDecreaseType.INCREASE)) { targetColor = new HSBType(currentColor.getHue(), currentColor.getSaturation(), PercentType.HUNDRED); } else { @@ -239,7 +239,7 @@ public class ColorThingHandler extends DmxThingHandler { dimTime = configuration.dimtime; logger.trace("setting dimTime to {} ms in {}", fadeTime, this.thing.getUID()); - String turnOnValueString = String.valueOf(fadeTime) + ":" + configuration.turnonvalue + ":-1"; + String turnOnValueString = fadeTime + ":" + configuration.turnonvalue + ":-1"; ValueSet turnOnValue = ValueSet.fromString(turnOnValueString); if (turnOnValue.size() % 3 == 0) { this.turnOnValue = turnOnValue; @@ -253,7 +253,7 @@ public class ColorThingHandler extends DmxThingHandler { dynamicTurnOnValue = configuration.dynamicturnonvalue; - String turnOffValueString = String.valueOf(fadeTime) + ":" + configuration.turnoffvalue + ":-1"; + String turnOffValueString = fadeTime + ":" + configuration.turnoffvalue + ":-1"; ValueSet turnOffValue = ValueSet.fromString(turnOffValueString); if (turnOffValue.size() % 3 == 0) { this.turnOffValue = turnOffValue; diff --git a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/handler/DimmerThingHandler.java b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/handler/DimmerThingHandler.java index 475a16f10..c289d1bcf 100644 --- a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/handler/DimmerThingHandler.java +++ b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/handler/DimmerThingHandler.java @@ -15,7 +15,6 @@ package org.openhab.binding.dmx.internal.handler; import static org.openhab.binding.dmx.internal.DmxBindingConstants.*; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Set; import java.util.stream.IntStream; @@ -52,7 +51,7 @@ import org.slf4j.LoggerFactory; */ public class DimmerThingHandler extends DmxThingHandler { - public static final Set SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_DIMMER); + public static final Set SUPPORTED_THING_TYPES = Set.of(THING_TYPE_DIMMER); private final Logger logger = LoggerFactory.getLogger(DimmerThingHandler.class); @@ -79,13 +78,13 @@ public class DimmerThingHandler extends DmxThingHandler { switch (channelUID.getId()) { case CHANNEL_BRIGHTNESS: { if (command instanceof PercentType || command instanceof DecimalType) { - PercentType brightness = (command instanceof PercentType) ? (PercentType) command + PercentType brightness = (command instanceof PercentType percentCommand) ? percentCommand : Util.toPercentValue(((DecimalType) command).intValue()); logger.trace("adding fade to channels in thing {}", this.thing.getUID()); targetValueSet.addValue(brightness); - } else if (command instanceof OnOffType) { + } else if (command instanceof OnOffType onOffCommand) { logger.trace("adding {} fade to channels in thing {}", command, this.thing.getUID()); - if (((OnOffType) command) == OnOffType.ON) { + if (onOffCommand == OnOffType.ON) { targetValueSet = turnOnValue; } else { if (dynamicTurnOnValue) { @@ -97,16 +96,15 @@ public class DimmerThingHandler extends DmxThingHandler { } targetValueSet = turnOffValue; } - } else if (command instanceof IncreaseDecreaseType) { - if (isDimming && ((IncreaseDecreaseType) command).equals(IncreaseDecreaseType.INCREASE)) { + } else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) { + if (isDimming && increaseDecreaseCommand.equals(IncreaseDecreaseType.INCREASE)) { logger.trace("stopping fade in thing {}", this.thing.getUID()); channels.forEach(DmxChannel::clearAction); isDimming = false; return; } else { logger.trace("starting {} fade in thing {}", command, this.thing.getUID()); - targetValueSet = ((IncreaseDecreaseType) command).equals(IncreaseDecreaseType.INCREASE) - ? turnOnValue + targetValueSet = increaseDecreaseCommand.equals(IncreaseDecreaseType.INCREASE) ? turnOnValue : turnOffValue; targetValueSet.setFadeTime(dimTime); isDimming = true; @@ -178,7 +176,7 @@ public class DimmerThingHandler extends DmxThingHandler { dimTime = configuration.dimtime; logger.trace("setting dimTime to {} ms in {}", fadeTime, this.thing.getUID()); - String turnOnValueString = String.valueOf(fadeTime) + ":" + configuration.turnonvalue + ":-1"; + String turnOnValueString = fadeTime + ":" + configuration.turnonvalue + ":-1"; ValueSet turnOnValue = ValueSet.fromString(turnOnValueString); if (!turnOnValue.isEmpty()) { @@ -194,7 +192,7 @@ public class DimmerThingHandler extends DmxThingHandler { dynamicTurnOnValue = configuration.dynamicturnonvalue; - String turnOffValueString = String.valueOf(fadeTime) + ":" + configuration.turnoffvalue + ":-1"; + String turnOffValueString = fadeTime + ":" + configuration.turnoffvalue + ":-1"; ValueSet turnOffValue = ValueSet.fromString(turnOffValueString); if (!turnOffValue.isEmpty()) { this.turnOffValue = turnOffValue; diff --git a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/handler/SacnBridgeHandler.java b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/handler/SacnBridgeHandler.java index c13449b8a..10bccb01b 100644 --- a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/handler/SacnBridgeHandler.java +++ b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/handler/SacnBridgeHandler.java @@ -65,7 +65,7 @@ public class SacnBridgeHandler extends DmxOverEthernetHandler { packetTemplate.setUniverse(universe.getUniverseId()); receiverNodes.clear(); - if ((configuration.mode.equals("unicast"))) { + if (("unicast".equals(configuration.mode))) { if (configuration.address.isEmpty()) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Could not initialize unicast sender (address not set)"); @@ -90,7 +90,7 @@ public class SacnBridgeHandler extends DmxOverEthernetHandler { } logger.debug("originating address is {} for {}", senderNode, this.thing.getUID()); - refreshAlways = configuration.refreshmode.equals("always"); + refreshAlways = "always".equals(configuration.refreshmode); logger.debug("refresh mode set to always: {}", refreshAlways); updateStatus(ThingStatus.UNKNOWN); diff --git a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/handler/TunableWhiteThingHandler.java b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/handler/TunableWhiteThingHandler.java index 915e7c75e..383b9aaf5 100644 --- a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/handler/TunableWhiteThingHandler.java +++ b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/handler/TunableWhiteThingHandler.java @@ -81,16 +81,16 @@ public class TunableWhiteThingHandler extends DmxThingHandler { switch (channelUID.getId()) { case CHANNEL_BRIGHTNESS: { if (command instanceof PercentType || command instanceof DecimalType) { - PercentType brightness = (command instanceof PercentType) ? (PercentType) command + PercentType brightness = (command instanceof PercentType percentCommand) ? percentCommand : Util.toPercentValue(((DecimalType) command).intValue()); logger.trace("adding fade to channels in thing {}", this.thing.getUID()); targetValueSet.addValue(Util.toDmxValue( Util.toDmxValue(brightness) * (100 - currentColorTemperature.intValue()) / 100)); targetValueSet.addValue( Util.toDmxValue(Util.toDmxValue(brightness) * currentColorTemperature.intValue() / 100)); - } else if (command instanceof OnOffType) { + } else if (command instanceof OnOffType onOffCommand) { logger.trace("adding {} fade to channels in thing {}", command, this.thing.getUID()); - if (((OnOffType) command) == OnOffType.ON) { + if (onOffCommand == OnOffType.ON) { targetValueSet = turnOnValue; } else { if (dynamicTurnOnValue) { @@ -102,16 +102,15 @@ public class TunableWhiteThingHandler extends DmxThingHandler { } targetValueSet = turnOffValue; } - } else if (command instanceof IncreaseDecreaseType) { - if (isDimming && ((IncreaseDecreaseType) command).equals(IncreaseDecreaseType.INCREASE)) { + } else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) { + if (isDimming && increaseDecreaseCommand.equals(IncreaseDecreaseType.INCREASE)) { logger.trace("stopping fade in thing {}", this.thing.getUID()); channels.forEach(DmxChannel::clearAction); isDimming = false; return; } else { logger.trace("starting {} fade in thing {}", command, this.thing.getUID()); - targetValueSet = ((IncreaseDecreaseType) command).equals(IncreaseDecreaseType.INCREASE) - ? turnOnValue + targetValueSet = increaseDecreaseCommand.equals(IncreaseDecreaseType.INCREASE) ? turnOnValue : turnOffValue; targetValueSet.setFadeTime(dimTime); isDimming = true; @@ -153,8 +152,7 @@ public class TunableWhiteThingHandler extends DmxThingHandler { return; } case CHANNEL_COLOR_TEMPERATURE: { - if (command instanceof PercentType) { - PercentType colorTemperature = (PercentType) command; + if (command instanceof PercentType colorTemperature) { targetValueSet.addValue(Util.toDmxValue( Util.toDmxValue(currentBrightness) * (100 - colorTemperature.intValue()) / 100)); targetValueSet.addValue( @@ -231,7 +229,7 @@ public class TunableWhiteThingHandler extends DmxThingHandler { dimTime = configuration.dimtime; logger.trace("setting dimTime to {} ms in {}", fadeTime, this.thing.getUID()); - String turnOnValueString = String.valueOf(fadeTime) + ":" + configuration.turnonvalue + ":-1"; + String turnOnValueString = fadeTime + ":" + configuration.turnonvalue + ":-1"; ValueSet turnOnValue = ValueSet.fromString(turnOnValueString); if (turnOnValue.size() % 2 == 0) { this.turnOnValue = turnOnValue; @@ -245,7 +243,7 @@ public class TunableWhiteThingHandler extends DmxThingHandler { dynamicTurnOnValue = configuration.dynamicturnonvalue; - String turnOffValueString = String.valueOf(fadeTime) + ":" + configuration.turnoffvalue + ":-1"; + String turnOffValueString = fadeTime + ":" + configuration.turnoffvalue + ":-1"; ValueSet turnOffValue = ValueSet.fromString(turnOffValueString); if (turnOffValue.size() % 2 == 0) { this.turnOffValue = turnOffValue; diff --git a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/multiverse/BaseDmxChannel.java b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/multiverse/BaseDmxChannel.java index b9480c588..bd3f9c819 100644 --- a/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/multiverse/BaseDmxChannel.java +++ b/bundles/org.openhab.binding.dmx/src/main/java/org/openhab/binding/dmx/internal/multiverse/BaseDmxChannel.java @@ -97,7 +97,7 @@ public class BaseDmxChannel implements Comparable { if (otherDmxChannel == null) { return -1; } - int universeCompare = Integer.valueOf(getUniverseId()).compareTo(otherDmxChannel.getUniverseId()); + int universeCompare = Integer.compare(getUniverseId(), otherDmxChannel.getUniverseId()); if (universeCompare == 0) { return Integer.compare(getChannelId(), otherDmxChannel.getChannelId()); } else { @@ -127,7 +127,7 @@ public class BaseDmxChannel implements Comparable { if (channelMatch.matches()) { final int universeId = (channelMatch.group(1) == null) ? defaultUniverseId : Integer.parseInt(channelMatch.group(1)); - dmxChannelWidth = channelMatch.group(3).equals("") ? 1 : Integer.parseInt(channelMatch.group(3)); + dmxChannelWidth = "".equals(channelMatch.group(3)) ? 1 : Integer.parseInt(channelMatch.group(3)); dmxChannelId = Integer.parseInt(channelMatch.group(2)); LOGGER.trace("parsed channel string {} to universe {}, id {}, width {}", singleDmxChannelString, universeId, dmxChannelId, dmxChannelWidth); diff --git a/bundles/org.openhab.binding.dmx/src/test/java/org/openhab/binding/dmx/test/TestBridgeHandler.java b/bundles/org.openhab.binding.dmx/src/test/java/org/openhab/binding/dmx/test/TestBridgeHandler.java index 3d58bf5b6..9a106f60d 100644 --- a/bundles/org.openhab.binding.dmx/src/test/java/org/openhab/binding/dmx/test/TestBridgeHandler.java +++ b/bundles/org.openhab.binding.dmx/src/test/java/org/openhab/binding/dmx/test/TestBridgeHandler.java @@ -14,7 +14,6 @@ package org.openhab.binding.dmx.test; import static org.openhab.binding.dmx.internal.DmxBindingConstants.*; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -38,7 +37,7 @@ import org.slf4j.LoggerFactory; @NonNullByDefault public class TestBridgeHandler extends DmxBridgeHandler { public static final ThingTypeUID THING_TYPE_TEST_BRIDGE = new ThingTypeUID(BINDING_ID, "test-bridge"); - public static final Set SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_TEST_BRIDGE); + public static final Set SUPPORTED_THING_TYPES = Set.of(THING_TYPE_TEST_BRIDGE); public static final int MIN_UNIVERSE_ID = 0; public static final int MAX_UNIVERSE_ID = 0; diff --git a/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/action/DoorbirdActions.java b/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/action/DoorbirdActions.java index 0e1831c42..6e1a1decc 100644 --- a/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/action/DoorbirdActions.java +++ b/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/action/DoorbirdActions.java @@ -41,8 +41,8 @@ public class DoorbirdActions implements ThingActions { @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof DoorbellHandler) { - this.handler = (DoorbellHandler) handler; + if (handler instanceof DoorbellHandler doorbellHandler) { + this.handler = doorbellHandler; } } diff --git a/bundles/org.openhab.binding.doorbird/src/test/java/org/openhab/binding/doorbird/internal/DoorbirdInfoTest.java b/bundles/org.openhab.binding.doorbird/src/test/java/org/openhab/binding/doorbird/internal/DoorbirdInfoTest.java index dce27e1fc..d275b720b 100644 --- a/bundles/org.openhab.binding.doorbird/src/test/java/org/openhab/binding/doorbird/internal/DoorbirdInfoTest.java +++ b/bundles/org.openhab.binding.doorbird/src/test/java/org/openhab/binding/doorbird/internal/DoorbirdInfoTest.java @@ -29,36 +29,40 @@ public class DoorbirdInfoTest { private final String infoWithControllerId = //@formatter:off - "{" + - "'BHA': {" + - "'RETURNCODE': '1'," + - "'VERSION': [{" + - "'FIRMWARE': '000109'," + - "'BUILD_NUMBER': '15120529'," + - "'PRIMARY_MAC_ADDR': '1CCAE3711111'," + - "'WIFI_MAC_ADDR': '1CCAE3799999'," + - "'RELAYS': ['1', '2', 'gggaaa@1', 'gggaaa@2']," + - "'DEVICE-TYPE': 'DoorBird D101'" + - "}]" + - "}" + - "}"; + """ + {\ + 'BHA': {\ + 'RETURNCODE': '1',\ + 'VERSION': [{\ + 'FIRMWARE': '000109',\ + 'BUILD_NUMBER': '15120529',\ + 'PRIMARY_MAC_ADDR': '1CCAE3711111',\ + 'WIFI_MAC_ADDR': '1CCAE3799999',\ + 'RELAYS': ['1', '2', 'gggaaa@1', 'gggaaa@2'],\ + 'DEVICE-TYPE': 'DoorBird D101'\ + }]\ + }\ + }\ + """; //@formatter:on private final String infoWithoutControllerId = //@formatter:off - "{" + - "'BHA': {" + - "'RETURNCODE': '1'," + - "'VERSION': [{" + - "'FIRMWARE': '000109'," + - "'BUILD_NUMBER': '15120529'," + - "'PRIMARY_MAC_ADDR': '1CCAE3711111'," + - "'WIFI_MAC_ADDR': '1CCAE3799999'," + - "'RELAYS': ['1', '2']," + - "'DEVICE-TYPE': 'DoorBird D101'" + - "}]" + - "}" + - "}"; + """ + {\ + 'BHA': {\ + 'RETURNCODE': '1',\ + 'VERSION': [{\ + 'FIRMWARE': '000109',\ + 'BUILD_NUMBER': '15120529',\ + 'PRIMARY_MAC_ADDR': '1CCAE3711111',\ + 'WIFI_MAC_ADDR': '1CCAE3799999',\ + 'RELAYS': ['1', '2'],\ + 'DEVICE-TYPE': 'DoorBird D101'\ + }]\ + }\ + }\ + """; //@formatter:on @Test diff --git a/bundles/org.openhab.binding.doorbird/src/test/java/org/openhab/binding/doorbird/internal/SipStatusTest.java b/bundles/org.openhab.binding.doorbird/src/test/java/org/openhab/binding/doorbird/internal/SipStatusTest.java index 06ef3fb8c..66640da2d 100644 --- a/bundles/org.openhab.binding.doorbird/src/test/java/org/openhab/binding/doorbird/internal/SipStatusTest.java +++ b/bundles/org.openhab.binding.doorbird/src/test/java/org/openhab/binding/doorbird/internal/SipStatusTest.java @@ -29,33 +29,35 @@ public class SipStatusTest { private final String sipStatusJson = //@formatter:off - "{" + - "'BHA': {" + - "'RETURNCODE': '1'," + - "'SIP': [{" + - "'ENABLE': '10'," + - "'PRIORITIZE_APP': '1'," + - "'REGISTER_URL': '192.168.178.1'," + - "'REGISTER_USER': 'xxxxx'," + - "'REGISTER_PASSWORD': 'yyyyy'," + - "'AUTOCALL_MOTIONSENSOR_URL': 'motion-url'," + - "'AUTOCALL_DOORBELL_URL': 'doorbell-url'," + - "'SPK_VOLUME': '70'," + - "'MIC_VOLUME': '33'," + - "'DTMF': '1'," + - "'relais:1': '0'," + - "'relais:2': '1'," + - "'LIGHT_PASSCODE': 'light-passcode'," + - "'INCOMING_CALL_ENABLE': '0'," + - "'INCOMING_CALL_USER': 'abcde'," + - "'ANC': '1'," + - "'LASTERRORCODE': '901'," + - "'LASTERRORTEXT': 'OK'," + - "'RING_TIME_LIMIT': '60'," + - "'CALL_TIME_LIMIT': '180'" + - "}]" + - "}" + - "}"; + """ + {\ + 'BHA': {\ + 'RETURNCODE': '1',\ + 'SIP': [{\ + 'ENABLE': '10',\ + 'PRIORITIZE_APP': '1',\ + 'REGISTER_URL': '192.168.178.1',\ + 'REGISTER_USER': 'xxxxx',\ + 'REGISTER_PASSWORD': 'yyyyy',\ + 'AUTOCALL_MOTIONSENSOR_URL': 'motion-url',\ + 'AUTOCALL_DOORBELL_URL': 'doorbell-url',\ + 'SPK_VOLUME': '70',\ + 'MIC_VOLUME': '33',\ + 'DTMF': '1',\ + 'relais:1': '0',\ + 'relais:2': '1',\ + 'LIGHT_PASSCODE': 'light-passcode',\ + 'INCOMING_CALL_ENABLE': '0',\ + 'INCOMING_CALL_USER': 'abcde',\ + 'ANC': '1',\ + 'LASTERRORCODE': '901',\ + 'LASTERRORTEXT': 'OK',\ + 'RING_TIME_LIMIT': '60',\ + 'CALL_TIME_LIMIT': '180'\ + }]\ + }\ + }\ + """; //@formatter:on @Test diff --git a/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/DraytonWiserBindingConstants.java b/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/DraytonWiserBindingConstants.java index 4443576fb..186a1486d 100644 --- a/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/DraytonWiserBindingConstants.java +++ b/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/DraytonWiserBindingConstants.java @@ -12,9 +12,6 @@ */ package org.openhab.binding.draytonwiser.internal; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -109,9 +106,8 @@ public class DraytonWiserBindingConstants { public static final String CHANNEL_SMARTPLUG_INSTANTANEOUS_POWER = "plugInstantaneousPower"; public static final String CHANNEL_SMARTPLUG_ENERGY_DELIVERED = "plugEnergyDelivered"; - public static final Set SUPPORTED_THING_TYPES_UIDS = Collections - .unmodifiableSet(new HashSet<>(Arrays.asList(THING_TYPE_CONTROLLER, THING_TYPE_ROOM, THING_TYPE_ROOMSTAT, - THING_TYPE_BRIDGE, THING_TYPE_ITRV, THING_TYPE_HOTWATER, THING_TYPE_SMARTPLUG))); + public static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_CONTROLLER, THING_TYPE_ROOM, + THING_TYPE_ROOMSTAT, THING_TYPE_BRIDGE, THING_TYPE_ITRV, THING_TYPE_HOTWATER, THING_TYPE_SMARTPLUG); // Lookups from text representations to useful values diff --git a/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/discovery/DraytonWiserDiscoveryService.java b/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/discovery/DraytonWiserDiscoveryService.java index 260799212..0f32dcf8f 100644 --- a/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/discovery/DraytonWiserDiscoveryService.java +++ b/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/discovery/DraytonWiserDiscoveryService.java @@ -202,8 +202,8 @@ public class DraytonWiserDiscoveryService extends AbstractDiscoveryService @Override public void setThingHandler(@Nullable final ThingHandler handler) { - if (handler instanceof HeatHubHandler) { - bridgeHandler = (HeatHubHandler) handler; + if (handler instanceof HeatHubHandler hubHandler) { + bridgeHandler = hubHandler; bridgeUID = handler.getThing().getUID(); } else { bridgeHandler = null; diff --git a/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/discovery/DraytonWiserMDNSDiscoveryParticipant.java b/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/discovery/DraytonWiserMDNSDiscoveryParticipant.java index 8cd56bce2..720f34189 100644 --- a/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/discovery/DraytonWiserMDNSDiscoveryParticipant.java +++ b/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/discovery/DraytonWiserMDNSDiscoveryParticipant.java @@ -15,7 +15,6 @@ package org.openhab.binding.draytonwiser.internal.discovery; import static org.openhab.binding.draytonwiser.internal.DraytonWiserBindingConstants.*; import java.net.InetAddress; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -50,7 +49,7 @@ public class DraytonWiserMDNSDiscoveryParticipant implements MDNSDiscoveryPartic @Override public Set getSupportedThingTypeUIDs() { - return Collections.singleton(THING_TYPE_BRIDGE); + return Set.of(THING_TYPE_BRIDGE); } @Override diff --git a/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/handler/HeatHubHandler.java b/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/handler/HeatHubHandler.java index e5e845147..cd9a4bd7a 100644 --- a/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/handler/HeatHubHandler.java +++ b/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/handler/HeatHubHandler.java @@ -13,8 +13,8 @@ package org.openhab.binding.draytonwiser.internal.handler; import java.util.Collection; -import java.util.Collections; import java.util.Map; +import java.util.Set; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -71,7 +71,7 @@ public class HeatHubHandler extends BaseBridgeHandler { @Override public Collection> getServices() { - return Collections.singleton(DraytonWiserDiscoveryService.class); + return Set.of(DraytonWiserDiscoveryService.class); } public void setDiscoveryService(final DraytonWiserRefreshListener discoveryService) { diff --git a/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/handler/RoomHandler.java b/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/handler/RoomHandler.java index 3885d8e5b..2414ee0d8 100644 --- a/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/handler/RoomHandler.java +++ b/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/handler/RoomHandler.java @@ -59,8 +59,8 @@ public class RoomHandler extends DraytonWiserThingHandler { protected void handleCommand(final String channelId, final Command command) throws DraytonWiserApiException { switch (channelId) { case CHANNEL_CURRENT_SETPOINT: - if (command instanceof QuantityType) { - setSetPoint((QuantityType) command); + if (command instanceof QuantityType quantityCommand) { + setSetPoint(quantityCommand); } break; case CHANNEL_MANUAL_MODE_STATE: @@ -69,8 +69,8 @@ public class RoomHandler extends DraytonWiserThingHandler { } break; case CHANNEL_ROOM_BOOST_DURATION: - if (command instanceof DecimalType) { - setBoostDuration(Math.round((((DecimalType) command).floatValue() * 60))); + if (command instanceof DecimalType decimalCommand) { + setBoostDuration(Math.round((decimalCommand.floatValue() * 60))); } break; case CHANNEL_ROOM_WINDOW_STATE_DETECTION: diff --git a/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/DSCAlarmMessage.java b/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/DSCAlarmMessage.java index 902ac1b93..52780beb8 100644 --- a/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/DSCAlarmMessage.java +++ b/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/DSCAlarmMessage.java @@ -233,15 +233,15 @@ public class DSCAlarmMessage { case UserClosing: /* 700 */ user = message.substring(4); name = name.concat(": " + user); - description = codeReceived + ": Partition " + String.valueOf(partition) - + " has been armed by user " + user + "."; + description = codeReceived + ": Partition " + partition + " has been armed by user " + user + + "."; messageType = DSCAlarmMessageType.PARTITION_EVENT; break; case UserOpening: /* 750 */ user = message.substring(4); name = name.concat(": " + user); - description = codeReceived + ": Partition " + String.valueOf(partition) - + " has been disarmed by user " + user + "."; + description = codeReceived + ": Partition " + partition + " has been disarmed by user " + user + + "."; messageType = DSCAlarmMessageType.PARTITION_EVENT; break; diff --git a/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/discovery/DSCAlarmDiscoveryService.java b/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/discovery/DSCAlarmDiscoveryService.java index 4b4a3e8d3..dc9fb4427 100644 --- a/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/discovery/DSCAlarmDiscoveryService.java +++ b/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/discovery/DSCAlarmDiscoveryService.java @@ -97,8 +97,8 @@ public class DSCAlarmDiscoveryService extends AbstractDiscoveryService { break; case PARTITION: if (partitionNumber >= 1 && partitionNumber <= 8) { - thingID = "partition" + String.valueOf(partitionNumber); - thingLabel = "Partition " + String.valueOf(partitionNumber); + thingID = "partition" + partitionNumber; + thingLabel = "Partition " + partitionNumber; properties = new HashMap<>(0); thingUID = new ThingUID(DSCAlarmBindingConstants.PARTITION_THING_TYPE, bridge.getUID(), thingID); properties.put(DSCAlarmPartitionConfiguration.PARTITION_NUMBER, partitionNumber); @@ -107,8 +107,8 @@ public class DSCAlarmDiscoveryService extends AbstractDiscoveryService { break; case ZONE: if (zoneNumber >= 1 && zoneNumber <= 64) { - thingID = "zone" + String.valueOf(zoneNumber); - thingLabel = "Zone " + String.valueOf(zoneNumber); + thingID = "zone" + zoneNumber; + thingLabel = "Zone " + zoneNumber; properties = new HashMap<>(0); thingUID = new ThingUID(DSCAlarmBindingConstants.ZONE_THING_TYPE, bridge.getUID(), thingID); properties.put(DSCAlarmZoneConfiguration.ZONE_NUMBER, zoneNumber); diff --git a/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/discovery/EnvisalinkBridgeDiscovery.java b/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/discovery/EnvisalinkBridgeDiscovery.java index 1cede2791..de26b1e88 100644 --- a/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/discovery/EnvisalinkBridgeDiscovery.java +++ b/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/discovery/EnvisalinkBridgeDiscovery.java @@ -136,7 +136,7 @@ public class EnvisalinkBridgeDiscovery { * @return */ private long convertIPToNumber(String ipAddress) { - String octets[] = ipAddress.split("\\."); + String[] octets = ipAddress.split("\\."); if (octets.length != 4) { throw new IllegalArgumentException("Invalid IP address: " + ipAddress); diff --git a/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/handler/PanelThingHandler.java b/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/handler/PanelThingHandler.java index c719f9afa..b677d2bb6 100644 --- a/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/handler/PanelThingHandler.java +++ b/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/handler/PanelThingHandler.java @@ -202,17 +202,17 @@ public class PanelThingHandler extends DSCAlarmBaseThingHandler { updateState(channelUID, new StringType(String.valueOf(-1))); break; case PANEL_TIME_STAMP: - if (command instanceof OnOffType) { + if (command instanceof OnOffType onOffCommand) { cmd = command == OnOffType.ON ? 1 : 0; dscAlarmBridgeHandler.sendCommand(DSCAlarmCode.TimeStampControl, String.valueOf(cmd)); - updateState(channelUID, (OnOffType) command); + updateState(channelUID, onOffCommand); } break; case PANEL_TIME_BROADCAST: - if (command instanceof OnOffType) { + if (command instanceof OnOffType onOffCommand) { cmd = command == OnOffType.ON ? 1 : 0; dscAlarmBridgeHandler.sendCommand(DSCAlarmCode.TimeDateBroadcastControl, String.valueOf(cmd)); - updateState(channelUID, (OnOffType) command); + updateState(channelUID, onOffCommand); } break; default: diff --git a/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/handler/ZoneThingHandler.java b/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/handler/ZoneThingHandler.java index 42dd1a9ba..d2dd43a68 100644 --- a/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/handler/ZoneThingHandler.java +++ b/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/handler/ZoneThingHandler.java @@ -107,7 +107,7 @@ public class ZoneThingHandler extends DSCAlarmBaseThingHandler { if (dscAlarmBridgeHandler != null && dscAlarmBridgeHandler.isConnected() && channelUID.getId().equals(ZONE_BYPASS_MODE)) { - String data = String.valueOf(getPartitionNumber()) + "*1" + String.format("%02d", getZoneNumber()) + "#"; + String data = getPartitionNumber() + "*1" + String.format("%02d", getZoneNumber()) + "#"; dscAlarmBridgeHandler.sendCommand(DSCAlarmCode.KeySequence, data); } diff --git a/bundles/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/OBISIdentifier.java b/bundles/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/OBISIdentifier.java index 8c7c84435..415bd9e30 100644 --- a/bundles/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/OBISIdentifier.java +++ b/bundles/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/OBISIdentifier.java @@ -194,8 +194,8 @@ public class OBISIdentifier { @Override public boolean equals(@Nullable final Object other) { OBISIdentifier o; - if (other != null && other instanceof OBISIdentifier) { - o = (OBISIdentifier) other; + if (other != null && other instanceof OBISIdentifier identifier) { + o = identifier; } else { return false; } diff --git a/bundles/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/discovery/DSMRBridgeDiscoveryService.java b/bundles/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/discovery/DSMRBridgeDiscoveryService.java index abc422d94..64c760644 100644 --- a/bundles/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/discovery/DSMRBridgeDiscoveryService.java +++ b/bundles/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/discovery/DSMRBridgeDiscoveryService.java @@ -125,9 +125,11 @@ public class DSMRBridgeDiscoveryService extends DSMRDiscoveryService implements logger.trace("Possible port to check:{}, owned:{} by:{}", currentScannedPortName, portIdentifier.isCurrentlyOwned(), portIdentifier.getCurrentOwner()); if (DSMR_PORT_NAME.equals(portIdentifier.getCurrentOwner())) { - logger.debug("The port {} is owned by this binding. If no DSMR meters will be found it " - + "might indicate the port is locked by an older instance of this binding. " - + "Restart the system to unlock the port.", currentScannedPortName); + logger.debug(""" + The port {} is owned by this binding. If no DSMR meters will be found it \ + might indicate the port is locked by an older instance of this binding. \ + Restart the system to unlock the port.\ + """, currentScannedPortName); } } else { logger.debug("Start discovery on serial port: {}", currentScannedPortName); diff --git a/bundles/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/discovery/DSMRMeterDiscoveryService.java b/bundles/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/discovery/DSMRMeterDiscoveryService.java index 7717699c0..0db8a986f 100644 --- a/bundles/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/discovery/DSMRMeterDiscoveryService.java +++ b/bundles/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/discovery/DSMRMeterDiscoveryService.java @@ -76,8 +76,8 @@ public class DSMRMeterDiscoveryService extends DSMRDiscoveryService implements P @Override public void setThingHandler(final ThingHandler handler) { - if (handler instanceof DSMRBridgeHandler) { - dsmrBridgeHandler = (DSMRBridgeHandler) handler; + if (handler instanceof DSMRBridgeHandler bridgeHandler) { + dsmrBridgeHandler = bridgeHandler; } } @@ -124,14 +124,18 @@ public class DSMRMeterDiscoveryService extends DSMRDiscoveryService implements P reportUnregisteredMeters(); } else { reportUnrecognizedCosemObjects(list); - logger.info("There are unrecognized cosem values in the data received from the meter," - + " which means some meters might not be detected. Please report your raw data as reference: {}", - telegram.getRawTelegram()); + logger.info(""" + There are unrecognized cosem values in the data received from the meter,\ + which means some meters might not be detected. Please report your raw data as reference: {}\ + """, telegram.getRawTelegram()); } } if (!telegram.getUnknownCosemObjects().isEmpty()) { - logger.info("There are unrecognized cosem values in the data received from the meter," - + " which means you have values that can't be read by a channel: {}. Please report them and your raw data as reference: {}", + logger.info( + """ + There are unrecognized cosem values in the data received from the meter,\ + which means you have values that can't be read by a channel: {}. Please report them and your raw data as reference: {}\ + """, telegram.getUnknownCosemObjects().stream() .map(e -> String.format("obis id:%s, value:%s", e.getKey(), e.getValue())) .collect(Collectors.joining(", ")), @@ -196,10 +200,10 @@ public class DSMRMeterDiscoveryService extends DSMRDiscoveryService implements P */ protected void reportConfigurationValidationResults(final List invalidConfigured, final List unconfiguredMeters) { - logger.info( - "Possible incorrect meters configured. These are configured: {}." - + "But the following unconfigured meters are found in the data received from the meter: {}", - invalidConfigured.stream().map(m -> m.name()).collect(Collectors.joining(", ")), + logger.info(""" + Possible incorrect meters configured. These are configured: {}.\ + But the following unconfigured meters are found in the data received from the meter: {}\ + """, invalidConfigured.stream().map(m -> m.name()).collect(Collectors.joining(", ")), unconfiguredMeters.stream().map(m -> m.name()).collect(Collectors.joining(", "))); } } diff --git a/bundles/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/meter/DSMRMeter.java b/bundles/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/meter/DSMRMeter.java index 179cc3a1c..5025351fb 100644 --- a/bundles/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/meter/DSMRMeter.java +++ b/bundles/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/meter/DSMRMeter.java @@ -73,12 +73,11 @@ public class DSMRMeter { */ public List filterMeterValues(List cosemObjects, int channel) { logger.trace("supported identifiers: {}, searching for objects {}", supportedIdentifiers, cosemObjects); - List filteredValues = cosemObjects.stream() + return cosemObjects.stream() .filter(cosemObject -> (DSMRMeterConstants.UNKNOWN_CHANNEL == channel || cosemObject.getObisIdentifier().getChannel() == channel) && supportedIdentifiers.contains(cosemObject.getObisIdentifier().getReducedOBISIdentifier())) .collect(Collectors.toList()); - return filteredValues; } /** diff --git a/bundles/org.openhab.binding.dsmr/src/test/java/org/openhab/binding/dsmr/internal/device/p1telegram/P1TelegramParserTest.java b/bundles/org.openhab.binding.dsmr/src/test/java/org/openhab/binding/dsmr/internal/device/p1telegram/P1TelegramParserTest.java index 818fcab56..1f0f7eecc 100644 --- a/bundles/org.openhab.binding.dsmr/src/test/java/org/openhab/binding/dsmr/internal/device/p1telegram/P1TelegramParserTest.java +++ b/bundles/org.openhab.binding.dsmr/src/test/java/org/openhab/binding/dsmr/internal/device/p1telegram/P1TelegramParserTest.java @@ -31,7 +31,7 @@ import org.openhab.binding.dsmr.internal.TelegramReaderUtil; public class P1TelegramParserTest { // @formatter:off - public static final List data() { + public static List data() { return Arrays.asList(new Object[][] { { "ace4000", 59, 0}, { "dsmr_40", 39, 0}, diff --git a/bundles/org.openhab.binding.dsmr/src/test/java/org/openhab/binding/dsmr/internal/discovery/DSMRMeterDetectorTest.java b/bundles/org.openhab.binding.dsmr/src/test/java/org/openhab/binding/dsmr/internal/discovery/DSMRMeterDetectorTest.java index 558ac6c53..60aa984d0 100644 --- a/bundles/org.openhab.binding.dsmr/src/test/java/org/openhab/binding/dsmr/internal/discovery/DSMRMeterDetectorTest.java +++ b/bundles/org.openhab.binding.dsmr/src/test/java/org/openhab/binding/dsmr/internal/discovery/DSMRMeterDetectorTest.java @@ -54,7 +54,7 @@ import org.openhab.binding.dsmr.internal.meter.DSMRMeterType; public class DSMRMeterDetectorTest { // @formatter:off - public static final List data() { + public static List data() { return Arrays.asList(new Object[][] { { "ace4000", EnumSet.of(ELECTRICITY_ACE4000, GAS_ACE4000)}, { "dsmr_40", EnumSet.of(DEVICE_V4, ELECTRICITY_V4_2, M3_V5_0)}, diff --git a/bundles/org.openhab.binding.dwdpollenflug/src/main/java/org/openhab/binding/dwdpollenflug/internal/handler/DWDPollenflugBridgeHandler.java b/bundles/org.openhab.binding.dwdpollenflug/src/main/java/org/openhab/binding/dwdpollenflug/internal/handler/DWDPollenflugBridgeHandler.java index 1e1fbda0c..a898083d4 100644 --- a/bundles/org.openhab.binding.dwdpollenflug/src/main/java/org/openhab/binding/dwdpollenflug/internal/handler/DWDPollenflugBridgeHandler.java +++ b/bundles/org.openhab.binding.dwdpollenflug/src/main/java/org/openhab/binding/dwdpollenflug/internal/handler/DWDPollenflugBridgeHandler.java @@ -170,9 +170,8 @@ public class DWDPollenflugBridgeHandler extends BaseBridgeHandler { @Override public void childHandlerInitialized(ThingHandler childHandler, Thing childThing) { - if (childHandler instanceof DWDPollenflugRegionHandler) { + if (childHandler instanceof DWDPollenflugRegionHandler regionListener) { logger.debug("Register region listener."); - final DWDPollenflugRegionHandler regionListener = (DWDPollenflugRegionHandler) childHandler; if (regionListeners.add(regionListener)) { final DWDPollenflug localPollenflug = pollenflug; if (localPollenflug != null) { @@ -187,9 +186,9 @@ public class DWDPollenflugBridgeHandler extends BaseBridgeHandler { @Override public void childHandlerDisposed(ThingHandler childHandler, Thing childThing) { - if (childHandler instanceof DWDPollenflugRegionHandler) { + if (childHandler instanceof DWDPollenflugRegionHandler handler) { logger.debug("Unregister region listener."); - if (!regionListeners.remove((DWDPollenflugRegionHandler) childHandler)) { + if (!regionListeners.remove(handler)) { logger.warn("Tried to remove listener {} but it was not registered. This is probably an error.", childHandler); } diff --git a/bundles/org.openhab.binding.dwdpollenflug/src/main/java/org/openhab/binding/dwdpollenflug/internal/handler/DWDPollenflugRegionHandler.java b/bundles/org.openhab.binding.dwdpollenflug/src/main/java/org/openhab/binding/dwdpollenflug/internal/handler/DWDPollenflugRegionHandler.java index 351c20a9a..0b131c268 100644 --- a/bundles/org.openhab.binding.dwdpollenflug/src/main/java/org/openhab/binding/dwdpollenflug/internal/handler/DWDPollenflugRegionHandler.java +++ b/bundles/org.openhab.binding.dwdpollenflug/src/main/java/org/openhab/binding/dwdpollenflug/internal/handler/DWDPollenflugRegionHandler.java @@ -66,8 +66,7 @@ public class DWDPollenflugRegionHandler extends BaseThingHandler { Bridge bridge = getBridge(); if (bridge != null) { ThingHandler handler = bridge.getHandler(); - if (handler instanceof DWDPollenflugBridgeHandler) { - DWDPollenflugBridgeHandler bridgeHandler = (DWDPollenflugBridgeHandler) handler; + if (handler instanceof DWDPollenflugBridgeHandler bridgeHandler) { return bridgeHandler; } } diff --git a/bundles/org.openhab.binding.dwdunwetter/src/main/java/org/openhab/binding/dwdunwetter/internal/factory/DwdUnwetterHandlerFactory.java b/bundles/org.openhab.binding.dwdunwetter/src/main/java/org/openhab/binding/dwdunwetter/internal/factory/DwdUnwetterHandlerFactory.java index 24bd9b099..3c9fa622c 100644 --- a/bundles/org.openhab.binding.dwdunwetter/src/main/java/org/openhab/binding/dwdunwetter/internal/factory/DwdUnwetterHandlerFactory.java +++ b/bundles/org.openhab.binding.dwdunwetter/src/main/java/org/openhab/binding/dwdunwetter/internal/factory/DwdUnwetterHandlerFactory.java @@ -14,7 +14,6 @@ package org.openhab.binding.dwdunwetter.internal.factory; import static org.openhab.binding.dwdunwetter.internal.DwdUnwetterBindingConstants.THING_TYPE_WARNINGS; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -36,7 +35,7 @@ import org.osgi.service.component.annotations.Component; @Component(configurationPid = "binding.dwdunwetter", service = ThingHandlerFactory.class) public class DwdUnwetterHandlerFactory extends BaseThingHandlerFactory { - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_WARNINGS); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_WARNINGS); @Override public boolean supportsThingType(ThingTypeUID thingTypeUID) { diff --git a/bundles/org.openhab.binding.dwdunwetter/src/test/java/org/openhab/binding/dwdunwetter/internal/handler/DwdUnwetterHandlerTest.java b/bundles/org.openhab.binding.dwdunwetter/src/test/java/org/openhab/binding/dwdunwetter/internal/handler/DwdUnwetterHandlerTest.java index 9a57d99ea..148630b4c 100644 --- a/bundles/org.openhab.binding.dwdunwetter/src/test/java/org/openhab/binding/dwdunwetter/internal/handler/DwdUnwetterHandlerTest.java +++ b/bundles/org.openhab.binding.dwdunwetter/src/test/java/org/openhab/binding/dwdunwetter/internal/handler/DwdUnwetterHandlerTest.java @@ -137,7 +137,7 @@ public class DwdUnwetterHandlerTest extends JavaTest { private String getLabel(NodeList nodeList) { for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); - if (node.getNodeName().equals("label")) { + if ("label".equals(node.getNodeName())) { return node.getTextContent(); } } diff --git a/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/Utils.java b/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/Utils.java index 4dbe0311e..53fcd3932 100644 --- a/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/Utils.java +++ b/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/Utils.java @@ -61,8 +61,7 @@ public final class Utils { formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssX"); } LOGGER.trace("parsing: {}", date); - ZonedDateTime zdt = ZonedDateTime.parse(date, formatter); - return zdt; + return ZonedDateTime.parse(date, formatter); } /** diff --git a/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/command/AbstractCommand.java b/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/command/AbstractCommand.java index 42cfb43d4..faaa252b4 100644 --- a/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/command/AbstractCommand.java +++ b/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/command/AbstractCommand.java @@ -52,14 +52,14 @@ import com.google.gson.ToNumberPolicy; @NonNullByDefault public abstract class AbstractCommand extends BufferingResponseListener implements EaseeCommand { - public static enum RetryOnFailure { + public enum RetryOnFailure { YES, - NO; + NO } - public static enum ProcessFailureResponse { + public enum ProcessFailureResponse { YES, - NO; + NO } /** diff --git a/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/command/AbstractWriteCommand.java b/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/command/AbstractWriteCommand.java index 93bfed6a9..a66644441 100644 --- a/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/command/AbstractWriteCommand.java +++ b/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/command/AbstractWriteCommand.java @@ -60,9 +60,9 @@ public abstract class AbstractWriteCommand extends AbstractCommand { * @return value as String without unit. */ protected String getCommandValue() { - if (command instanceof QuantityType) { + if (command instanceof QuantityType quantityCommand) { // this is necessary because we must not send the unit to the backend - return String.valueOf(((QuantityType) command).doubleValue()); + return String.valueOf(quantityCommand.doubleValue()); } else if (command instanceof OnOffType) { // this is necessary because we must send booleans and not ON/OFF to the backend return String.valueOf(command.equals(OnOffType.ON)); diff --git a/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/discovery/EaseeSiteDiscoveryService.java b/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/discovery/EaseeSiteDiscoveryService.java index 4065f71ef..db7ee8676 100644 --- a/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/discovery/EaseeSiteDiscoveryService.java +++ b/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/discovery/EaseeSiteDiscoveryService.java @@ -57,8 +57,8 @@ public class EaseeSiteDiscoveryService extends AbstractDiscoveryService implemen @Override public void setThingHandler(ThingHandler handler) { - if (handler instanceof EaseeSiteHandler) { - this.bridgeHandler = (EaseeSiteHandler) handler; + if (handler instanceof EaseeSiteHandler siteHandler) { + this.bridgeHandler = siteHandler; this.bridgeHandler.setDiscoveryService(this); } } diff --git a/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/handler/EaseeSiteHandler.java b/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/handler/EaseeSiteHandler.java index ef007fe58..58adde308 100644 --- a/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/handler/EaseeSiteHandler.java +++ b/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/handler/EaseeSiteHandler.java @@ -15,9 +15,9 @@ package org.openhab.binding.easee.internal.handler; import static org.openhab.binding.easee.internal.EaseeBindingConstants.*; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.Set; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; @@ -181,7 +181,7 @@ public class EaseeSiteHandler extends BaseBridgeHandler implements EaseeBridgeHa @Override public Collection> getServices() { - return Collections.singleton(EaseeSiteDiscoveryService.class); + return Set.of(EaseeSiteDiscoveryService.class); } public void setDiscoveryService(EaseeSiteDiscoveryService discoveryService) { diff --git a/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/handler/EaseeThingHandler.java b/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/handler/EaseeThingHandler.java index 7b9d46584..3f7edf8a1 100644 --- a/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/handler/EaseeThingHandler.java +++ b/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/handler/EaseeThingHandler.java @@ -130,7 +130,6 @@ public interface EaseeThingHandler extends ThingHandler, ChannelProvider { default @Nullable Channel getChannel(String groupId, String channelId) { ThingUID thingUID = this.getThing().getUID(); ChannelGroupUID channelGroupUID = new ChannelGroupUID(thingUID, groupId); - Channel channel = getThing().getChannel(new ChannelUID(channelGroupUID, channelId)); - return channel; + return getThing().getChannel(new ChannelUID(channelGroupUID, channelId)); } } diff --git a/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/model/CustomResponseTransformer.java b/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/model/CustomResponseTransformer.java index ebea21f43..de6ab958a 100644 --- a/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/model/CustomResponseTransformer.java +++ b/bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/model/CustomResponseTransformer.java @@ -122,9 +122,9 @@ class CustomResponseTransformer { String phase2 = Utils.getAsString(rawData, channelPhase2); String phase3 = Utils.getAsString(rawData, channelPhase3); if (channel != null && phase1 != null && phase2 != null && phase3 != null) { - phase1 = phase1.replaceAll("\\.0", ""); - phase2 = phase2.replaceAll("\\.0", ""); - phase3 = phase3.replaceAll("\\.0", ""); + phase1 = phase1.replace(".0", ""); + phase2 = phase2.replace(".0", ""); + phase3 = phase3.replace(".0", ""); result.put(channel, new StringType(phase1 + ";" + phase2 + ";" + phase3)); } } diff --git a/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetClass.java b/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetClass.java index 05f39debc..2d6822f43 100644 --- a/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetClass.java +++ b/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetClass.java @@ -70,6 +70,7 @@ public enum EchonetClass { return classProperties; } + @Override public String toString() { return name() + "{" + "groupCode=0x" + Integer.toHexString(groupCode) + ", classCode=0x" + Integer.toHexString(0xFF & classCode) + '}'; diff --git a/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetDevice.java b/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetDevice.java index 3091cdb98..41dfd62be 100644 --- a/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetDevice.java +++ b/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetDevice.java @@ -48,6 +48,7 @@ public class EchonetDevice extends EchonetObject { this.listener = listener; } + @Override public void applyProperty(InstanceKey sourceInstanceKey, Esv esv, final int epcCode, final int pdc, final ByteBuffer edt) { final Epc epc = Epc.lookup(instanceKey().klass.groupCode(), instanceKey().klass.classCode(), epcCode); @@ -112,6 +113,7 @@ public class EchonetDevice extends EchonetObject { return identificationNumber.toString(); } + @Override public boolean buildUpdateMessage(final EchonetMessageBuilder messageBuilder, final ShortSupplier tidSupplier, final long nowMs, InstanceKey managementControllerKey) { if (pendingSets.isEmpty()) { @@ -141,6 +143,7 @@ public class EchonetDevice extends EchonetObject { return true; } + @Override public void update(String channelId, State state) { final Epc epc = epcByChannelId.get(channelId); if (null == epc) { @@ -156,12 +159,14 @@ public class EchonetDevice extends EchonetObject { listener.onRemoved(); } + @Override public void checkTimeouts() { if (EchonetLiteBindingConstants.OFFLINE_TIMEOUT_COUNT <= inflightGetRequest.timeoutCount()) { listener.onOffline(); } } + @Override public void refreshAll(long nowMs) { final EchonetPropertyMap getPropertyMap = this.getPropertyMap; if (lastPollMs + pollIntervalMs <= nowMs && null != getPropertyMap) { diff --git a/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetDiscoveryService.java b/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetDiscoveryService.java index 5a1f20a1e..aeceb5584 100644 --- a/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetDiscoveryService.java +++ b/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetDiscoveryService.java @@ -100,8 +100,8 @@ public class EchonetDiscoveryService extends AbstractDiscoveryService @Override public void setThingHandler(ThingHandler thingHandler) { - if (thingHandler instanceof EchonetLiteBridgeHandler) { - this.bridgeHandler = (EchonetLiteBridgeHandler) thingHandler; + if (thingHandler instanceof EchonetLiteBridgeHandler bridgeHandler) { + this.bridgeHandler = bridgeHandler; } } diff --git a/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetLiteBridgeHandler.java b/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetLiteBridgeHandler.java index b526f6d04..8fb51e7eb 100644 --- a/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetLiteBridgeHandler.java +++ b/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetLiteBridgeHandler.java @@ -19,8 +19,8 @@ import java.net.InetSocketAddress; import java.net.SocketAddress; import java.nio.ByteBuffer; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.TimeUnit; @@ -90,9 +90,8 @@ public class EchonetLiteBridgeHandler extends BaseBridgeHandler { private void newDeviceInternal(final NewDeviceMessage message) { final EchonetObject echonetObject = devicesByKey.get(message.instanceKey); if (null != echonetObject) { - if (echonetObject instanceof EchonetDevice) { + if (echonetObject instanceof EchonetDevice device) { logger.debug("Update item: {} already discovered", message.instanceKey); - EchonetDevice device = (EchonetDevice) echonetObject; device.setTimeouts(message.pollIntervalMs, message.retryTimeoutMs); device.setListener(message.echonetDeviceListener); } else { @@ -198,18 +197,18 @@ public class EchonetLiteBridgeHandler extends BaseBridgeHandler { Message message; while (null != (message = requestsPoll())) { logger.debug("Received request: {}", message); - if (message instanceof NewDeviceMessage) { - newDeviceInternal((NewDeviceMessage) message); - } else if (message instanceof RefreshMessage) { - refreshDeviceInternal((RefreshMessage) message); - } else if (message instanceof RemoveDevice) { - removeDeviceInternal((RemoveDevice) message); - } else if (message instanceof UpdateDevice) { - updateDeviceInternal((UpdateDevice) message); - } else if (message instanceof StartDiscoveryMessage) { - startDiscoveryInternal((StartDiscoveryMessage) message); - } else if (message instanceof StopDiscoveryMessage) { - stopDiscoveryInternal((StopDiscoveryMessage) message); + if (message instanceof NewDeviceMessage deviceMessage) { + newDeviceInternal(deviceMessage); + } else if (message instanceof RefreshMessage refreshMessage) { + refreshDeviceInternal(refreshMessage); + } else if (message instanceof RemoveDevice device) { + removeDeviceInternal(device); + } else if (message instanceof UpdateDevice device) { + updateDeviceInternal(device); + } else if (message instanceof StartDiscoveryMessage discoveryMessage) { + startDiscoveryInternal(discoveryMessage); + } else if (message instanceof StopDiscoveryMessage discoveryMessage) { + stopDiscoveryInternal(discoveryMessage); } } } @@ -319,7 +318,7 @@ public class EchonetLiteBridgeHandler extends BaseBridgeHandler { @Override public Collection> getServices() { - return Collections.singletonList(EchonetDiscoveryService.class); + return List.of(EchonetDiscoveryService.class); } private abstract static class Message { @@ -390,6 +389,7 @@ public class EchonetLiteBridgeHandler extends BaseBridgeHandler { this.state = state; } + @Override public String toString() { return "UpdateDevice{" + "instanceKey=" + instanceKey + ", channelId='" + channelId + '\'' + ", state=" + state + "} " + super.toString(); diff --git a/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetLiteHandler.java b/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetLiteHandler.java index 571748dd9..acef67b57 100644 --- a/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetLiteHandler.java +++ b/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetLiteHandler.java @@ -88,10 +88,10 @@ public class EchonetLiteHandler extends BaseThingHandler implements EchonetDevic } else { updateState(channelUID, currentState); } - } else if (command instanceof State) { + } else if (command instanceof State stateCommand) { logger.debug("Updating: {} to {}", channelUID, command); - handler.updateDevice(requireNonNull(instanceKey), channelUID.getId(), (State) command); + handler.updateDevice(requireNonNull(instanceKey), channelUID.getId(), stateCommand); } } @@ -124,6 +124,7 @@ public class EchonetLiteHandler extends BaseThingHandler implements EchonetDevic } } + @Override public void handleRemoval() { @Nullable final EchonetLiteBridgeHandler bridgeHandler = bridgeHandler(); @@ -136,6 +137,7 @@ public class EchonetLiteHandler extends BaseThingHandler implements EchonetDevic bridgeHandler.removeDevice(requireNonNull(instanceKey)); } + @Override public void onInitialised(String identifier, InstanceKey instanceKey, Map channelIdAndType) { logger.debug("Initialised Channels: {}", channelIdAndType); @@ -167,6 +169,7 @@ public class EchonetLiteHandler extends BaseThingHandler implements EchonetDevic updateStatus(ThingStatus.ONLINE); } + @Override public void onUpdated(final String channelId, final State value) { stateByChannelId.put(channelId, value); @@ -176,10 +179,12 @@ public class EchonetLiteHandler extends BaseThingHandler implements EchonetDevic updateState(channelId, value); } + @Override public void onRemoved() { updateStatus(ThingStatus.REMOVED); } + @Override public void onOffline() { if (ThingStatus.OFFLINE != getThing().getStatus()) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR); diff --git a/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetObject.java b/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetObject.java index c479bbf64..0439ca2dc 100644 --- a/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetObject.java +++ b/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetObject.java @@ -96,6 +96,7 @@ public abstract class EchonetObject { public void refreshAll(long nowMs) { } + @Override public String toString() { return "ItemBase{" + "instanceKey=" + instanceKey + ", pendingProperties=" + pendingGets + '}'; } diff --git a/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetPropertyMap.java b/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetPropertyMap.java index 54539204c..3bbda8ab8 100644 --- a/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetPropertyMap.java +++ b/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/EchonetPropertyMap.java @@ -86,6 +86,7 @@ public class EchonetPropertyMap { return properties; } + @Override public String toString() { return "EnPropertyMap{" + "propertyMap=" + HexUtil.hex(propertyMap) + '}'; } diff --git a/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/Epc.java b/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/Epc.java index 04cd6767b..224587457 100644 --- a/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/Epc.java +++ b/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/Epc.java @@ -234,16 +234,19 @@ public interface Epc { this(code, stateCodec, stateCodec); } + @Override public int code() { return code; } @Nullable + @Override public StateDecode decoder() { return stateDecode; } @Nullable + @Override public StateEncode encoder() { return stateEncode; } @@ -363,16 +366,19 @@ public interface Epc { this(code, stateCodec, stateCodec); } + @Override public int code() { return code; } @Nullable + @Override public StateDecode decoder() { return stateDecode; } @Nullable + @Override public StateEncode encoder() { return stateEncode; } @@ -389,6 +395,7 @@ public interface Epc { this.code = code; } + @Override public int code() { return code; } @@ -421,16 +428,19 @@ public interface Epc { this(code, stateCodec, stateCodec); } + @Override public int code() { return code; } @Nullable + @Override public StateDecode decoder() { return stateDecode; } @Nullable + @Override public StateEncode encoder() { return stateEncode; } @@ -445,6 +455,7 @@ public interface Epc { this.code = code; } + @Override public int code() { return code; } @@ -480,6 +491,7 @@ public interface Epc { this.code = code; } + @Override public int code() { return code; } diff --git a/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/InstanceKey.java b/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/InstanceKey.java index cebb946fa..08abf06d9 100644 --- a/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/InstanceKey.java +++ b/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/InstanceKey.java @@ -36,6 +36,7 @@ public class InstanceKey { this.instance = instance; } + @Override public String toString() { return "InstanceKey{" + "address=" + address + ", klass=" + klass + ", instance=" + instance + '}'; } @@ -45,6 +46,7 @@ public class InstanceKey { + hex(instance); } + @Override public boolean equals(@Nullable final Object o) { if (this == o) { return true; @@ -56,6 +58,7 @@ public class InstanceKey { return instance == that.instance && address.equals(that.address) && klass == that.klass; } + @Override public int hashCode() { return Objects.hash(address, klass, instance); } diff --git a/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/StateCodec.java b/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/StateCodec.java index 44e3fb34d..44f857d13 100644 --- a/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/StateCodec.java +++ b/bundles/org.openhab.binding.echonetlite/src/main/java/org/openhab/binding/echonetlite/internal/StateCodec.java @@ -49,15 +49,18 @@ public interface StateCodec extends StateEncode, StateDecode { this.off = off; } + @Override public State decodeState(final ByteBuffer edt) { return b(on) == edt.get() ? OnOffType.ON : OnOffType.OFF; } + @Override public void encodeState(final State state, final ByteBuffer edt) { final OnOffType onOff = (OnOffType) state; edt.put(onOff == OnOffType.ON ? b(on) : b(off)); } + @Override public String itemType() { return "Switch"; } @@ -67,6 +70,7 @@ public interface StateCodec extends StateEncode, StateDecode { INSTANCE; + @Override public State decodeState(final ByteBuffer edt) { final int pdc = edt.remaining(); if (pdc != 4) { @@ -76,6 +80,7 @@ public interface StateCodec extends StateEncode, StateDecode { return new StringType("" + (char) edt.get(edt.position() + 2)); } + @Override public String itemType() { return "String"; } @@ -85,10 +90,12 @@ public interface StateCodec extends StateEncode, StateDecode { INSTANCE; + @Override public State decodeState(final ByteBuffer edt) { return new StringType(hex(edt, "", "", "", "")); } + @Override public String itemType() { return "String"; } @@ -97,6 +104,7 @@ public interface StateCodec extends StateEncode, StateDecode { enum OperatingTimeDecode implements StateDecode { INSTANCE; + @Override public State decodeState(final ByteBuffer edt) { // Specification isn't explicit about byte order, but seems to be work with testing. edt.order(ByteOrder.BIG_ENDIAN); @@ -127,6 +135,7 @@ public interface StateCodec extends StateEncode, StateDecode { return new QuantityType<>(timeUnit.toSeconds(time), Units.SECOND); } + @Override public String itemType() { return "Number:Time"; } @@ -158,16 +167,19 @@ public interface StateCodec extends StateEncode, StateDecode { } } + @Override public String itemType() { return "String"; } + @Override public State decodeState(final ByteBuffer edt) { final int value = edt.get() & 0xFF; final Option option = optionByValue[value]; return null != option ? option.state : unknown; } + @Override public void encodeState(final State state, final ByteBuffer edt) { final Option option = optionByName.get(state.toFullString()); if (null != option) { @@ -182,15 +194,18 @@ public interface StateCodec extends StateEncode, StateDecode { INSTANCE; + @Override public String itemType() { return "Number"; } + @Override public State decodeState(final ByteBuffer edt) { final int value = edt.get(); // Should expand to typed value (mask excluded) return new DecimalType(value); } + @Override public void encodeState(final State state, final ByteBuffer edt) { edt.put((byte) (((DecimalType) state).intValue())); } @@ -199,15 +214,18 @@ public interface StateCodec extends StateEncode, StateDecode { enum Temperature8bitCodec implements StateCodec { INSTANCE; + @Override public State decodeState(final ByteBuffer edt) { final int value = edt.get(); return new QuantityType<>(value, SIUnits.CELSIUS); } + @Override public String itemType() { return "Number:Temperature"; } + @Override public void encodeState(final State state, final ByteBuffer edt) { final @Nullable QuantityType tempCelsius = ((QuantityType) state).toUnit(SIUnits.CELSIUS); edt.put((byte) (Objects.requireNonNull(tempCelsius).intValue())); diff --git a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/action/EcobeeActions.java b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/action/EcobeeActions.java index 3fa2251c0..1d5f1d765 100644 --- a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/action/EcobeeActions.java +++ b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/action/EcobeeActions.java @@ -69,8 +69,8 @@ public class EcobeeActions implements ThingActions { @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof EcobeeThermostatBridgeHandler) { - this.handler = (EcobeeThermostatBridgeHandler) handler; + if (handler instanceof EcobeeThermostatBridgeHandler bridgeHandler) { + this.handler = bridgeHandler; } } diff --git a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/api/EcobeeAuthState.java b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/api/EcobeeAuthState.java index d50fc820c..252e7e5df 100644 --- a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/api/EcobeeAuthState.java +++ b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/api/EcobeeAuthState.java @@ -39,5 +39,5 @@ enum EcobeeAuthState { /* * This state indicates that the "authorize" and "token" steps were successful. */ - COMPLETE; + COMPLETE } diff --git a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/discovery/EcobeeDiscoveryService.java b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/discovery/EcobeeDiscoveryService.java index 18870310a..5465e62ac 100644 --- a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/discovery/EcobeeDiscoveryService.java +++ b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/discovery/EcobeeDiscoveryService.java @@ -61,8 +61,8 @@ public class EcobeeDiscoveryService extends AbstractDiscoveryService implements @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof EcobeeAccountBridgeHandler) { - this.bridgeHandler = (EcobeeAccountBridgeHandler) handler; + if (handler instanceof EcobeeAccountBridgeHandler accountBridgeHandler) { + this.bridgeHandler = accountBridgeHandler; } } diff --git a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/handler/EcobeeAccountBridgeHandler.java b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/handler/EcobeeAccountBridgeHandler.java index 1d61419d8..57314acd8 100644 --- a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/handler/EcobeeAccountBridgeHandler.java +++ b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/handler/EcobeeAccountBridgeHandler.java @@ -16,7 +16,6 @@ import static org.openhab.binding.ecobee.internal.EcobeeBindingConstants.CONFIG_ import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; @@ -137,7 +136,7 @@ public class EcobeeAccountBridgeHandler extends BaseBridgeHandler { @Override public Collection> getServices() { - return Collections.singleton(EcobeeDiscoveryService.class); + return Set.of(EcobeeDiscoveryService.class); } @Override diff --git a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/handler/EcobeeThermostatBridgeHandler.java b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/handler/EcobeeThermostatBridgeHandler.java index 208672096..91fbfcdc2 100644 --- a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/handler/EcobeeThermostatBridgeHandler.java +++ b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/handler/EcobeeThermostatBridgeHandler.java @@ -16,10 +16,10 @@ import static org.openhab.binding.ecobee.internal.EcobeeBindingConstants.*; import java.lang.reflect.Field; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; @@ -237,9 +237,9 @@ public class EcobeeThermostatBridgeHandler extends BaseBridgeHandler { public boolean actionPerformFunction(AbstractFunction function) { logger.debug("ThermostatBridge: Perform function '{}' on thermostat {}", function.type, thermostatId); SelectionDTO selection = new SelectionDTO(); - selection.setThermostats(Collections.singleton(thermostatId)); + selection.setThermostats(Set.of(thermostatId)); FunctionRequest request = new FunctionRequest(selection); - request.functions = Collections.singletonList(function); + request.functions = List.of(function); EcobeeAccountBridgeHandler handler = getBridgeHandler(); if (handler != null) { return handler.performThermostatFunction(request); @@ -249,7 +249,7 @@ public class EcobeeThermostatBridgeHandler extends BaseBridgeHandler { @Override public Collection> getServices() { - return Collections.singletonList(EcobeeActions.class); + return List.of(EcobeeActions.class); } public void updateChannels(ThermostatDTO thermostat) { @@ -329,15 +329,15 @@ public class EcobeeThermostatBridgeHandler extends BaseBridgeHandler { success = true; } } else if (Integer.class.isAssignableFrom(fieldClass)) { - if (command instanceof DecimalType) { + if (command instanceof DecimalType decimalCommand) { logger.debug("Set field of type Integer to value of DecimalType"); - field.set(object, Integer.valueOf(((DecimalType) command).intValue())); + field.set(object, Integer.valueOf(decimalCommand.intValue())); success = true; - } else if (command instanceof QuantityType) { - Unit unit = ((QuantityType) command).getUnit(); + } else if (command instanceof QuantityType quantityCommand) { + Unit unit = quantityCommand.getUnit(); logger.debug("Set field of type Integer to value of QuantityType with unit {}", unit); if (unit.equals(ImperialUnits.FAHRENHEIT) || unit.equals(SIUnits.CELSIUS)) { - QuantityType quantity = ((QuantityType) command).toUnit(ImperialUnits.FAHRENHEIT); + QuantityType quantity = quantityCommand.toUnit(ImperialUnits.FAHRENHEIT); if (quantity != null) { field.set(object, quantity.intValue() * 10); success = true; @@ -801,7 +801,7 @@ public class EcobeeThermostatBridgeHandler extends BaseBridgeHandler { private void performThermostatUpdate(ThermostatDTO thermostat) { SelectionDTO selection = new SelectionDTO(); - selection.setThermostats(Collections.singleton(thermostatId)); + selection.setThermostats(Set.of(thermostatId)); ThermostatUpdateRequestDTO request = new ThermostatUpdateRequestDTO(selection); request.thermostat = thermostat; EcobeeAccountBridgeHandler handler = getBridgeHandler(); diff --git a/bundles/org.openhab.binding.ecotouch/src/main/java/org/openhab/binding/ecotouch/internal/EcoTouchConnector.java b/bundles/org.openhab.binding.ecotouch/src/main/java/org/openhab/binding/ecotouch/internal/EcoTouchConnector.java index 2f27e1df8..589959caa 100644 --- a/bundles/org.openhab.binding.ecotouch/src/main/java/org/openhab/binding/ecotouch/internal/EcoTouchConnector.java +++ b/bundles/org.openhab.binding.ecotouch/src/main/java/org/openhab/binding/ecotouch/internal/EcoTouchConnector.java @@ -104,13 +104,13 @@ public class EcoTouchConnector { cause = e.toString(); } - if (line2 != null && line2.trim().equals("#E_USER_DONT_EXIST")) { + if (line2 != null && "#E_USER_DONT_EXIST".equals(line2.trim())) { throw new IOException("Username does not exist."); } - if (line2 != null && line2.trim().equals("#E_PASS_DONT_MATCH")) { + if (line2 != null && "#E_PASS_DONT_MATCH".equals(line2.trim())) { throw new IOException("Password does not match."); } - if (line2 != null && line2.trim().equals("#E_TOO_MANY_USERS")) { + if (line2 != null && "#E_TOO_MANY_USERS".equals(line2.trim())) { throw new IOException("Too many users already logged in."); } if (cookies == null) { diff --git a/bundles/org.openhab.binding.ecotouch/src/main/java/org/openhab/binding/ecotouch/internal/EcoTouchHandler.java b/bundles/org.openhab.binding.ecotouch/src/main/java/org/openhab/binding/ecotouch/internal/EcoTouchHandler.java index e605b280e..34e19f1ed 100644 --- a/bundles/org.openhab.binding.ecotouch/src/main/java/org/openhab/binding/ecotouch/internal/EcoTouchHandler.java +++ b/bundles/org.openhab.binding.ecotouch/src/main/java/org/openhab/binding/ecotouch/internal/EcoTouchHandler.java @@ -122,10 +122,8 @@ public class EcoTouchHandler extends BaseThingHandler { localConnector.setValue(ecoTouchTag.getTagName(), raw); } else { if (ecoTouchTag.getUnit() != ONE) { - if (command instanceof QuantityType) { - // convert from user unit to heat pump unit - QuantityType value = (QuantityType) command; - QuantityType rawUnit = value.toUnit(ecoTouchTag.getUnit()); + if (command instanceof QuantityType quantityCommand) { + QuantityType rawUnit = quantityCommand.toUnit(ecoTouchTag.getUnit()); if (rawUnit != null) { int raw = (int) (rawUnit.doubleValue() * ecoTouchTag.getDivisor()); localConnector.setValue(ecoTouchTag.getTagName(), raw); diff --git a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/action/EcovacsVacuumActions.java b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/action/EcovacsVacuumActions.java index 1d0a94166..a3f56762c 100644 --- a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/action/EcovacsVacuumActions.java +++ b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/action/EcovacsVacuumActions.java @@ -71,14 +71,14 @@ public class EcovacsVacuumActions implements ThingActions { } public static void playSound(@Nullable ThingActions actions, String type) { - if (actions instanceof EcovacsVacuumActions) { - ((EcovacsVacuumActions) actions).playSound(type); + if (actions instanceof EcovacsVacuumActions action) { + action.playSound(type); } } public static void playSoundWithId(@Nullable ThingActions actions, int soundId) { - if (actions instanceof EcovacsVacuumActions) { - ((EcovacsVacuumActions) actions).playSoundWithId(soundId); + if (actions instanceof EcovacsVacuumActions action) { + action.playSoundWithId(soundId); } } } diff --git a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetActiveMapIdCommand.java b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetActiveMapIdCommand.java index 943846afd..9d7a78f69 100644 --- a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetActiveMapIdCommand.java +++ b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetActiveMapIdCommand.java @@ -40,9 +40,8 @@ public class GetActiveMapIdCommand extends IotDeviceCommand { @Override public String convertResponse(AbstractPortalIotCommandResponse response, ProtocolVersion version, Gson gson) throws DataParsingException { - if (response instanceof PortalIotCommandJsonResponse) { - CachedMapInfoReport resp = ((PortalIotCommandJsonResponse) response).getResponsePayloadAs(gson, - CachedMapInfoReport.class); + if (response instanceof PortalIotCommandJsonResponse jsonResponse) { + CachedMapInfoReport resp = jsonResponse.getResponsePayloadAs(gson, CachedMapInfoReport.class); return resp.mapInfos.stream().filter(i -> i.used != 0).map(i -> i.mapId).findFirst().orElse(""); } else { String payload = ((PortalIotCommandXmlResponse) response).getResponsePayloadXml(); diff --git a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetBatteryInfoCommand.java b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetBatteryInfoCommand.java index 9b5b0cdcf..f88d7c753 100644 --- a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetBatteryInfoCommand.java +++ b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetBatteryInfoCommand.java @@ -40,9 +40,8 @@ public class GetBatteryInfoCommand extends IotDeviceCommand { @Override public Integer convertResponse(AbstractPortalIotCommandResponse response, ProtocolVersion version, Gson gson) throws DataParsingException { - if (response instanceof PortalIotCommandJsonResponse) { - BatteryReport resp = ((PortalIotCommandJsonResponse) response).getResponsePayloadAs(gson, - BatteryReport.class); + if (response instanceof PortalIotCommandJsonResponse jsonResponse) { + BatteryReport resp = jsonResponse.getResponsePayloadAs(gson, BatteryReport.class); return resp.percent; } else { String payload = ((PortalIotCommandXmlResponse) response).getResponsePayloadXml(); diff --git a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetChargeStateCommand.java b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetChargeStateCommand.java index ebf79af19..1d952f59c 100644 --- a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetChargeStateCommand.java +++ b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetChargeStateCommand.java @@ -41,9 +41,8 @@ public class GetChargeStateCommand extends IotDeviceCommand { @Override public ChargeMode convertResponse(AbstractPortalIotCommandResponse response, ProtocolVersion version, Gson gson) throws DataParsingException { - if (response instanceof PortalIotCommandJsonResponse) { - ChargeReport resp = ((PortalIotCommandJsonResponse) response).getResponsePayloadAs(gson, - ChargeReport.class); + if (response instanceof PortalIotCommandJsonResponse jsonResponse) { + ChargeReport resp = jsonResponse.getResponsePayloadAs(gson, ChargeReport.class); return resp.isCharging != 0 ? ChargeMode.CHARGING : ChargeMode.IDLE; } else { String payload = ((PortalIotCommandXmlResponse) response).getResponsePayloadXml(); diff --git a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetCleanStateCommand.java b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetCleanStateCommand.java index 66b23e652..f15d80ee6 100644 --- a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetCleanStateCommand.java +++ b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetCleanStateCommand.java @@ -50,8 +50,7 @@ public class GetCleanStateCommand extends IotDeviceCommand { @Override public CleanMode convertResponse(AbstractPortalIotCommandResponse response, ProtocolVersion version, Gson gson) throws DataParsingException { - if (response instanceof PortalIotCommandJsonResponse) { - final PortalIotCommandJsonResponse jsonResponse = (PortalIotCommandJsonResponse) response; + if (response instanceof PortalIotCommandJsonResponse jsonResponse) { final CleanMode mode; if (version == ProtocolVersion.JSON) { CleanReport resp = jsonResponse.getResponsePayloadAs(gson, CleanReport.class); diff --git a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetComponentLifeSpanCommand.java b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetComponentLifeSpanCommand.java index 92dbaed61..b190d8662 100644 --- a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetComponentLifeSpanCommand.java +++ b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetComponentLifeSpanCommand.java @@ -65,8 +65,8 @@ public class GetComponentLifeSpanCommand extends IotDeviceCommand { @Override public Integer convertResponse(AbstractPortalIotCommandResponse response, ProtocolVersion version, Gson gson) throws DataParsingException { - if (response instanceof PortalIotCommandJsonResponse) { - JsonElement respPayloadRaw = ((PortalIotCommandJsonResponse) response).getResponsePayload(gson); + if (response instanceof PortalIotCommandJsonResponse jsonResponse) { + JsonElement respPayloadRaw = jsonResponse.getResponsePayload(gson); Type type = new TypeToken>() { }.getType(); try { diff --git a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetContinuousCleaningCommand.java b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetContinuousCleaningCommand.java index 7c12ccee2..889b7128d 100644 --- a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetContinuousCleaningCommand.java +++ b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetContinuousCleaningCommand.java @@ -47,9 +47,8 @@ public class GetContinuousCleaningCommand extends IotDeviceCommand { @Override public Boolean convertResponse(AbstractPortalIotCommandResponse response, ProtocolVersion version, Gson gson) throws DataParsingException { - if (response instanceof PortalIotCommandJsonResponse) { - EnabledStateReport resp = ((PortalIotCommandJsonResponse) response).getResponsePayloadAs(gson, - EnabledStateReport.class); + if (response instanceof PortalIotCommandJsonResponse jsonResponse) { + EnabledStateReport resp = jsonResponse.getResponsePayloadAs(gson, EnabledStateReport.class); return resp.enabled != 0; } else { String payload = ((PortalIotCommandXmlResponse) response).getResponsePayloadXml(); diff --git a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetErrorCommand.java b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetErrorCommand.java index fac4743c9..f1f2327f1 100644 --- a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetErrorCommand.java +++ b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetErrorCommand.java @@ -42,8 +42,8 @@ public class GetErrorCommand extends IotDeviceCommand> { @Override public Optional convertResponse(AbstractPortalIotCommandResponse response, ProtocolVersion version, Gson gson) throws DataParsingException { - if (response instanceof PortalIotCommandJsonResponse) { - ErrorReport resp = ((PortalIotCommandJsonResponse) response).getResponsePayloadAs(gson, ErrorReport.class); + if (response instanceof PortalIotCommandJsonResponse jsonResponse) { + ErrorReport resp = jsonResponse.getResponsePayloadAs(gson, ErrorReport.class); if (resp.errorCodes.isEmpty()) { return Optional.empty(); } diff --git a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetMapSpotAreasWithMapIdCommand.java b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetMapSpotAreasWithMapIdCommand.java index 496fbb49f..ad7392c69 100644 --- a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetMapSpotAreasWithMapIdCommand.java +++ b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetMapSpotAreasWithMapIdCommand.java @@ -65,9 +65,8 @@ public class GetMapSpotAreasWithMapIdCommand extends IotDeviceCommand convertResponse(AbstractPortalIotCommandResponse response, ProtocolVersion version, Gson gson) throws DataParsingException { - if (response instanceof PortalIotCommandJsonResponse) { - MapSetReport resp = ((PortalIotCommandJsonResponse) response).getResponsePayloadAs(gson, - MapSetReport.class); + if (response instanceof PortalIotCommandJsonResponse jsonResponse) { + MapSetReport resp = jsonResponse.getResponsePayloadAs(gson, MapSetReport.class); return resp.subsets.stream().map(i -> i.id).collect(Collectors.toList()); } else { String payload = ((PortalIotCommandXmlResponse) response).getResponsePayloadXml(); diff --git a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetMoppingWaterAmountCommand.java b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetMoppingWaterAmountCommand.java index e300e9879..31cf3c5f2 100644 --- a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetMoppingWaterAmountCommand.java +++ b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetMoppingWaterAmountCommand.java @@ -41,9 +41,8 @@ public class GetMoppingWaterAmountCommand extends IotDeviceCommand { @Override public NetworkInfo convertResponse(AbstractPortalIotCommandResponse response, ProtocolVersion version, Gson gson) throws DataParsingException { - if (response instanceof PortalIotCommandJsonResponse) { - NetworkInfoReport resp = ((PortalIotCommandJsonResponse) response).getResponsePayloadAs(gson, - NetworkInfoReport.class); + if (response instanceof PortalIotCommandJsonResponse jsonResponse) { + NetworkInfoReport resp = jsonResponse.getResponsePayloadAs(gson, NetworkInfoReport.class); try { return new NetworkInfo(resp.ip, resp.mac, resp.ssid, Integer.valueOf(resp.rssi)); } catch (NumberFormatException e) { diff --git a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetSuctionPowerCommand.java b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetSuctionPowerCommand.java index 45b86d8ea..f1b524228 100644 --- a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetSuctionPowerCommand.java +++ b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetSuctionPowerCommand.java @@ -41,8 +41,8 @@ public class GetSuctionPowerCommand extends IotDeviceCommand { @Override public SuctionPower convertResponse(AbstractPortalIotCommandResponse response, ProtocolVersion version, Gson gson) throws DataParsingException { - if (response instanceof PortalIotCommandJsonResponse) { - SpeedReport resp = ((PortalIotCommandJsonResponse) response).getResponsePayloadAs(gson, SpeedReport.class); + if (response instanceof PortalIotCommandJsonResponse jsonResponse) { + SpeedReport resp = jsonResponse.getResponsePayloadAs(gson, SpeedReport.class); return SuctionPower.fromJsonValue(resp.speedLevel); } else { String payload = ((PortalIotCommandXmlResponse) response).getResponsePayloadXml(); diff --git a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetTotalStatsCommand.java b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetTotalStatsCommand.java index 04179c1c5..b1edd847f 100644 --- a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetTotalStatsCommand.java +++ b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetTotalStatsCommand.java @@ -55,8 +55,8 @@ public class GetTotalStatsCommand extends IotDeviceCommand { @Override public Integer convertResponse(AbstractPortalIotCommandResponse response, ProtocolVersion version, Gson gson) throws DataParsingException { - if (response instanceof PortalIotCommandJsonResponse) { - JsonResponse resp = ((PortalIotCommandJsonResponse) response).getResponsePayloadAs(gson, - JsonResponse.class); + if (response instanceof PortalIotCommandJsonResponse jsonResponse) { + JsonResponse resp = jsonResponse.getResponsePayloadAs(gson, JsonResponse.class); return resp.volume; } else { // unsupported in XML case? diff --git a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetWaterSystemPresentCommand.java b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetWaterSystemPresentCommand.java index 55e5d3265..57ef18edf 100644 --- a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetWaterSystemPresentCommand.java +++ b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/commands/GetWaterSystemPresentCommand.java @@ -40,9 +40,8 @@ public class GetWaterSystemPresentCommand extends IotDeviceCommand { @Override public Boolean convertResponse(AbstractPortalIotCommandResponse response, ProtocolVersion version, Gson gson) throws DataParsingException { - if (response instanceof PortalIotCommandJsonResponse) { - WaterInfoReport resp = ((PortalIotCommandJsonResponse) response).getResponsePayloadAs(gson, - WaterInfoReport.class); + if (response instanceof PortalIotCommandJsonResponse jsonResponse) { + WaterInfoReport resp = jsonResponse.getResponsePayloadAs(gson, WaterInfoReport.class); return resp.waterPlatePresent != 0; } else { String payload = ((PortalIotCommandXmlResponse) response).getResponsePayloadXml(); diff --git a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/EcovacsApiImpl.java b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/EcovacsApiImpl.java index 2411fe504..a9f4d65f5 100644 --- a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/EcovacsApiImpl.java +++ b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/EcovacsApiImpl.java @@ -172,7 +172,7 @@ public final class EcovacsApiImpl implements EcovacsApi { List devices = new ArrayList<>(); for (Device dev : getDeviceList()) { Optional descOpt = Optional.ofNullable(descriptions.get(dev.getDeviceClass())); - if (!descOpt.isPresent()) { + if (descOpt.isEmpty()) { if (products == null) { products = getIotProductMap(); } @@ -226,7 +226,7 @@ public final class EcovacsApiImpl implements EcovacsApi { DeviceDescription desc = descEntry.getValue(); if (desc.deviceClassLink != null) { Optional linkedDescOpt = Optional.ofNullable(descs.get(desc.deviceClassLink)); - if (!linkedDescOpt.isPresent()) { + if (linkedDescOpt.isEmpty()) { logger.warn("Device description {} links unknown description {}", desc.deviceClass, desc.deviceClassLink); } diff --git a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/EcovacsIotMqDevice.java b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/EcovacsIotMqDevice.java index fe57fd3f2..e9e9a5b1d 100644 --- a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/EcovacsIotMqDevice.java +++ b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/EcovacsIotMqDevice.java @@ -177,8 +177,8 @@ public class EcovacsIotMqDevice implements EcovacsDevice { logger.debug("Established MQTT connection to device {}", getSerialNumber()); } catch (ExecutionException e) { Throwable cause = e.getCause(); - boolean isAuthFailure = cause instanceof Mqtt3ConnAckException && ((Mqtt3ConnAckException) cause) - .getMqttMessage().getReturnCode() == Mqtt3ConnAckReturnCode.NOT_AUTHORIZED; + boolean isAuthFailure = cause instanceof Mqtt3ConnAckException connAckException + && connAckException.getMqttMessage().getReturnCode() == Mqtt3ConnAckReturnCode.NOT_AUTHORIZED; throw new EcovacsApiException(e, isAuthFailure); } } diff --git a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/EcovacsXmppDevice.java b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/EcovacsXmppDevice.java index 193ed6ad9..1c4229e00 100644 --- a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/EcovacsXmppDevice.java +++ b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/EcovacsXmppDevice.java @@ -347,8 +347,7 @@ public class EcovacsXmppDevice implements EcovacsDevice { return null; } - if (iqRequest instanceof DeviceCommandIQ) { - DeviceCommandIQ iq = (DeviceCommandIQ) iqRequest; + if (iqRequest instanceof DeviceCommandIQ iq) { try { if (!iq.id.isEmpty()) { @@ -372,8 +371,8 @@ public class EcovacsXmppDevice implements EcovacsDevice { } catch (DataParsingException e) { listener.onEventStreamFailure(EcovacsXmppDevice.this, e); } - } else if (iqRequest instanceof ErrorIQ) { - StanzaError error = ((ErrorIQ) iqRequest).getError(); + } else if (iqRequest instanceof ErrorIQ errorIQ) { + StanzaError error = errorIQ.getError(); logger.trace("{}: Got error response {}", getSerialNumber(), error); listener.onEventStreamFailure(EcovacsXmppDevice.this, new XMPPException.XMPPErrorException(iqRequest, error)); diff --git a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/PortalTodo.java b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/PortalTodo.java index 13987989f..3692a1420 100644 --- a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/PortalTodo.java +++ b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/PortalTodo.java @@ -24,5 +24,5 @@ public enum PortalTodo { @SerializedName("GetDeviceList") GET_DEVICE_LIST, @SerializedName("loginByItToken") - LOGIN_BY_TOKEN; + LOGIN_BY_TOKEN } diff --git a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/model/ChargeMode.java b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/model/ChargeMode.java index c8230abf0..e3c763856 100644 --- a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/model/ChargeMode.java +++ b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/model/ChargeMode.java @@ -28,5 +28,5 @@ public enum ChargeMode { @SerializedName("SlotCharging") CHARGING, @SerializedName("Idle") - IDLE; + IDLE } diff --git a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/discovery/EcovacsDeviceDiscoveryService.java b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/discovery/EcovacsDeviceDiscoveryService.java index 33a3ce49c..a1e06e3a1 100644 --- a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/discovery/EcovacsDeviceDiscoveryService.java +++ b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/discovery/EcovacsDeviceDiscoveryService.java @@ -14,9 +14,9 @@ package org.openhab.binding.ecovacs.internal.discovery; import static org.openhab.binding.ecovacs.internal.EcovacsBindingConstants.*; -import java.util.Collections; import java.util.List; import java.util.Optional; +import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -57,13 +57,13 @@ public class EcovacsDeviceDiscoveryService extends AbstractDiscoveryService impl this::scanForDevices); public EcovacsDeviceDiscoveryService() { - super(Collections.singleton(THING_TYPE_VACUUM), DISCOVER_TIMEOUT_SECONDS, true); + super(Set.of(THING_TYPE_VACUUM), DISCOVER_TIMEOUT_SECONDS, true); } @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof EcovacsApiHandler) { - this.apiHandler = (EcovacsApiHandler) handler; + if (handler instanceof EcovacsApiHandler ecovacsApiHandler) { + this.apiHandler = ecovacsApiHandler; this.apiHandler.setDiscoveryService(this); } } diff --git a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/handler/EcovacsApiHandler.java b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/handler/EcovacsApiHandler.java index 70c26224a..4367d45a2 100644 --- a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/handler/EcovacsApiHandler.java +++ b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/handler/EcovacsApiHandler.java @@ -15,8 +15,8 @@ package org.openhab.binding.ecovacs.internal.handler; import static org.openhab.binding.ecovacs.internal.EcovacsBindingConstants.*; import java.util.Collection; -import java.util.Collections; import java.util.Optional; +import java.util.Set; import java.util.UUID; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -96,7 +96,7 @@ public class EcovacsApiHandler extends BaseBridgeHandler { @Override public Collection> getServices() { - return Collections.singleton(EcovacsDeviceDiscoveryService.class); + return Set.of(EcovacsDeviceDiscoveryService.class); } @Override diff --git a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/handler/EcovacsVacuumHandler.java b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/handler/EcovacsVacuumHandler.java index febdb7edc..128afa340 100644 --- a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/handler/EcovacsVacuumHandler.java +++ b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/handler/EcovacsVacuumHandler.java @@ -18,10 +18,10 @@ import java.time.ZoneId; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Locale; import java.util.Optional; +import java.util.Set; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -152,7 +152,7 @@ public class EcovacsVacuumHandler extends BaseThingHandler implements EcovacsDev @Override public Collection> getServices() { - return Collections.singleton(EcovacsVacuumActions.class); + return Set.of(EcovacsVacuumActions.class); } @Override @@ -171,8 +171,8 @@ public class EcovacsVacuumHandler extends BaseThingHandler implements EcovacsDev device.sendCommand(cmd); return; } - } else if (channel.equals(CHANNEL_ID_VOICE_VOLUME) && command instanceof DecimalType) { - int volumePercent = ((DecimalType) command).intValue(); + } else if (channel.equals(CHANNEL_ID_VOICE_VOLUME) && command instanceof DecimalType volume) { + int volumePercent = volume.intValue(); device.sendCommand(new SetVolumeCommand((volumePercent + 5) / 10)); return; } else if (channel.equals(CHANNEL_ID_SUCTION_POWER) && command instanceof StringType) { @@ -191,7 +191,7 @@ public class EcovacsVacuumHandler extends BaseThingHandler implements EcovacsDev if (command instanceof OnOffType) { device.sendCommand(new SetDustbinAutoEmptyCommand(command == OnOffType.ON)); return; - } else if (command instanceof StringType && command.toString().equals("trigger")) { + } else if (command instanceof StringType && "trigger".equals(command.toString())) { device.sendCommand(new EmptyDustbinCommand()); return; } @@ -201,8 +201,8 @@ public class EcovacsVacuumHandler extends BaseThingHandler implements EcovacsDev } else if (channel.equals(CHANNEL_ID_CONTINUOUS_CLEANING) && command instanceof OnOffType) { device.sendCommand(new SetContinuousCleaningCommand(command == OnOffType.ON)); return; - } else if (channel.equals(CHANNEL_ID_CLEANING_PASSES) && command instanceof DecimalType) { - int passes = ((DecimalType) command).intValue(); + } else if (channel.equals(CHANNEL_ID_CLEANING_PASSES) && command instanceof DecimalType type) { + int passes = type.intValue(); device.sendCommand(new SetDefaultCleanPassesCommand(passes)); lastDefaultCleaningPasses = passes; // if we get here, the command was executed successfully return; diff --git a/bundles/org.openhab.binding.ecowatt/src/main/java/org/openhab/binding/ecowatt/internal/handler/EcowattHandler.java b/bundles/org.openhab.binding.ecowatt/src/main/java/org/openhab/binding/ecowatt/internal/handler/EcowattHandler.java index e29d69ea3..365d65c67 100644 --- a/bundles/org.openhab.binding.ecowatt/src/main/java/org/openhab/binding/ecowatt/internal/handler/EcowattHandler.java +++ b/bundles/org.openhab.binding.ecowatt/src/main/java/org/openhab/binding/ecowatt/internal/handler/EcowattHandler.java @@ -201,10 +201,10 @@ public class EcowattHandler extends BaseThingHandler { // Invalidate the cache to be sure the next request will trigger the API cachedApiResponse.invalidateValue(); - if (retryIfApiLimitReached && exception instanceof EcowattApiLimitException - && ((EcowattApiLimitException) exception).getRetryAfter() > 0) { + if (retryIfApiLimitReached && exception instanceof EcowattApiLimitException limitException + && limitException.getRetryAfter() > 0) { // Will retry when the API is available again (just after the limit expired) - retryDelay = ((EcowattApiLimitException) exception).getRetryAfter(); + retryDelay = limitException.getRetryAfter(); } } else { updateStatus(ThingStatus.ONLINE); diff --git a/bundles/org.openhab.binding.electroluxair/src/main/java/org/openhab/binding/electroluxair/internal/discovery/ElectroluxAirDiscoveryService.java b/bundles/org.openhab.binding.electroluxair/src/main/java/org/openhab/binding/electroluxair/internal/discovery/ElectroluxAirDiscoveryService.java index d918783a0..4f7d70a5a 100644 --- a/bundles/org.openhab.binding.electroluxair/src/main/java/org/openhab/binding/electroluxair/internal/discovery/ElectroluxAirDiscoveryService.java +++ b/bundles/org.openhab.binding.electroluxair/src/main/java/org/openhab/binding/electroluxair/internal/discovery/ElectroluxAirDiscoveryService.java @@ -45,8 +45,8 @@ public class ElectroluxAirDiscoveryService extends AbstractDiscoveryService @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof ElectroluxAirBridgeHandler) { - this.handler = (ElectroluxAirBridgeHandler) handler; + if (handler instanceof ElectroluxAirBridgeHandler bridgeHandler) { + this.handler = bridgeHandler; } } diff --git a/bundles/org.openhab.binding.electroluxair/src/main/java/org/openhab/binding/electroluxair/internal/handler/ElectroluxAirBridgeHandler.java b/bundles/org.openhab.binding.electroluxair/src/main/java/org/openhab/binding/electroluxair/internal/handler/ElectroluxAirBridgeHandler.java index b510aadcb..f8f37555a 100644 --- a/bundles/org.openhab.binding.electroluxair/src/main/java/org/openhab/binding/electroluxair/internal/handler/ElectroluxAirBridgeHandler.java +++ b/bundles/org.openhab.binding.electroluxair/src/main/java/org/openhab/binding/electroluxair/internal/handler/ElectroluxAirBridgeHandler.java @@ -15,7 +15,6 @@ package org.openhab.binding.electroluxair.internal.handler; import static org.openhab.binding.electroluxair.internal.ElectroluxAirBindingConstants.*; import java.util.Collection; -import java.util.Collections; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -50,7 +49,7 @@ import com.google.gson.Gson; @NonNullByDefault public class ElectroluxAirBridgeHandler 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 int refreshTimeInSeconds = 300; @@ -100,7 +99,7 @@ public class ElectroluxAirBridgeHandler extends BaseBridgeHandler { @Override public Collection> getServices() { - return Collections.singleton(ElectroluxAirDiscoveryService.class); + return Set.of(ElectroluxAirDiscoveryService.class); } @Override diff --git a/bundles/org.openhab.binding.elerotransmitterstick/src/main/java/org/openhab/binding/elerotransmitterstick/internal/EleroTransmitterStickHandlerFactory.java b/bundles/org.openhab.binding.elerotransmitterstick/src/main/java/org/openhab/binding/elerotransmitterstick/internal/EleroTransmitterStickHandlerFactory.java index e0196c29b..936da60cd 100644 --- a/bundles/org.openhab.binding.elerotransmitterstick/src/main/java/org/openhab/binding/elerotransmitterstick/internal/EleroTransmitterStickHandlerFactory.java +++ b/bundles/org.openhab.binding.elerotransmitterstick/src/main/java/org/openhab/binding/elerotransmitterstick/internal/EleroTransmitterStickHandlerFactory.java @@ -82,9 +82,7 @@ public class EleroTransmitterStickHandlerFactory extends BaseThingHandlerFactory return bridgeHandler; } else if (thingTypeUID.equals(THING_TYPE_ELERO_CHANNEL)) { - EleroChannelHandler h = new EleroChannelHandler(thing); - - return h; + return new EleroChannelHandler(thing); } return null; diff --git a/bundles/org.openhab.binding.elerotransmitterstick/src/main/java/org/openhab/binding/elerotransmitterstick/internal/discovery/EleroChannelDiscoveryService.java b/bundles/org.openhab.binding.elerotransmitterstick/src/main/java/org/openhab/binding/elerotransmitterstick/internal/discovery/EleroChannelDiscoveryService.java index 9d273a2ff..0f5760bc6 100644 --- a/bundles/org.openhab.binding.elerotransmitterstick/src/main/java/org/openhab/binding/elerotransmitterstick/internal/discovery/EleroChannelDiscoveryService.java +++ b/bundles/org.openhab.binding.elerotransmitterstick/src/main/java/org/openhab/binding/elerotransmitterstick/internal/discovery/EleroChannelDiscoveryService.java @@ -15,7 +15,7 @@ package org.openhab.binding.elerotransmitterstick.internal.discovery; import static org.openhab.binding.elerotransmitterstick.internal.EleroTransmitterStickBindingConstants.*; import java.util.ArrayList; -import java.util.Collections; +import java.util.Set; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -44,7 +44,7 @@ public class EleroChannelDiscoveryService extends AbstractDiscoveryService { * Creates the discovery service for the given handler and converter. */ public EleroChannelDiscoveryService(EleroTransmitterStickHandler stickHandler) { - super(Collections.singleton(THING_TYPE_ELERO_CHANNEL), DISCOVER_TIMEOUT_SECONDS, true); + super(Set.of(THING_TYPE_ELERO_CHANNEL), DISCOVER_TIMEOUT_SECONDS, true); bridge = stickHandler; } diff --git a/bundles/org.openhab.binding.elerotransmitterstick/src/main/java/org/openhab/binding/elerotransmitterstick/internal/handler/EleroChannelHandler.java b/bundles/org.openhab.binding.elerotransmitterstick/src/main/java/org/openhab/binding/elerotransmitterstick/internal/handler/EleroChannelHandler.java index 8d3b0b049..dda33d817 100644 --- a/bundles/org.openhab.binding.elerotransmitterstick/src/main/java/org/openhab/binding/elerotransmitterstick/internal/handler/EleroChannelHandler.java +++ b/bundles/org.openhab.binding.elerotransmitterstick/src/main/java/org/openhab/binding/elerotransmitterstick/internal/handler/EleroChannelHandler.java @@ -14,7 +14,7 @@ package org.openhab.binding.elerotransmitterstick.internal.handler; import static org.openhab.binding.elerotransmitterstick.internal.EleroTransmitterStickBindingConstants.*; -import java.util.Collections; +import java.util.List; import org.openhab.binding.elerotransmitterstick.internal.config.EleroChannelConfig; import org.openhab.binding.elerotransmitterstick.internal.stick.CommandType; @@ -88,20 +88,20 @@ public class EleroChannelHandler extends BaseThingHandler implements StatusListe if (channelUID.getIdWithoutGroup().equals(CONTROL_CHANNEL)) { if (command == UpDownType.UP) { - bridge.getStick().sendCommand(CommandType.UP, Collections.singletonList(channelId)); + bridge.getStick().sendCommand(CommandType.UP, List.of(channelId)); } else if (command == UpDownType.DOWN) { - bridge.getStick().sendCommand(CommandType.DOWN, Collections.singletonList(channelId)); + bridge.getStick().sendCommand(CommandType.DOWN, List.of(channelId)); } else if (command == StopMoveType.STOP) { - bridge.getStick().sendCommand(CommandType.STOP, Collections.singletonList(channelId)); - } else if (command instanceof PercentType) { - CommandType cmd = CommandType.getForPercent(((PercentType) command).intValue()); + bridge.getStick().sendCommand(CommandType.STOP, List.of(channelId)); + } else if (command instanceof PercentType pt) { + CommandType cmd = CommandType.getForPercent(pt.intValue()); if (cmd != null) { - bridge.getStick().sendCommand(cmd, Collections.singletonList(channelId)); + bridge.getStick().sendCommand(cmd, List.of(channelId)); } else { logger.debug("Unhandled command {}.", command); } } else if (command == RefreshType.REFRESH) { - bridge.getStick().requestUpdate(Collections.singletonList(channelId)); + bridge.getStick().requestUpdate(List.of(channelId)); } } } diff --git a/bundles/org.openhab.binding.elerotransmitterstick/src/main/java/org/openhab/binding/elerotransmitterstick/internal/stick/TransmitterStick.java b/bundles/org.openhab.binding.elerotransmitterstick/src/main/java/org/openhab/binding/elerotransmitterstick/internal/stick/TransmitterStick.java index 35ca54579..4462cfac2 100644 --- a/bundles/org.openhab.binding.elerotransmitterstick/src/main/java/org/openhab/binding/elerotransmitterstick/internal/stick/TransmitterStick.java +++ b/bundles/org.openhab.binding.elerotransmitterstick/src/main/java/org/openhab/binding/elerotransmitterstick/internal/stick/TransmitterStick.java @@ -16,7 +16,6 @@ import java.io.IOException; 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.Iterator; @@ -226,7 +225,7 @@ public class TransmitterStick { // handle commands that are sent to multiple channels correctly if (channelIds.size() > 1) { for (int channelId : channelIds) { - requestUpdates(Collections.singletonList(channelId)); + requestUpdates(List.of(channelId)); } } else if (!channelIds.isEmpty()) { final Integer[] ids = channelIds.toArray(new Integer[channelIds.size()]); @@ -241,7 +240,7 @@ public class TransmitterStick { // handle commands that are sent to multiple channels correctly if (channelIds.size() > 1) { for (int channelId : channelIds) { - executeCommand(command, Collections.singletonList(channelId)); + executeCommand(command, List.of(channelId)); } } else if (!channelIds.isEmpty()) { final Integer[] ids = channelIds.toArray(new Integer[channelIds.size()]); @@ -307,8 +306,8 @@ public class TransmitterStick { } } - if (cmd instanceof TimedCommand) { - long delay = 1000 * ((TimedCommand) cmd).getDuration(); + if (cmd instanceof TimedCommand timedCommand) { + long delay = 1000 * timedCommand.getDuration(); logger.debug("adding timed command STOP for channel ids {} to queue with delay {}...", cmd.getChannelIds(), delay); diff --git a/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/ElroConnectsBindingConstants.java b/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/ElroConnectsBindingConstants.java index b602e96a6..570a03ba1 100644 --- a/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/ElroConnectsBindingConstants.java +++ b/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/ElroConnectsBindingConstants.java @@ -136,7 +136,7 @@ public class ElroConnectsBindingConstants { .collect(Collectors.toUnmodifiableMap(Map.Entry::getValue, Map.Entry::getKey)); // ELRO device types - public static enum ElroDeviceType { + public enum ElroDeviceType { ENTRY_SENSOR, CO_ALARM, CXSM_ALARM, @@ -197,7 +197,7 @@ public class ElroConnectsBindingConstants { .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue)); // ELRO device status - public static enum ElroDeviceStatus { + public enum ElroDeviceStatus { NORMAL, TRIGGERED, TEST, diff --git a/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/ElroConnectsDynamicStateDescriptionProvider.java b/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/ElroConnectsDynamicStateDescriptionProvider.java index fd3f0114e..bb882d088 100644 --- a/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/ElroConnectsDynamicStateDescriptionProvider.java +++ b/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/ElroConnectsDynamicStateDescriptionProvider.java @@ -52,8 +52,7 @@ public class ElroConnectsDynamicStateDescriptionProvider implements DynamicState @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.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/devices/ElroConnectsDevice.java b/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/devices/ElroConnectsDevice.java index 1f804bbfe..3a5c9d121 100644 --- a/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/devices/ElroConnectsDevice.java +++ b/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/devices/ElroConnectsDevice.java @@ -110,7 +110,7 @@ public abstract class ElroConnectsDevice { typeName = getDeviceType(); } - return deviceName.isEmpty() ? typeName + "-" + String.valueOf(deviceId) : deviceName; + return deviceName.isEmpty() ? typeName + "-" + deviceId : deviceName; } public String getDeviceType() { diff --git a/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/discovery/ElroConnectsBridgeDiscoveryService.java b/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/discovery/ElroConnectsBridgeDiscoveryService.java index c0dffb242..8d21f443b 100644 --- a/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/discovery/ElroConnectsBridgeDiscoveryService.java +++ b/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/discovery/ElroConnectsBridgeDiscoveryService.java @@ -85,7 +85,7 @@ public class ElroConnectsBridgeDiscoveryService extends AbstractDiscoveryService String firmwareVersion = c.getValue().binVersion; boolean legacy = false; try { - legacy = !(Integer.valueOf(firmwareVersion.substring(firmwareVersion.lastIndexOf(".") + 1)) > 14); + legacy = Integer.valueOf(firmwareVersion.substring(firmwareVersion.lastIndexOf(".") + 1)) <= 14; } catch (NumberFormatException e) { // Assume new firmware if we cannot decode firmwareVersion logger.debug("Cannot get firmware version from {}, assume new firmware", firmwareVersion); @@ -141,14 +141,9 @@ public class ElroConnectsBridgeDiscoveryService extends AbstractDiscoveryService @Override public void setThingHandler(@Nullable ThingHandler handler) { - ElroConnectsAccountHandler account = null; - if (handler instanceof ElroConnectsAccountHandler) { - account = (ElroConnectsAccountHandler) handler; - accountHandler = account; - } - - if (account != null) { - account.setDiscoveryService(this); + if (handler instanceof ElroConnectsAccountHandler accountHandler) { + this.accountHandler = accountHandler; + accountHandler.setDiscoveryService(this); } } diff --git a/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/discovery/ElroConnectsDiscoveryService.java b/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/discovery/ElroConnectsDiscoveryService.java index c8f02b52a..a15375505 100644 --- a/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/discovery/ElroConnectsDiscoveryService.java +++ b/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/discovery/ElroConnectsDiscoveryService.java @@ -121,14 +121,9 @@ public class ElroConnectsDiscoveryService extends AbstractDiscoveryService imple @Override public void setThingHandler(@Nullable ThingHandler handler) { - ElroConnectsBridgeHandler bridge = null; - if (handler instanceof ElroConnectsBridgeHandler) { - bridge = (ElroConnectsBridgeHandler) handler; - bridgeHandler = bridge; - } - - if (bridge != null) { - bridge.setDiscoveryService(this); + if (handler instanceof ElroConnectsBridgeHandler bridgeHandler) { + this.bridgeHandler = bridgeHandler; + bridgeHandler.setDiscoveryService(this); } } diff --git a/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/handler/ElroConnectsAccountHandler.java b/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/handler/ElroConnectsAccountHandler.java index 6046d5912..d2a818bcd 100644 --- a/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/handler/ElroConnectsAccountHandler.java +++ b/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/handler/ElroConnectsAccountHandler.java @@ -16,10 +16,10 @@ import java.lang.reflect.Type; import java.net.SocketTimeoutException; import java.net.URI; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.ScheduledFuture; @@ -349,7 +349,7 @@ public class ElroConnectsAccountHandler extends BaseBridgeHandler { @Override public Collection> getServices() { - return Collections.singleton(ElroConnectsBridgeDiscoveryService.class); + return Set.of(ElroConnectsBridgeDiscoveryService.class); } /** diff --git a/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/handler/ElroConnectsBridgeHandler.java b/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/handler/ElroConnectsBridgeHandler.java index d387dbb4e..1d62817f4 100644 --- a/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/handler/ElroConnectsBridgeHandler.java +++ b/bundles/org.openhab.binding.elroconnects/src/main/java/org/openhab/binding/elroconnects/internal/handler/ElroConnectsBridgeHandler.java @@ -23,9 +23,9 @@ import java.net.UnknownHostException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutionException; @@ -864,9 +864,9 @@ public class ElroConnectsBridgeHandler extends BaseBridgeHandler { if (SCENE.equals(channelUID.getId())) { if (command instanceof RefreshType) { updateState(SCENE, new StringType(String.valueOf(currentScene))); - } else if (command instanceof StringType) { + } else if (command instanceof StringType stringCommand) { try { - selectScene(Integer.valueOf(((StringType) command).toString())); + selectScene(Integer.valueOf(stringCommand.toString())); } catch (NumberFormatException nfe) { logger.debug("Cannot interpret scene command {}", command); } @@ -965,7 +965,7 @@ public class ElroConnectsBridgeHandler extends BaseBridgeHandler { @Override public Collection> getServices() { - return Collections.singleton(ElroConnectsDiscoveryService.class); + return Set.of(ElroConnectsDiscoveryService.class); } public Map listDevicesFromConsole() { diff --git a/bundles/org.openhab.binding.energidataservice/src/main/java/org/openhab/binding/energidataservice/internal/action/EnergiDataServiceActions.java b/bundles/org.openhab.binding.energidataservice/src/main/java/org/openhab/binding/energidataservice/internal/action/EnergiDataServiceActions.java index a39897deb..3e9a3e642 100644 --- a/bundles/org.openhab.binding.energidataservice/src/main/java/org/openhab/binding/energidataservice/internal/action/EnergiDataServiceActions.java +++ b/bundles/org.openhab.binding.energidataservice/src/main/java/org/openhab/binding/energidataservice/internal/action/EnergiDataServiceActions.java @@ -280,11 +280,11 @@ public class EnergiDataServiceActions implements ThingActions { * @return Map of prices */ public static Map getPrices(@Nullable ThingActions actions, @Nullable String priceElements) { - if (actions instanceof EnergiDataServiceActions) { + if (actions instanceof EnergiDataServiceActions serviceActions) { if (priceElements != null && !priceElements.isBlank()) { - return ((EnergiDataServiceActions) actions).getPrices(priceElements); + return serviceActions.getPrices(priceElements); } else { - return ((EnergiDataServiceActions) actions).getPrices(); + return serviceActions.getPrices(); } } else { throw new IllegalArgumentException("Instance is not an EnergiDataServiceActions class."); @@ -305,8 +305,8 @@ public class EnergiDataServiceActions implements ThingActions { if (start == null || end == null || power == null) { return BigDecimal.ZERO; } - if (actions instanceof EnergiDataServiceActions) { - return ((EnergiDataServiceActions) actions).calculatePrice(start, end, power); + if (actions instanceof EnergiDataServiceActions serviceActions) { + return serviceActions.calculatePrice(start, end, power); } else { throw new IllegalArgumentException("Instance is not an EnergiDataServiceActions class."); } @@ -314,11 +314,11 @@ public class EnergiDataServiceActions implements ThingActions { public static Map calculateCheapestPeriod(@Nullable ThingActions actions, @Nullable Instant earliestStart, @Nullable Instant latestEnd, @Nullable Duration duration) { - if (actions instanceof EnergiDataServiceActions) { + if (actions instanceof EnergiDataServiceActions serviceActions) { if (earliestStart == null || latestEnd == null || duration == null) { return Map.of(); } - return ((EnergiDataServiceActions) actions).calculateCheapestPeriod(earliestStart, latestEnd, duration); + return serviceActions.calculateCheapestPeriod(earliestStart, latestEnd, duration); } else { throw new IllegalArgumentException("Instance is not an EnergiDataServiceActions class."); } @@ -327,12 +327,11 @@ public class EnergiDataServiceActions implements ThingActions { public static Map calculateCheapestPeriod(@Nullable ThingActions actions, @Nullable Instant earliestStart, @Nullable Instant latestEnd, @Nullable Duration duration, @Nullable QuantityType power) { - if (actions instanceof EnergiDataServiceActions) { + if (actions instanceof EnergiDataServiceActions serviceActions) { if (earliestStart == null || latestEnd == null || duration == null || power == null) { return Map.of(); } - return ((EnergiDataServiceActions) actions).calculateCheapestPeriod(earliestStart, latestEnd, duration, - power); + return serviceActions.calculateCheapestPeriod(earliestStart, latestEnd, duration, power); } else { throw new IllegalArgumentException("Instance is not an EnergiDataServiceActions class."); } @@ -341,13 +340,13 @@ public class EnergiDataServiceActions implements ThingActions { public static Map calculateCheapestPeriod(@Nullable ThingActions actions, @Nullable Instant earliestStart, @Nullable Instant latestEnd, @Nullable Duration totalDuration, @Nullable List durationPhases, @Nullable QuantityType energyUsedPerPhase) { - if (actions instanceof EnergiDataServiceActions) { + if (actions instanceof EnergiDataServiceActions serviceActions) { if (earliestStart == null || latestEnd == null || totalDuration == null || durationPhases == null || energyUsedPerPhase == null) { return Map.of(); } - return ((EnergiDataServiceActions) actions).calculateCheapestPeriod(earliestStart, latestEnd, totalDuration, - durationPhases, energyUsedPerPhase); + return serviceActions.calculateCheapestPeriod(earliestStart, latestEnd, totalDuration, durationPhases, + energyUsedPerPhase); } else { throw new IllegalArgumentException("Instance is not an EnergiDataServiceActions class."); } @@ -356,12 +355,11 @@ public class EnergiDataServiceActions implements ThingActions { public static Map calculateCheapestPeriod(@Nullable ThingActions actions, @Nullable Instant earliestStart, @Nullable Instant latestEnd, @Nullable List durationPhases, @Nullable List> powerPhases) { - if (actions instanceof EnergiDataServiceActions) { + if (actions instanceof EnergiDataServiceActions serviceActions) { if (earliestStart == null || latestEnd == null || durationPhases == null || powerPhases == null) { return Map.of(); } - return ((EnergiDataServiceActions) actions).calculateCheapestPeriod(earliestStart, latestEnd, - durationPhases, powerPhases); + return serviceActions.calculateCheapestPeriod(earliestStart, latestEnd, durationPhases, powerPhases); } else { throw new IllegalArgumentException("Instance is not an EnergiDataServiceActions class."); } @@ -369,8 +367,8 @@ public class EnergiDataServiceActions implements ThingActions { @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof EnergiDataServiceHandler) { - this.handler = (EnergiDataServiceHandler) handler; + if (handler instanceof EnergiDataServiceHandler serviceHandler) { + this.handler = serviceHandler; } } diff --git a/bundles/org.openhab.binding.energidataservice/src/main/java/org/openhab/binding/energidataservice/internal/retry/strategy/FixedTime.java b/bundles/org.openhab.binding.energidataservice/src/main/java/org/openhab/binding/energidataservice/internal/retry/strategy/FixedTime.java index 98d78a048..999b5dbdc 100644 --- a/bundles/org.openhab.binding.energidataservice/src/main/java/org/openhab/binding/energidataservice/internal/retry/strategy/FixedTime.java +++ b/bundles/org.openhab.binding.energidataservice/src/main/java/org/openhab/binding/energidataservice/internal/retry/strategy/FixedTime.java @@ -80,7 +80,6 @@ public class FixedTime implements RetryStrategy { @Override public final int hashCode() { - final int result = 1; - return result; + return 1; } } diff --git a/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/internal/Enigma2BindingConstants.java b/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/internal/Enigma2BindingConstants.java index bab5f0aa6..29b4afa1d 100644 --- a/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/internal/Enigma2BindingConstants.java +++ b/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/internal/Enigma2BindingConstants.java @@ -12,7 +12,6 @@ */ package org.openhab.binding.enigma2.internal; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -32,7 +31,7 @@ public class Enigma2BindingConstants { // List of all Thing Type UIDs public static final ThingTypeUID THING_TYPE_DEVICE = new ThingTypeUID(BINDING_ID, "device"); - public static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_DEVICE); + public static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_DEVICE); // List of all Channel ids public static final String CHANNEL_VOLUME = "volume"; diff --git a/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/internal/handler/Enigma2Handler.java b/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/internal/handler/Enigma2Handler.java index 002897341..d5735fb05 100644 --- a/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/internal/handler/Enigma2Handler.java +++ b/bundles/org.openhab.binding.enigma2/src/main/java/org/openhab/binding/enigma2/internal/handler/Enigma2Handler.java @@ -16,8 +16,8 @@ import static org.openhab.binding.enigma2.internal.Enigma2BindingConstants.*; import java.time.LocalDateTime; import java.util.Collection; -import java.util.Collections; import java.util.Optional; +import java.util.Set; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -155,10 +155,10 @@ public class Enigma2Handler extends BaseThingHandler { if (command instanceof RefreshType) { client.refreshVolume(); updateState(channelUID, new PercentType(client.getVolume())); - } else if (command instanceof PercentType) { - client.setVolume(((PercentType) command).intValue()); - } else if (command instanceof DecimalType) { - client.setVolume(((DecimalType) command).intValue()); + } else if (command instanceof PercentType percentCommand) { + client.setVolume(percentCommand.intValue()); + } else if (command instanceof DecimalType decimalCommand) { + client.setVolume(decimalCommand.intValue()); } else { logger.info("Channel {} only accepts PercentType, DecimalType, RefreshType. Type was {}.", channelUID, command.getClass()); @@ -293,7 +293,7 @@ public class Enigma2Handler extends BaseThingHandler { @Override public Collection> getServices() { - return Collections.singleton(Enigma2Actions.class); + return Set.of(Enigma2Actions.class); } /** diff --git a/bundles/org.openhab.binding.enigma2/src/test/java/org/openhab/binding/enigma2/internal/Enigma2ClientTest.java b/bundles/org.openhab.binding.enigma2/src/test/java/org/openhab/binding/enigma2/internal/Enigma2ClientTest.java index 4cf3f5525..29cb958da 100644 --- a/bundles/org.openhab.binding.enigma2/src/test/java/org/openhab/binding/enigma2/internal/Enigma2ClientTest.java +++ b/bundles/org.openhab.binding.enigma2/src/test/java/org/openhab/binding/enigma2/internal/Enigma2ClientTest.java @@ -312,13 +312,29 @@ public class Enigma2ClientTest { } private void whenAllServices() throws IOException { - when(enigma2HttpClient.get(HOST + Enigma2Client.PATH_ALL_SERVICES)) - .thenReturn("" + "" + "" + "" - + "1" + "Channel 1" - + "" + "" + "2" - + "Channel 2" + "" + "" - + "" + "" + "" + "" - + "3" + "Channel 3" - + "" + "" + "" + ""); + when(enigma2HttpClient.get(HOST + Enigma2Client.PATH_ALL_SERVICES)).thenReturn(""" + \ + \ + \ + \ + 1\ + Channel 1\ + \ + \ + 2\ + Channel 2\ + \ + \ + \ + \ + \ + \ + 3\ + Channel 3\ + \ + \ + \ + \ + """); } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/discovery/EnOceanDeviceDiscoveryService.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/discovery/EnOceanDeviceDiscoveryService.java index 6d0af65ec..99fac21ca 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/discovery/EnOceanDeviceDiscoveryService.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/discovery/EnOceanDeviceDiscoveryService.java @@ -132,7 +132,7 @@ public class EnOceanDeviceDiscoveryService extends AbstractDiscoveryService impl if (senderIdOffset == null) { return; } - } else if ((eep instanceof _4BSMessage) && ((_4BSMessage) eep).isTeachInVariation3Supported()) { + } else if (eep instanceof _4BSMessage message && message.isTeachInVariation3Supported()) { // if 4BS teach in variation 3 => send response logger.debug("Sending 4BS teach in variation 3 response to {}", enoceanId); senderIdOffset = sendTeachInResponse(msg, enoceanId); diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_20/A5_20_04.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_20/A5_20_04.java index 5924c7845..9aa7bf154 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_20/A5_20_04.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_20/A5_20_04.java @@ -60,7 +60,7 @@ public class A5_20_04 extends A5_20 { } private String getStatusRequestEvent() { - return Boolean.valueOf(getBit(getDB0Value(), 6)).toString(); + return Boolean.toString(getBit(getDB0Value(), 6)); // return getBit(getDB_0Value(), 6) ? "triggered" : null; } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_38/A5_38_08_Blinds.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_38/A5_38_08_Blinds.java index a48bb39af..be36533b8 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_38/A5_38_08_Blinds.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_38/A5_38_08_Blinds.java @@ -77,15 +77,15 @@ public class A5_38_08_Blinds extends _4BSMessage { byte angle = 0; // for now, no angle configuration supported boolean doStop = false; - if (outputCommand instanceof DecimalType) { - position = ((DecimalType) outputCommand).byteValue(); - } else if (outputCommand instanceof OnOffType) { - position = (byte) (((OnOffType) outputCommand == OnOffType.ON) ? 0 : 100); + if (outputCommand instanceof DecimalType decimalCommand) { + position = decimalCommand.byteValue(); + } else if (outputCommand instanceof OnOffType onOffCommand) { + position = (byte) ((onOffCommand == OnOffType.ON) ? 0 : 100); } else if (outputCommand instanceof StopMoveType) { position = ZERO; doStop = true; - } else if (outputCommand instanceof UpDownType) { - position = (byte) (((UpDownType) outputCommand == UpDownType.UP) ? 0 : 100); + } else if (outputCommand instanceof UpDownType upDownCommand) { + position = (byte) ((upDownCommand == UpDownType.UP) ? 0 : 100); } else { logger.warn("Unknown command type {}", outputCommand.getClass().getCanonicalName()); return; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_38/A5_38_08_Dimming.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_38/A5_38_08_Dimming.java index 148b5fc70..2d5771c21 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_38/A5_38_08_Dimming.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_38/A5_38_08_Dimming.java @@ -63,16 +63,14 @@ public class A5_38_08_Dimming extends _4BSMessage { case CHANNEL_DIMMER: byte dimmValue; - if (outputCommand instanceof DecimalType) { - dimmValue = ((DecimalType) outputCommand).byteValue(); - } else if (outputCommand instanceof OnOffType) { - dimmValue = ((OnOffType) outputCommand == OnOffType.ON) ? SWITCH_100_PERCENT : ZERO; - } else if (outputCommand instanceof IncreaseDecreaseType) { - dimmValue = ((IncreaseDecreaseType) outputCommand == IncreaseDecreaseType.INCREASE) - ? SWITCH_100_PERCENT - : ZERO; - } else if (outputCommand instanceof UpDownType) { - dimmValue = ((UpDownType) outputCommand == UpDownType.UP) ? SWITCH_100_PERCENT : ZERO; + if (outputCommand instanceof DecimalType decimalCommand) { + dimmValue = decimalCommand.byteValue(); + } else if (outputCommand instanceof OnOffType onOffCommand) { + dimmValue = (onOffCommand == OnOffType.ON) ? SWITCH_100_PERCENT : ZERO; + } else if (outputCommand instanceof IncreaseDecreaseType increaseDecreaseCommand) { + dimmValue = (increaseDecreaseCommand == IncreaseDecreaseType.INCREASE) ? SWITCH_100_PERCENT : ZERO; + } else if (outputCommand instanceof UpDownType upDownCommand) { + dimmValue = (upDownCommand == UpDownType.UP) ? SWITCH_100_PERCENT : ZERO; } else { throw new IllegalArgumentException(outputCommand.toFullString() + " is no valid dimming command."); } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_3F/A5_3F_7F_EltakoFRM.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_3F/A5_3F_7F_EltakoFRM.java index b10ba9096..a4b9edb66 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_3F/A5_3F_7F_EltakoFRM.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_3F/A5_3F_7F_EltakoFRM.java @@ -52,20 +52,19 @@ public class A5_3F_7F_EltakoFRM extends _4BSMessage { @Override protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command, Function getCurrentStateFunc, @Nullable Configuration config) { - if (command instanceof PercentType) { - PercentType target = (PercentType) command; - int rawPosition = Math.round( - (PercentType.HUNDRED.floatValue() - target.floatValue()) * TOP / PercentType.HUNDRED.floatValue()); + if (command instanceof PercentType percentCommand) { + int rawPosition = Math.round((PercentType.HUNDRED.floatValue() - percentCommand.floatValue()) * TOP + / PercentType.HUNDRED.floatValue()); int position = Math.min(TOP, Math.max(BOTTOM, rawPosition)); setData((byte) position, ZERO, MOVE, TEACHIN_BIT); - } else if (command instanceof UpDownType) { - if ((UpDownType) command == UpDownType.UP) { + } else if (command instanceof UpDownType upDownCommand) { + if (upDownCommand == UpDownType.UP) { setData((byte) TOP, ZERO, MOVE, TEACHIN_BIT); // => 0 percent - } else if ((UpDownType) command == UpDownType.DOWN) { + } else if (upDownCommand == UpDownType.DOWN) { setData((byte) BOTTOM, ZERO, MOVE, TEACHIN_BIT); // => 100 percent } - } else if (command instanceof StopMoveType) { - if ((StopMoveType) command == StopMoveType.STOP) { + } else if (command instanceof StopMoveType stopMoveCommand) { + if (stopMoveCommand == StopMoveType.STOP) { setData(ZERO, ZERO, STOP, TEACHIN_BIT); } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_3F/A5_3F_7F_EltakoFSB.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_3F/A5_3F_7F_EltakoFSB.java index 3d6e55d0c..67f016f17 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_3F/A5_3F_7F_EltakoFSB.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_3F/A5_3F_7F_EltakoFSB.java @@ -61,21 +61,19 @@ public class A5_3F_7F_EltakoFSB extends _4BSMessage { shutTime = Math.min(255, config.as(EnOceanChannelRollershutterConfig.class).shutTime); } - if (command instanceof PercentType) { + if (command instanceof PercentType percentCommand) { State channelState = getCurrentStateFunc.apply(channelId); - - PercentType target = (PercentType) command; - if (target.intValue() == PercentType.ZERO.intValue()) { + if (percentCommand.intValue() == PercentType.ZERO.intValue()) { setData(ZERO, (byte) shutTime, MOVE_UP, TEACHIN_BIT); // => move completely up - } else if (target.intValue() == PercentType.HUNDRED.intValue()) { + } else if (percentCommand.intValue() == PercentType.HUNDRED.intValue()) { setData(ZERO, (byte) shutTime, MOVE_DOWN, TEACHIN_BIT); // => move completely down } else if (channelState != null) { PercentType current = channelState.as(PercentType.class); if (current != null) { - if (current.intValue() != target.intValue()) { - byte direction = current.intValue() > target.intValue() ? MOVE_UP : MOVE_DOWN; + if (current.intValue() != percentCommand.intValue()) { + byte direction = current.intValue() > percentCommand.intValue() ? MOVE_UP : MOVE_DOWN; byte duration = (byte) Math.min(255, - (Math.abs(current.intValue() - target.intValue()) * shutTime) + (Math.abs(current.intValue() - percentCommand.intValue()) * shutTime) / PercentType.HUNDRED.intValue()); setData(ZERO, duration, direction, TEACHIN_BIT); @@ -83,14 +81,14 @@ public class A5_3F_7F_EltakoFSB extends _4BSMessage { } } - } else if (command instanceof UpDownType) { - if ((UpDownType) command == UpDownType.UP) { + } else if (command instanceof UpDownType upDownCommand) { + if (upDownCommand == UpDownType.UP) { setData(ZERO, (byte) shutTime, MOVE_UP, TEACHIN_BIT); // => 0 percent - } else if ((UpDownType) command == UpDownType.DOWN) { + } else if (upDownCommand == UpDownType.DOWN) { setData(ZERO, (byte) shutTime, MOVE_DOWN, TEACHIN_BIT); // => 100 percent } - } else if (command instanceof StopMoveType) { - if ((StopMoveType) command == StopMoveType.STOP) { + } else if (command instanceof StopMoveType stopMoveCommand) { + if (stopMoveCommand == StopMoveType.STOP) { setData(ZERO, (byte) 0xFF, STOP, TEACHIN_BIT); } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01.java index 074ba0af2..3775eff16 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01.java @@ -107,11 +107,11 @@ public abstract class D2_01 extends _VLDMessage { protected void setDimmingData(Command command, byte outputChannel, Configuration config) { byte outputValue; - if (command instanceof DecimalType) { - if (((DecimalType) command).equals(DecimalType.ZERO)) { + if (command instanceof DecimalType decimalCommand) { + if (decimalCommand.equals(DecimalType.ZERO)) { outputValue = STATUS_SWITCHING_OFF; } else { - outputValue = ((DecimalType) command).byteValue(); + outputValue = decimalCommand.byteValue(); } } else if ((OnOffType) command == OnOffType.ON) { outputValue = STATUS_DIMMING_100; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_09_Permundo.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_09_Permundo.java index 75bbde8fd..9307d9d87 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_09_Permundo.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_09_Permundo.java @@ -58,8 +58,8 @@ public class D2_01_09_Permundo extends D2_01 { private void setRepeaterMode(Command command) { if (command == RefreshType.REFRESH) { senderId = new byte[0]; // make this message invalid as we do not support refresh of repeater status - } else if (command instanceof StringType) { - switch (((StringType) command).toString()) { + } else if (command instanceof StringType stringCommand) { + switch (stringCommand.toString()) { case EnOceanBindingConstants.REPEATERMODE_LEVEL_1: setRORG(RORG.MSC).setData((byte) 0x03, (byte) 0x35, (byte) 0x01); break; @@ -75,8 +75,8 @@ public class D2_01_09_Permundo extends D2_01 { private void setEcoMode(Command command) { if (command == RefreshType.REFRESH) { senderId = new byte[0]; // make this message invalid as we do not support refresh of ecomode status - } else if (command instanceof OnOffType) { - if (((OnOffType) command) == OnOffType.ON) { + } else if (command instanceof OnOffType onOffCommand) { + if (onOffCommand == OnOffType.ON) { setRORG(RORG.MSC).setData((byte) 0x03, (byte) 0x36, (byte) 0x01); } else { setRORG(RORG.MSC).setData((byte) 0x03, (byte) 0x36, (byte) 0x00); diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0F_NodON.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0F_NodON.java index dcea0e6f2..68522bdcb 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0F_NodON.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_0F_NodON.java @@ -48,8 +48,8 @@ public class D2_01_0F_NodON extends D2_01 { if (channelId.equalsIgnoreCase(CHANNEL_REPEATERMODE)) { if (command instanceof RefreshType) { senderId = new byte[0]; // make this message invalid as we do not support refresh of repeter status - } else if (command instanceof StringType) { - switch (((StringType) command).toString()) { + } else if (command instanceof StringType stringCommand) { + switch (stringCommand.toString()) { case EnOceanBindingConstants.REPEATERMODE_LEVEL_1: setRORG(RORG.MSC).setData((byte) 0x00, (byte) 0x46, (byte) 0x08, (byte) 0x01, (byte) 0x01); break; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_12_NodON.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_12_NodON.java index 28af568f2..61df5f8ba 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_12_NodON.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_01/D2_01_12_NodON.java @@ -48,8 +48,8 @@ public class D2_01_12_NodON extends D2_01 { if (channelId.equalsIgnoreCase(CHANNEL_REPEATERMODE)) { if (command instanceof RefreshType) { senderId = new byte[0]; // make this message invalid as we do not support refresh of repeter status - } else if (command instanceof StringType) { - switch (((StringType) command).toString()) { + } else if (command instanceof StringType stringCommand) { + switch (stringCommand.toString()) { case EnOceanBindingConstants.REPEATERMODE_LEVEL_1: setRORG(RORG.MSC).setData((byte) 0x00, (byte) 0x46, (byte) 0x08, (byte) 0x01, (byte) 0x01); break; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_05/D2_05_00.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_05/D2_05_00.java index eeab198a8..107a7b793 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_05/D2_05_00.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_05/D2_05_00.java @@ -75,8 +75,8 @@ public class D2_05_00 extends _VLDMessage { if (command == StopMoveType.STOP) { setData((byte) (outputChannel + CMD_ACTUATOR_STOP)); } - } else if (command instanceof PercentType) { - setData((byte) (((PercentType) command).intValue()), (byte) 0x00, (byte) 0x00, + } else if (command instanceof PercentType percentCommand) { + setData((byte) (percentCommand.intValue()), (byte) 0x00, (byte) 0x00, (byte) (outputChannel + CMD_ACTUATOR_SET_POSITION)); } } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_05/D2_05_00_NodON.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_05/D2_05_00_NodON.java index a74dcba4e..6e5c048da 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_05/D2_05_00_NodON.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_05/D2_05_00_NodON.java @@ -49,8 +49,8 @@ public class D2_05_00_NodON extends D2_05_00 { if (channelId.equals(CHANNEL_REPEATERMODE)) { if (command == RefreshType.REFRESH) { senderId = new byte[0]; // make this message invalid as we do not support refresh of repeter status - } else if (command instanceof StringType) { - switch (((StringType) command).toString()) { + } else if (command instanceof StringType stringCommand) { + switch (stringCommand.toString()) { case EnOceanBindingConstants.REPEATERMODE_LEVEL_1: setRORG(RORG.MSC).setData((byte) 0x00, (byte) 0x46, (byte) 0x08, (byte) 0x01, (byte) 0x01); break; diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_50/D2_50.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_50/D2_50.java index eb211b2f4..b94cece7f 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_50/D2_50.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_50/D2_50.java @@ -86,15 +86,15 @@ public class D2_50 extends _VLDMessage { } else { switch (channelId) { case CHANNEL_VENTILATIONOPERATIONMODE: - if (command instanceof StringType) { - byte value = (byte) (Helper.tryParseInt(((StringType) command).toString(), 15) & 0x0f); + if (command instanceof StringType stringCommand) { + byte value = (byte) (Helper.tryParseInt(stringCommand.toString(), 15) & 0x0f); setData((byte) (MT_CONTROL + value), CONTROL_NOACTION, TMOC_NOACTION, THRESHOLD_NOACTION, THRESHOLD_NOACTION, CONTROL_NOACTION); } break; case CHANNEL_TIMEROPERATIONMODE: - if (command instanceof OnOffType) { - byte value = (OnOffType) command == OnOffType.ON ? TMOC_ACTIVATE : TMOC_NOACTION; + if (command instanceof OnOffType onOffCommand) { + byte value = onOffCommand == OnOffType.ON ? TMOC_ACTIVATE : TMOC_NOACTION; setData((byte) (MT_CONTROL + DOMC_NOACTION), CONTROL_NOACTION, value, THRESHOLD_NOACTION, THRESHOLD_NOACTION, CONTROL_NOACTION); } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/EEPFactory.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/EEPFactory.java index 59d9b9540..ba23b7b99 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/EEPFactory.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/EEPFactory.java @@ -95,7 +95,7 @@ public class EEPFactory { } public static @Nullable EEP buildEEPFromTeachInERP1(ERP1Message msg) { - if (!msg.getIsTeachIn() && !(msg.getRORG() == RORG.RPS)) { + if (!msg.getIsTeachIn() && msg.getRORG() != RORG.RPS) { return null; } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02_01.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02_01.java index 80e7db349..7e604fde7 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02_01.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02_01.java @@ -74,8 +74,8 @@ public class F6_02_01 extends F6_02 { @Override protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command, Function getCurrentStateFunc, @Nullable Configuration config) { - if (command instanceof StringType) { - String s = ((StringType) command).toString(); + if (command instanceof StringType stringCommand) { + String s = stringCommand.toString(); if (s.equals(CommonTriggerEvents.DIR1_RELEASED) || s.equals(CommonTriggerEvents.DIR2_RELEASED)) { setStatus(_RPSMessage.T21_FLAG); diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02_02.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02_02.java index ed63201e8..d94127539 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02_02.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02_02.java @@ -73,8 +73,8 @@ public class F6_02_02 extends F6_02 { @Override protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command, Function getCurrentStateFunc, @Nullable Configuration config) { - if (command instanceof StringType) { - String s = ((StringType) command).toString(); + if (command instanceof StringType stringCommand) { + String s = stringCommand.toString(); if (s.equals(CommonTriggerEvents.DIR1_RELEASED) || s.equals(CommonTriggerEvents.DIR2_RELEASED)) { setStatus(_RPSMessage.T21_FLAG); diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBaseThingHandler.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBaseThingHandler.java index c598caa30..974aa056e 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBaseThingHandler.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBaseThingHandler.java @@ -209,8 +209,8 @@ public abstract class EnOceanBaseThingHandler extends ConfigStatusThingHandler { return null; } ThingHandler handler = bridge.getHandler(); - if (handler instanceof EnOceanBridgeHandler) { - this.gateway = (EnOceanBridgeHandler) handler; + if (handler instanceof EnOceanBridgeHandler bridgeHandler) { + this.gateway = bridgeHandler; } else { return null; } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBridgeHandler.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBridgeHandler.java index 303936c16..f75a774a4 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBridgeHandler.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBridgeHandler.java @@ -116,13 +116,13 @@ public class EnOceanBridgeHandler extends ConfigStatusBridgeHandler implements T } } }); - } else if (command instanceof StringType) { - sendMessage(ESP3PacketFactory.CO_WR_REPEATER((StringType) command), + } else if (command instanceof StringType stringCommand) { + sendMessage(ESP3PacketFactory.CO_WR_REPEATER(stringCommand), new ResponseListenerIgnoringTimeouts() { @Override public void responseReceived(BaseResponse response) { if (response.isOK()) { - updateState(channelUID, (StringType) command); + updateState(channelUID, stringCommand); } } }); @@ -130,9 +130,9 @@ public class EnOceanBridgeHandler extends ConfigStatusBridgeHandler implements T break; case CHANNEL_SETBASEID: - if (command instanceof StringType) { + if (command instanceof StringType stringCommand) { try { - byte[] id = HexUtils.hexToBytes(((StringType) command).toFullString()); + byte[] id = HexUtils.hexToBytes(stringCommand.toFullString()); sendMessage(ESP3PacketFactory.CO_WR_IDBASE(id), new ResponseListenerIgnoringTimeouts() { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanClassicDeviceHandler.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanClassicDeviceHandler.java index ae1ca7314..657568458 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanClassicDeviceHandler.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanClassicDeviceHandler.java @@ -180,8 +180,8 @@ public class EnOceanClassicDeviceHandler extends EnOceanBaseActuatorHandler { } private @Nullable StringType convertToPressedCommand(Command command, SwitchMode switchMode) { - if (command instanceof StringType) { - return (StringType) command; + if (command instanceof StringType stringCommand) { + return stringCommand; } else if (command instanceof OnOffType) { switch (switchMode) { case RockerSwitch: diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ESP2Packet.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ESP2Packet.java index 3f0e277b4..7c860bc81 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ESP2Packet.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ESP2Packet.java @@ -210,7 +210,7 @@ public class ESP2Packet { return ZERO; } - private byte calcCheckSum(byte data[], int offset, int length) { + private byte calcCheckSum(byte[] data, int offset, int length) { int checkSum = 0; for (int i = 0; i < length; i++) { checkSum += (data[offset + i] & 0xff); @@ -251,7 +251,7 @@ public class ESP2Packet { } } - public static boolean validateCheckSum(byte data[], int length, byte checkSum) { + public static boolean validateCheckSum(byte[] data, int length, byte checkSum) { int sum = 0; for (int i = 0; i < length; i++) { sum += (data[i] & 0xff); diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ESP3Packet.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ESP3Packet.java index b27a01f41..011b33a9b 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ESP3Packet.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/ESP3Packet.java @@ -73,7 +73,7 @@ public class ESP3Packet { this.basePacket = basePacket; } - private byte calcCRC8(byte data[], int offset, int length) { + private byte calcCRC8(byte[] data, int offset, int length) { byte output = 0; for (int i = offset; i < offset + length; i++) { int index = (output ^ data[i]) & 0xff; @@ -112,7 +112,7 @@ public class ESP3Packet { } } - public static boolean checkCRC8(byte data[], int length, byte crc8) { + public static boolean checkCRC8(byte[] data, int length, byte crc8) { byte output = 0; for (int i = 0; i < length; i++) { int index = (output ^ data[i]) & 0xff; diff --git a/bundles/org.openhab.binding.enphase/src/main/java/org/openhab/binding/enphase/internal/discovery/EnphaseDevicesDiscoveryService.java b/bundles/org.openhab.binding.enphase/src/main/java/org/openhab/binding/enphase/internal/discovery/EnphaseDevicesDiscoveryService.java index 46a82fdac..bf664b17f 100644 --- a/bundles/org.openhab.binding.enphase/src/main/java/org/openhab/binding/enphase/internal/discovery/EnphaseDevicesDiscoveryService.java +++ b/bundles/org.openhab.binding.enphase/src/main/java/org/openhab/binding/enphase/internal/discovery/EnphaseDevicesDiscoveryService.java @@ -14,10 +14,10 @@ package org.openhab.binding.enphase.internal.discovery; import static org.openhab.binding.enphase.internal.EnphaseBindingConstants.*; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -52,13 +52,13 @@ public class EnphaseDevicesDiscoveryService extends AbstractDiscoveryService private @Nullable EnvoyBridgeHandler envoyHandler; public EnphaseDevicesDiscoveryService() { - super(Collections.singleton(THING_TYPE_ENPHASE_INVERTER), TIMEOUT_SECONDS, false); + super(Set.of(THING_TYPE_ENPHASE_INVERTER), TIMEOUT_SECONDS, false); } @Override public void setThingHandler(final @Nullable ThingHandler handler) { - if (handler instanceof EnvoyBridgeHandler) { - envoyHandler = (EnvoyBridgeHandler) handler; + if (handler instanceof EnvoyBridgeHandler bridgeHandler) { + envoyHandler = bridgeHandler; } } diff --git a/bundles/org.openhab.binding.enphase/src/main/java/org/openhab/binding/enphase/internal/discovery/EnvoyDiscoveryParticipant.java b/bundles/org.openhab.binding.enphase/src/main/java/org/openhab/binding/enphase/internal/discovery/EnvoyDiscoveryParticipant.java index 9e99b2c6d..02fe022f2 100644 --- a/bundles/org.openhab.binding.enphase/src/main/java/org/openhab/binding/enphase/internal/discovery/EnvoyDiscoveryParticipant.java +++ b/bundles/org.openhab.binding.enphase/src/main/java/org/openhab/binding/enphase/internal/discovery/EnvoyDiscoveryParticipant.java @@ -15,7 +15,6 @@ package org.openhab.binding.enphase.internal.discovery; import static org.openhab.binding.enphase.internal.EnphaseBindingConstants.*; import java.net.Inet4Address; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -56,7 +55,7 @@ public class EnvoyDiscoveryParticipant implements MDNSDiscoveryParticipant, Envo @Override public Set getSupportedThingTypeUIDs() { - return Collections.singleton(EnphaseBindingConstants.THING_TYPE_ENPHASE_ENVOY); + return Set.of(EnphaseBindingConstants.THING_TYPE_ENPHASE_ENVOY); } @Override diff --git a/bundles/org.openhab.binding.enphase/src/main/java/org/openhab/binding/enphase/internal/handler/EnvoyBridgeHandler.java b/bundles/org.openhab.binding.enphase/src/main/java/org/openhab/binding/enphase/internal/handler/EnvoyBridgeHandler.java index be703b526..4ebb1f6ec 100644 --- a/bundles/org.openhab.binding.enphase/src/main/java/org/openhab/binding/enphase/internal/handler/EnvoyBridgeHandler.java +++ b/bundles/org.openhab.binding.enphase/src/main/java/org/openhab/binding/enphase/internal/handler/EnvoyBridgeHandler.java @@ -22,8 +22,8 @@ import static org.openhab.binding.enphase.internal.EnphaseBindingConstants.ENVOY import java.time.Duration; import java.time.temporal.ChronoUnit; import java.util.Collection; -import java.util.Collections; import java.util.Map; +import java.util.Set; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.function.Function; @@ -132,7 +132,7 @@ public class EnvoyBridgeHandler extends BaseBridgeHandler { @Override public Collection> getServices() { - return Collections.singleton(EnphaseDevicesDiscoveryService.class); + return Set.of(EnphaseDevicesDiscoveryService.class); } @Override @@ -347,15 +347,14 @@ public class EnvoyBridgeHandler extends BaseBridgeHandler { @Override public void childHandlerInitialized(final ThingHandler childHandler, final Thing childThing) { - if (childHandler instanceof EnphaseInverterHandler) { - updateInverter(getInvertersData(false), (EnphaseInverterHandler) childHandler); + if (childHandler instanceof EnphaseInverterHandler handler) { + updateInverter(getInvertersData(false), handler); } - if (childHandler instanceof EnphaseDeviceHandler) { + if (childHandler instanceof EnphaseDeviceHandler handler) { final Map devices = getDevices(false); if (devices != null) { - ((EnphaseDeviceHandler) childHandler) - .refreshDeviceState(devices.get(((EnphaseDeviceHandler) childHandler).getSerialNumber())); + handler.refreshDeviceState(devices.get(handler.getSerialNumber())); } } } diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/EnturNoHandlerFactory.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/EnturNoHandlerFactory.java index cb5c3ed93..19575e2a9 100644 --- a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/EnturNoHandlerFactory.java +++ b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/EnturNoHandlerFactory.java @@ -14,7 +14,6 @@ package org.openhab.binding.enturno.internal; import static org.openhab.binding.enturno.internal.EnturNoBindingConstants.LINESTOP; -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.enturno", service = ThingHandlerFactory.class) public class EnturNoHandlerFactory extends BaseThingHandlerFactory { - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(LINESTOP); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(LINESTOP); private final HttpClient httpClient; diff --git a/bundles/org.openhab.binding.epsonprojector/src/main/java/org/openhab/binding/epsonprojector/internal/enums/Switch.java b/bundles/org.openhab.binding.epsonprojector/src/main/java/org/openhab/binding/epsonprojector/internal/enums/Switch.java index 2e2b87d89..9bf18a1a7 100644 --- a/bundles/org.openhab.binding.epsonprojector/src/main/java/org/openhab/binding/epsonprojector/internal/enums/Switch.java +++ b/bundles/org.openhab.binding.epsonprojector/src/main/java/org/openhab/binding/epsonprojector/internal/enums/Switch.java @@ -23,5 +23,5 @@ import org.eclipse.jdt.annotation.NonNullByDefault; @NonNullByDefault public enum Switch { ON, - OFF; + OFF } diff --git a/bundles/org.openhab.binding.etherrain/src/main/java/org/openhab/binding/etherrain/internal/EtherRainBindingConstants.java b/bundles/org.openhab.binding.etherrain/src/main/java/org/openhab/binding/etherrain/internal/EtherRainBindingConstants.java index a39eb8d13..4ec1f4077 100644 --- a/bundles/org.openhab.binding.etherrain/src/main/java/org/openhab/binding/etherrain/internal/EtherRainBindingConstants.java +++ b/bundles/org.openhab.binding.etherrain/src/main/java/org/openhab/binding/etherrain/internal/EtherRainBindingConstants.java @@ -12,7 +12,6 @@ */ package org.openhab.binding.etherrain.internal; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -36,7 +35,7 @@ public class EtherRainBindingConstants { // List of all Thing Type UIDs public static final ThingTypeUID ETHERRAIN_THING = new ThingTypeUID(BINDING_ID, ETHERRAIN); - public static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(ETHERRAIN_THING); + public static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(ETHERRAIN_THING); // List of internal default values diff --git a/bundles/org.openhab.binding.etherrain/src/main/java/org/openhab/binding/etherrain/internal/config/EtherRainConfiguration.java b/bundles/org.openhab.binding.etherrain/src/main/java/org/openhab/binding/etherrain/internal/config/EtherRainConfiguration.java index 44a6855ac..b1d89950c 100644 --- a/bundles/org.openhab.binding.etherrain/src/main/java/org/openhab/binding/etherrain/internal/config/EtherRainConfiguration.java +++ b/bundles/org.openhab.binding.etherrain/src/main/java/org/openhab/binding/etherrain/internal/config/EtherRainConfiguration.java @@ -12,7 +12,6 @@ */ package org.openhab.binding.etherrain.internal.config; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -31,7 +30,7 @@ public class EtherRainConfiguration { public static final ThingTypeUID ETHERRAIN_THING_TYPE = new ThingTypeUID(BINDING_ID, "etherrain"); - public static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(ETHERRAIN_THING_TYPE); + public static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(ETHERRAIN_THING_TYPE); /** * Hostname of the EtherRain API. diff --git a/bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/EvccHandler.java b/bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/EvccHandler.java index d59e3c3e2..cb26e80d7 100644 --- a/bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/EvccHandler.java +++ b/bundles/org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/EvccHandler.java @@ -475,7 +475,7 @@ public class EvccHandler extends BaseThingHandler { updateState(channel, new QuantityType<>(targetSoC, Units.PERCENT)); String targetTime = loadpoint.getTargetTime(); - if (targetTime == null || targetTime.equals("0001-01-01T00:00:00Z")) { + if (targetTime == null || "0001-01-01T00:00:00Z".equals(targetTime)) { channel = new ChannelUID(uid, loadpointName, CHANNEL_LOADPOINT_TARGET_TIME_ENABLED); updateState(channel, OnOffType.OFF); targetTimeEnabled = false; diff --git a/bundles/org.openhab.binding.evohome/src/main/java/org/openhab/binding/evohome/internal/handler/EvohomeAccountBridgeHandler.java b/bundles/org.openhab.binding.evohome/src/main/java/org/openhab/binding/evohome/internal/handler/EvohomeAccountBridgeHandler.java index e472ce968..db292b034 100644 --- a/bundles/org.openhab.binding.evohome/src/main/java/org/openhab/binding/evohome/internal/handler/EvohomeAccountBridgeHandler.java +++ b/bundles/org.openhab.binding.evohome/src/main/java/org/openhab/binding/evohome/internal/handler/EvohomeAccountBridgeHandler.java @@ -296,13 +296,11 @@ public class EvohomeAccountBridgeHandler extends BaseBridgeHandler { for (Thing handler : getThing().getThings()) { ThingHandler thingHandler = handler.getHandler(); - if (thingHandler instanceof EvohomeTemperatureControlSystemHandler) { - EvohomeTemperatureControlSystemHandler tcsHandler = (EvohomeTemperatureControlSystemHandler) thingHandler; + if (thingHandler instanceof EvohomeTemperatureControlSystemHandler tcsHandler) { tcsHandler.update(tcsIdToGatewayMap.get(tcsHandler.getId()), idToTcsMap.get(tcsHandler.getId())); idToTcsThingsStatusMap.put(tcsHandler.getId(), tcsHandler.getThing().getStatus()); } - if (thingHandler instanceof EvohomeHeatingZoneHandler) { - EvohomeHeatingZoneHandler zoneHandler = (EvohomeHeatingZoneHandler) thingHandler; + if (thingHandler instanceof EvohomeHeatingZoneHandler zoneHandler) { zoneHandler.update(idToTcsThingsStatusMap.get(zoneIdToTcsIdMap.get(zoneHandler.getId())), idToZoneMap.get(zoneHandler.getId())); } diff --git a/bundles/org.openhab.binding.evohome/src/main/java/org/openhab/binding/evohome/internal/handler/EvohomeHeatingZoneHandler.java b/bundles/org.openhab.binding.evohome/src/main/java/org/openhab/binding/evohome/internal/handler/EvohomeHeatingZoneHandler.java index 8dc6cbb39..d15e067c0 100644 --- a/bundles/org.openhab.binding.evohome/src/main/java/org/openhab/binding/evohome/internal/handler/EvohomeHeatingZoneHandler.java +++ b/bundles/org.openhab.binding.evohome/src/main/java/org/openhab/binding/evohome/internal/handler/EvohomeHeatingZoneHandler.java @@ -86,8 +86,8 @@ public class EvohomeHeatingZoneHandler extends BaseEvohomeHandler { if (bridge != null) { String channelId = channelUID.getId(); if (EvohomeBindingConstants.ZONE_SET_POINT_CHANNEL.equals(channelId)) { - if (command instanceof QuantityType) { - QuantityType state = ((QuantityType) command).toUnit(SIUnits.CELSIUS); + if (command instanceof QuantityType quantityCommand) { + QuantityType state = quantityCommand.toUnit(SIUnits.CELSIUS); double newTempInCelsius = state.doubleValue(); if (newTempInCelsius == CANCEL_SET_POINT_OVERRIDE) { diff --git a/bundles/org.openhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/ExecHandlerFactory.java b/bundles/org.openhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/ExecHandlerFactory.java index 314725f22..47705820d 100644 --- a/bundles/org.openhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/ExecHandlerFactory.java +++ b/bundles/org.openhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/ExecHandlerFactory.java @@ -14,7 +14,6 @@ package org.openhab.binding.exec.internal; import static org.openhab.binding.exec.internal.ExecBindingConstants.THING_COMMAND; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -40,7 +39,7 @@ import org.slf4j.LoggerFactory; @NonNullByDefault @Component(service = ThingHandlerFactory.class, configurationPid = "binding.exec") public class ExecHandlerFactory extends BaseThingHandlerFactory { - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_COMMAND); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_COMMAND); private final Logger logger = LoggerFactory.getLogger(ExecHandlerFactory.class); private final ExecWhitelistWatchService execWhitelistWatchService; diff --git a/bundles/org.openhab.binding.feican/src/main/java/org/openhab/binding/feican/internal/FeicanBindingConstants.java b/bundles/org.openhab.binding.feican/src/main/java/org/openhab/binding/feican/internal/FeicanBindingConstants.java index b86323f36..9d93d2f9c 100644 --- a/bundles/org.openhab.binding.feican/src/main/java/org/openhab/binding/feican/internal/FeicanBindingConstants.java +++ b/bundles/org.openhab.binding.feican/src/main/java/org/openhab/binding/feican/internal/FeicanBindingConstants.java @@ -12,7 +12,6 @@ */ package org.openhab.binding.feican.internal; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -32,7 +31,7 @@ public final class FeicanBindingConstants { // List of all Thing Type UIDs public static final ThingTypeUID THING_TYPE_BULB = new ThingTypeUID(BINDING_ID, "bulb"); - public static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_BULB); + public static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_BULB); // List of all Channel ids public static final String CHANNEL_COLOR = "color"; diff --git a/bundles/org.openhab.binding.feican/src/main/java/org/openhab/binding/feican/internal/handler/FeicanHandler.java b/bundles/org.openhab.binding.feican/src/main/java/org/openhab/binding/feican/internal/handler/FeicanHandler.java index 4eb02edd3..66a64a839 100644 --- a/bundles/org.openhab.binding.feican/src/main/java/org/openhab/binding/feican/internal/handler/FeicanHandler.java +++ b/bundles/org.openhab.binding.feican/src/main/java/org/openhab/binding/feican/internal/handler/FeicanHandler.java @@ -61,14 +61,14 @@ public class FeicanHandler extends BaseThingHandler { @Override public void handleCommand(ChannelUID channelUID, Command command) { try { - if (command instanceof OnOffType) { - handleOnOff((OnOffType) command); - } else if (command instanceof HSBType) { - handleColor(channelUID, (HSBType) command); - } else if (command instanceof PercentType) { - handlePercentage(channelUID, (PercentType) command); - } else if (command instanceof StringType) { - handleString(channelUID, (StringType) command); + if (command instanceof OnOffType onOffCommand) { + handleOnOff(onOffCommand); + } else if (command instanceof HSBType hsbCommand) { + handleColor(channelUID, hsbCommand); + } else if (command instanceof PercentType percentCommand) { + handlePercentage(channelUID, percentCommand); + } else if (command instanceof StringType stringCommand) { + handleString(channelUID, stringCommand); } } catch (IOException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR, e.getMessage()); diff --git a/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/FineOffsetWeatherStationHandlerFactory.java b/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/FineOffsetWeatherStationHandlerFactory.java index eec2be3fc..cde55cec0 100644 --- a/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/FineOffsetWeatherStationHandlerFactory.java +++ b/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/FineOffsetWeatherStationHandlerFactory.java @@ -71,8 +71,8 @@ public class FineOffsetWeatherStationHandlerFactory extends BaseThingHandlerFact protected @Nullable ThingHandler createHandler(Thing thing) { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); - if (THING_TYPE_GATEWAY.equals(thingTypeUID) && thing instanceof Bridge) { - return new FineOffsetGatewayHandler((Bridge) thing, gatewayDiscoveryService, channelTypeRegistry, + if (THING_TYPE_GATEWAY.equals(thingTypeUID) && thing instanceof Bridge bridge) { + return new FineOffsetGatewayHandler(bridge, gatewayDiscoveryService, channelTypeRegistry, translationProvider, localeProvider, timeZoneProvider); } if (THING_TYPE_SENSOR.equals(thingTypeUID)) { diff --git a/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/discovery/FineOffsetGatewayDiscoveryService.java b/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/discovery/FineOffsetGatewayDiscoveryService.java index 18e36712e..65a44dfeb 100644 --- a/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/discovery/FineOffsetGatewayDiscoveryService.java +++ b/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/discovery/FineOffsetGatewayDiscoveryService.java @@ -24,9 +24,9 @@ import java.net.SocketException; import java.time.ZoneOffset; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.Set; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -83,7 +83,7 @@ public class FineOffsetGatewayDiscoveryService extends AbstractDiscoveryService @Activate public FineOffsetGatewayDiscoveryService(@Reference TranslationProvider translationProvider, @Reference LocaleProvider localeProvider) throws IllegalArgumentException { - super(Collections.singleton(THING_TYPE_GATEWAY), DISCOVERY_TIME, true); + super(Set.of(THING_TYPE_GATEWAY), DISCOVERY_TIME, true); this.translationProvider = translationProvider; this.localeProvider = localeProvider; this.bundle = FrameworkUtil.getBundle(FineOffsetGatewayDiscoveryService.class); diff --git a/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/domain/Measurand.java b/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/domain/Measurand.java index 786cc992a..65d3f15f7 100644 --- a/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/domain/Measurand.java +++ b/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/domain/Measurand.java @@ -336,6 +336,7 @@ public enum Measurand { } } + @Override public int extractMeasuredValues(byte[] data, int offset, @Nullable Integer channel, ConversionContext context, @Nullable ParserCustomizationType customizationType, List result) { MeasureType measureType = getMeasureType(customizationType); diff --git a/bundles/org.openhab.binding.flicbutton/src/3rdparty/java/io/flic/fliclib/javaclient/Packets.java b/bundles/org.openhab.binding.flicbutton/src/3rdparty/java/io/flic/fliclib/javaclient/Packets.java index 7cdcf011c..f8ae06a18 100644 --- a/bundles/org.openhab.binding.flicbutton/src/3rdparty/java/io/flic/fliclib/javaclient/Packets.java +++ b/bundles/org.openhab.binding.flicbutton/src/3rdparty/java/io/flic/fliclib/javaclient/Packets.java @@ -26,7 +26,7 @@ abstract class CommandPacket { return res; } - abstract protected void write(OutputStream stream) throws IOException; + protected abstract void write(OutputStream stream) throws IOException; } class CmdGetInfo extends CommandPacket { @@ -210,7 +210,7 @@ abstract class EventPacket { } } - abstract protected void parseInternal(InputStream stream) throws IOException; + protected abstract void parseInternal(InputStream stream) throws IOException; } class EvtAdvertisementPacket extends EventPacket { @@ -366,7 +366,7 @@ class EvtGetButtonInfoResponse extends EventPacket { sb.append(String.format("%02x", uuidBytes[i])); } uuid = sb.toString(); - if (uuid.equals("00000000000000000000000000000000")) { + if ("00000000000000000000000000000000".equals(uuid)) { uuid = null; } color = StreamUtils.getString(stream, 16); diff --git a/bundles/org.openhab.binding.flicbutton/src/main/java/org/openhab/binding/flicbutton/internal/FlicButtonBindingConstants.java b/bundles/org.openhab.binding.flicbutton/src/main/java/org/openhab/binding/flicbutton/internal/FlicButtonBindingConstants.java index c1e06150f..f0f6f4d7b 100644 --- a/bundles/org.openhab.binding.flicbutton/src/main/java/org/openhab/binding/flicbutton/internal/FlicButtonBindingConstants.java +++ b/bundles/org.openhab.binding.flicbutton/src/main/java/org/openhab/binding/flicbutton/internal/FlicButtonBindingConstants.java @@ -36,8 +36,8 @@ public class FlicButtonBindingConstants { public static final ThingTypeUID BRIDGE_THING_TYPE = new ThingTypeUID(BINDING_ID, "flicd-bridge"); public static final ThingTypeUID FLICBUTTON_THING_TYPE = new ThingTypeUID(BINDING_ID, "button"); - public static final Set BRIDGE_THING_TYPES_UIDS = Collections.singleton(BRIDGE_THING_TYPE); - public static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(FLICBUTTON_THING_TYPE); + public static final Set BRIDGE_THING_TYPES_UIDS = Set.of(BRIDGE_THING_TYPE); + public static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(FLICBUTTON_THING_TYPE); // List of all configuration options public static final String CONFIG_HOST_NAME = "hostname"; diff --git a/bundles/org.openhab.binding.flicbutton/src/main/java/org/openhab/binding/flicbutton/internal/handler/ChildThingHandler.java b/bundles/org.openhab.binding.flicbutton/src/main/java/org/openhab/binding/flicbutton/internal/handler/ChildThingHandler.java index c42f2c4e1..277ea2908 100644 --- a/bundles/org.openhab.binding.flicbutton/src/main/java/org/openhab/binding/flicbutton/internal/handler/ChildThingHandler.java +++ b/bundles/org.openhab.binding.flicbutton/src/main/java/org/openhab/binding/flicbutton/internal/handler/ChildThingHandler.java @@ -14,7 +14,7 @@ package org.openhab.binding.flicbutton.internal.handler; import java.util.Collection; -import java.util.Collections; +import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -34,8 +34,7 @@ import org.openhab.core.thing.binding.BridgeHandler; */ @NonNullByDefault public abstract class ChildThingHandler extends BaseThingHandler { - private static final Collection DEFAULT_TOLERATED_BRIDGE_STATUSES = Collections - .singleton(ThingStatus.ONLINE); + private static final Collection DEFAULT_TOLERATED_BRIDGE_STATUSES = Set.of(ThingStatus.ONLINE); protected boolean bridgeValid = false; protected @Nullable BridgeHandlerType bridgeHandler; diff --git a/bundles/org.openhab.binding.fmiweather/src/main/java/org/openhab/binding/fmiweather/internal/client/FMISID.java b/bundles/org.openhab.binding.fmiweather/src/main/java/org/openhab/binding/fmiweather/internal/client/FMISID.java index 06965ff71..7b4751832 100644 --- a/bundles/org.openhab.binding.fmiweather/src/main/java/org/openhab/binding/fmiweather/internal/client/FMISID.java +++ b/bundles/org.openhab.binding.fmiweather/src/main/java/org/openhab/binding/fmiweather/internal/client/FMISID.java @@ -13,7 +13,6 @@ package org.openhab.binding.fmiweather.internal.client; import java.util.AbstractMap; -import java.util.Collections; import java.util.List; import java.util.Map; @@ -36,6 +35,6 @@ public class FMISID implements QueryParameter { @Override public List> toRequestParameters() { - return Collections.singletonList(new AbstractMap.SimpleImmutableEntry<>("fmisid", fmisid)); + return List.of(new AbstractMap.SimpleImmutableEntry<>("fmisid", fmisid)); } } diff --git a/bundles/org.openhab.binding.fmiweather/src/main/java/org/openhab/binding/fmiweather/internal/client/LatLon.java b/bundles/org.openhab.binding.fmiweather/src/main/java/org/openhab/binding/fmiweather/internal/client/LatLon.java index d6e4836da..a00ae2ab3 100644 --- a/bundles/org.openhab.binding.fmiweather/src/main/java/org/openhab/binding/fmiweather/internal/client/LatLon.java +++ b/bundles/org.openhab.binding.fmiweather/src/main/java/org/openhab/binding/fmiweather/internal/client/LatLon.java @@ -14,7 +14,6 @@ package org.openhab.binding.fmiweather.internal.client; import java.math.BigDecimal; import java.util.AbstractMap; -import java.util.Collections; import java.util.List; import java.util.Map; @@ -37,6 +36,6 @@ public class LatLon implements QueryParameter { @Override public List> toRequestParameters() { - return Collections.singletonList(new AbstractMap.SimpleImmutableEntry<>("latlon", latlon)); + return List.of(new AbstractMap.SimpleImmutableEntry<>("latlon", latlon)); } } diff --git a/bundles/org.openhab.binding.fmiweather/src/test/java/org/openhab/binding/fmiweather/AbstractWeatherHandlerTest.java b/bundles/org.openhab.binding.fmiweather/src/test/java/org/openhab/binding/fmiweather/AbstractWeatherHandlerTest.java index c96b8debb..689790eb8 100644 --- a/bundles/org.openhab.binding.fmiweather/src/test/java/org/openhab/binding/fmiweather/AbstractWeatherHandlerTest.java +++ b/bundles/org.openhab.binding.fmiweather/src/test/java/org/openhab/binding/fmiweather/AbstractWeatherHandlerTest.java @@ -70,7 +70,7 @@ public class AbstractWeatherHandlerTest { } } - public static final List parametersForFloorToEvenMinutes() { + public static List parametersForFloorToEvenMinutes() { return Arrays.asList(new Object[][] { // { 1626605128L /* 2021-07-18 10:45:28 */, 1, 1626605100 /* 10:45 */ }, // { 1626605128L /* 2021-07-18 10:45:28 */, 5, 1626605100 /* 10:45 */ }, // @@ -101,7 +101,7 @@ public class AbstractWeatherHandlerTest { assertEquals(expected, floorToEvenMinutes(epochSeconds, roundMinutes)); } - public static final List parametersForCeilToEvenMinutes() { + public static List parametersForCeilToEvenMinutes() { return Arrays.asList(new Object[][] { // { 1626605128L /* 2021-07-18 10:45:28 */, 1, 1626605160 /* 10:46 */ }, // { 1626605128L /* 2021-07-18 10:45:28 */, 5, 1626605400 /* 10:50 */ }, // @@ -117,7 +117,7 @@ public class AbstractWeatherHandlerTest { assertEquals(expected, ceilToEvenMinutes(epochSeconds, roundMinutes)); } - public static final List parametersForLastValidIndex() { + public static List parametersForLastValidIndex() { return Arrays.asList(new Object[][] { // { "no nulls", 1, new BigDecimal[] { bd(1), bd(2) } }, // { "one null in beginning", 1, new BigDecimal[] { null, bd(2) } }, // diff --git a/bundles/org.openhab.binding.fmiweather/src/test/java/org/openhab/binding/fmiweather/FMIRequestTest.java b/bundles/org.openhab.binding.fmiweather/src/test/java/org/openhab/binding/fmiweather/FMIRequestTest.java index 1aa631fc3..5e2bc898c 100644 --- a/bundles/org.openhab.binding.fmiweather/src/test/java/org/openhab/binding/fmiweather/FMIRequestTest.java +++ b/bundles/org.openhab.binding.fmiweather/src/test/java/org/openhab/binding/fmiweather/FMIRequestTest.java @@ -40,20 +40,24 @@ public class FMIRequestTest { @Test public void testObservationRequestToUrl() { ObservationRequest request = new ObservationRequest(new FMISID("101023"), 1552215664L, 1552215665L, 61); - assertThat(request.toUrl(), is( - "https://opendata.fmi.fi/wfs?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::observations::weather::multipointcoverage" - + "&starttime=2019-03-10T11:01:04Z&endtime=2019-03-10T11:01:05Z×tep=61&fmisid=101023" - + "¶meters=t2m,rh,wd_10min,ws_10min,wg_10min,p_sea,r_1h,snow_aws,vis,n_man,wawa")); + assertThat(request.toUrl(), + is(""" + https://opendata.fmi.fi/wfs?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::observations::weather::multipointcoverage\ + &starttime=2019-03-10T11:01:04Z&endtime=2019-03-10T11:01:05Z×tep=61&fmisid=101023\ + ¶meters=t2m,rh,wd_10min,ws_10min,wg_10min,p_sea,r_1h,snow_aws,vis,n_man,wawa\ + """)); } @Test public void testForecastRequestToUrl() { ForecastRequest request = new ForecastRequest(new LatLon(new BigDecimal("9"), new BigDecimal("8")), 1552215664L, 1552215665L, 61); - assertThat(request.toUrl(), is( - "https://opendata.fmi.fi/wfs?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::forecast::harmonie::surface::point::multipointcoverage" - + "&starttime=2019-03-10T11:01:04Z&endtime=2019-03-10T11:01:05Z×tep=61&latlon=9,8" - + "¶meters=Temperature,Humidity,WindDirection,WindSpeedMS,WindGust,Pressure,Precipitation1h,TotalCloudCover,WeatherSymbol3")); + assertThat(request.toUrl(), + is(""" + https://opendata.fmi.fi/wfs?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::forecast::harmonie::surface::point::multipointcoverage\ + &starttime=2019-03-10T11:01:04Z&endtime=2019-03-10T11:01:05Z×tep=61&latlon=9,8\ + ¶meters=Temperature,Humidity,WindDirection,WindSpeedMS,WindGust,Pressure,Precipitation1h,TotalCloudCover,WeatherSymbol3\ + """)); } @Test @@ -68,9 +72,11 @@ public class FMIRequestTest { } }; ObservationRequest request = new ObservationRequest(location, 1552215664L, 1552215665L, 61); - assertThat(request.toUrl(), is( - "https://opendata.fmi.fi/wfs?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::observations::weather::multipointcoverage" - + "&starttime=2019-03-10T11:01:04Z&endtime=2019-03-10T11:01:05Z×tep=61&lat=MYLAT&lon=FOO&special=x,y,z" - + "¶meters=t2m,rh,wd_10min,ws_10min,wg_10min,p_sea,r_1h,snow_aws,vis,n_man,wawa")); + assertThat(request.toUrl(), + is(""" + https://opendata.fmi.fi/wfs?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::observations::weather::multipointcoverage\ + &starttime=2019-03-10T11:01:04Z&endtime=2019-03-10T11:01:05Z×tep=61&lat=MYLAT&lon=FOO&special=x,y,z\ + ¶meters=t2m,rh,wd_10min,ws_10min,wg_10min,p_sea,r_1h,snow_aws,vis,n_man,wawa\ + """)); } } diff --git a/bundles/org.openhab.binding.folderwatcher/src/main/java/org/openhab/binding/folderwatcher/internal/api/S3Actions.java b/bundles/org.openhab.binding.folderwatcher/src/main/java/org/openhab/binding/folderwatcher/internal/api/S3Actions.java index 131ac7f79..2ba0fd5fe 100644 --- a/bundles/org.openhab.binding.folderwatcher/src/main/java/org/openhab/binding/folderwatcher/internal/api/S3Actions.java +++ b/bundles/org.openhab.binding.folderwatcher/src/main/java/org/openhab/binding/folderwatcher/internal/api/S3Actions.java @@ -124,7 +124,7 @@ public class S3Actions { nameNodesList = doc.getElementsByTagName("IsTruncated"); if (nameNodesList.getLength() > 0) { - if (nameNodesList.item(0).getFirstChild().getTextContent().equals("true")) { + if ("true".equals(nameNodesList.item(0).getFirstChild().getTextContent())) { nameNodesList = doc.getElementsByTagName("NextContinuationToken"); if (nameNodesList.getLength() > 0) { String continueToken = nameNodesList.item(0).getFirstChild().getTextContent(); diff --git a/bundles/org.openhab.binding.folderwatcher/src/main/java/org/openhab/binding/folderwatcher/internal/api/auth/AWS4SignerBase.java b/bundles/org.openhab.binding.folderwatcher/src/main/java/org/openhab/binding/folderwatcher/internal/api/auth/AWS4SignerBase.java index 53c8cacae..cd872a2fa 100644 --- a/bundles/org.openhab.binding.folderwatcher/src/main/java/org/openhab/binding/folderwatcher/internal/api/auth/AWS4SignerBase.java +++ b/bundles/org.openhab.binding.folderwatcher/src/main/java/org/openhab/binding/folderwatcher/internal/api/auth/AWS4SignerBase.java @@ -101,9 +101,8 @@ public abstract class AWS4SignerBase { protected static String getCanonicalRequest(URL endpoint, String httpMethod, String queryParameters, String canonicalizedHeaderNames, String canonicalizedHeaders, String bodyHash) { - String canonicalRequest = httpMethod + "\n" + getCanonicalizedResourcePath(endpoint) + "\n" + queryParameters - + "\n" + canonicalizedHeaders + "\n" + canonicalizedHeaderNames + "\n" + bodyHash; - return canonicalRequest; + return httpMethod + "\n" + getCanonicalizedResourcePath(endpoint) + "\n" + queryParameters + "\n" + + canonicalizedHeaders + "\n" + canonicalizedHeaderNames + "\n" + bodyHash; } protected static String getCanonicalizedResourcePath(URL endpoint) { @@ -154,9 +153,8 @@ public abstract class AWS4SignerBase { protected static String getStringToSign(String scheme, String algorithm, String dateTime, String scope, String canonicalRequest) { - String stringToSign = scheme + "-" + algorithm + "\n" + dateTime + "\n" + scope + "\n" + return scheme + "-" + algorithm + "\n" + dateTime + "\n" + scope + "\n" + BinaryUtils.toHex(hash(canonicalRequest)); - return stringToSign; } public static byte[] hash(String text) { diff --git a/bundles/org.openhab.binding.folderwatcher/src/main/java/org/openhab/binding/folderwatcher/internal/api/auth/AWS4SignerForAuthorizationHeader.java b/bundles/org.openhab.binding.folderwatcher/src/main/java/org/openhab/binding/folderwatcher/internal/api/auth/AWS4SignerForAuthorizationHeader.java index 17a73a831..db6b7cb26 100644 --- a/bundles/org.openhab.binding.folderwatcher/src/main/java/org/openhab/binding/folderwatcher/internal/api/auth/AWS4SignerForAuthorizationHeader.java +++ b/bundles/org.openhab.binding.folderwatcher/src/main/java/org/openhab/binding/folderwatcher/internal/api/auth/AWS4SignerForAuthorizationHeader.java @@ -63,8 +63,7 @@ public class AWS4SignerForAuthorizationHeader extends AWS4SignerBase { String credentialsAuthorizationHeader = "Credential=" + awsAccessKey + "/" + scope; String signedHeadersAuthorizationHeader = "SignedHeaders=" + canonicalizedHeaderNames; String signatureAuthorizationHeader = "Signature=" + BinaryUtils.toHex(signature); - String authorizationHeader = SCHEME + "-" + ALGORITHM + " " + credentialsAuthorizationHeader + ", " - + signedHeadersAuthorizationHeader + ", " + signatureAuthorizationHeader; - return authorizationHeader; + return SCHEME + "-" + ALGORITHM + " " + credentialsAuthorizationHeader + ", " + signedHeadersAuthorizationHeader + + ", " + signatureAuthorizationHeader; } } diff --git a/bundles/org.openhab.binding.folderwatcher/src/main/java/org/openhab/binding/folderwatcher/internal/handler/FtpFolderWatcherHandler.java b/bundles/org.openhab.binding.folderwatcher/src/main/java/org/openhab/binding/folderwatcher/internal/handler/FtpFolderWatcherHandler.java index 88d9f6688..74a8bbe7c 100644 --- a/bundles/org.openhab.binding.folderwatcher/src/main/java/org/openhab/binding/folderwatcher/internal/handler/FtpFolderWatcherHandler.java +++ b/bundles/org.openhab.binding.folderwatcher/src/main/java/org/openhab/binding/folderwatcher/internal/handler/FtpFolderWatcherHandler.java @@ -129,7 +129,7 @@ public class FtpFolderWatcherHandler extends BaseThingHandler { Instant dateNow = Instant.now(); for (FTPFile file : ftpClient.listFiles(dirPath)) { String currentFileName = file.getName(); - if (currentFileName.equals(".") || currentFileName.equals("..")) { + if (".".equals(currentFileName) || "..".equals(currentFileName)) { continue; } String filePath = dirPath + "/" + currentFileName; diff --git a/bundles/org.openhab.binding.folding/src/main/java/org/openhab/binding/folding/internal/discovery/FoldingSlotDiscoveryService.java b/bundles/org.openhab.binding.folding/src/main/java/org/openhab/binding/folding/internal/discovery/FoldingSlotDiscoveryService.java index da7403ba4..793c4442c 100644 --- a/bundles/org.openhab.binding.folding/src/main/java/org/openhab/binding/folding/internal/discovery/FoldingSlotDiscoveryService.java +++ b/bundles/org.openhab.binding.folding/src/main/java/org/openhab/binding/folding/internal/discovery/FoldingSlotDiscoveryService.java @@ -12,9 +12,9 @@ */ package org.openhab.binding.folding.internal.discovery; -import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.Set; import org.openhab.binding.folding.internal.FoldingBindingConstants; import org.openhab.core.config.discovery.AbstractDiscoveryService; @@ -37,7 +37,7 @@ import org.osgi.service.component.annotations.Component; public class FoldingSlotDiscoveryService extends AbstractDiscoveryService { public FoldingSlotDiscoveryService() { - super(Collections.singleton(FoldingBindingConstants.THING_TYPE_SLOT), 10, true); + super(Set.of(FoldingBindingConstants.THING_TYPE_SLOT), 10, true); FoldingDiscoveryProxy.getInstance().setService(this); } diff --git a/bundles/org.openhab.binding.folding/src/main/java/org/openhab/binding/folding/internal/handler/FoldingClientHandler.java b/bundles/org.openhab.binding.folding/src/main/java/org/openhab/binding/folding/internal/handler/FoldingClientHandler.java index 5d672c83f..8641ba9f1 100644 --- a/bundles/org.openhab.binding.folding/src/main/java/org/openhab/binding/folding/internal/handler/FoldingClientHandler.java +++ b/bundles/org.openhab.binding.folding/src/main/java/org/openhab/binding/folding/internal/handler/FoldingClientHandler.java @@ -74,7 +74,7 @@ public class FoldingClientHandler extends BaseBridgeHandler { try { if (command instanceof RefreshType) { refresh(); - } else if (channelUID.getId().equals("run")) { + } else if ("run".equals(channelUID.getId())) { if (command == OnOffType.ON) { sendCommand("unpause"); } else if (command == OnOffType.OFF) { @@ -82,7 +82,7 @@ public class FoldingClientHandler extends BaseBridgeHandler { } refresh(); delayedRefresh(); - } else if (channelUID.getId().equals("finish")) { + } else if ("finish".equals(channelUID.getId())) { if (command == OnOffType.ON) { sendCommand("finish"); } else if (command == OnOffType.OFF) { diff --git a/bundles/org.openhab.binding.folding/src/main/java/org/openhab/binding/folding/internal/handler/SlotHandler.java b/bundles/org.openhab.binding.folding/src/main/java/org/openhab/binding/folding/internal/handler/SlotHandler.java index 83a31ad08..dc87c23ea 100644 --- a/bundles/org.openhab.binding.folding/src/main/java/org/openhab/binding/folding/internal/handler/SlotHandler.java +++ b/bundles/org.openhab.binding.folding/src/main/java/org/openhab/binding/folding/internal/handler/SlotHandler.java @@ -57,13 +57,13 @@ public class SlotHandler extends BaseThingHandler implements SlotUpdateListener @Override public void handleCommand(ChannelUID channelUID, Command command) { try { - if (channelUID.getId().equals("run")) { + if ("run".equals(channelUID.getId())) { if (command == OnOffType.ON) { getBridgeHandler().sendCommand("unpause " + myId()); } else if (command == OnOffType.OFF) { getBridgeHandler().sendCommand("pause " + myId()); } - } else if (channelUID.getId().equals("finish")) { + } else if ("finish".equals(channelUID.getId())) { if (command == OnOffType.ON) { getBridgeHandler().sendCommand("finish " + myId()); } else if (command == OnOffType.OFF) { diff --git a/bundles/org.openhab.binding.foobot/src/main/java/org/openhab/binding/foobot/internal/FoobotHandlerFactory.java b/bundles/org.openhab.binding.foobot/src/main/java/org/openhab/binding/foobot/internal/FoobotHandlerFactory.java index cf7639a16..c0de792df 100644 --- a/bundles/org.openhab.binding.foobot/src/main/java/org/openhab/binding/foobot/internal/FoobotHandlerFactory.java +++ b/bundles/org.openhab.binding.foobot/src/main/java/org/openhab/binding/foobot/internal/FoobotHandlerFactory.java @@ -48,7 +48,7 @@ public class FoobotHandlerFactory extends BaseThingHandlerFactory { public static final Set SUPPORTED_THING_TYPE_UIDS = Collections .unmodifiableSet(Stream.of(BRIDGE_TYPE_FOOBOTACCOUNT, THING_TYPE_FOOBOT).collect(Collectors.toSet())); - public static final Set DISCOVERABLE_THING_TYPE_UIDS = Collections.singleton(THING_TYPE_FOOBOT); + public static final Set DISCOVERABLE_THING_TYPE_UIDS = Set.of(THING_TYPE_FOOBOT); private final FoobotApiConnector connector = new FoobotApiConnector(); diff --git a/bundles/org.openhab.binding.foobot/src/main/java/org/openhab/binding/foobot/internal/discovery/FoobotAccountDiscoveryService.java b/bundles/org.openhab.binding.foobot/src/main/java/org/openhab/binding/foobot/internal/discovery/FoobotAccountDiscoveryService.java index 2280f190d..39f921e52 100644 --- a/bundles/org.openhab.binding.foobot/src/main/java/org/openhab/binding/foobot/internal/discovery/FoobotAccountDiscoveryService.java +++ b/bundles/org.openhab.binding.foobot/src/main/java/org/openhab/binding/foobot/internal/discovery/FoobotAccountDiscoveryService.java @@ -98,8 +98,8 @@ public class FoobotAccountDiscoveryService extends AbstractDiscoveryService @Override public void setThingHandler(@Nullable final ThingHandler handler) { - if (handler instanceof FoobotAccountHandler) { - this.handler = (FoobotAccountHandler) handler; + if (handler instanceof FoobotAccountHandler accountHandler) { + this.handler = accountHandler; } } diff --git a/bundles/org.openhab.binding.foobot/src/main/java/org/openhab/binding/foobot/internal/handler/FoobotAccountHandler.java b/bundles/org.openhab.binding.foobot/src/main/java/org/openhab/binding/foobot/internal/handler/FoobotAccountHandler.java index bfc9a194a..527fae562 100644 --- a/bundles/org.openhab.binding.foobot/src/main/java/org/openhab/binding/foobot/internal/handler/FoobotAccountHandler.java +++ b/bundles/org.openhab.binding.foobot/src/main/java/org/openhab/binding/foobot/internal/handler/FoobotAccountHandler.java @@ -17,8 +17,8 @@ import static org.openhab.binding.foobot.internal.FoobotBindingConstants.*; import java.time.Duration; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; +import java.util.Set; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -79,7 +79,7 @@ public class FoobotAccountHandler extends BaseBridgeHandler { @Override public Collection> getServices() { - return Collections.singleton(FoobotAccountDiscoveryService.class); + return Set.of(FoobotAccountDiscoveryService.class); } public List getDeviceList() throws FoobotApiException { @@ -192,12 +192,12 @@ public class FoobotAccountHandler extends BaseBridgeHandler { @Override public void childHandlerInitialized(ThingHandler childHandler, Thing childThing) { - if (childHandler instanceof FoobotDeviceHandler) { - final String uuid = ((FoobotDeviceHandler) childHandler).getUuid(); + if (childHandler instanceof FoobotDeviceHandler handler) { + final String uuid = handler.getUuid(); try { getDeviceList().stream().filter(d -> d.getUuid().equals(uuid)).findAny() - .ifPresent(fd -> ((FoobotDeviceHandler) childHandler).handleUpdateProperties(fd)); + .ifPresent(fd -> handler.handleUpdateProperties(fd)); } catch (FoobotApiException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage()); } diff --git a/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/FreeboxBindingConstants.java b/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/FreeboxBindingConstants.java index 81bab765d..7f10dd73d 100644 --- a/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/FreeboxBindingConstants.java +++ b/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/FreeboxBindingConstants.java @@ -41,8 +41,7 @@ public class FreeboxBindingConstants { public static final ThingTypeUID FREEBOX_THING_TYPE_AIRPLAY = new ThingTypeUID(BINDING_ID, "airplay"); // All supported Bridge types - public static final Set SUPPORTED_BRIDGE_TYPES_UIDS = Collections - .singleton(FREEBOX_BRIDGE_TYPE_SERVER); + public static final Set SUPPORTED_BRIDGE_TYPES_UIDS = Set.of(FREEBOX_BRIDGE_TYPE_SERVER); // All supported Thing types public static final Set SUPPORTED_THING_TYPES_UIDS = Collections diff --git a/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/api/FreeboxApiManager.java b/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/api/FreeboxApiManager.java index e861c1f90..13de16311 100644 --- a/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/api/FreeboxApiManager.java +++ b/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/api/FreeboxApiManager.java @@ -464,8 +464,7 @@ public class FreeboxApiManager { // Parse the full response in case of success T fullResponse = gson.fromJson(jsonResponse, responseClass); fullResponse.evaluate(); - F result = fullResponse.getResult(); - return result; + return fullResponse.getResult(); } private String encodeUrl(String url) throws FreeboxException { diff --git a/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/api/model/FreeboxAirMediaReceiverRequest.java b/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/api/model/FreeboxAirMediaReceiverRequest.java index 68e3104cf..21bdd1a6b 100644 --- a/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/api/model/FreeboxAirMediaReceiverRequest.java +++ b/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/api/model/FreeboxAirMediaReceiverRequest.java @@ -21,7 +21,7 @@ package org.openhab.binding.freebox.internal.api.model; */ public class FreeboxAirMediaReceiverRequest { - private static enum MediaAction { + private enum MediaAction { START("start"), STOP("stop"); @@ -36,7 +36,7 @@ public class FreeboxAirMediaReceiverRequest { } } - private static enum MediaType { + private enum MediaType { VIDEO("video"), PHOTO("photo"); diff --git a/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/api/model/FreeboxAuthorizationStatus.java b/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/api/model/FreeboxAuthorizationStatus.java index 9cfd7aaf0..5f91070b7 100644 --- a/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/api/model/FreeboxAuthorizationStatus.java +++ b/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/api/model/FreeboxAuthorizationStatus.java @@ -21,7 +21,7 @@ package org.openhab.binding.freebox.internal.api.model; */ public class FreeboxAuthorizationStatus { - private static enum AuthorizationStatus { + private enum AuthorizationStatus { UNKNOWN("unknown"), PENDING("pending"), TIMEOUT("timeout"), diff --git a/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/console/FreeboxCommandExtension.java b/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/console/FreeboxCommandExtension.java index 1899d0521..ab4f16caf 100644 --- a/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/console/FreeboxCommandExtension.java +++ b/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/console/FreeboxCommandExtension.java @@ -62,8 +62,8 @@ public class FreeboxCommandExtension extends AbstractConsoleCommandExtension imp FreeboxHandler handler = null; if (thing != null) { thingHandler = thing.getHandler(); - if (thingHandler instanceof FreeboxHandler) { - handler = (FreeboxHandler) thingHandler; + if (thingHandler instanceof FreeboxHandler freeboxHandler) { + handler = freeboxHandler; } } if (thing == null) { diff --git a/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/discovery/FreeboxDiscoveryService.java b/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/discovery/FreeboxDiscoveryService.java index 0f034e4b5..e794c2dc2 100644 --- a/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/discovery/FreeboxDiscoveryService.java +++ b/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/discovery/FreeboxDiscoveryService.java @@ -79,8 +79,8 @@ public class FreeboxDiscoveryService extends AbstractDiscoveryService @Override public void setThingHandler(ThingHandler handler) { - if (handler instanceof FreeboxHandler) { - bridgeHandler = (FreeboxHandler) handler; + if (handler instanceof FreeboxHandler freeboxHandler) { + bridgeHandler = freeboxHandler; } } diff --git a/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/handler/FreeboxHandler.java b/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/handler/FreeboxHandler.java index da6fc3add..db210bfd2 100644 --- a/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/handler/FreeboxHandler.java +++ b/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/handler/FreeboxHandler.java @@ -16,9 +16,9 @@ import static org.openhab.binding.freebox.internal.FreeboxBindingConstants.*; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -92,7 +92,7 @@ public class FreeboxHandler extends BaseBridgeHandler { @Override public Collection> getServices() { - return Collections.singleton(FreeboxDiscoveryService.class); + return Set.of(FreeboxDiscoveryService.class); } @Override @@ -494,8 +494,8 @@ public class FreeboxHandler extends BaseBridgeHandler { continue; } ThingHandler handler = thing.getHandler(); - if (handler instanceof FreeboxThingHandler) { - ((FreeboxThingHandler) handler).updateNetInfo(hosts); + if (handler instanceof FreeboxThingHandler thingHandler) { + thingHandler.updateNetInfo(hosts); } } @@ -519,8 +519,8 @@ public class FreeboxHandler extends BaseBridgeHandler { continue; } ThingHandler handler = thing.getHandler(); - if (handler instanceof FreeboxThingHandler) { - ((FreeboxThingHandler) handler).updateAirPlayDevice(devices); + if (handler instanceof FreeboxThingHandler thingHandler) { + thingHandler.updateAirPlayDevice(devices); } } @@ -542,12 +542,10 @@ public class FreeboxHandler extends BaseBridgeHandler { } else if (command instanceof OnOffType) { updateChannelDecimalState(LCDBRIGHTNESS, apiManager.setLcdBrightness((command == OnOffType.ON) ? 100 : 0)); - } else if (command instanceof DecimalType) { - updateChannelDecimalState(LCDBRIGHTNESS, - apiManager.setLcdBrightness(((DecimalType) command).intValue())); - } else if (command instanceof PercentType) { - updateChannelDecimalState(LCDBRIGHTNESS, - apiManager.setLcdBrightness(((PercentType) command).intValue())); + } else if (command instanceof DecimalType decimalCommand) { + updateChannelDecimalState(LCDBRIGHTNESS, apiManager.setLcdBrightness(decimalCommand.intValue())); + } else if (command instanceof PercentType percentCommand) { + updateChannelDecimalState(LCDBRIGHTNESS, apiManager.setLcdBrightness(percentCommand.intValue())); } else { logger.debug("Thing {}: invalid command {} from channel {}", getThing().getUID(), command, channelUID.getId()); @@ -559,9 +557,9 @@ public class FreeboxHandler extends BaseBridgeHandler { } private void setOrientation(ChannelUID channelUID, Command command) { - if (command instanceof DecimalType) { + if (command instanceof DecimalType orientation) { try { - FreeboxLcdConfig config = apiManager.setLcdOrientation(((DecimalType) command).intValue()); + FreeboxLcdConfig config = apiManager.setLcdOrientation(orientation.intValue()); updateChannelDecimalState(LCDORIENTATION, config.getOrientation()); updateChannelSwitchState(LCDFORCED, config.isOrientationForced()); } catch (FreeboxException e) { diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/Response.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/Response.java index 1b95cf408..94645ce40 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/Response.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/Response.java @@ -24,7 +24,7 @@ import org.openhab.binding.freeboxos.internal.api.rest.LoginManager; */ @NonNullByDefault public class Response { - public static enum ErrorCode { + public enum ErrorCode { AUTH_REQUIRED, BAD_LOGIN, TOO_SHORT, @@ -91,7 +91,7 @@ public class Response { ERR_030, ERR_031, NONE, - UNKNOWN; + UNKNOWN } private ErrorCode errorCode = ErrorCode.NONE; diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/APManager.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/APManager.java index 233046da0..db87b2721 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/APManager.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/APManager.java @@ -57,10 +57,10 @@ public class APManager extends ListableRest { } - public static enum Type { + public enum Type { ACCEPTED, MISSED, OUTGOING, INCOMING, - UNKNOWN; + UNKNOWN } public static record Call(Type type, // diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/ConnectionManager.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/ConnectionManager.java index c500847a6..c8be49c48 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/ConnectionManager.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/ConnectionManager.java @@ -35,27 +35,27 @@ public class ConnectionManager extends ConfigurableRest { } - private static enum State { + private enum State { GOING_UP, UP, GOING_DOWN, DOWN, - UNKNOWN; + UNKNOWN } - private static enum Type { + private enum Type { ETHERNET, RFC2684, PPPOATM, - UNKNOWN; + UNKNOWN } - private static enum Media { + private enum Media { FTTH, ETHERNET, XDSL, BACKUP_4G, - UNKNOWN; + UNKNOWN } public static record Status(State state, Type type, Media media, @Nullable List ipv4PortRange, diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/FreeboxOsSession.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/FreeboxOsSession.java index d67b3edc7..f02553357 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/FreeboxOsSession.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/FreeboxOsSession.java @@ -52,7 +52,7 @@ public class FreeboxOsSession { private @Nullable Session session; private String appToken = ""; - public static enum BoxModel { + public enum BoxModel { FBXGW_R1_FULL, // Freebox Server (v6) revision 1 FBXGW_R2_FULL, // Freebox Server (v6) revision 2 FBXGW_R1_MINI, // Freebox Mini revision 1 @@ -60,7 +60,7 @@ public class FreeboxOsSession { FBXGW_R1_ONE, // Freebox One revision 1 FBXGW_R2_ONE, // Freebox One revision 2 FBXGW7_R1_FULL, // Freebox v7 revision 1 - UNKNOWN; + UNKNOWN } public static record ApiVersion(String apiBaseUrl, @Nullable String apiDomain, String apiVersion, BoxModel boxModel, @@ -156,8 +156,8 @@ public class FreeboxOsSession { manager = addManager(clazz, managerConstructor.newInstance(this)); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); - if (cause instanceof PermissionException) { - throw (PermissionException) cause; + if (cause instanceof PermissionException exception) { + throw exception; } throw new FreeboxException(e, "Unable to call RestManager constructor for %s", clazz.getName()); } catch (ReflectiveOperationException e) { diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/FreeplugManager.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/FreeplugManager.java index 659904882..2f7fd291c 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/FreeplugManager.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/FreeplugManager.java @@ -36,11 +36,11 @@ public class FreeplugManager extends RestManager { private static class Networks extends Response { } - public static enum NetRole { + public enum NetRole { STA, // Freeplug station PCO, // Freeplug proxy coordinator CCO, // Central Coordinator - UNKNOWN; + UNKNOWN } private enum Status { diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/HomeManager.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/HomeManager.java index fbb64ecaf..a14829616 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/HomeManager.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/HomeManager.java @@ -42,14 +42,14 @@ public class HomeManager extends RestManager { private static class HomeNodesResponse extends Response { } - private static enum AccessType { + private enum AccessType { R, W, RW, - UNKNOWN; + UNKNOWN } - private static enum DisplayType { + private enum DisplayType { TEXT, ICON, BUTTON, @@ -57,7 +57,7 @@ public class HomeManager extends RestManager { TOGGLE, COLOR, WARNING, - UNKNOWN; + UNKNOWN } private static record EndpointValue (T value) { @@ -66,13 +66,13 @@ public class HomeManager extends RestManager { private static record EndpointUi(AccessType access, DisplayType display, String iconUrl, @Nullable String unit) { } - private static enum ValueType { + private enum ValueType { BOOL, INT, FLOAT, VOID, STRING, - UNKNOWN; + UNKNOWN } public static record EndpointState(@Nullable String value, ValueType valueType, long refresh) { @@ -91,7 +91,7 @@ public class HomeManager extends RestManager { } } - public static enum EpType { + public enum EpType { SIGNAL, SLOT, UNKNOWN; @@ -106,23 +106,23 @@ public class HomeManager extends RestManager { public static record Endpoint(int id, String name, String label, EpType epType, Visibility visibility, int refresh, ValueType valueType, EndpointUi ui, @Nullable String category, Object value, List history) { - private static enum Visibility { + private enum Visibility { INTERNAL, NORMAL, DASHBOARD, - UNKNOWN; + UNKNOWN } } - private static enum Status { + private enum Status { UNREACHABLE, DISABLED, ACTIVE, UNPAIRED, - UNKNOWN; + UNKNOWN } - public static enum Category { + public enum Category { BASIC_SHUTTER, SHUTTER, ALARM, diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/LanBrowserManager.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/LanBrowserManager.java index ac4e44e77..01eb82f5b 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/LanBrowserManager.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/LanBrowserManager.java @@ -50,14 +50,14 @@ public class LanBrowserManager extends ListableRest { } - public static enum Source { + public enum Source { DHCP, NETBIOS, MDNS, MDNS_SRV, UPNP, WSD, - UNKNOWN; + UNKNOWN } public record HostName(@Nullable String name, Source source) { @@ -69,9 +69,9 @@ public class LanBrowserManager extends ListableRest { } - private static enum Mode { + private enum Mode { ROUTER, BRIDGE, - UNKNOWN; + UNKNOWN } public static record LanConfig(IPAddress ip, String name, String nameDns, String nameMdns, String nameNetbios, diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/LoginManager.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/LoginManager.java index 41e38e235..21ec0db9d 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/LoginManager.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/LoginManager.java @@ -44,12 +44,12 @@ public class LoginManager extends RestManager { private static final String AUTHORIZE_ACTION = "authorize"; private static final String LOGOUT = "logout"; - private static enum Status { + private enum Status { PENDING, // the user has not confirmed the autorization request yet TIMEOUT, // the user did not confirmed the authorization within the given time GRANTED, // the app_token is valid and can be used to open a session DENIED, // the user denied the authorization request - UNKNOWN; // the app_token is invalid or has been revoked + UNKNOWN // the app_token is invalid or has been revoked } private static record AuthorizationStatus(Status status, boolean loggedIn, String challenge, @@ -65,7 +65,7 @@ public class LoginManager extends RestManager { private static class AuthResponse extends Response { } - public static enum Permission { + public enum Permission { PARENTAL, CONTACTS, EXPLORER, @@ -81,7 +81,7 @@ public class LoginManager extends RestManager { VM, PLAYER, NONE, - UNKNOWN; + UNKNOWN } public static record Session(Map permissions, diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/MediaReceiverManager.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/MediaReceiverManager.java index da7849b9e..f9ee9c71d 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/MediaReceiverManager.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/MediaReceiverManager.java @@ -40,18 +40,18 @@ public class MediaReceiverManager extends ListableRest { } - public static enum Action { + public enum Action { START, STOP, - UNKNOWN; + UNKNOWN } - public static enum MediaType { + public enum MediaType { VIDEO, PHOTO, AUDIO, SCREEN, - UNKNOWN; + UNKNOWN } private static record Request(String password, Action action, MediaType mediaType, @Nullable String media, diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/PhoneManager.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/PhoneManager.java index dc797a177..ed774ad07 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/PhoneManager.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/PhoneManager.java @@ -37,9 +37,9 @@ public class PhoneManager extends ConfigurableRest { } - private static enum NetworkStatus { + private enum NetworkStatus { WORKING, - UNKNOWN; + UNKNOWN } public static record Config(NetworkStatus network, boolean dectEcoMode, String dectPin, int dectRingPattern, @@ -49,7 +49,7 @@ public class PhoneManager extends ConfigurableRest { } - public static enum DeviceModel { + public enum DeviceModel { FBX7HD_DELTA, // Freebox Player Devialet TBX8AM, // Player Pop FBX6HD, @@ -57,18 +57,18 @@ public class PlayerManager extends ListableRest lanGids) { - private static enum StbType { + private enum StbType { STB_ANDROID, STB_V6, STB_V7, STB_V8, - UNKNOWN; + UNKNOWN } /** @@ -83,10 +83,10 @@ public class PlayerManager extends ListableRest { } - public static enum PowerState { + public enum PowerState { STANDBY, RUNNING, - UNKNOWN; + UNKNOWN } public static record Status(PowerState powerState, StatusInformation player, @@ -113,7 +113,7 @@ public class PlayerManager extends ListableRest sensors, ModelInfo modelInfo, List fans, List expansions) { - private static enum DiskStatus { + private enum DiskStatus { NOT_DETECTED, DISABLED, INITIALIZING, ERROR, ACTIVE, - UNKNOWN; + UNKNOWN } } diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/VmManager.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/VmManager.java index 07b75d6ac..c27faa11f 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/VmManager.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/VmManager.java @@ -31,10 +31,10 @@ public class VmManager extends ListableRest { } - public static enum Status { + public enum Status { STOPPED, RUNNING, - UNKNOWN; + UNKNOWN } public static record VirtualMachine(int id, String name, MACAddress mac, Status status) { diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/console/FreeboxOsCommandExtension.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/console/FreeboxOsCommandExtension.java index 3303d95b2..ff3371e27 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/console/FreeboxOsCommandExtension.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/console/FreeboxOsCommandExtension.java @@ -63,8 +63,8 @@ public class FreeboxOsCommandExtension extends AbstractConsoleCommandExtension { FreeboxOsHandler handler = null; if (thing != null) { thingHandler = thing.getHandler(); - if (thingHandler instanceof FreeboxOsHandler) { - handler = (FreeboxOsHandler) thingHandler; + if (thingHandler instanceof FreeboxOsHandler osHandler) { + handler = osHandler; } } if (thing == null) { diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/ActivePlayerHandler.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/ActivePlayerHandler.java index bc7d7812b..52c806366 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/ActivePlayerHandler.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/ActivePlayerHandler.java @@ -15,7 +15,7 @@ package org.openhab.binding.freeboxos.internal.handler; import static org.openhab.binding.freeboxos.internal.FreeboxOsBindingConstants.*; import java.util.Collection; -import java.util.Collections; +import java.util.List; import java.util.Map; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -93,7 +93,7 @@ public class ActivePlayerHandler extends PlayerHandler implements FreeDeviceIntf @Override public Collection> getServices() { - return Collections.singletonList(ActivePlayerActions.class); + return List.of(ActivePlayerActions.class); } @Override diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/CallHandler.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/CallHandler.java index 780f9fab7..03d3e9b48 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/CallHandler.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/CallHandler.java @@ -17,10 +17,10 @@ import static org.openhab.binding.freeboxos.internal.FreeboxOsBindingConstants.* import java.time.ZonedDateTime; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.freeboxos.internal.action.CallActions; @@ -103,6 +103,6 @@ public class CallHandler extends ApiConsumerHandler { @Override public Collection> getServices() { - return Collections.singleton(CallActions.class); + return Set.of(CallActions.class); } } diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/DectHandler.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/DectHandler.java index ae89dc28d..d18ef19fb 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/DectHandler.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/DectHandler.java @@ -66,15 +66,14 @@ public class DectHandler extends FxsHandler { return true; } } - if (command instanceof PercentType) { - PercentType percent = (PercentType) command; + if (command instanceof PercentType percentCommand) { if (GAIN_RX.equals(channelId)) { - phoneManager.setGainRx(getClientId(), percent.intValue()); - updateIfActive(GAIN_RX, percent); + phoneManager.setGainRx(getClientId(), percentCommand.intValue()); + updateIfActive(GAIN_RX, percentCommand); return true; } else if (GAIN_TX.equals(channelId)) { - phoneManager.setGainTx(getClientId(), percent.intValue()); - updateIfActive(GAIN_RX, percent); + phoneManager.setGainTx(getClientId(), percentCommand.intValue()); + updateIfActive(GAIN_RX, percentCommand); return true; } } diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/FreeboxOsHandler.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/FreeboxOsHandler.java index bb62c4f37..a2395810f 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/FreeboxOsHandler.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/FreeboxOsHandler.java @@ -13,8 +13,8 @@ package org.openhab.binding.freeboxos.internal.handler; import java.util.Collection; -import java.util.Collections; import java.util.Optional; +import java.util.Set; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -126,7 +126,7 @@ public class FreeboxOsHandler extends BaseBridgeHandler { @Override public Collection> getServices() { - return Collections.singleton(FreeboxOsDiscoveryService.class); + return Set.of(FreeboxOsDiscoveryService.class); } @Override diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/FreeplugHandler.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/FreeplugHandler.java index ba0693c30..6967ba030 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/FreeplugHandler.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/FreeplugHandler.java @@ -54,8 +54,8 @@ public class FreeplugHandler extends ApiConsumerHandler { properties.put(ROLE, plug.netRole().name()); properties.put(NET_ID, plug.netId()); properties.put(ETHERNET_SPEED, "%d Mb/s".formatted(plug.ethSpeed())); - properties.put(LOCAL, Boolean.valueOf(plug.local()).toString()); - properties.put(FULL_DUPLEX, Boolean.valueOf(plug.ethFullDuplex()).toString()); + properties.put(LOCAL, Boolean.toString(plug.local())); + properties.put(FULL_DUPLEX, Boolean.toString(plug.ethFullDuplex())); if (plug.local()) { // Plug connected to the freebox does not provide rate up or down List channels = new ArrayList<>(getThing().getChannels()); diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/PlayerHandler.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/PlayerHandler.java index c4eb95947..34c8ae793 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/PlayerHandler.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/PlayerHandler.java @@ -16,7 +16,6 @@ import static org.openhab.binding.freeboxos.internal.FreeboxOsBindingConstants.K import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Map; @@ -109,6 +108,6 @@ public class PlayerHandler extends HostHandler { @Override public Collection> getServices() { - return Collections.singletonList(PlayerActions.class); + return List.of(PlayerActions.class); } } diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/RepeaterHandler.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/RepeaterHandler.java index 6b345a88c..e4da9d985 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/RepeaterHandler.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/RepeaterHandler.java @@ -15,9 +15,9 @@ package org.openhab.binding.freeboxos.internal.handler; import static org.openhab.binding.freeboxos.internal.FreeboxOsBindingConstants.*; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.freeboxos.internal.action.RepeaterActions; @@ -104,7 +104,7 @@ public class RepeaterHandler extends HostHandler implements FreeDeviceIntf { @Override public Collection> getServices() { - return Collections.singleton(RepeaterActions.class); + return Set.of(RepeaterActions.class); } @Override diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/RevolutionHandler.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/RevolutionHandler.java index 1771690fe..6cf8ba3e5 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/RevolutionHandler.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/RevolutionHandler.java @@ -73,8 +73,8 @@ public class RevolutionHandler extends ServerHandler { } private void setOrientation(LcdManager manager, Config config, Command command) throws FreeboxException { - if (command instanceof DecimalType) { - manager.setOrientation(((DecimalType) command).intValue()); + if (command instanceof DecimalType orientation) { + manager.setOrientation(orientation.intValue()); } else { logger.warn("Invalid command {} from channel {}", command, LCD_ORIENTATION); } @@ -93,8 +93,8 @@ public class RevolutionHandler extends ServerHandler { manager.setBrightness(() -> config.brightness() + (command == IncreaseDecreaseType.INCREASE ? 1 : -1)); } else if (command instanceof OnOffType) { manager.setBrightness(() -> command == OnOffType.ON ? 100 : 0); - } else if (command instanceof QuantityType) { - manager.setBrightness(() -> ((QuantityType) command).intValue()); + } else if (command instanceof QuantityType brightness) { + manager.setBrightness(() -> brightness.intValue()); } else if (command instanceof DecimalType || command instanceof PercentType) { manager.setBrightness(() -> ((DecimalType) command).intValue()); } else { diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/ServerHandler.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/ServerHandler.java index f6d607efe..8fbd24af6 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/ServerHandler.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/handler/ServerHandler.java @@ -18,9 +18,9 @@ import static org.openhab.core.library.unit.Units.*; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.freeboxos.internal.action.ServerActions; @@ -200,7 +200,7 @@ public class ServerHandler extends ApiConsumerHandler implements FreeDeviceIntf @Override public Collection> getServices() { - return Collections.singleton(ServerActions.class); + return Set.of(ServerActions.class); } @Override diff --git a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusBridgeHandler.java b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusBridgeHandler.java index 50929b814..b2fd676b3 100644 --- a/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusBridgeHandler.java +++ b/bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusBridgeHandler.java @@ -93,8 +93,8 @@ public class FroniusBridgeHandler extends BaseBridgeHandler { @Override public void childHandlerInitialized(ThingHandler childHandler, Thing childThing) { - if (childHandler instanceof FroniusBaseThingHandler) { - this.services.add((FroniusBaseThingHandler) childHandler); + if (childHandler instanceof FroniusBaseThingHandler handler) { + this.services.add(handler); restartAutomaticRefresh(); } else { logger.debug("Child handler {} not added because it is not an instance of FroniusBaseThingHandler", diff --git a/bundles/org.openhab.binding.fsinternetradio/src/main/java/org/openhab/binding/fsinternetradio/internal/FSInternetRadioDiscoveryParticipant.java b/bundles/org.openhab.binding.fsinternetradio/src/main/java/org/openhab/binding/fsinternetradio/internal/FSInternetRadioDiscoveryParticipant.java index b73d8e9c9..276c75fb0 100644 --- a/bundles/org.openhab.binding.fsinternetradio/src/main/java/org/openhab/binding/fsinternetradio/internal/FSInternetRadioDiscoveryParticipant.java +++ b/bundles/org.openhab.binding.fsinternetradio/src/main/java/org/openhab/binding/fsinternetradio/internal/FSInternetRadioDiscoveryParticipant.java @@ -14,7 +14,6 @@ package org.openhab.binding.fsinternetradio.internal; import static org.openhab.binding.fsinternetradio.internal.FSInternetRadioBindingConstants.*; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -141,7 +140,7 @@ public class FSInternetRadioDiscoveryParticipant implements UpnpDiscoveryPartici @Override public Set getSupportedThingTypeUIDs() { - return Collections.singleton(THING_TYPE_RADIO); + return Set.of(THING_TYPE_RADIO); } @Override diff --git a/bundles/org.openhab.binding.fsinternetradio/src/main/java/org/openhab/binding/fsinternetradio/internal/FSInternetRadioHandlerFactory.java b/bundles/org.openhab.binding.fsinternetradio/src/main/java/org/openhab/binding/fsinternetradio/internal/FSInternetRadioHandlerFactory.java index deb22628b..f9a11d226 100644 --- a/bundles/org.openhab.binding.fsinternetradio/src/main/java/org/openhab/binding/fsinternetradio/internal/FSInternetRadioHandlerFactory.java +++ b/bundles/org.openhab.binding.fsinternetradio/src/main/java/org/openhab/binding/fsinternetradio/internal/FSInternetRadioHandlerFactory.java @@ -14,7 +14,6 @@ package org.openhab.binding.fsinternetradio.internal; import static org.openhab.binding.fsinternetradio.internal.FSInternetRadioBindingConstants.THING_TYPE_RADIO; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -41,7 +40,7 @@ import org.osgi.service.component.annotations.Reference; @NonNullByDefault public class FSInternetRadioHandlerFactory extends BaseThingHandlerFactory { - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_RADIO); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_RADIO); private final HttpClient httpClient; diff --git a/bundles/org.openhab.binding.fsinternetradio/src/main/java/org/openhab/binding/fsinternetradio/internal/handler/FSInternetRadioHandler.java b/bundles/org.openhab.binding.fsinternetradio/src/main/java/org/openhab/binding/fsinternetradio/internal/handler/FSInternetRadioHandler.java index 161a30fa1..ae0c0d715 100644 --- a/bundles/org.openhab.binding.fsinternetradio/src/main/java/org/openhab/binding/fsinternetradio/internal/handler/FSInternetRadioHandler.java +++ b/bundles/org.openhab.binding.fsinternetradio/src/main/java/org/openhab/binding/fsinternetradio/internal/handler/FSInternetRadioHandler.java @@ -200,8 +200,8 @@ public class FSInternetRadioHandler extends BaseThingHandler { radio.increaseVolumeAbsolute(); } else if (IncreaseDecreaseType.DECREASE.equals(command) || UpDownType.DOWN.equals(command)) { radio.decreaseVolumeAbsolute(); - } else if (command instanceof PercentType) { - radio.setVolumePercent(((PercentType) command).intValue()); + } else if (command instanceof PercentType percentCommand) { + radio.setVolumePercent(percentCommand.intValue()); } // absolute value should also be updated now, so let's update all items scheduler.schedule(updateRunnable, 1, SECONDS); @@ -211,20 +211,20 @@ public class FSInternetRadioHandler extends BaseThingHandler { radio.increaseVolumeAbsolute(); } else if (IncreaseDecreaseType.DECREASE.equals(command) || UpDownType.DOWN.equals(command)) { radio.decreaseVolumeAbsolute(); - } else if (command instanceof DecimalType) { - radio.setVolumeAbsolute(((DecimalType) command).intValue()); + } else if (command instanceof DecimalType decimalCommand) { + radio.setVolumeAbsolute(decimalCommand.intValue()); } // percent value should also be updated now, so let's update all items scheduler.schedule(updateRunnable, 1, SECONDS); break; case CHANNEL_MODE: - if (command instanceof DecimalType) { - radio.setMode(((DecimalType) command).intValue()); + if (command instanceof DecimalType decimalCommand) { + radio.setMode(decimalCommand.intValue()); } break; case CHANNEL_PRESET: - if (command instanceof DecimalType) { - radio.setPreset(((DecimalType) command).intValue()); + if (command instanceof DecimalType decimalCommand) { + radio.setPreset(decimalCommand.intValue()); } break; case CHANNEL_MUTE: diff --git a/bundles/org.openhab.binding.fsinternetradio/src/main/java/org/openhab/binding/fsinternetradio/internal/radio/FrontierSiliconRadioApiResult.java b/bundles/org.openhab.binding.fsinternetradio/src/main/java/org/openhab/binding/fsinternetradio/internal/radio/FrontierSiliconRadioApiResult.java index 1451af23b..0299f705a 100644 --- a/bundles/org.openhab.binding.fsinternetradio/src/main/java/org/openhab/binding/fsinternetradio/internal/radio/FrontierSiliconRadioApiResult.java +++ b/bundles/org.openhab.binding.fsinternetradio/src/main/java/org/openhab/binding/fsinternetradio/internal/radio/FrontierSiliconRadioApiResult.java @@ -69,8 +69,8 @@ public class FrontierSiliconRadioApiResult { logger.trace("converting to XML failed: '{}' with {}: {}", requestResultString, e.getClass().getName(), e.getMessage()); logger.debug("converting to XML failed with {}: {}", e.getClass().getName(), e.getMessage()); - if (e instanceof IOException) { - throw (IOException) e; + if (e instanceof IOException exception) { + throw exception; } throw new IOException(e); } @@ -192,8 +192,7 @@ public class FrontierSiliconRadioApiResult { */ public String getSessionId() { final NodeList sessionIdTagList = xmlDoc.getElementsByTagName("sessionId"); - final String givenSessId = getCharacterDataFromElement((Element) sessionIdTagList.item(0)); - return givenSessId; + return getCharacterDataFromElement((Element) sessionIdTagList.item(0)); } /** @@ -216,8 +215,7 @@ public class FrontierSiliconRadioApiResult { factory.setXIncludeAware(false); factory.setExpandEntityReferences(false); final DocumentBuilder builder = factory.newDocumentBuilder(); - final Document xmlDocument = builder.parse(new InputSource(new StringReader(xmlString))); - return xmlDocument; + return builder.parse(new InputSource(new StringReader(xmlString))); } /** @@ -229,8 +227,7 @@ public class FrontierSiliconRadioApiResult { */ private static String getCharacterDataFromElement(Element e) { final Node child = e.getFirstChild(); - if (child instanceof CharacterData) { - final CharacterData cd = (CharacterData) child; + if (child instanceof CharacterData cd) { return cd.getData(); } return ""; diff --git a/bundles/org.openhab.binding.fsinternetradio/src/test/java/org/openhab/binding/fsinternetradio/test/FSInternetRadioHandlerJavaTest.java b/bundles/org.openhab.binding.fsinternetradio/src/test/java/org/openhab/binding/fsinternetradio/test/FSInternetRadioHandlerJavaTest.java index 7b4b9a1cd..5f08b267d 100644 --- a/bundles/org.openhab.binding.fsinternetradio/src/test/java/org/openhab/binding/fsinternetradio/test/FSInternetRadioHandlerJavaTest.java +++ b/bundles/org.openhab.binding.fsinternetradio/src/test/java/org/openhab/binding/fsinternetradio/test/FSInternetRadioHandlerJavaTest.java @@ -818,8 +818,8 @@ public class FSInternetRadioHandlerJavaTest extends JavaTest { private boolean isConfigurationComplete(Configuration config) { String ip = (String) config.get(FSInternetRadioBindingConstants.CONFIG_PROPERTY_IP); - BigDecimal port = (BigDecimal) config.get(FSInternetRadioBindingConstants.CONFIG_PROPERTY_PORT.toString()); - String pin = (String) config.get(FSInternetRadioBindingConstants.CONFIG_PROPERTY_PIN.toString()); + BigDecimal port = (BigDecimal) config.get(FSInternetRadioBindingConstants.CONFIG_PROPERTY_PORT); + String pin = (String) config.get(FSInternetRadioBindingConstants.CONFIG_PROPERTY_PIN); return !(ip == null || port.compareTo(BigDecimal.ZERO) == 0 || pin == null || pin.isEmpty()); } diff --git a/bundles/org.openhab.binding.ftpupload/src/main/java/org/openhab/binding/ftpupload/internal/FtpUploadHandlerFactory.java b/bundles/org.openhab.binding.ftpupload/src/main/java/org/openhab/binding/ftpupload/internal/FtpUploadHandlerFactory.java index d2788d0f6..bce18648c 100644 --- a/bundles/org.openhab.binding.ftpupload/src/main/java/org/openhab/binding/ftpupload/internal/FtpUploadHandlerFactory.java +++ b/bundles/org.openhab.binding.ftpupload/src/main/java/org/openhab/binding/ftpupload/internal/FtpUploadHandlerFactory.java @@ -14,7 +14,6 @@ package org.openhab.binding.ftpupload.internal; import static org.openhab.binding.ftpupload.internal.FtpUploadBindingConstants.THING_TYPE_IMAGERECEIVER; -import java.util.Collections; import java.util.Dictionary; import java.util.Set; @@ -46,7 +45,7 @@ import org.slf4j.LoggerFactory; public class FtpUploadHandlerFactory extends BaseThingHandlerFactory { private final Logger logger = LoggerFactory.getLogger(FtpUploadHandlerFactory.class); - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_IMAGERECEIVER); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_IMAGERECEIVER); private final int DEFAULT_PORT = 2121; private final int DEFAULT_IDLE_TIMEOUT = 60; diff --git a/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/handler/GardenaAccountHandler.java b/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/handler/GardenaAccountHandler.java index 7f6896b2d..f0fcad349 100644 --- a/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/handler/GardenaAccountHandler.java +++ b/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/handler/GardenaAccountHandler.java @@ -21,8 +21,8 @@ import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.time.format.FormatStyle; import java.util.Collection; -import java.util.Collections; import java.util.Map; +import java.util.Set; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -262,7 +262,7 @@ public class GardenaAccountHandler extends BaseBridgeHandler implements GardenaS @Override public Collection> getServices() { - return Collections.singleton(GardenaDeviceDiscoveryService.class); + return Set.of(GardenaDeviceDiscoveryService.class); } @Override diff --git a/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/handler/GardenaThingHandler.java b/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/handler/GardenaThingHandler.java index 1a47ca3fe..b90b29d50 100644 --- a/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/handler/GardenaThingHandler.java +++ b/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/handler/GardenaThingHandler.java @@ -231,7 +231,7 @@ public class GardenaThingHandler extends BaseThingHandler { public void handleCommand(ChannelUID channelUID, Command command) { logger.debug("Command received: {}", command); try { - boolean isOnCommand = command instanceof OnOffType && ((OnOffType) command) == OnOffType.ON; + boolean isOnCommand = command instanceof OnOffType onOffCommand && onOffCommand == OnOffType.ON; String dataItemProperty = getDeviceDataItemProperty(channelUID); if (RefreshType.REFRESH == command) { logger.debug("Refreshing Gardena connection"); diff --git a/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/model/dto/command/ValveCommand.java b/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/model/dto/command/ValveCommand.java index 2eeccf8b7..61b25b3fe 100644 --- a/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/model/dto/command/ValveCommand.java +++ b/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/model/dto/command/ValveCommand.java @@ -20,7 +20,7 @@ package org.openhab.binding.gardena.internal.model.dto.command; public class ValveCommand extends GardenaCommand { private static final String COMMAND_TYPE = "VALVE_CONTROL"; - public static enum ValveControl { + public enum ValveControl { START_SECONDS_TO_OVERRIDE, STOP_UNTIL_NEXT_TASK, PAUSE, diff --git a/bundles/org.openhab.binding.gce/src/main/java/org/openhab/binding/gce/internal/action/Ipx800Actions.java b/bundles/org.openhab.binding.gce/src/main/java/org/openhab/binding/gce/internal/action/Ipx800Actions.java index 8fd9574c7..e1100de97 100644 --- a/bundles/org.openhab.binding.gce/src/main/java/org/openhab/binding/gce/internal/action/Ipx800Actions.java +++ b/bundles/org.openhab.binding.gce/src/main/java/org/openhab/binding/gce/internal/action/Ipx800Actions.java @@ -41,8 +41,8 @@ public class Ipx800Actions implements ThingActions { @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof Ipx800v3Handler) { - this.handler = (Ipx800v3Handler) handler; + if (handler instanceof Ipx800v3Handler ipx800v3Handler) { + this.handler = ipx800v3Handler; } } diff --git a/bundles/org.openhab.binding.gce/src/main/java/org/openhab/binding/gce/internal/handler/Ipx800v3Handler.java b/bundles/org.openhab.binding.gce/src/main/java/org/openhab/binding/gce/internal/handler/Ipx800v3Handler.java index b31e2afb3..79a0217fe 100644 --- a/bundles/org.openhab.binding.gce/src/main/java/org/openhab/binding/gce/internal/handler/Ipx800v3Handler.java +++ b/bundles/org.openhab.binding.gce/src/main/java/org/openhab/binding/gce/internal/handler/Ipx800v3Handler.java @@ -20,7 +20,6 @@ import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -327,11 +326,11 @@ public class Ipx800v3Handler extends BaseThingHandler implements Ipx800EventList if (channel == null || groupId == null) { return; } - if (command instanceof OnOffType && isValidPortId(channelUID) + if (command instanceof OnOffType onOffCommand && isValidPortId(channelUID) && PortDefinition.fromGroupId(groupId) == PortDefinition.RELAY) { RelayOutputConfiguration config = channel.getConfiguration().as(RelayOutputConfiguration.class); String id = channelUID.getIdWithoutGroup(); - parser.ifPresent(p -> p.setOutput(id, (OnOffType) command == OnOffType.ON ? 1 : 0, config.pulse)); + parser.ifPresent(p -> p.setOutput(id, onOffCommand == OnOffType.ON ? 1 : 0, config.pulse)); return; } logger.debug("Can not handle command '{}' on channel '{}'", command, channelUID); @@ -351,6 +350,6 @@ public class Ipx800v3Handler extends BaseThingHandler implements Ipx800EventList @Override public Collection> getServices() { - return Collections.singletonList(Ipx800Actions.class); + return List.of(Ipx800Actions.class); } } diff --git a/bundles/org.openhab.binding.gce/src/main/java/org/openhab/binding/gce/internal/model/M2MMessageParser.java b/bundles/org.openhab.binding.gce/src/main/java/org/openhab/binding/gce/internal/model/M2MMessageParser.java index e8a257d18..38dbf809a 100644 --- a/bundles/org.openhab.binding.gce/src/main/java/org/openhab/binding/gce/internal/model/M2MMessageParser.java +++ b/bundles/org.openhab.binding.gce/src/main/java/org/openhab/binding/gce/internal/model/M2MMessageParser.java @@ -54,7 +54,7 @@ public class M2MMessageParser { decodeDataLine(portDefinition, data); } else if (VALIDATION_PATTERN.matcher(data).matches()) { for (String status : data.split("&")) { - String statusPart[] = status.split("="); + String[] statusPart = status.split("="); int portNumShift = 1; PortDefinition portDefinition = PortDefinition.fromPortName(statusPart[0].substring(0, 1)); switch (portDefinition) { diff --git a/bundles/org.openhab.binding.gce/src/main/java/org/openhab/binding/gce/internal/model/StatusFileInterpreter.java b/bundles/org.openhab.binding.gce/src/main/java/org/openhab/binding/gce/internal/model/StatusFileInterpreter.java index f1a636d7c..421a5cc69 100644 --- a/bundles/org.openhab.binding.gce/src/main/java/org/openhab/binding/gce/internal/model/StatusFileInterpreter.java +++ b/bundles/org.openhab.binding.gce/src/main/java/org/openhab/binding/gce/internal/model/StatusFileInterpreter.java @@ -52,9 +52,9 @@ public class StatusFileInterpreter { private Optional doc = Optional.empty(); - public static enum StatusEntry { + public enum StatusEntry { VERSION, - CONFIG_MAC; + CONFIG_MAC } public StatusFileInterpreter(String hostname, Ipx800EventListener listener) { diff --git a/bundles/org.openhab.binding.generacmobilelink/src/main/java/org/openhab/binding/generacmobilelink/internal/discovery/GeneracMobileLinkDiscoveryService.java b/bundles/org.openhab.binding.generacmobilelink/src/main/java/org/openhab/binding/generacmobilelink/internal/discovery/GeneracMobileLinkDiscoveryService.java index 78c9c5567..ce91144df 100644 --- a/bundles/org.openhab.binding.generacmobilelink/src/main/java/org/openhab/binding/generacmobilelink/internal/discovery/GeneracMobileLinkDiscoveryService.java +++ b/bundles/org.openhab.binding.generacmobilelink/src/main/java/org/openhab/binding/generacmobilelink/internal/discovery/GeneracMobileLinkDiscoveryService.java @@ -56,7 +56,7 @@ public class GeneracMobileLinkDiscoveryService extends AbstractDiscoveryService DiscoveryResult result = DiscoveryResultBuilder .create(new ThingUID(THING_TYPE_GENERATOR, bridgeUID, String.valueOf(apparatus.apparatusId))) .withLabel("MobileLink Generator " + apparatus.name) - .withProperty(Thing.PROPERTY_SERIAL_NUMBER, String.valueOf(apparatus.serialNumber)) + .withProperty(Thing.PROPERTY_SERIAL_NUMBER, apparatus.serialNumber) .withProperty(PROPERTY_GENERATOR_ID, String.valueOf(apparatus.apparatusId)) .withRepresentationProperty(PROPERTY_GENERATOR_ID).withBridge(bridgeUID).build(); thingDiscovered(result); diff --git a/bundles/org.openhab.binding.generacmobilelink/src/main/java/org/openhab/binding/generacmobilelink/internal/handler/GeneracMobileLinkAccountHandler.java b/bundles/org.openhab.binding.generacmobilelink/src/main/java/org/openhab/binding/generacmobilelink/internal/handler/GeneracMobileLinkAccountHandler.java index a18c0a218..09ca46d44 100644 --- a/bundles/org.openhab.binding.generacmobilelink/src/main/java/org/openhab/binding/generacmobilelink/internal/handler/GeneracMobileLinkAccountHandler.java +++ b/bundles/org.openhab.binding.generacmobilelink/src/main/java/org/openhab/binding/generacmobilelink/internal/handler/GeneracMobileLinkAccountHandler.java @@ -73,10 +73,10 @@ public class GeneracMobileLinkAccountHandler extends BaseBridgeHandler { private static final String API_BASE = "https://app.mobilelinkgen.com/api"; private static final String LOGIN_BASE = "https://generacconnectivity.b2clogin.com/generacconnectivity.onmicrosoft.com/B2C_1A_MobileLink_SignIn"; private static final Pattern SETTINGS_PATTERN = Pattern.compile("^var SETTINGS = (.*);$", Pattern.MULTILINE); - private static final Gson GSON = new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, - (JsonDeserializer) (json, type, jsonDeserializationContext) -> { - return ZonedDateTime.parse(json.getAsJsonPrimitive().getAsString()); - }).create(); + private static final Gson GSON = new GsonBuilder() + .registerTypeAdapter(ZonedDateTime.class, (JsonDeserializer) (json, type, + jsonDeserializationContext) -> ZonedDateTime.parse(json.getAsJsonPrimitive().getAsString())) + .create(); private HttpClient httpClient; private GeneracMobileLinkDiscoveryService discoveryService; private Map apparatusesCache = new HashMap(); @@ -201,7 +201,7 @@ public class GeneracMobileLinkAccountHandler extends BaseBridgeHandler { Optional thing = getThing().getThings().stream().filter( t -> t.getConfiguration().as(GeneracMobileLinkGeneratorConfiguration.class).generatorId.equals(id)) .findFirst(); - if (!thing.isPresent()) { + if (thing.isEmpty()) { discoveryService.generatorDiscovered(apparatus, getThing().getUID()); } else { ThingHandler handler = thing.get().getHandler(); diff --git a/bundles/org.openhab.binding.generacmobilelink/src/main/java/org/openhab/binding/generacmobilelink/internal/handler/GeneracMobileLinkGeneratorHandler.java b/bundles/org.openhab.binding.generacmobilelink/src/main/java/org/openhab/binding/generacmobilelink/internal/handler/GeneracMobileLinkGeneratorHandler.java index a02fbf91a..d60993c8d 100644 --- a/bundles/org.openhab.binding.generacmobilelink/src/main/java/org/openhab/binding/generacmobilelink/internal/handler/GeneracMobileLinkGeneratorHandler.java +++ b/bundles/org.openhab.binding.generacmobilelink/src/main/java/org/openhab/binding/generacmobilelink/internal/handler/GeneracMobileLinkGeneratorHandler.java @@ -122,7 +122,7 @@ public class GeneracMobileLinkGeneratorHandler extends BaseThingHandler { try { if (p.value.signalStrength != null) { updateState(CHANNEL_SIGNAL_STRENGH, new QuantityType( - Integer.parseInt(p.value.signalStrength.replaceAll("%", "")), Units.PERCENT)); + Integer.parseInt(p.value.signalStrength.replace("%", "")), Units.PERCENT)); } } catch (NumberFormatException e) { logger.debug("Could not parse signalStrength {}", p.value.signalStrength); diff --git a/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/command/CommandGetserial.java b/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/command/CommandGetserial.java index 314abb1a8..625bd5311 100644 --- a/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/command/CommandGetserial.java +++ b/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/command/CommandGetserial.java @@ -54,7 +54,7 @@ public class CommandGetserial extends AbstractCommand { return; } - String fields[] = deviceReply.split(","); + String[] fields = deviceReply.split(","); if (fields.length != 5) { return; } diff --git a/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/command/CommandSendir.java b/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/command/CommandSendir.java index aed0f493f..515be914c 100644 --- a/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/command/CommandSendir.java +++ b/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/command/CommandSendir.java @@ -38,7 +38,7 @@ public class CommandSendir extends AbstractCommand { super(thing, queue, "sendir", CommandType.COMMAND); this.command = command; - deviceCommand = "sendir," + mod + ":" + con + "," + String.valueOf(sendCounter) + "," + code; + deviceCommand = "sendir," + mod + ":" + con + "," + sendCounter + "," + code; } @Override diff --git a/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/command/CommandSendserial.java b/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/command/CommandSendserial.java index 02b90ddd3..bd284a4b4 100644 --- a/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/command/CommandSendserial.java +++ b/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/command/CommandSendserial.java @@ -34,7 +34,7 @@ public class CommandSendserial extends AbstractCommand { String con, String code) { super(thing, queue, "sendserial", CommandType.SERIAL1); // Check to see if this is for the second serial port on a GC-100-12 - if (isGC100Model12() && mod.equals("2")) { + if (isGC100Model12() && "2".equals(mod)) { setCommandType(CommandType.SERIAL2); } this.command = command; diff --git a/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/command/CommandSetserial.java b/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/command/CommandSetserial.java index 55ec19c2d..237971565 100644 --- a/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/command/CommandSetserial.java +++ b/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/command/CommandSetserial.java @@ -55,7 +55,7 @@ public class CommandSetserial extends AbstractCommand { return; } - String fields[] = deviceReply.split(","); + String[] fields = deviceReply.split(","); if (fields.length != 5) { return; } diff --git a/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/command/CommandSetstate.java b/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/command/CommandSetstate.java index eaf5ee7f0..07fc4045b 100644 --- a/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/command/CommandSetstate.java +++ b/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/command/CommandSetstate.java @@ -69,7 +69,7 @@ public class CommandSetstate extends AbstractCommand { if (m.groupCount() == 4) { setModule(m.group(2)); setConnector(m.group(3)); - setState(m.group(4).equals("0") ? OnOffType.OFF : OnOffType.ON); + setState("0".equals(m.group(4)) ? OnOffType.OFF : OnOffType.ON); return true; } } diff --git a/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/handler/GlobalCacheHandler.java b/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/handler/GlobalCacheHandler.java index a56c65c39..051eb041a 100644 --- a/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/handler/GlobalCacheHandler.java +++ b/bundles/org.openhab.binding.globalcache/src/main/java/org/openhab/binding/globalcache/internal/handler/GlobalCacheHandler.java @@ -310,7 +310,7 @@ public class GlobalCacheHandler extends BaseThingHandler { throw new HexCodeConversionException("Hex code is too short"); } - if (!hexCodeArray[0].equals("0000")) { + if (!"0000".equals(hexCodeArray[0])) { throw new HexCodeConversionException("Illegal hex code element 0, should be 0000"); } diff --git a/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/GoEChargerHandlerFactory.java b/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/GoEChargerHandlerFactory.java index c7d80ac9f..b12faee0a 100644 --- a/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/GoEChargerHandlerFactory.java +++ b/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/GoEChargerHandlerFactory.java @@ -14,7 +14,6 @@ package org.openhab.binding.goecharger.internal; import static org.openhab.binding.goecharger.internal.GoEChargerBindingConstants.*; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -41,7 +40,7 @@ import org.osgi.service.component.annotations.Reference; @NonNullByDefault @Component(configurationPid = "binding.goecharger", service = ThingHandlerFactory.class) public class GoEChargerHandlerFactory extends BaseThingHandlerFactory { - private static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_GOE); + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_GOE); private final HttpClient httpClient; @Activate diff --git a/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/handler/GoEChargerHandler.java b/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/handler/GoEChargerHandler.java index 1ec1bb9cd..6d2bdb269 100644 --- a/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/handler/GoEChargerHandler.java +++ b/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/handler/GoEChargerHandler.java @@ -254,16 +254,16 @@ public class GoEChargerHandler extends GoEChargerBaseHandler { switch (channelUID.getId()) { case MAX_CURRENT: key = "amp"; - if (command instanceof DecimalType) { - value = String.valueOf(((DecimalType) command).intValue()); + if (command instanceof DecimalType decimalCommand) { + value = String.valueOf(decimalCommand.intValue()); } else if (command instanceof QuantityType) { value = String.valueOf(((QuantityType) command).toUnit(Units.AMPERE).intValue()); } break; case MAX_CURRENT_TEMPORARY: key = "amx"; - if (command instanceof DecimalType) { - value = String.valueOf(((DecimalType) command).intValue()); + if (command instanceof DecimalType decimalCommand) { + value = String.valueOf(decimalCommand.intValue()); } else if (command instanceof QuantityType) { value = String.valueOf(((QuantityType) command).toUnit(Units.AMPERE).intValue()); } @@ -271,8 +271,8 @@ public class GoEChargerHandler extends GoEChargerBaseHandler { case SESSION_CHARGE_CONSUMPTION_LIMIT: key = "dwo"; var multiplier = 10; - if (command instanceof DecimalType) { - value = String.valueOf(((DecimalType) command).intValue() * multiplier); + if (command instanceof DecimalType decimalCommand) { + value = String.valueOf(decimalCommand.intValue() * multiplier); } else if (command instanceof QuantityType) { value = String.valueOf( ((QuantityType) command).toUnit(Units.KILOWATT_HOUR).intValue() * multiplier); diff --git a/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/handler/GoEChargerV2Handler.java b/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/handler/GoEChargerV2Handler.java index 1056663cf..b48a93fbf 100644 --- a/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/handler/GoEChargerV2Handler.java +++ b/bundles/org.openhab.binding.goecharger/src/main/java/org/openhab/binding/goecharger/internal/handler/GoEChargerV2Handler.java @@ -143,7 +143,7 @@ public class GoEChargerV2Handler extends GoEChargerBaseHandler { } return new DecimalType(goeResponse.transaction); case ALLOW_CHARGING: - return goeResponse.allowCharging == true ? OnOffType.ON : OnOffType.OFF; + return goeResponse.allowCharging ? OnOffType.ON : OnOffType.OFF; case TEMPERATURE_TYPE2_PORT: // It was reported that the temperature is invalid when only one value is returned // That's why it is checked that at least 2 values are returned @@ -244,8 +244,8 @@ public class GoEChargerV2Handler extends GoEChargerBaseHandler { switch (channelUID.getId()) { case MAX_CURRENT: key = "amp"; - if (command instanceof DecimalType) { - value = String.valueOf(((DecimalType) command).intValue()); + if (command instanceof DecimalType decimalCommand) { + value = String.valueOf(decimalCommand.intValue()); } else if (command instanceof QuantityType) { value = String.valueOf(((QuantityType) command).toUnit(Units.AMPERE).intValue()); } @@ -253,8 +253,8 @@ public class GoEChargerV2Handler extends GoEChargerBaseHandler { case SESSION_CHARGE_CONSUMPTION_LIMIT: key = "dwo"; var multiplier = 1000; - if (command instanceof DecimalType) { - value = String.valueOf(((DecimalType) command).intValue() * multiplier); + if (command instanceof DecimalType decimalCommand) { + value = String.valueOf(decimalCommand.intValue() * multiplier); } else if (command instanceof QuantityType) { value = String.valueOf( ((QuantityType) command).toUnit(Units.KILOWATT_HOUR).intValue() * multiplier); @@ -262,10 +262,9 @@ public class GoEChargerV2Handler extends GoEChargerBaseHandler { break; case PHASES: key = "psm"; - if (command instanceof DecimalType) { + if (command instanceof DecimalType decimalCommand) { var phases = 1; - var help = (DecimalType) command; - if (help.intValue() == 3) { + if (decimalCommand.intValue() == 3) { // set value 2 for 3 phases phases = 2; } @@ -274,14 +273,14 @@ public class GoEChargerV2Handler extends GoEChargerBaseHandler { break; case FORCE_STATE: key = "frc"; - if (command instanceof DecimalType) { - value = String.valueOf(((DecimalType) command).intValue()); + if (command instanceof DecimalType decimalCommand) { + value = String.valueOf(decimalCommand.intValue()); } break; case TRANSACTION: key = "trx"; - if (command instanceof DecimalType) { - value = String.valueOf(((DecimalType) command).intValue()); + if (command instanceof DecimalType decimalCommand) { + value = String.valueOf(decimalCommand.intValue()); } break; } diff --git a/bundles/org.openhab.binding.gpstracker/src/main/java/org/openhab/binding/gpstracker/internal/message/NotificationHandler.java b/bundles/org.openhab.binding.gpstracker/src/main/java/org/openhab/binding/gpstracker/internal/message/NotificationHandler.java index 446ebd626..c1c83af76 100644 --- a/bundles/org.openhab.binding.gpstracker/src/main/java/org/openhab/binding/gpstracker/internal/message/NotificationHandler.java +++ b/bundles/org.openhab.binding.gpstracker/src/main/java/org/openhab/binding/gpstracker/internal/message/NotificationHandler.java @@ -48,11 +48,11 @@ public class NotificationHandler { public void handleNotification(LocationMessage msg) { synchronized (this) { String trackerId = msg.getTrackerId(); - if (msg instanceof TransitionMessage) { + if (msg instanceof TransitionMessage message) { List transitionMessages = transitionNotifications.computeIfAbsent(trackerId, k -> new ArrayList<>()); if (transitionMessages != null) { - transitionMessages.add((TransitionMessage) msg); + transitionMessages.add(message); } } else { locationNotifications.put(trackerId, msg); diff --git a/bundles/org.openhab.binding.gpstracker/src/main/java/org/openhab/binding/gpstracker/internal/provider/AbstractCallbackServlet.java b/bundles/org.openhab.binding.gpstracker/src/main/java/org/openhab/binding/gpstracker/internal/provider/AbstractCallbackServlet.java index c92b75fca..a5aee9df6 100644 --- a/bundles/org.openhab.binding.gpstracker/src/main/java/org/openhab/binding/gpstracker/internal/provider/AbstractCallbackServlet.java +++ b/bundles/org.openhab.binding.gpstracker/src/main/java/org/openhab/binding/gpstracker/internal/provider/AbstractCallbackServlet.java @@ -120,9 +120,8 @@ public abstract class AbstractCallbackServlet extends HttpServlet { if (!trackerId.isEmpty()) { TrackerHandler recorder = getHandlerById(trackerId); if (recorder != null) { - if (message instanceof TransitionMessage) { - TransitionMessage tm = (TransitionMessage) message; - recorder.doTransition(tm); + if (message instanceof TransitionMessage transitionMessage) { + recorder.doTransition(transitionMessage); } else { recorder.updateLocation(message); } diff --git a/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/GreeBindingConstants.java b/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/GreeBindingConstants.java index 43421f98f..acd0a1e70 100644 --- a/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/GreeBindingConstants.java +++ b/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/GreeBindingConstants.java @@ -12,7 +12,6 @@ */ package org.openhab.binding.gree.internal; -import java.util.Collections; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -31,7 +30,7 @@ public class GreeBindingConstants { public static final String BINDING_ID = "gree"; public static final ThingTypeUID THING_TYPE_GREEAIRCON = new ThingTypeUID(BINDING_ID, "airconditioner"); - public static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_GREEAIRCON); + public static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_GREEAIRCON); // List of all Thing Type UIDs public static final ThingTypeUID GREE_THING_TYPE = new ThingTypeUID(BINDING_ID, "airconditioner"); diff --git a/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/discovery/GreeDeviceFinder.java b/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/discovery/GreeDeviceFinder.java index d39066793..bdcc415dc 100644 --- a/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/discovery/GreeDeviceFinder.java +++ b/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/discovery/GreeDeviceFinder.java @@ -111,7 +111,7 @@ public class GreeDeviceFinder { scanResponseGson.packJson = GSON.fromJson(decryptedMsg, GreeScanReponsePackDTO.class); // Now make sure the device is reported as a Gree device - if (scanResponseGson.packJson.brand.equalsIgnoreCase("gree")) { + if ("gree".equalsIgnoreCase(scanResponseGson.packJson.brand)) { // Create a new GreeDevice logger.debug("Discovered device at {}:{}", remoteAddress.getHostAddress(), remotePort); GreeAirDevice newDevice = new GreeAirDevice(remoteAddress, remotePort, scanResponseGson); diff --git a/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/handler/GreeAirDevice.java b/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/handler/GreeAirDevice.java index 66dc1e69b..621f31af4 100644 --- a/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/handler/GreeAirDevice.java +++ b/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/handler/GreeAirDevice.java @@ -21,7 +21,6 @@ import java.net.InetAddress; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -370,8 +369,7 @@ public class GreeAirDevice { int valueArrayposition = colList.indexOf(valueName); if (valueArrayposition != -1) { // get the Corresponding value - Integer value = valList.get(valueArrayposition); - return value; + return valList.get(valueArrayposition); } } @@ -384,7 +382,7 @@ public class GreeAirDevice { } public boolean hasStatusValChanged(String valueName) throws GreeException { - if (!prevStatusResponsePackGson.isPresent()) { + if (prevStatusResponsePackGson.isEmpty()) { return true; // update value if there is no previous one } // Find the valueName in the Current Status object @@ -442,7 +440,7 @@ public class GreeAirDevice { } private void setCommandValue(DatagramSocket clientSocket, String command, int value) throws GreeException { - executeCommand(clientSocket, Collections.singletonMap(command, value)); + executeCommand(clientSocket, Map.of(command, value)); } private void setCommandValue(DatagramSocket clientSocket, String command, int value, int min, int max) @@ -450,7 +448,7 @@ public class GreeAirDevice { if ((value < min) || (value > max)) { throw new GreeException("Command value out of range!"); } - executeCommand(clientSocket, Collections.singletonMap(command, value)); + executeCommand(clientSocket, Map.of(command, value)); } private DatagramPacket createPackRequest(int i, String pack) { @@ -462,8 +460,7 @@ public class GreeAirDevice { request.tcid = getId(); request.pack = pack; byte[] sendData = GSON.toJson(request).getBytes(StandardCharsets.UTF_8); - DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, ipAddress, port); - return sendPacket; + return new DatagramPacket(sendData, sendData.length, ipAddress, port); } private T receiveResponse(DatagramSocket clientSocket, Class classOfT) diff --git a/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/handler/GreeHandler.java b/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/handler/GreeHandler.java index ca364da20..6e809b4ef 100644 --- a/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/handler/GreeHandler.java +++ b/bundles/org.openhab.binding.gree/src/main/java/org/openhab/binding/gree/internal/handler/GreeHandler.java @@ -103,7 +103,7 @@ public class GreeHandler extends BaseThingHandler { private void initializeThing() { String message = ""; try { - if (!clientSocket.isPresent()) { + if (clientSocket.isEmpty()) { clientSocket = Optional.of(new DatagramSocket()); clientSocket.get().setSoTimeout(DATAGRAM_SOCKET_TIMEOUT); } @@ -224,9 +224,9 @@ public class GreeHandler extends BaseThingHandler { int mode = -1; String modeStr = ""; boolean isNumber = false; - if (command instanceof DecimalType) { + if (command instanceof DecimalType decimalCommand) { // backward compatibility when channel was Number - mode = ((DecimalType) command).intValue(); + mode = decimalCommand.intValue(); } else if (command instanceof OnOffType) { // Switch logger.debug("{}: Send Power-{}", thingId, command); @@ -295,8 +295,8 @@ public class GreeHandler extends BaseThingHandler { private void handleQuietCommand(DatagramSocket socket, Command command) throws GreeException { int mode = -1; - if (command instanceof DecimalType) { - mode = ((DecimalType) command).intValue(); + if (command instanceof DecimalType decimalCommand) { + mode = decimalCommand.intValue(); } else if (command instanceof StringType) { switch (command.toString().toLowerCase()) { case QUIET_OFF: @@ -321,8 +321,8 @@ public class GreeHandler extends BaseThingHandler { if (command instanceof OnOffType) { return command == OnOffType.ON ? 1 : 0; } - if (command instanceof DecimalType) { - int value = ((DecimalType) command).intValue(); + if (command instanceof DecimalType decimalCommand) { + int value = decimalCommand.intValue(); if ((value == 0) || (value == 1)) { return value; } @@ -331,22 +331,22 @@ public class GreeHandler extends BaseThingHandler { } private int getNumber(Command command) { - if (command instanceof DecimalType) { - return ((DecimalType) command).intValue(); + if (command instanceof DecimalType decimalCommand) { + return decimalCommand.intValue(); } throw new IllegalArgumentException("Invalid Number type"); } private QuantityType convertTemp(Command command) { - if (command instanceof DecimalType) { + if (command instanceof DecimalType temperature) { // The Number alone doesn't specify the temp unit // for this get current setting from the A/C unit int unit = device.getIntStatusVal(GREE_PROP_TEMPUNIT); - return toQuantityType((DecimalType) command, DIGITS_TEMP, + return toQuantityType(temperature, DIGITS_TEMP, unit == TEMP_UNIT_CELSIUS ? SIUnits.CELSIUS : ImperialUnits.FAHRENHEIT); } - if (command instanceof QuantityType) { - return (QuantityType) command; + if (command instanceof QuantityType quantityCommand) { + return quantityCommand; } throw new IllegalArgumentException("Invalud Temp type"); } diff --git a/bundles/org.openhab.binding.groheondus/src/main/java/org/openhab/binding/groheondus/internal/handler/GroheOndusSenseGuardHandler.java b/bundles/org.openhab.binding.groheondus/src/main/java/org/openhab/binding/groheondus/internal/handler/GroheOndusSenseGuardHandler.java index 1a9ae66ed..5d4b342ae 100644 --- a/bundles/org.openhab.binding.groheondus/src/main/java/org/openhab/binding/groheondus/internal/handler/GroheOndusSenseGuardHandler.java +++ b/bundles/org.openhab.binding.groheondus/src/main/java/org/openhab/binding/groheondus/internal/handler/GroheOndusSenseGuardHandler.java @@ -153,7 +153,7 @@ public class GroheOndusSenseGuardHandler extends GroheOndusBaseHandler extends GroheOndusBaseHandler applianceStatusOptional; try { applianceStatusOptional = ondusService.applianceStatus(appliance); - if (!applianceStatusOptional.isPresent()) { + if (applianceStatusOptional.isEmpty()) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "@text/error.empty.response"); return null; } diff --git a/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/bridge/GroupePSABridgeHandler.java b/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/bridge/GroupePSABridgeHandler.java index 5a830e158..9f0decd6a 100644 --- a/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/bridge/GroupePSABridgeHandler.java +++ b/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/bridge/GroupePSABridgeHandler.java @@ -16,7 +16,6 @@ import static org.openhab.binding.groupepsa.internal.GroupePSABindingConstants.T import java.io.IOException; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Set; import java.util.concurrent.ScheduledFuture; @@ -53,7 +52,7 @@ import org.openhab.core.types.Command; */ @NonNullByDefault public class GroupePSABridgeHandler 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 long DEFAULT_POLLING_INTERVAL_M = TimeUnit.HOURS.toMinutes(1); private final OAuthFactory oAuthFactory; @@ -229,6 +228,6 @@ public class GroupePSABridgeHandler extends BaseBridgeHandler { @Override public Collection> getServices() { - return Collections.singleton(GroupePSADiscoveryService.class); + return Set.of(GroupePSADiscoveryService.class); } } diff --git a/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/discovery/GroupePSADiscoveryService.java b/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/discovery/GroupePSADiscoveryService.java index ae0a0cbdd..ee42a5836 100644 --- a/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/discovery/GroupePSADiscoveryService.java +++ b/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/discovery/GroupePSADiscoveryService.java @@ -14,10 +14,10 @@ package org.openhab.binding.groupepsa.internal.discovery; import static org.openhab.binding.groupepsa.internal.GroupePSABindingConstants.THING_TYPE_VEHICLE; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -50,13 +50,13 @@ public class GroupePSADiscoveryService extends AbstractDiscoveryService implemen private @Nullable GroupePSABridgeHandler bridgeHandler; public GroupePSADiscoveryService() { - super(Collections.singleton(THING_TYPE_VEHICLE), 10, false); + super(Set.of(THING_TYPE_VEHICLE), 10, false); } @Override public void setThingHandler(@Nullable ThingHandler handler) { - if (handler instanceof GroupePSABridgeHandler) { - bridgeHandler = (GroupePSABridgeHandler) handler; + if (handler instanceof GroupePSABridgeHandler bridgeHandler) { + this.bridgeHandler = bridgeHandler; } } diff --git a/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/rest/api/GroupePSAConnectApi.java b/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/rest/api/GroupePSAConnectApi.java index 06b9d21f1..3eb3d558f 100644 --- a/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/rest/api/GroupePSAConnectApi.java +++ b/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/rest/api/GroupePSAConnectApi.java @@ -196,8 +196,6 @@ public class GroupePSAConnectApi { public @Nullable VehicleStatus getVehicleStatus(String vin) throws GroupePSACommunicationException { ContentResponse responseOdometer = executeRequest(getBaseUrl() + "/user/vehicles/" + vin + "/status"); - VehicleStatus status = parseResponse(responseOdometer, VehicleStatus.class); - - return status; + return parseResponse(responseOdometer, VehicleStatus.class); } } diff --git a/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/things/GroupePSAHandler.java b/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/things/GroupePSAHandler.java index e3dc71b2e..8fe61bab4 100644 --- a/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/things/GroupePSAHandler.java +++ b/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/things/GroupePSAHandler.java @@ -165,8 +165,8 @@ public class GroupePSAHandler extends BaseThingHandler { Bridge bridge = getBridge(); if (bridge != null) { ThingHandler handler = bridge.getHandler(); - if (handler instanceof GroupePSABridgeHandler) { - return (GroupePSABridgeHandler) handler; + if (handler instanceof GroupePSABridgeHandler bridgeHandler) { + return bridgeHandler; } } return null;