mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-02-04 11:24:10 +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) {
|
} catch (KNXMLException e) {
|
||||||
throw new KnxSecureException("keyring file configured, but loading failed: ", 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);
|
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
|
// step 6: tunnel: load data from keyring
|
||||||
if (secureTunnelSourceAddr != null) {
|
if (secureTunnelSourceAddr != null) {
|
||||||
// requires a valid keyring
|
// requires a valid keyring
|
||||||
if (!keyring.isPresent()) {
|
if (keyring.isEmpty()) {
|
||||||
throw new KnxSecureException("valid keyring specification required for secure tunnel mode");
|
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
|
// 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();
|
ChannelUID linkedChannelUID = callback.getItemChannelLink().getLinkedUID();
|
||||||
logger.trace("onStateUpdateFromItem({}) to {}", state.toString(), linkedChannelUID);
|
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);
|
logger.debug("The given state {} could not be transformed to a command", state);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Command command = (Command) state;
|
|
||||||
|
|
||||||
// this does not have effect for contact items
|
// this does not have effect for contact items
|
||||||
// callback.handleCommand(command);
|
// callback.handleCommand(command);
|
||||||
|
@ -86,12 +86,10 @@ public class KNXProfileFactory implements ProfileFactory, ProfileAdvisor, Profil
|
|||||||
private @Nullable ProfileTypeUID getSuggestedProfileTypeUID(@Nullable ChannelTypeUID channelTypeUID,
|
private @Nullable ProfileTypeUID getSuggestedProfileTypeUID(@Nullable ChannelTypeUID channelTypeUID,
|
||||||
@Nullable String itemType) {
|
@Nullable String itemType) {
|
||||||
if (KNXBindingConstants.CHANNEL_CONTACT_CONTROL_UID.equals(channelTypeUID) && itemType != null) {
|
if (KNXBindingConstants.CHANNEL_CONTACT_CONTROL_UID.equals(channelTypeUID) && itemType != null) {
|
||||||
switch (itemType) {
|
return switch (itemType) {
|
||||||
case CoreItemFactory.CONTACT:
|
case CoreItemFactory.CONTACT -> UID_CONTACT_CONTROL;
|
||||||
return UID_CONTACT_CONTROL;
|
default -> null;
|
||||||
default:
|
};
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.openhab.binding.knx.internal.dpt;
|
package org.openhab.binding.knx.internal.dpt;
|
||||||
|
|
||||||
|
import static java.lang.Double.*;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
@ -152,7 +153,7 @@ class DPTTest {
|
|||||||
void testToDPT9ValueFromQuantityType() {
|
void testToDPT9ValueFromQuantityType() {
|
||||||
assertEquals("23.1", ValueEncoder.encode(new QuantityType<>("23.1 °C"), "9.001"));
|
assertEquals("23.1", ValueEncoder.encode(new QuantityType<>("23.1 °C"), "9.001"));
|
||||||
assertEquals(5.0,
|
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<>("274.15 K"), "9.001"));
|
||||||
assertEquals("1", ValueEncoder.encode(new QuantityType<>("1 K"), "9.002"));
|
assertEquals("1", ValueEncoder.encode(new QuantityType<>("1 K"), "9.002"));
|
||||||
assertEquals("1", ValueEncoder.encode(new QuantityType<>("1000 mK"), "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"));
|
assertEquals("1", ValueEncoder.encode(new QuantityType<>("1 m/s"), "9.005"));
|
||||||
assertTrue(Objects.requireNonNullElse(ValueEncoder.encode(new QuantityType<>("1.94 kn"), "9.005"), "")
|
assertTrue(Objects.requireNonNullElse(ValueEncoder.encode(new QuantityType<>("1.94 kn"), "9.005"), "")
|
||||||
.startsWith("0.99"));
|
.startsWith("0.99"));
|
||||||
assertEquals(1.0, Double
|
assertEquals(1.0,
|
||||||
.parseDouble(Objects.requireNonNull(ValueEncoder.encode(new QuantityType<>("3.6 km/h"), "9.005"))));
|
parseDouble(Objects.requireNonNull(ValueEncoder.encode(new QuantityType<>("3.6 km/h"), "9.005"))));
|
||||||
assertEquals("456", ValueEncoder.encode(new QuantityType<>("456 Pa"), "9.006"));
|
assertEquals("456", ValueEncoder.encode(new QuantityType<>("456 Pa"), "9.006"));
|
||||||
assertEquals("70", ValueEncoder.encode(new QuantityType<>("70 %"), "9.007"));
|
assertEquals("70", ValueEncoder.encode(new QuantityType<>("70 %"), "9.007"));
|
||||||
assertEquals("8", ValueEncoder.encode(new QuantityType<>("8 ppm"), "9.008"));
|
assertEquals("8", ValueEncoder.encode(new QuantityType<>("8 ppm"), "9.008"));
|
||||||
@ -469,9 +470,9 @@ class DPTTest {
|
|||||||
String[] parts = enc.split(" ");
|
String[] parts = enc.split(" ");
|
||||||
assertEquals(5, parts.length);
|
assertEquals(5, parts.length);
|
||||||
int[] rgb = ColorUtil.hsbToRgb(hsbType);
|
int[] rgb = ColorUtil.hsbToRgb(hsbType);
|
||||||
assertEquals(rgb[0] * 100d / 255, Double.valueOf(parts[0].replace(',', '.')), 1);
|
assertEquals(rgb[0] * 100d / 255, valueOf(parts[0].replace(',', '.')), 1);
|
||||||
assertEquals(rgb[1] * 100d / 255, Double.valueOf(parts[1].replace(',', '.')), 1);
|
assertEquals(rgb[1] * 100d / 255, valueOf(parts[1].replace(',', '.')), 1);
|
||||||
assertEquals(rgb[2] * 100d / 255, Double.valueOf(parts[2].replace(',', '.')), 1);
|
assertEquals(rgb[2] * 100d / 255, valueOf(parts[2].replace(',', '.')), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -491,9 +492,9 @@ class DPTTest {
|
|||||||
String[] parts = enc.split(" ");
|
String[] parts = enc.split(" ");
|
||||||
assertEquals(5, parts.length);
|
assertEquals(5, parts.length);
|
||||||
int[] rgb = ColorUtil.hsbToRgb(hsbType);
|
int[] rgb = ColorUtil.hsbToRgb(hsbType);
|
||||||
assertEquals(rgb[0] * 100d / 255, Double.valueOf(parts[0].replace(',', '.')), 1);
|
assertEquals(rgb[0] * 100d / 255, valueOf(parts[0].replace(',', '.')), 1);
|
||||||
assertEquals(rgb[1] * 100d / 255, Double.valueOf(parts[1].replace(',', '.')), 1);
|
assertEquals(rgb[1] * 100d / 255, valueOf(parts[1].replace(',', '.')), 1);
|
||||||
assertEquals(rgb[2] * 100d / 255, Double.valueOf(parts[2].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
|
// 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 %"
|
// encoding will return a String in notation defined by Calimero: "(x,xxxx y,yyyy) YY,Y %"
|
||||||
String result = ValueEncoder.encode(hsb, dpt);
|
String result = ValueEncoder.encode(hsb, dpt);
|
||||||
|
assertNotNull(result);
|
||||||
|
|
||||||
// for back to back test, compare numerical values to allow tolerances
|
// for back to back test, compare numerical values to allow tolerances
|
||||||
double dx = (((value[0] & 0xff) << 8) | (value[1] & 0xff)) / 65535.0;
|
double dx = (((value[0] & 0xff) << 8) | (value[1] & 0xff)) / 65535.0;
|
||||||
@ -626,9 +628,9 @@ class DPTTest {
|
|||||||
Assertions.assertNotNull(stringx);
|
Assertions.assertNotNull(stringx);
|
||||||
Assertions.assertNotNull(stringy);
|
Assertions.assertNotNull(stringy);
|
||||||
Assertions.assertNotNull(stringY);
|
Assertions.assertNotNull(stringY);
|
||||||
double rx = Double.parseDouble(stringx.replace(',', '.'));
|
double rx = parseDouble(stringx.replace(',', '.'));
|
||||||
double ry = Double.parseDouble(stringy.replace(',', '.'));
|
double ry = parseDouble(stringy.replace(',', '.'));
|
||||||
double rY = Double.parseDouble(stringY.replace(',', '.'));
|
double rY = parseDouble(stringY.replace(',', '.'));
|
||||||
|
|
||||||
final double tolerance = 0.001;
|
final double tolerance = 0.001;
|
||||||
if ((Math.abs(dx - rx) > tolerance) || (Math.abs(dy - ry) > tolerance)
|
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[] { 42 }, new DecimalType(42));
|
||||||
helper("18.001", new byte[] { 63 }, new DecimalType(63));
|
helper("18.001", new byte[] { 63 }, new DecimalType(63));
|
||||||
// scene, learn += 0x80
|
// 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 + 42) }, new DecimalType(0x80 + 42));
|
||||||
helper("18.001", new byte[] { (byte) (0x80 + 63) }, new DecimalType(0x80 + 63));
|
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 });
|
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 },
|
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 });
|
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
|
@Test
|
||||||
|
@ -106,18 +106,15 @@ public class KNXSecurityTest {
|
|||||||
Security openhabSecurity = Security.newSecurity();
|
Security openhabSecurity = Security.newSecurity();
|
||||||
openhabSecurity.useKeyring(keys, password);
|
openhabSecurity.useKeyring(keys, password);
|
||||||
|
|
||||||
assertThrows(KnxSecureException.class, () -> {
|
assertThrows(KnxSecureException.class,
|
||||||
KNXBridgeBaseThingHandler.secHelperReadBackboneKey(Optional.empty(), passwordString);
|
() -> KNXBridgeBaseThingHandler.secHelperReadBackboneKey(Optional.empty(), passwordString));
|
||||||
});
|
|
||||||
assertTrue(KNXBridgeBaseThingHandler.secHelperReadBackboneKey(Optional.ofNullable(keys), passwordString)
|
assertTrue(KNXBridgeBaseThingHandler.secHelperReadBackboneKey(Optional.ofNullable(keys), passwordString)
|
||||||
.isEmpty());
|
.isEmpty());
|
||||||
|
|
||||||
// now check tunnel (expected to fail, not included)
|
// now check tunnel (expected to fail, not included)
|
||||||
IndividualAddress secureTunnelSourceAddr = new IndividualAddress(2, 8, 20);
|
IndividualAddress secureTunnelSourceAddr = new IndividualAddress(2, 8, 20);
|
||||||
assertThrows(KnxSecureException.class, () -> {
|
assertThrows(KnxSecureException.class, () -> KNXBridgeBaseThingHandler
|
||||||
KNXBridgeBaseThingHandler.secHelperReadTunnelConfig(Optional.empty(), passwordString,
|
.secHelperReadTunnelConfig(Optional.empty(), passwordString, secureTunnelSourceAddr));
|
||||||
secureTunnelSourceAddr);
|
|
||||||
});
|
|
||||||
assertTrue(KNXBridgeBaseThingHandler
|
assertTrue(KNXBridgeBaseThingHandler
|
||||||
.secHelperReadTunnelConfig(Optional.ofNullable(keys), passwordString, secureTunnelSourceAddr)
|
.secHelperReadTunnelConfig(Optional.ofNullable(keys), passwordString, secureTunnelSourceAddr)
|
||||||
.isEmpty());
|
.isEmpty());
|
||||||
|
Loading…
Reference in New Issue
Block a user