From ee54882841ea5c8f1c02869149fc6709f6bf0cff Mon Sep 17 00:00:00 2001 From: Holger Friedrich Date: Fri, 13 Jan 2023 19:10:59 +0100 Subject: [PATCH] Fix SAT warnings (#14214) Signed-off-by: Holger Friedrich --- .../danfossairunit/internal/Commands.java | 80 +++++++++---------- .../DanfossAirUnitBindingConstants.java | 6 +- .../internal/timetable/TimetablesV1Impl.java | 1 + .../DeutscheBahnTimetableHandlerTest.java | 2 - .../accessories/HomekitAccessoryFactory.java | 3 +- .../HomekitMetadataCharacteristicFactory.java | 5 +- bundles/org.openhab.io.hueemulation/README.md | 6 +- .../hueemulation/internal/NetworkUtils.java | 2 +- .../internal/rest/CommonSetup.java | 2 +- .../internal/rest/UsersAndConfigTests.java | 2 +- 10 files changed, 57 insertions(+), 52 deletions(-) diff --git a/bundles/org.openhab.binding.danfossairunit/src/main/java/org/openhab/binding/danfossairunit/internal/Commands.java b/bundles/org.openhab.binding.danfossairunit/src/main/java/org/openhab/binding/danfossairunit/internal/Commands.java index 2bdc21585..6b6c03339 100644 --- a/bundles/org.openhab.binding.danfossairunit/src/main/java/org/openhab/binding/danfossairunit/internal/Commands.java +++ b/bundles/org.openhab.binding.danfossairunit/src/main/java/org/openhab/binding/danfossairunit/internal/Commands.java @@ -24,44 +24,44 @@ import org.eclipse.jdt.annotation.NonNullByDefault; @NonNullByDefault public class Commands { - public static byte[] DISCOVER_SEND = { 0x0c, 0x00, 0x30, 0x00, 0x11, 0x00, 0x12, 0x00, 0x13 }; - public static byte[] DISCOVER_RECEIVE = { 0x0d, 0x00, 0x07, 0x00, 0x02, 0x02, 0x00 }; - public static byte[] EMPTY = {}; - public static byte[] GET_HISTORY = { 0x00, 0x30 }; - public static byte[] REGISTER_0_READ = { 0x00, 0x04 }; - public static byte[] REGISTER_1_READ = { 0x01, 0x04 }; - public static byte[] REGISTER_1_WRITE = { 0x01, 0x06 }; - public static byte[] REGISTER_2_READ = { 0x02, 0x04 }; - public static byte[] REGISTER_4_READ = { 0x04, 0x04 }; - public static byte[] REGISTER_6_READ = { 0x06, 0x04 }; - public static byte[] MODE = { 0x14, 0x12 }; - public static byte[] MANUAL_FAN_SPEED_STEP = { 0x15, 0x61 }; - public static byte[] SUPPLY_FAN_SPEED = { 0x14, 0x50 }; - public static byte[] EXTRACT_FAN_SPEED = { 0x14, 0x51 }; - public static byte[] SUPPLY_FAN_STEP = { 0x14, 0x28 }; - public static byte[] EXTRACT_FAN_STEP = { 0x14, 0x29 }; - public static byte[] BASE_IN = { 0x14, 0x40 }; - public static byte[] BASE_OUT = { 0x14, 0x41 }; - public static byte[] BYPASS = { 0x14, 0x60 }; - public static byte[] BYPASS_DEACTIVATION = { 0x14, 0x63 }; - public static byte[] BOOST = { 0x15, 0x30 }; - public static byte[] NIGHT_COOLING = { 0x15, 0x71 }; - public static byte[] AUTOMATIC_BYPASS = { 0x17, 0x06 }; - public static byte[] AUTOMATIC_RUSH_AIRING = { 0x17, 0x02 }; - public static byte[] HUMIDITY = { 0x14, 0x70 }; - public static byte[] ROOM_TEMPERATURE = { 0x03, 0x00 }; - public static byte[] ROOM_TEMPERATURE_CALCULATED = { 0x14, (byte) 0x96 }; - public static byte[] OUTDOOR_TEMPERATURE = { 0x03, 0x34 }; - public static byte[] SUPPLY_TEMPERATURE = { 0x14, 0x73 }; - public static byte[] EXTRACT_TEMPERATURE = { 0x14, 0x74 }; - public static byte[] EXHAUST_TEMPERATURE = { 0x14, 0x75 }; - public static byte[] BATTERY_LIFE = { 0x03, 0x0f }; - public static byte[] FILTER_LIFE = { 0x14, 0x6a }; - public static byte[] FILTER_PERIOD = { 0x14, 0x69 }; - public static byte[] CURRENT_TIME = { 0x15, (byte) 0xe0 }; - public static byte[] AWAY_TO = { 0x15, 0x20 }; - public static byte[] AWAY_FROM = { 0x15, 0x21 }; - public static byte[] UNIT_SERIAL = { 0x00, 0x25 }; // endpoint 4 - public static byte[] UNIT_NAME = { 0x15, (byte) 0xe5 }; // endpoint 1 - public static byte[] CCM_SERIAL = { 0x14, 0x6a }; // endpoint 0 + public static final byte[] DISCOVER_SEND = { 0x0c, 0x00, 0x30, 0x00, 0x11, 0x00, 0x12, 0x00, 0x13 }; + public static final byte[] DISCOVER_RECEIVE = { 0x0d, 0x00, 0x07, 0x00, 0x02, 0x02, 0x00 }; + public static final byte[] EMPTY = {}; + public static final byte[] GET_HISTORY = { 0x00, 0x30 }; + public static final byte[] REGISTER_0_READ = { 0x00, 0x04 }; + public static final byte[] REGISTER_1_READ = { 0x01, 0x04 }; + public static final byte[] REGISTER_1_WRITE = { 0x01, 0x06 }; + public static final byte[] REGISTER_2_READ = { 0x02, 0x04 }; + public static final byte[] REGISTER_4_READ = { 0x04, 0x04 }; + public static final byte[] REGISTER_6_READ = { 0x06, 0x04 }; + public static final byte[] MODE = { 0x14, 0x12 }; + public static final byte[] MANUAL_FAN_SPEED_STEP = { 0x15, 0x61 }; + public static final byte[] SUPPLY_FAN_SPEED = { 0x14, 0x50 }; + public static final byte[] EXTRACT_FAN_SPEED = { 0x14, 0x51 }; + public static final byte[] SUPPLY_FAN_STEP = { 0x14, 0x28 }; + public static final byte[] EXTRACT_FAN_STEP = { 0x14, 0x29 }; + public static final byte[] BASE_IN = { 0x14, 0x40 }; + public static final byte[] BASE_OUT = { 0x14, 0x41 }; + public static final byte[] BYPASS = { 0x14, 0x60 }; + public static final byte[] BYPASS_DEACTIVATION = { 0x14, 0x63 }; + public static final byte[] BOOST = { 0x15, 0x30 }; + public static final byte[] NIGHT_COOLING = { 0x15, 0x71 }; + public static final byte[] AUTOMATIC_BYPASS = { 0x17, 0x06 }; + public static final byte[] AUTOMATIC_RUSH_AIRING = { 0x17, 0x02 }; + public static final byte[] HUMIDITY = { 0x14, 0x70 }; + public static final byte[] ROOM_TEMPERATURE = { 0x03, 0x00 }; + public static final byte[] ROOM_TEMPERATURE_CALCULATED = { 0x14, (byte) 0x96 }; + public static final byte[] OUTDOOR_TEMPERATURE = { 0x03, 0x34 }; + public static final byte[] SUPPLY_TEMPERATURE = { 0x14, 0x73 }; + public static final byte[] EXTRACT_TEMPERATURE = { 0x14, 0x74 }; + public static final byte[] EXHAUST_TEMPERATURE = { 0x14, 0x75 }; + public static final byte[] BATTERY_LIFE = { 0x03, 0x0f }; + public static final byte[] FILTER_LIFE = { 0x14, 0x6a }; + public static final byte[] FILTER_PERIOD = { 0x14, 0x69 }; + public static final byte[] CURRENT_TIME = { 0x15, (byte) 0xe0 }; + public static final byte[] AWAY_TO = { 0x15, 0x20 }; + public static final byte[] AWAY_FROM = { 0x15, 0x21 }; + public static final byte[] UNIT_SERIAL = { 0x00, 0x25 }; // endpoint 4 + public static final byte[] UNIT_NAME = { 0x15, (byte) 0xe5 }; // endpoint 1 + public static final byte[] CCM_SERIAL = { 0x14, 0x6a }; // endpoint 0 } diff --git a/bundles/org.openhab.binding.danfossairunit/src/main/java/org/openhab/binding/danfossairunit/internal/DanfossAirUnitBindingConstants.java b/bundles/org.openhab.binding.danfossairunit/src/main/java/org/openhab/binding/danfossairunit/internal/DanfossAirUnitBindingConstants.java index 84d20fbed..535c8130d 100644 --- a/bundles/org.openhab.binding.danfossairunit/src/main/java/org/openhab/binding/danfossairunit/internal/DanfossAirUnitBindingConstants.java +++ b/bundles/org.openhab.binding.danfossairunit/src/main/java/org/openhab/binding/danfossairunit/internal/DanfossAirUnitBindingConstants.java @@ -28,11 +28,11 @@ import org.openhab.core.thing.ThingTypeUID; @NonNullByDefault public class DanfossAirUnitBindingConstants { - public static String BINDING_ID = "danfossairunit"; + public static final String BINDING_ID = "danfossairunit"; // The only thing type UIDs - public static ThingTypeUID THING_TYPE_AIRUNIT = new ThingTypeUID(BINDING_ID, "airunit"); + public static final ThingTypeUID THING_TYPE_AIRUNIT = new ThingTypeUID(BINDING_ID, "airunit"); // The thing type as a set - public static Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_AIRUNIT); + public static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_AIRUNIT); } diff --git a/bundles/org.openhab.binding.deutschebahn/src/main/java/org/openhab/binding/deutschebahn/internal/timetable/TimetablesV1Impl.java b/bundles/org.openhab.binding.deutschebahn/src/main/java/org/openhab/binding/deutschebahn/internal/timetable/TimetablesV1Impl.java index 4946d24c8..475bf0168 100644 --- a/bundles/org.openhab.binding.deutschebahn/src/main/java/org/openhab/binding/deutschebahn/internal/timetable/TimetablesV1Impl.java +++ b/bundles/org.openhab.binding.deutschebahn/src/main/java/org/openhab/binding/deutschebahn/internal/timetable/TimetablesV1Impl.java @@ -193,6 +193,7 @@ public final class TimetablesV1Impl implements TimetablesV1Api { /** * Build rest endpoint URL for request the planned timetable. */ + @SuppressWarnings("PMD.UnsynchronizedStaticFormatter") private String buildPlanRequestURL(final String evaNr, final Date date) { synchronized (this) { final String dateParam = DATE_FORMAT.format(date); diff --git a/bundles/org.openhab.binding.deutschebahn/src/test/java/org/openhab/binding/deutschebahn/internal/DeutscheBahnTimetableHandlerTest.java b/bundles/org.openhab.binding.deutschebahn/src/test/java/org/openhab/binding/deutschebahn/internal/DeutscheBahnTimetableHandlerTest.java index 8e87d391b..87b975f1f 100644 --- a/bundles/org.openhab.binding.deutschebahn/src/test/java/org/openhab/binding/deutschebahn/internal/DeutscheBahnTimetableHandlerTest.java +++ b/bundles/org.openhab.binding.deutschebahn/src/test/java/org/openhab/binding/deutschebahn/internal/DeutscheBahnTimetableHandlerTest.java @@ -186,7 +186,6 @@ public class DeutscheBahnTimetableHandlerTest implements TimetablesV1ImplTestHel verifyChannelsUpdatedToUndef(bridge, 0, callback); verifyChannelsUpdatedToUndef(bridge, 1, callback); verifyChannelsUpdatedToUndef(bridge, 2, callback); - } finally { handler.dispose(); } @@ -226,7 +225,6 @@ public class DeutscheBahnTimetableHandlerTest implements TimetablesV1ImplTestHel verifyThingUpdated(bridge, 0, stop01.getId()); verifyChannelsUpdatedToUndef(bridge, 1, callback); verifyChannelsUpdatedToUndef(bridge, 2, callback); - } finally { handler.dispose(); } diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitAccessoryFactory.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitAccessoryFactory.java index d8a20b535..a3c15b481 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitAccessoryFactory.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitAccessoryFactory.java @@ -413,8 +413,9 @@ public class HomekitAccessoryFactory { .collect(Collectors.toList())) { var characteristic = HomekitMetadataCharacteristicFactory.createCharacteristic(entry.getKey(), entry.getValue()); - if (characteristic.isPresent()) + if (characteristic.isPresent()) { accessory.addCharacteristic(characteristic.get()); + } } } diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitMetadataCharacteristicFactory.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitMetadataCharacteristicFactory.java index 5c0c88bfc..0458a9bac 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitMetadataCharacteristicFactory.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitMetadataCharacteristicFactory.java @@ -72,7 +72,7 @@ public class HomekitMetadataCharacteristicFactory { private static final Logger logger = LoggerFactory.getLogger(HomekitMetadataCharacteristicFactory.class); // List of optional characteristics that can be set via metadata, and the corresponding method to create them. - private final static Map> optional = new HashMap<>() { + private static final Map> optional = new HashMap<>() { { put(ACTIVE_IDENTIFIER, HomekitMetadataCharacteristicFactory::createActiveIdentifierCharacteristic); put(ACTIVE_STATUS, HomekitMetadataCharacteristicFactory::createActiveStatusCharacteristic); @@ -101,8 +101,9 @@ public class HomekitMetadataCharacteristicFactory { public static Optional createCharacteristic(String characteristic, Object value) { var type = HomekitCharacteristicType.valueOfTag(characteristic); - if (type.isEmpty() || !optional.containsKey(type.get())) + if (type.isEmpty() || !optional.containsKey(type.get())) { return Optional.empty(); + } return Optional.of(optional.get(type.get()).apply(value)); } diff --git a/bundles/org.openhab.io.hueemulation/README.md b/bundles/org.openhab.io.hueemulation/README.md index 56e4c53b6..c9c068c08 100644 --- a/bundles/org.openhab.io.hueemulation/README.md +++ b/bundles/org.openhab.io.hueemulation/README.md @@ -155,6 +155,7 @@ You must either * port forward your openHAB installation to port 80, (`iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080`) * install a reverse proxy on port 80, for example nginx with the following configuration: + ``` server { listen 80; @@ -167,10 +168,12 @@ You must either } } ``` + * or let openHAB run on port 80 (the entire java process requires elevated privileges). * For Amazon Echo the pairing process may fail due to a 302 response from openHAB, this can be resolved by using a reverse proxy to change the request url from `/api` to `/api/`, for example nginx with the following configuration: -``` + + ``` server { listen 80; location /api { @@ -178,6 +181,7 @@ You must either } } ``` + Please open port 80 tcp and port 1900 udp in your firewall installation. You can test if the hue emulation does its job by enabling pairing mode including the option "Amazon Echo device discovery fix". diff --git a/bundles/org.openhab.io.hueemulation/src/main/java/org/openhab/io/hueemulation/internal/NetworkUtils.java b/bundles/org.openhab.io.hueemulation/src/main/java/org/openhab/io/hueemulation/internal/NetworkUtils.java index af2328f54..f2c42fcd2 100644 --- a/bundles/org.openhab.io.hueemulation/src/main/java/org/openhab/io/hueemulation/internal/NetworkUtils.java +++ b/bundles/org.openhab.io.hueemulation/src/main/java/org/openhab/io/hueemulation/internal/NetworkUtils.java @@ -74,7 +74,7 @@ public class NetworkUtils { /** * Adds cors headers to the given response and returns it. */ - public static ResponseBuilder ResponseWithCors(ResponseBuilder response) { + public static ResponseBuilder responseWithCors(ResponseBuilder response) { return response.encoding(StandardCharsets.UTF_8.name()) // .header("Access-Control-Allow-Origin", "*") .header("Access-Control-Allow-Headers", "origin, content-type, accept, authorization") diff --git a/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/CommonSetup.java b/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/CommonSetup.java index 55dd9d316..58a47cb09 100644 --- a/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/CommonSetup.java +++ b/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/CommonSetup.java @@ -95,7 +95,7 @@ public class CommonSetup { @SuppressWarnings("unchecked") @Override public Storage getStorage(String name) { - if (name.equals("hueEmulationUsers")) { + if ("hueEmulationUsers".equals(name)) { return (Storage) new DummyUsersStorage(); } throw new IllegalStateException(); diff --git a/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/UsersAndConfigTests.java b/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/UsersAndConfigTests.java index 961af8812..d015e3eff 100644 --- a/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/UsersAndConfigTests.java +++ b/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/UsersAndConfigTests.java @@ -122,7 +122,7 @@ public class UsersAndConfigTests { } @Test - public void UnauthorizedAccessTest() { + public void unauthorizedAccessTest() { // Unauthorized config Response response; response = commonSetup.client.target(commonSetup.basePath + "/config").request().get();