From e847139f97a9c1addc856582a429f3932dc8b5eb Mon Sep 17 00:00:00 2001 From: lsiepel Date: Fri, 22 Sep 2023 23:25:06 +0200 Subject: [PATCH] [homematic] checkstyle fixes (#15604) Signed-off-by: Leo Siepel --- .../internal/common/HomematicConfig.java | 1 - .../communicator/message/XmlRpcRequest.java | 6 ++++-- .../communicator/message/XmlRpcResponse.java | 2 +- .../parser/DisplayOptionsParser.java | 4 ++-- .../BatteryTypeVirtualDatapointHandler.java | 6 +++--- .../virtual/ButtonVirtualDatapointHandler.java | 3 +-- .../converter/type/AbstractTypeConverter.java | 16 ++++++++-------- .../converter/type/QuantityTypeConverter.java | 4 ++-- .../internal/discovery/eq3udp/Eq3UdpRequest.java | 6 +++--- .../internal/handler/HomematicThingHandler.java | 7 ++++--- .../internal/handler/SimplePortPool.java | 6 +++--- .../homematic/internal/misc/MiscUtils.java | 4 ++-- .../homematic/internal/type/MetadataUtils.java | 12 ++++++------ .../type/HomematicThingTypeExcluder.java | 5 ++--- .../converter/ConvertFromBindingTest.java | 16 +++++++--------- .../internal/converter/ConvertToBindingTest.java | 5 ++--- 16 files changed, 50 insertions(+), 53 deletions(-) diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/common/HomematicConfig.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/common/HomematicConfig.java index e4ad10af7..d405f734b 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/common/HomematicConfig.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/common/HomematicConfig.java @@ -58,7 +58,6 @@ public class HomematicConfig { private int bufferSize = 2048; private HmGatewayInfo gatewayInfo; - private int callbackRegistrationRetries; private int callbackRegTimeout; /** diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/message/XmlRpcRequest.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/message/XmlRpcRequest.java index 05ea0fe4f..af517dcf3 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/message/XmlRpcRequest.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/message/XmlRpcRequest.java @@ -39,7 +39,7 @@ public class XmlRpcRequest implements RpcRequest { private List parms; private StringBuilder sb; private TYPE type; - public static SimpleDateFormat xmlRpcDateFormat = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss"); + public static final SimpleDateFormat XML_RPC_DATEFORMAT = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss"); public XmlRpcRequest(String methodName) { this(methodName, TYPE.REQUEST); @@ -135,7 +135,9 @@ public class XmlRpcRequest implements RpcRequest { } else if (clazz == Boolean.class) { tag("boolean", ((Boolean) value).booleanValue() ? "1" : "0"); } else if (clazz == Date.class) { - tag("dateTime.iso8601", xmlRpcDateFormat.format(((Date) value))); + synchronized (XML_RPC_DATEFORMAT) { + tag("dateTime.iso8601", XML_RPC_DATEFORMAT.format(((Date) value))); + } } else if (value instanceof Calendar calendar) { generateValue(calendar.getTime()); } else if (value instanceof byte[] bytes) { diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/message/XmlRpcResponse.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/message/XmlRpcResponse.java index ae5aa4f2f..a993efcf7 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/message/XmlRpcResponse.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/message/XmlRpcResponse.java @@ -149,7 +149,7 @@ public class XmlRpcResponse implements RpcResponse { break; case "datetime.iso8601": try { - data.add(XmlRpcRequest.xmlRpcDateFormat.parse(currentValue)); + data.add(XmlRpcRequest.XML_RPC_DATEFORMAT.parse(currentValue)); } catch (ParseException ex) { throw new SAXException(ex.getMessage(), ex); } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/DisplayOptionsParser.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/DisplayOptionsParser.java index 31222c354..8d5c2c25e 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/DisplayOptionsParser.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/DisplayOptionsParser.java @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; public class DisplayOptionsParser extends CommonRpcParser { private final Logger logger = LoggerFactory.getLogger(DisplayOptionsParser.class); - private static final String[] onOff = new String[] { "ON", "OFF" }; + private static final String[] ON_OFF = new String[] { "ON", "OFF" }; private static final int IDX_NOT_FOUND = -1; private HmChannel channel; private String text; @@ -128,7 +128,7 @@ public class DisplayOptionsParser extends CommonRpcParser { String[] dpOpts = dp.getOptions(); String[] options = new String[dpOpts.length - 1]; options = Arrays.copyOfRange(dpOpts, 1, dpOpts.length); - for (String onOffString : onOff) { + for (String onOffString : ON_OFF) { int onIdx = findInArray(options, onOffString); if (onIdx != IDX_NOT_FOUND) { options[onIdx] = datapointName + "_" + onOffString; diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/BatteryTypeVirtualDatapointHandler.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/BatteryTypeVirtualDatapointHandler.java index ea5021698..af8b84c07 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/BatteryTypeVirtualDatapointHandler.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/BatteryTypeVirtualDatapointHandler.java @@ -33,12 +33,12 @@ import org.slf4j.LoggerFactory; public class BatteryTypeVirtualDatapointHandler extends AbstractVirtualDatapointHandler { private final Logger logger = LoggerFactory.getLogger(BatteryTypeVirtualDatapointHandler.class); - private static final Properties batteries = new Properties(); + private static final Properties BATT_PROPERTIES = new Properties(); public BatteryTypeVirtualDatapointHandler() { Bundle bundle = FrameworkUtil.getBundle(getClass()); try (InputStream stream = bundle.getResource("homematic/batteries.properties").openStream()) { - batteries.load(stream); + BATT_PROPERTIES.load(stream); } catch (IllegalStateException | IOException e) { logger.warn("The resource homematic/batteries.properties could not be loaded! Battery types not available", e); @@ -52,7 +52,7 @@ public class BatteryTypeVirtualDatapointHandler extends AbstractVirtualDatapoint @Override public void initialize(HmDevice device) { - String batteryType = batteries.getProperty(device.getType()); + String batteryType = BATT_PROPERTIES.getProperty(device.getType()); if (batteryType != null) { addDatapoint(device, 0, getName(), HmValueType.STRING, batteryType, true); } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/ButtonVirtualDatapointHandler.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/ButtonVirtualDatapointHandler.java index 36a9c49f0..5caa73d36 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/ButtonVirtualDatapointHandler.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/virtual/ButtonVirtualDatapointHandler.java @@ -22,13 +22,12 @@ import org.openhab.binding.homematic.internal.model.HmDatapoint; import org.openhab.binding.homematic.internal.model.HmDevice; import org.openhab.binding.homematic.internal.model.HmValueType; import org.openhab.core.thing.CommonTriggerEvents; -import org.openhab.core.thing.DefaultSystemChannelTypeProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * A virtual String datapoint which adds a BUTTON datapoint. It will forward key events to the - * system channel {@link DefaultSystemChannelTypeProvider#SYSTEM_BUTTON}. + * system channel {@link org.openhab.core.thing.DefaultSystemChannelTypeProvider#SYSTEM_BUTTON}. * * @author Michael Reitler - Initial contribution */ diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/converter/type/AbstractTypeConverter.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/converter/type/AbstractTypeConverter.java index 0374b25f1..288eee826 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/converter/type/AbstractTypeConverter.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/converter/type/AbstractTypeConverter.java @@ -43,15 +43,15 @@ public abstract class AbstractTypeConverter implements TypeConv /** * Defines all devices where the state datapoint must be inverted. */ - private static final List stateInvertDevices = new ArrayList<>(3); + private static final List STATE_INVERT_INFO_LIST = new ArrayList<>(3); static { - stateInvertDevices.add(new StateInvertInfo(DEVICE_TYPE_SHUTTER_CONTACT)); - stateInvertDevices.add(new StateInvertInfo(DEVICE_TYPE_SHUTTER_CONTACT_2)); - stateInvertDevices.add(new StateInvertInfo(DEVICE_TYPE_INCLINATION_SENSOR)); - stateInvertDevices.add(new StateInvertInfo(DEVICE_TYPE_WIRED_IO_MODULE, 15, 26)); - stateInvertDevices.add(new StateInvertInfo(DEVICE_TYPE_MAX_WINDOW_SENSOR)); - stateInvertDevices.add(new StateInvertInfo(DEVICE_TYPE_SHUTTER_CONTACT_INTERFACE)); + STATE_INVERT_INFO_LIST.add(new StateInvertInfo(DEVICE_TYPE_SHUTTER_CONTACT)); + STATE_INVERT_INFO_LIST.add(new StateInvertInfo(DEVICE_TYPE_SHUTTER_CONTACT_2)); + STATE_INVERT_INFO_LIST.add(new StateInvertInfo(DEVICE_TYPE_INCLINATION_SENSOR)); + STATE_INVERT_INFO_LIST.add(new StateInvertInfo(DEVICE_TYPE_WIRED_IO_MODULE, 15, 26)); + STATE_INVERT_INFO_LIST.add(new StateInvertInfo(DEVICE_TYPE_MAX_WINDOW_SENSOR)); + STATE_INVERT_INFO_LIST.add(new StateInvertInfo(DEVICE_TYPE_SHUTTER_CONTACT_INTERFACE)); } /** @@ -59,7 +59,7 @@ public abstract class AbstractTypeConverter implements TypeConv */ protected boolean isStateInvertDatapoint(HmDatapoint dp) { if (DATAPOINT_NAME_STATE.equals(dp.getName())) { - for (StateInvertInfo stateInvertInfo : stateInvertDevices) { + for (StateInvertInfo stateInvertInfo : STATE_INVERT_INFO_LIST) { if (stateInvertInfo.isToInvert(dp)) { return true; } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/converter/type/QuantityTypeConverter.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/converter/type/QuantityTypeConverter.java index 5a51f9df7..37fd497d8 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/converter/type/QuantityTypeConverter.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/converter/type/QuantityTypeConverter.java @@ -32,11 +32,11 @@ import org.openhab.core.types.Type; public class QuantityTypeConverter extends AbstractTypeConverter>> { // this literal is required because some gateway types are mixing up encodings in their XML-RPC responses - private final String UNCORRECT_ENCODED_CELSIUS = "°C"; + private static final String UNCORRECT_ENCODED_CELSIUS = "°C"; // "100%" is a commonly used "unit" in datapoints. Generated channel-type is of DecimalType, // but clients may define a QuantityType if preferred - private final String HUNDRED_PERCENT = "100%"; + private static final String HUNDRED_PERCENT = "100%"; @Override protected boolean toBindingValidation(HmDatapoint dp, Class typeClass) { diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/discovery/eq3udp/Eq3UdpRequest.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/discovery/eq3udp/Eq3UdpRequest.java index 7d853ce8b..cdfa1b20e 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/discovery/eq3udp/Eq3UdpRequest.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/discovery/eq3udp/Eq3UdpRequest.java @@ -26,7 +26,7 @@ public class Eq3UdpRequest { private static final byte UDP_IDENTIFY = 73; private static final byte UDP_SEPARATOR = 0; - private static final int senderId = new Random().nextInt() & 0xFFFFFF; + private static final int SENDER_ID = new Random().nextInt() & 0xFFFFFF; private static final String EQ3_DEVICE_TYPE = "eQ3-*"; private static final String EQ3_SERIAL_NUMBER = "*"; @@ -41,7 +41,7 @@ public class Eq3UdpRequest { * Returns the sender id. */ public static int getSenderId() { - return senderId; + return SENDER_ID; } /** @@ -51,7 +51,7 @@ public class Eq3UdpRequest { ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(2); for (int i = 2; i >= 0; i--) { - byte temp = (byte) (senderId >> i * 8 & 0xFF); + byte temp = (byte) (SENDER_ID >> i * 8 & 0xFF); baos.write(temp); } baos.write(UDP_SEPARATOR); diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicThingHandler.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicThingHandler.java index de3b66aa4..9289660a7 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicThingHandler.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicThingHandler.java @@ -27,7 +27,6 @@ import java.util.Objects; import java.util.concurrent.Future; import org.eclipse.jdt.annotation.Nullable; -import org.openhab.binding.homematic.internal.HomematicBindingConstants; import org.openhab.binding.homematic.internal.common.HomematicConfig; import org.openhab.binding.homematic.internal.communicator.HomematicGateway; import org.openhab.binding.homematic.internal.converter.ConverterException; @@ -372,8 +371,10 @@ public class HomematicThingHandler extends BaseThingHandler { * @param datapointName The datapoint that will be updated on the device * @param currentValue The current value of the datapoint * @param newValue The value that will be sent to the device - * @return The rxMode ({@link HomematicBindingConstants#RX_BURST_MODE "BURST"} for burst mode, - * {@link HomematicBindingConstants#RX_WAKEUP_MODE "WAKEUP"} for wakeup mode, or null for the default mode) + * @return The rxMode ({@link org.openhab.binding.homematic.internal.HomematicBindingConstants#RX_BURST_MODE + * "BURST"} for burst mode, + * {@link org.openhab.binding.homematic.internal.HomematicBindingConstants#RX_WAKEUP_MODE "WAKEUP"} for + * wakeup mode, or null for the default mode) */ protected String getRxModeForDatapointTransmission(String datapointName, Object currentValue, Object newValue) { return null; diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/SimplePortPool.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/SimplePortPool.java index cab26f1c2..f33bd5de2 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/SimplePortPool.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/SimplePortPool.java @@ -22,7 +22,7 @@ import java.util.List; * @author Gerhard Riegler - Initial contribution */ public class SimplePortPool { - private static int START_PORT = 9125; + private static int startPort = 9125; private List availablePorts = new ArrayList<>(); @@ -48,9 +48,9 @@ public class SimplePortPool { } PortInfo portInfo = new PortInfo(); - while (isPortInUse(START_PORT++)) { + while (isPortInUse(startPort++)) { } - portInfo.port = START_PORT - 1; + portInfo.port = startPort - 1; portInfo.free = false; availablePorts.add(portInfo); diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/misc/MiscUtils.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/misc/MiscUtils.java index de317d63f..40cff3a0f 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/misc/MiscUtils.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/misc/MiscUtils.java @@ -21,7 +21,7 @@ import org.slf4j.LoggerFactory; * @author Gerhard Riegler - Initial contribution */ public class MiscUtils { - private static final Logger logger = LoggerFactory.getLogger(MiscUtils.class); + private static final Logger LOGGER = LoggerFactory.getLogger(MiscUtils.class); /** * Replaces invalid characters of the text to fit into an openHAB UID. @@ -32,7 +32,7 @@ public class MiscUtils { } String cleanedText = text.replaceAll("[^A-Za-z0-9_-]", replaceChar); if (!text.equals(cleanedText)) { - logger.info("{} '{}' contains invalid characters, new {} '{}'", textType, text, textType, cleanedText); + LOGGER.info("{} '{}' contains invalid characters, new {} '{}'", textType, text, textType, cleanedText); } return cleanedText; } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/MetadataUtils.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/MetadataUtils.java index 588b0a0ac..4ee82f6d8 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/MetadataUtils.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/MetadataUtils.java @@ -47,7 +47,7 @@ import org.slf4j.LoggerFactory; */ public class MetadataUtils { - private static final Logger logger = LoggerFactory.getLogger(MetadataUtils.class); + private static final Logger LOGGER = LoggerFactory.getLogger(MetadataUtils.class); private static ResourceBundle descriptionsBundle; private static Map descriptions = new HashMap<>(); private static Map> standardDatapoints = new HashMap<>(); @@ -98,7 +98,7 @@ public class MetadataUtils { } } } catch (IllegalStateException | IOException e) { - logger.warn("Can't load standard-datapoints.properties file!", e); + LOGGER.warn("Can't load standard-datapoints.properties file!", e); } } @@ -112,7 +112,7 @@ public class MetadataUtils { public static List generateOptions(HmDatapoint dp, OptionsBuilder optionsBuilder) { List options = null; if (dp.getOptions() == null) { - logger.warn("No options for ENUM datapoint {}", dp); + LOGGER.warn("No options for ENUM datapoint {}", dp); } else { options = new ArrayList<>(); for (int i = 0; i < dp.getOptions().length; i++) { @@ -214,8 +214,8 @@ public class MetadataUtils { } sb.append(key).append(", "); } - if (logger.isTraceEnabled()) { - logger.trace("Description not found for: {}", sb.toString().substring(0, sb.length() - 2)); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Description not found for: {}", sb.toString().substring(0, sb.length() - 2)); } return null; } @@ -271,7 +271,7 @@ public class MetadataUtils { try { return new BigDecimal(number.toString()); } catch (Exception ex) { - logger.warn("Can't create BigDecimal for number: {}", number.toString()); + LOGGER.warn("Can't create BigDecimal for number: {}", number.toString()); return null; } } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/type/HomematicThingTypeExcluder.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/type/HomematicThingTypeExcluder.java index 5a360a225..e63d1b287 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/type/HomematicThingTypeExcluder.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/type/HomematicThingTypeExcluder.java @@ -18,7 +18,6 @@ import java.util.Set; import org.openhab.core.thing.ThingTypeUID; import org.openhab.core.thing.type.ChannelGroupTypeUID; import org.openhab.core.thing.type.ChannelTypeUID; -import org.openhab.core.thing.type.ThingType; /** * Allows external definition of @@ -35,7 +34,7 @@ public interface HomematicThingTypeExcluder { * are henceforth responsible to ... *
  • provide any excluded ThingType on their own - e.g. in a custom * {@link org.openhab.core.thing.binding.ThingTypeProvider} or by - * defining those {@link ThingType}s in XML.
  • + * defining those {@link org.openhab.core.thing.type.ThingType}s in XML. *
  • provide {@link org.openhab.core.thing.type.ChannelType}s * which are introduced by the provided thing-types
  • *
  • ensure compatibility and completeness of those thing-types (for any @@ -55,7 +54,7 @@ public interface HomematicThingTypeExcluder { * {@link HomematicThingTypeExcluder} or not * * @param thingType a specific ThingType, specified by its {@link ThingTypeUID} - * @return true, if the {@link ThingType} is excluded + * @return true, if the {@link org.openhab.core.thing.type.ThingType} is excluded */ boolean isThingTypeExcluded(ThingTypeUID thingType); diff --git a/bundles/org.openhab.binding.homematic/src/test/java/org/openhab/binding/homematic/internal/converter/ConvertFromBindingTest.java b/bundles/org.openhab.binding.homematic/src/test/java/org/openhab/binding/homematic/internal/converter/ConvertFromBindingTest.java index 115d55bad..4b7e8ef68 100644 --- a/bundles/org.openhab.binding.homematic/src/test/java/org/openhab/binding/homematic/internal/converter/ConvertFromBindingTest.java +++ b/bundles/org.openhab.binding.homematic/src/test/java/org/openhab/binding/homematic/internal/converter/ConvertFromBindingTest.java @@ -16,18 +16,17 @@ import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; import org.junit.jupiter.api.Test; -import org.openhab.binding.homematic.internal.converter.type.AbstractTypeConverter; import org.openhab.binding.homematic.internal.model.HmDatapoint; import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.unit.ImperialUnits; +import org.openhab.core.library.unit.SIUnits; import org.openhab.core.library.unit.Units; import org.openhab.core.types.State; -import tech.units.indriya.unit.UnitDimension; - /** - * Tests for {@link AbstractTypeConverter#convertFromBinding(HmDatapoint)}. + * Tests for + * {@link org.openhab.binding.homematic.internal.converter.type.AbstractTypeConverter#convertFromBinding(HmDatapoint)}. * * @author Michael Reitler - Initial Contribution * @@ -75,20 +74,19 @@ public class ConvertFromBindingTest extends BaseConverterTest { floatQuantityDp.setUnit("°C"); convertedState = temperatureConverter.convertFromBinding(floatQuantityDp); assertThat(convertedState, instanceOf(QuantityType.class)); - assertThat(((QuantityType) convertedState).getDimension(), is(UnitDimension.TEMPERATURE)); + assertThat(((QuantityType) convertedState).getDimension(), is(equalTo(SIUnits.CELSIUS.getDimension()))); assertThat(((QuantityType) convertedState).doubleValue(), is(10.5)); assertThat(((QuantityType) convertedState).toUnit(ImperialUnits.FAHRENHEIT).doubleValue(), is(50.9)); floatQuantityDp.setUnit("°C"); - assertThat(((QuantityType) convertedState).getDimension(), is(UnitDimension.TEMPERATURE)); + assertThat(((QuantityType) convertedState).getDimension(), is(equalTo(SIUnits.CELSIUS.getDimension()))); assertThat(((QuantityType) convertedState).doubleValue(), is(10.5)); integerQuantityDp.setValue(50000); integerQuantityDp.setUnit("mHz"); convertedState = frequencyConverter.convertFromBinding(integerQuantityDp); assertThat(convertedState, instanceOf(QuantityType.class)); - assertThat(((QuantityType) convertedState).getDimension(), - is(UnitDimension.NONE.divide(UnitDimension.TIME))); + assertThat(((QuantityType) convertedState).getDimension(), is(equalTo(Units.HERTZ.getDimension()))); assertThat(((QuantityType) convertedState).intValue(), is(50000)); assertThat(((QuantityType) convertedState).toUnit(Units.HERTZ).intValue(), is(50)); @@ -96,7 +94,7 @@ public class ConvertFromBindingTest extends BaseConverterTest { floatQuantityDp.setUnit("100%"); convertedState = timeConverter.convertFromBinding(floatQuantityDp); assertThat(convertedState, instanceOf(QuantityType.class)); - assertThat(((QuantityType) convertedState).getDimension(), is(UnitDimension.NONE)); + assertThat(((QuantityType) convertedState).getDimension(), is(equalTo(Units.ONE.getDimension()))); assertThat(((QuantityType) convertedState).doubleValue(), is(70.0)); assertThat(((QuantityType) convertedState).getUnit(), is(Units.PERCENT)); assertThat(((QuantityType) convertedState).toUnit(Units.ONE).doubleValue(), is(0.7)); diff --git a/bundles/org.openhab.binding.homematic/src/test/java/org/openhab/binding/homematic/internal/converter/ConvertToBindingTest.java b/bundles/org.openhab.binding.homematic/src/test/java/org/openhab/binding/homematic/internal/converter/ConvertToBindingTest.java index 6bd48909c..8f60c567e 100644 --- a/bundles/org.openhab.binding.homematic/src/test/java/org/openhab/binding/homematic/internal/converter/ConvertToBindingTest.java +++ b/bundles/org.openhab.binding.homematic/src/test/java/org/openhab/binding/homematic/internal/converter/ConvertToBindingTest.java @@ -17,15 +17,14 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import org.junit.jupiter.api.Test; -import org.openhab.binding.homematic.internal.converter.type.AbstractTypeConverter; import org.openhab.binding.homematic.internal.converter.type.DecimalTypeConverter; import org.openhab.binding.homematic.internal.converter.type.QuantityTypeConverter; -import org.openhab.binding.homematic.internal.model.HmDatapoint; import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.QuantityType; /** - * Tests for {@link AbstractTypeConverter#convertToBinding(org.openhab.core.types.Type, HmDatapoint)}. + * Tests for + * {@link org.openhab.binding.homematic.internal.converter.type.AbstractTypeConverter#convertToBinding(org.openhab.core.types.Type, HmDatapoint)}. * * @author Michael Reitler - Initial Contribution *