From 12a6c1d31ba95ed2c658f0025e5554a612024ab1 Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Fri, 24 Jul 2020 00:39:11 +0200 Subject: [PATCH] Cleanedup property names --- .../src/se/hal/plugin/nutups/NutUpsController.java | 12 ++++++++---- .../se/hal/plugin/tellstick/TellstickSerialComm.java | 2 +- .../src/se/hal/plugin/zwave/HalZWaveController.java | 4 ++-- src/se/hal/HalContext.java | 1 + src/se/hal/page/MapWebPage.java | 4 ++-- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/plugins/hal-nutups/src/se/hal/plugin/nutups/NutUpsController.java b/plugins/hal-nutups/src/se/hal/plugin/nutups/NutUpsController.java index 4186e649..126fc6c8 100644 --- a/plugins/hal-nutups/src/se/hal/plugin/nutups/NutUpsController.java +++ b/plugins/hal-nutups/src/se/hal/plugin/nutups/NutUpsController.java @@ -65,7 +65,10 @@ import java.util.logging.Logger; public class NutUpsController implements HalSensorController, HalAutoScannableController, Runnable{ public static Logger logger = LogUtil.getLogger(); + private static final int SYNC_INTERVAL = 60 * 1000; + public static final String PROPERTY_HOST = "nutups.host"; + public static final String PROPERTY_PORT = "nutups.port"; private HashMap registeredDevices = new HashMap<>(); private NutUPSClient client; @@ -76,15 +79,16 @@ public class NutUpsController implements HalSensorController, HalAutoScannableCo @Override public boolean isAvailable() { - return HalContext.getStringProperty("nutups.host") != null; + return HalContext.containsProperty(PROPERTY_HOST); } @Override public void initialize() throws Exception { if (client == null) { int port = NutUPSClient.DEFAULT_PORT; - if (HalContext.getStringProperty("nutups.port") != null) - port = Integer.parseInt(HalContext.getStringProperty("nutups.port")); - client = new NutUPSClient(HalContext.getStringProperty("nutups.host"), port); + if (HalContext.containsProperty(PROPERTY_PORT)) + port = HalContext.getIntegerProperty(PROPERTY_PORT); + + client = new NutUPSClient(HalContext.getStringProperty(PROPERTY_HOST), port); executor = Executors.newScheduledThreadPool(1); executor.scheduleAtFixedRate(this, 5000, SYNC_INTERVAL, TimeUnit.MILLISECONDS); diff --git a/plugins/hal-tellstick/src/se/hal/plugin/tellstick/TellstickSerialComm.java b/plugins/hal-tellstick/src/se/hal/plugin/tellstick/TellstickSerialComm.java index cb1a8279..f0605b82 100644 --- a/plugins/hal-tellstick/src/se/hal/plugin/tellstick/TellstickSerialComm.java +++ b/plugins/hal-tellstick/src/se/hal/plugin/tellstick/TellstickSerialComm.java @@ -78,7 +78,7 @@ public class TellstickSerialComm implements Runnable, @Override public boolean isAvailable() { - return HalContext.getStringProperty(CONFIG_TELLSTICK_COM_PORT) != null; + return HalContext.containsProperty(CONFIG_TELLSTICK_COM_PORT); } @Override public void initialize() throws Exception { 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 38109f26..d9cc1f8f 100644 --- a/plugins/hal-zwave/src/se/hal/plugin/zwave/HalZWaveController.java +++ b/plugins/hal-zwave/src/se/hal/plugin/zwave/HalZWaveController.java @@ -42,8 +42,8 @@ public class HalZWaveController implements HalSensorController, HalEventControll @Override public boolean isAvailable() { - return HalContext.getStringProperty(CONFIG_ZWAVE_PORT) != null && - HalContext.getStringProperty(CONFIG_ZWAVE_CFG_PATH) != null; + return HalContext.containsProperty(CONFIG_ZWAVE_PORT) && + HalContext.containsProperty(CONFIG_ZWAVE_CFG_PATH); } @Override public void initialize() { diff --git a/src/se/hal/HalContext.java b/src/se/hal/HalContext.java index 66bb5959..85aa74b2 100755 --- a/src/se/hal/HalContext.java +++ b/src/se/hal/HalContext.java @@ -22,6 +22,7 @@ public class HalContext { // Constants public static final String PROPERTY_DB_VERSION = "hal.db_version"; public static final String PROPERTY_HTTP_PORT = "hal.http_port"; + public static final String PROPERTY_MAP_BACKGROUND_IMAGE = "hal.map_bgimage"; private static final String CONF_FILE = "hal.conf"; private static final String DB_FILE = "hal.db"; diff --git a/src/se/hal/page/MapWebPage.java b/src/se/hal/page/MapWebPage.java index 266a7979..523b4877 100644 --- a/src/se/hal/page/MapWebPage.java +++ b/src/se/hal/page/MapWebPage.java @@ -77,7 +77,7 @@ public class MapWebPage extends HalWebPage { private void loadBgImage() { - String property = HalContext.getStringProperty("map_bgimage"); + String property = HalContext.getStringProperty(HalContext.PROPERTY_MAP_BACKGROUND_IMAGE); if (property != null) { String[] split = property.split(",", 2); bgType = split[0]; @@ -86,6 +86,6 @@ public class MapWebPage extends HalWebPage { } private void saveBgImage(String type, byte[] data) throws SQLException { - HalContext.setProperty("map_bgimage", type + "," + Base64Encoder.encode(data)); + HalContext.setProperty(HalContext.PROPERTY_MAP_BACKGROUND_IMAGE, type + "," + Base64Encoder.encode(data)); } }