mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-02-04 03:14:07 +01:00
Rework
Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
parent
fad4c1cc66
commit
ff89a6e505
@ -207,7 +207,7 @@ public abstract class KNXBridgeBaseThingHandler extends BaseBridgeHandler implem
|
||||
} catch (KNXMLException e) {
|
||||
throw new KnxSecureException("keyring file configured, but loading failed: ", e);
|
||||
}
|
||||
if (!keyring.isPresent()) {
|
||||
if (keyring.isEmpty()) {
|
||||
throw new KnxSecureException("keyring file configured, but loading failed: " + keyringUri);
|
||||
}
|
||||
|
||||
@ -263,7 +263,7 @@ public abstract class KNXBridgeBaseThingHandler extends BaseBridgeHandler implem
|
||||
// step 6: tunnel: load data from keyring
|
||||
if (secureTunnelSourceAddr != null) {
|
||||
// requires a valid keyring
|
||||
if (!keyring.isPresent()) {
|
||||
if (keyring.isEmpty()) {
|
||||
throw new KnxSecureException("valid keyring specification required for secure tunnel mode");
|
||||
}
|
||||
// other parameters will not be accepted, since all is read from keyring in this case
|
||||
|
@ -56,11 +56,10 @@ public class KNXContactControlProfile implements StateProfile {
|
||||
ChannelUID linkedChannelUID = callback.getItemChannelLink().getLinkedUID();
|
||||
logger.trace("onStateUpdateFromItem({}) to {}", state.toString(), linkedChannelUID);
|
||||
|
||||
if (!(state instanceof Command)) {
|
||||
if (!(state instanceof Command command)) {
|
||||
logger.debug("The given state {} could not be transformed to a command", state);
|
||||
return;
|
||||
}
|
||||
Command command = (Command) state;
|
||||
|
||||
// this does not have effect for contact items
|
||||
// callback.handleCommand(command);
|
||||
|
@ -86,12 +86,10 @@ public class KNXProfileFactory implements ProfileFactory, ProfileAdvisor, Profil
|
||||
private @Nullable ProfileTypeUID getSuggestedProfileTypeUID(@Nullable ChannelTypeUID channelTypeUID,
|
||||
@Nullable String itemType) {
|
||||
if (KNXBindingConstants.CHANNEL_CONTACT_CONTROL_UID.equals(channelTypeUID) && itemType != null) {
|
||||
switch (itemType) {
|
||||
case CoreItemFactory.CONTACT:
|
||||
return UID_CONTACT_CONTROL;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return switch (itemType) {
|
||||
case CoreItemFactory.CONTACT -> UID_CONTACT_CONTROL;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
*/
|
||||
package org.openhab.binding.knx.internal.dpt;
|
||||
|
||||
import static java.lang.Double.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
@ -152,7 +153,7 @@ class DPTTest {
|
||||
void testToDPT9ValueFromQuantityType() {
|
||||
assertEquals("23.1", ValueEncoder.encode(new QuantityType<>("23.1 °C"), "9.001"));
|
||||
assertEquals(5.0,
|
||||
Double.parseDouble(Objects.requireNonNull(ValueEncoder.encode(new QuantityType<>("41 °F"), "9.001"))));
|
||||
parseDouble(Objects.requireNonNull(ValueEncoder.encode(new QuantityType<>("41 °F"), "9.001"))));
|
||||
assertEquals("1", ValueEncoder.encode(new QuantityType<>("274.15 K"), "9.001"));
|
||||
assertEquals("1", ValueEncoder.encode(new QuantityType<>("1 K"), "9.002"));
|
||||
assertEquals("1", ValueEncoder.encode(new QuantityType<>("1000 mK"), "9.002"));
|
||||
@ -167,8 +168,8 @@ class DPTTest {
|
||||
assertEquals("1", ValueEncoder.encode(new QuantityType<>("1 m/s"), "9.005"));
|
||||
assertTrue(Objects.requireNonNullElse(ValueEncoder.encode(new QuantityType<>("1.94 kn"), "9.005"), "")
|
||||
.startsWith("0.99"));
|
||||
assertEquals(1.0, Double
|
||||
.parseDouble(Objects.requireNonNull(ValueEncoder.encode(new QuantityType<>("3.6 km/h"), "9.005"))));
|
||||
assertEquals(1.0,
|
||||
parseDouble(Objects.requireNonNull(ValueEncoder.encode(new QuantityType<>("3.6 km/h"), "9.005"))));
|
||||
assertEquals("456", ValueEncoder.encode(new QuantityType<>("456 Pa"), "9.006"));
|
||||
assertEquals("70", ValueEncoder.encode(new QuantityType<>("70 %"), "9.007"));
|
||||
assertEquals("8", ValueEncoder.encode(new QuantityType<>("8 ppm"), "9.008"));
|
||||
@ -469,9 +470,9 @@ class DPTTest {
|
||||
String[] parts = enc.split(" ");
|
||||
assertEquals(5, parts.length);
|
||||
int[] rgb = ColorUtil.hsbToRgb(hsbType);
|
||||
assertEquals(rgb[0] * 100d / 255, Double.valueOf(parts[0].replace(',', '.')), 1);
|
||||
assertEquals(rgb[1] * 100d / 255, Double.valueOf(parts[1].replace(',', '.')), 1);
|
||||
assertEquals(rgb[2] * 100d / 255, Double.valueOf(parts[2].replace(',', '.')), 1);
|
||||
assertEquals(rgb[0] * 100d / 255, valueOf(parts[0].replace(',', '.')), 1);
|
||||
assertEquals(rgb[1] * 100d / 255, valueOf(parts[1].replace(',', '.')), 1);
|
||||
assertEquals(rgb[2] * 100d / 255, valueOf(parts[2].replace(',', '.')), 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -491,9 +492,9 @@ class DPTTest {
|
||||
String[] parts = enc.split(" ");
|
||||
assertEquals(5, parts.length);
|
||||
int[] rgb = ColorUtil.hsbToRgb(hsbType);
|
||||
assertEquals(rgb[0] * 100d / 255, Double.valueOf(parts[0].replace(',', '.')), 1);
|
||||
assertEquals(rgb[1] * 100d / 255, Double.valueOf(parts[1].replace(',', '.')), 1);
|
||||
assertEquals(rgb[2] * 100d / 255, Double.valueOf(parts[2].replace(',', '.')), 1);
|
||||
assertEquals(rgb[0] * 100d / 255, valueOf(parts[0].replace(',', '.')), 1);
|
||||
assertEquals(rgb[1] * 100d / 255, valueOf(parts[1].replace(',', '.')), 1);
|
||||
assertEquals(rgb[2] * 100d / 255, valueOf(parts[2].replace(',', '.')), 1);
|
||||
}
|
||||
|
||||
// This test checks all our overrides for units. It allows to detect unnecessary overrides when we
|
||||
@ -612,6 +613,7 @@ class DPTTest {
|
||||
|
||||
// encoding will return a String in notation defined by Calimero: "(x,xxxx y,yyyy) YY,Y %"
|
||||
String result = ValueEncoder.encode(hsb, dpt);
|
||||
assertNotNull(result);
|
||||
|
||||
// for back to back test, compare numerical values to allow tolerances
|
||||
double dx = (((value[0] & 0xff) << 8) | (value[1] & 0xff)) / 65535.0;
|
||||
@ -626,9 +628,9 @@ class DPTTest {
|
||||
Assertions.assertNotNull(stringx);
|
||||
Assertions.assertNotNull(stringy);
|
||||
Assertions.assertNotNull(stringY);
|
||||
double rx = Double.parseDouble(stringx.replace(',', '.'));
|
||||
double ry = Double.parseDouble(stringy.replace(',', '.'));
|
||||
double rY = Double.parseDouble(stringY.replace(',', '.'));
|
||||
double rx = parseDouble(stringx.replace(',', '.'));
|
||||
double ry = parseDouble(stringy.replace(',', '.'));
|
||||
double rY = parseDouble(stringY.replace(',', '.'));
|
||||
|
||||
final double tolerance = 0.001;
|
||||
if ((Math.abs(dx - rx) > tolerance) || (Math.abs(dy - ry) > tolerance)
|
||||
|
@ -769,7 +769,7 @@ public class Back2BackTest {
|
||||
helper("18.001", new byte[] { 42 }, new DecimalType(42));
|
||||
helper("18.001", new byte[] { 63 }, new DecimalType(63));
|
||||
// scene, learn += 0x80
|
||||
helper("18.001", new byte[] { (byte) (0x80 + 0) }, new DecimalType(0x80));
|
||||
helper("18.001", new byte[] { (byte) (0x80) }, new DecimalType(0x80));
|
||||
helper("18.001", new byte[] { (byte) (0x80 + 42) }, new DecimalType(0x80 + 42));
|
||||
helper("18.001", new byte[] { (byte) (0x80 + 63) }, new DecimalType(0x80 + 63));
|
||||
}
|
||||
@ -786,7 +786,7 @@ public class Back2BackTest {
|
||||
new DateTimeType("2019-07-15T17:30:00"), new byte[0], new byte[] { 0, 0, 0, 0, 0, 0, 0, 1 });
|
||||
helper("19.001", new byte[] { (byte) (2019 - 1900), 7, 15, 17, 30, 0, (byte) 0x24, (byte) 0x00 },
|
||||
new DateTimeType("2019-07-15T17:30:00"), new byte[0], new byte[] { 0, 0, 0, 0, 0, 0, 0, 1 });
|
||||
// TODO add tests for incompletly filled frames (e.g. containing only date or time)
|
||||
// TODO add tests for incompletely filled frames (e.g. containing only date or time)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -106,18 +106,15 @@ public class KNXSecurityTest {
|
||||
Security openhabSecurity = Security.newSecurity();
|
||||
openhabSecurity.useKeyring(keys, password);
|
||||
|
||||
assertThrows(KnxSecureException.class, () -> {
|
||||
KNXBridgeBaseThingHandler.secHelperReadBackboneKey(Optional.empty(), passwordString);
|
||||
});
|
||||
assertThrows(KnxSecureException.class,
|
||||
() -> KNXBridgeBaseThingHandler.secHelperReadBackboneKey(Optional.empty(), passwordString));
|
||||
assertTrue(KNXBridgeBaseThingHandler.secHelperReadBackboneKey(Optional.ofNullable(keys), passwordString)
|
||||
.isEmpty());
|
||||
|
||||
// now check tunnel (expected to fail, not included)
|
||||
IndividualAddress secureTunnelSourceAddr = new IndividualAddress(2, 8, 20);
|
||||
assertThrows(KnxSecureException.class, () -> {
|
||||
KNXBridgeBaseThingHandler.secHelperReadTunnelConfig(Optional.empty(), passwordString,
|
||||
secureTunnelSourceAddr);
|
||||
});
|
||||
assertThrows(KnxSecureException.class, () -> KNXBridgeBaseThingHandler
|
||||
.secHelperReadTunnelConfig(Optional.empty(), passwordString, secureTunnelSourceAddr));
|
||||
assertTrue(KNXBridgeBaseThingHandler
|
||||
.secHelperReadTunnelConfig(Optional.ofNullable(keys), passwordString, secureTunnelSourceAddr)
|
||||
.isEmpty());
|
||||
|
Loading…
Reference in New Issue
Block a user