From 454fdfe82fa215eefcb5826b937f0bb341f667d2 Mon Sep 17 00:00:00 2001 From: Eugen Freiter Date: Sun, 15 Mar 2020 23:55:09 +0100 Subject: [PATCH] refactoring to new HAP 2.0 --- pom.xml | 37 +++++++++++++++++-- .../java/com/beowulfe/hap/sample/Main.java | 7 ++-- .../com/beowulfe/hap/sample/MockAuthInfo.java | 7 ++-- .../com/beowulfe/hap/sample/MockSwitch.java | 33 +++++++++++------ src/main/resources/log4j2.xml | 17 +++++++++ src/main/resources/logback.xml | 2 +- src/main/resources/simplelogger.properties | 1 + 7 files changed, 79 insertions(+), 25 deletions(-) create mode 100644 src/main/resources/log4j2.xml create mode 100644 src/main/resources/simplelogger.properties diff --git a/pom.xml b/pom.xml index af8e41da1..a288948ca 100644 --- a/pom.xml +++ b/pom.xml @@ -2,13 +2,13 @@ 4.0.0 com.beowulfe.hap hap-sample - 0.0.1-SNAPSHOT + 0.0.2-SNAPSHOT hap-java-sample - com.beowulfe.hap + io.github.hap-java hap - 0.0.1-SNAPSHOT + 2.0.0-snapshot ch.qos.logback @@ -28,6 +28,35 @@ 1.8 + + + org.apache.maven.plugins + maven-jar-plugin + 3.1.0 + + + + true + lib/ + com.beowulfe.hap.sample.Main + + + + + + maven-dependency-plugin + + + install + + copy-dependencies + + + ${project.build.directory}/lib + + + + - \ No newline at end of file + diff --git a/src/main/java/com/beowulfe/hap/sample/Main.java b/src/main/java/com/beowulfe/hap/sample/Main.java index eb332b69b..b74bb57a7 100644 --- a/src/main/java/com/beowulfe/hap/sample/Main.java +++ b/src/main/java/com/beowulfe/hap/sample/Main.java @@ -6,9 +6,8 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; - -import com.beowulfe.hap.HomekitRoot; -import com.beowulfe.hap.HomekitServer; +import io.github.hapjava.server.impl.HomekitRoot; +import io.github.hapjava.server.impl.HomekitServer; public class Main { @@ -33,7 +32,7 @@ public static void main(String[] args) { } HomekitServer homekit = new HomekitServer(PORT); - HomekitRoot bridge = homekit.createBridge(mockAuth, "Test Bridge", "TestBridge, Inc.", "G6", "111abe234"); + HomekitRoot bridge = homekit.createBridge(mockAuth, "Test Bridge", "TestBridge, Inc.", "G6", "111abe234", "1.1", "1.2"); mockAuth.onChange(state -> { try { diff --git a/src/main/java/com/beowulfe/hap/sample/MockAuthInfo.java b/src/main/java/com/beowulfe/hap/sample/MockAuthInfo.java index b38b8a977..ed152ce6f 100644 --- a/src/main/java/com/beowulfe/hap/sample/MockAuthInfo.java +++ b/src/main/java/com/beowulfe/hap/sample/MockAuthInfo.java @@ -3,9 +3,8 @@ import java.math.BigInteger; import java.security.InvalidAlgorithmParameterException; import java.util.function.Consumer; - -import com.beowulfe.hap.HomekitAuthInfo; -import com.beowulfe.hap.HomekitServer; +import io.github.hapjava.server.HomekitAuthInfo; +import io.github.hapjava.server.impl.HomekitServer; /** * This is a simple implementation that should never be used in actual production. The mac, salt, and privateKey @@ -22,7 +21,7 @@ public class MockAuthInfo implements HomekitAuthInfo { public MockAuthInfo() throws InvalidAlgorithmParameterException { this(new AuthState("031-45-154", HomekitServer.generateMac(), HomekitServer.generateSalt(), - HomekitServer.generateKey())); + HomekitServer.generateKey())); } public MockAuthInfo(AuthState _authState) { diff --git a/src/main/java/com/beowulfe/hap/sample/MockSwitch.java b/src/main/java/com/beowulfe/hap/sample/MockSwitch.java index b770737bb..585f4cff7 100644 --- a/src/main/java/com/beowulfe/hap/sample/MockSwitch.java +++ b/src/main/java/com/beowulfe/hap/sample/MockSwitch.java @@ -1,11 +1,11 @@ package com.beowulfe.hap.sample; import java.util.concurrent.CompletableFuture; +import io.github.hapjava.accessories.LightbulbAccessory; +import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithHardwareRevision; +import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import com.beowulfe.hap.HomekitCharacteristicChangeCallback; -import com.beowulfe.hap.accessories.Lightbulb; - -public class MockSwitch implements Lightbulb { +public class MockSwitch implements LightbulbAccessory, AccessoryWithHardwareRevision { private boolean powerState = false; private HomekitCharacteristicChangeCallback subscribeCallback = null; @@ -16,8 +16,8 @@ public int getId() { } @Override - public String getLabel() { - return "Test Lightbulb"; + public CompletableFuture getName() { + return CompletableFuture.completedFuture("Test Switch Name"); } @Override @@ -26,18 +26,23 @@ public void identify() { } @Override - public String getSerialNumber() { - return "none"; + public CompletableFuture getSerialNumber() { + return CompletableFuture.completedFuture("Test SwitchSN"); + } + + @Override + public CompletableFuture getModel() { + return CompletableFuture.completedFuture("TestSwitch Model"); } @Override - public String getModel() { - return "none"; + public CompletableFuture getManufacturer() { + return CompletableFuture.completedFuture("Test SwitchManufacturer"); } @Override - public String getManufacturer() { - return "none"; + public CompletableFuture getFirmwareRevision() { + return CompletableFuture.completedFuture("Test Switch Firmware"); } @Override @@ -67,4 +72,8 @@ public void unsubscribeLightbulbPowerState() { this.subscribeCallback = null; } + @Override + public CompletableFuture getHardwareRevision() { + return CompletableFuture.completedFuture("Test Switch Hardware"); + } } diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml new file mode 100644 index 000000000..83266680b --- /dev/null +++ b/src/main/resources/log4j2.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 0e383f4ac..dc8dfec8a 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -21,7 +21,7 @@ - + diff --git a/src/main/resources/simplelogger.properties b/src/main/resources/simplelogger.properties new file mode 100644 index 000000000..5c89a5a26 --- /dev/null +++ b/src/main/resources/simplelogger.properties @@ -0,0 +1 @@ +org.slf4j.simpleLogger.defaultLogLevel=DEBUG \ No newline at end of file