From b7c7913c924fe28ca1ac31920cae6be15cf731b9 Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Fri, 22 Nov 2019 21:05:55 +0100 Subject: [PATCH] Moved main class into a test class --- Hal.iml | 1 + .../hal/plugin/zwave/HalZWaveController.java | 25 +++++++-------- .../plugin/zwave/HalZWaveControllerTest.java | 32 +++++++++++++++++++ 3 files changed, 45 insertions(+), 13 deletions(-) create mode 100644 plugins/hal-zwave/test/se/hal/plugin/zwave/HalZWaveControllerTest.java diff --git a/Hal.iml b/Hal.iml index 0dab5dab..0a3e95e6 100755 --- a/Hal.iml +++ b/Hal.iml @@ -11,6 +11,7 @@ + diff --git a/plugins/hal-zwave/src/se/hal/plugin/zwave/HalZWaveController.java b/plugins/hal-zwave/src/se/hal/plugin/zwave/HalZWaveController.java index fb3e5d86..c868b533 100644 --- a/plugins/hal-zwave/src/se/hal/plugin/zwave/HalZWaveController.java +++ b/plugins/hal-zwave/src/se/hal/plugin/zwave/HalZWaveController.java @@ -32,20 +32,11 @@ public class HalZWaveController implements HalSensorController, HalEventControll private List registeredDevices; - public static void main(String[] args) throws IOException { - LogUtil.setGlobalFormatter(new CompactLogFormatter()); - HalZWaveController controller = new HalZWaveController(); - controller.initialize( - "/dev/serial/by-id/usb-0658_0200-if00", - "./"); - - System.in.read(); - } - public HalZWaveController() { NativeLibraryLoader.loadLibrary(ZWave4j.LIBRARY_NAME, ZWave4j.class); } + @Override public boolean isAvailable() { return HalContext.getStringProperty(CONFIG_ZWAVE_PORT) != null && @@ -72,13 +63,18 @@ public class HalZWaveController implements HalSensorController, HalEventControll @Override public void close() { + logger.info("Shutting down OpenZWave Manager..."); manager.removeWatcher(this, null); manager.removeDriver(serialPort); - manager.destroy(); + Manager.destroy(); Options.destroy(); } + // -------------------------- + // OpenZWave Overrides + // -------------------------- + @Override public void onNotification(Notification notification, Object context) { switch (notification.getType()) { @@ -100,8 +96,9 @@ public class HalZWaveController implements HalSensorController, HalEventControll case ALL_NODES_QUERIED: logger.info("All nodes queried"); manager.writeConfig(homeId); - // Controller is done initializing + logger.info(" Controller is done initializing"); break; + case POLLING_ENABLED: System.out.println("Polling enabled"); break; @@ -309,7 +306,9 @@ public class HalZWaveController implements HalSensorController, HalEventControll } } - + // -------------------------- + // Hal Overrides + // -------------------------- @Override public void register(HalEventConfig event) { diff --git a/plugins/hal-zwave/test/se/hal/plugin/zwave/HalZWaveControllerTest.java b/plugins/hal-zwave/test/se/hal/plugin/zwave/HalZWaveControllerTest.java new file mode 100644 index 00000000..bf0ee157 --- /dev/null +++ b/plugins/hal-zwave/test/se/hal/plugin/zwave/HalZWaveControllerTest.java @@ -0,0 +1,32 @@ +package se.hal.plugin.zwave; + +import org.zwave4j.*; +import se.hal.HalContext; +import se.hal.intf.*; +import se.hal.struct.AbstractDevice; +import zutil.log.CompactLogFormatter; +import zutil.log.LogUtil; + +import java.io.IOException; +import java.util.List; +import java.util.concurrent.atomic.AtomicReference; +import java.util.logging.Logger; + +/** + * @author zagumennikov + */ +public class HalZWaveControllerTest { + + public static void main(String[] args) throws IOException { + LogUtil.setGlobalFormatter(new CompactLogFormatter()); + HalZWaveController controller = new HalZWaveController(); + controller.initialize( + "/dev/serial/by-id/usb-0658_0200-if00", + "./"); + + System.out.println("Press ENTER to exit application."); + System.in.read(); + + controller.close(); + } +}