Added hal prefix to all config properties

This commit is contained in:
Ziver Koc 2021-07-19 18:06:00 +02:00
parent 4dfa80c17f
commit 203bb67f7f
12 changed files with 123 additions and 62 deletions

View file

@ -1,10 +1,7 @@
package se.hal;
import se.hal.struct.User;
import zutil.ObjectUtil;
import zutil.db.DBConnection;
import zutil.db.DBUpgradeHandler;
import zutil.db.SQLResultHandler;
import zutil.db.handler.PropertiesSQLResult;
import zutil.io.file.FileUtil;
import zutil.log.LogUtil;
@ -12,12 +9,11 @@ import zutil.log.LogUtil;
import java.io.File;
import java.io.FileReader;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -25,8 +21,8 @@ public class HalContext {
private static final Logger logger = LogUtil.getLogger();
// Constants
public static final String PROPERTY_HTTP_PORT = "hal.http_port";
public static final String PROPERTY_MAP_BACKGROUND_IMAGE = "hal.map_bgimage";
public static final String CONFIG_HTTP_PORT = "hal_core.http_port";
public static final String CONFIG_MAP_BACKGROUND_IMAGE = "hal_core.map_bgimage";
public static final String RESOURCE_ROOT;
static {
@ -53,7 +49,7 @@ public class HalContext {
static {
// Set default values to get Hal up and running
fileConf.setProperty(PROPERTY_HTTP_PORT, "" + 8080);
fileConf.setProperty(CONFIG_HTTP_PORT, "" + 8080);
}
@ -141,12 +137,16 @@ public class HalContext {
return getBooleanProperty(key);
}
public static void setProperty(String key, String value) throws SQLException {
PreparedStatement stmt = db.getPreparedStatement("REPLACE INTO conf (key, value) VALUES (?, ?)");
stmt.setObject(1, key);
stmt.setObject(2, value);
DBConnection.exec(stmt);
dbConf.setProperty(key, value);
public static void setProperty(String key, String value) {
try {
PreparedStatement stmt = db.getPreparedStatement("REPLACE INTO conf (key, value) VALUES (?, ?)");
stmt.setObject(1, key);
stmt.setObject(2, value);
DBConnection.exec(stmt);
dbConf.setProperty(key, value);
} catch (SQLException e) {
logger.log(Level.SEVERE, "Was unable to save property: " + key + " = " + value, e);
}
}

View file

@ -52,7 +52,7 @@ public class HalServer {
// init variables
pluginManager = new PluginManager();
daemonExecutor = Executors.newScheduledThreadPool(1); // We set only one thread for easier troubleshooting
http = new HttpServer(HalContext.getIntegerProperty(HalContext.PROPERTY_HTTP_PORT));
http = new HttpServer(HalContext.getIntegerProperty(HalContext.CONFIG_HTTP_PORT));
// Upgrade database
HalDatabaseUpgradeManager.initialize(pluginManager);

View file

@ -77,7 +77,7 @@ public class MapWebPage extends HalWebPage {
private void loadBgImage() {
String property = HalContext.getStringProperty(HalContext.PROPERTY_MAP_BACKGROUND_IMAGE);
String property = HalContext.getStringProperty(HalContext.CONFIG_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(HalContext.PROPERTY_MAP_BACKGROUND_IMAGE, type + "," + Base64Encoder.encode(data));
HalContext.setProperty(HalContext.CONFIG_MAP_BACKGROUND_IMAGE, type + "," + Base64Encoder.encode(data));
}
}

View file

@ -2,7 +2,7 @@
# Core settings
# ------------------------------------
hal.http_port=8080
hal_core.http_port=8080
# ------------------------------------------------------------------------
# Plugin configurations
@ -13,31 +13,31 @@ hal.http_port=8080
# ------------------------------------
## Tellstick plugin
#tellstick.com_port=COM5
#tellstick.com_port=/dev/serial/by-id/usb-Telldus_TellStick_Duo_A6XNNE6Z-if00-port0
#hal_tellstick.com_port=COM5
#hal_tellstick.com_port=/dev/serial/by-id/usb-Telldus_TellStick_Duo_A6XNNE6Z-if00-port0
## NetUPS plugin
#nutups.host=
#nutups.port=
#hal_nutups.host=
#hal_nutups.port=
## NetScan plugin
# Network scanning should probably be disabled in some networks (default on)
#netscan.ipscan=false
#hal_netscan.ipscan=false
## Zigbee plugin
#zigbee.com_port=COM4
#zigbee.dongle=CC2531|CONBEE|XBEE
#hal_zigbee.com_port=COM4
#hal_zigbee.dongle=CC2531|CONBEE|XBEE
## ZWave plugin
#zwave.com_port=COM4
#hal_zwave.com_port=COM4
## Power Challenge Plugin
powerchallenge.sync_port=6666
hal_powerchallenge.sync_port=6666
# ------------------------------------
# Assistants
# ------------------------------------
## Google Assistant
assistant.google.port=8081
assistant.google.client_id=https://oauth-redirect.googleusercontent.com/r/optimal-comfort-XXXXX
hal_assistant.google.port=8081
hal_assistant.google.client_id=https://oauth-redirect.googleusercontent.com/r/optimal-comfort-XXXXX

View file

@ -43,8 +43,8 @@ public class SmartHomeDaemon implements HalDaemon {
public static final String ENDPOINT_TOKEN = "api/assistant/google/auth/token";
public static final String ENDPOINT_SMARTHOME = "api/assistant/google/smarthome";
private static final String PARAM_PORT = "assistant.google.port";
private static final String PARAM_CLIENT_ID = "assistant.google.client_id";
private static final String CONFIG_PORT = "hal_assistant.google.port";
private static final String CONFIG_CLIENT_ID = "hal_assistant.google.client_id";
private SmartHomeImpl smartHome;
private OAuth2Registry oAuth2Registry;
@ -53,8 +53,8 @@ public class SmartHomeDaemon implements HalDaemon {
@Override
public void initiate(ScheduledExecutorService executor) {
if (smartHome == null) {
if (!HalContext.containsProperty(PARAM_PORT) ||
!HalContext.containsProperty(PARAM_CLIENT_ID)) {
if (!HalContext.containsProperty(CONFIG_PORT) ||
!HalContext.containsProperty(CONFIG_CLIENT_ID)) {
logger.severe("Missing configuration, abort initializations.");
return;
}
@ -62,10 +62,10 @@ public class SmartHomeDaemon implements HalDaemon {
smartHome = new SmartHomeImpl();
oAuth2Registry = new OAuth2Registry();
oAuth2Registry.addWhitelist(HalContext.getStringProperty(PARAM_CLIENT_ID));
oAuth2Registry.addWhitelist(HalContext.getStringProperty(CONFIG_CLIENT_ID));
oAuth2Registry.setTokenListener(smartHome);
httpServer = new HttpServer(HalContext.getIntegerProperty(PARAM_PORT));
httpServer = new HttpServer(HalContext.getIntegerProperty(CONFIG_PORT));
httpServer.setPage(ENDPOINT_AUTH, new OAuth2AuthorizationPage(oAuth2Registry));
httpServer.setPage(ENDPOINT_TOKEN, new OAuth2TokenPage(oAuth2Registry));
httpServer.setPage(ENDPOINT_SMARTHOME, new SmartHomePage(smartHome));

View file

@ -70,8 +70,8 @@ public class NutUpsController implements HalSensorController, HalAutostartContro
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";
public static final String CONFIG_HOST = "hal_nutups.host";
public static final String CONFIG_PORT = "hal_nutups.port";
private HashMap<String, NutUpsDevice> registeredDevices = new HashMap<>();
private NutUPSClient client;
@ -82,16 +82,16 @@ public class NutUpsController implements HalSensorController, HalAutostartContro
@Override
public boolean isAvailable() {
return HalContext.containsProperty(PROPERTY_HOST);
return HalContext.containsProperty(CONFIG_HOST);
}
@Override
public void initialize() throws Exception {
if (client == null) {
int port = NutUPSClient.DEFAULT_PORT;
if (HalContext.containsProperty(PROPERTY_PORT))
port = HalContext.getIntegerProperty(PROPERTY_PORT);
if (HalContext.containsProperty(CONFIG_PORT))
port = HalContext.getIntegerProperty(CONFIG_PORT);
client = new NutUPSClient(HalContext.getStringProperty(PROPERTY_HOST), port);
client = new NutUPSClient(HalContext.getStringProperty(CONFIG_HOST), port);
executor = Executors.newScheduledThreadPool(1);
executor.scheduleAtFixedRate(this, 5000, SYNC_INTERVAL, TimeUnit.MILLISECONDS);

View file

@ -54,7 +54,7 @@ import java.util.logging.Logger;
public class PCDataSynchronizationDaemon extends ThreadedTCPNetworkServer implements HalDaemon {
private static final Logger logger = LogUtil.getLogger();
public static final String PROPERTY_SYNC_PORT = "powerchallenge.sync_port";
public static final String PROPERTY_SYNC_PORT = "hal_powerchallenge.sync_port";
public static final int PROTOCOL_VERSION = 5; // Increment for protocol changes

View file

@ -50,7 +50,7 @@ public class TellstickSerialComm implements Runnable,
HalSensorController, HalEventController, HalAutostartController {
private static final Logger logger = LogUtil.getLogger();
private static String CONFIG_TELLSTICK_COM_PORT = "tellstick.com_port";
private static String CONFIG_TELLSTICK_COM_PORT = "hal_tellstick.com_port";
private static final long TRANSMISSION_UNIQUENESS_TTL = 1000; // milliseconds
private static TellstickSerialComm instance; // Todo: Don't like this but it is the best I could come up with

View file

@ -1,5 +1,35 @@
<h1 class="page-header">Zigbee Node Overview</h1>
<h2>Network info</h2>
<div class="row">
<div class="col-md-6">
<div class="panel panel-default drop-shadow">
<div class="panel-heading">Node Description</div>
<div class="panel-body">
<table class="table table-hover table-condensed">
<thead>
<tr>
<th class="text-right">PAN ID:</th>
<td>{{controller.getZigbeePanId()}}</td>
</tr>
<tr>
<th class="text-right">Extended PAN ID:</th>
<td>{{controller.getZigbeeExtendedPanId()}}</td>
</tr>
</thead>
<tr>
<th class="text-right">Channel:</th>
<td>{{controller.getZigbeeChannel()}}</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<h2>Connected Nodes</h2>
{{#nodes}}
<div class="col-md-12">
<div class="panel panel-default drop-shadow">

View file

@ -51,8 +51,13 @@ public class ZigbeeController implements HalSensorController,
public static final String ZIGBEE_DONGLE_CONBEE = "CONBEE";
public static final String ZIGBEE_DONGLE_XBEE = "XBEE";
private static final String CONFIG_ZIGBEE_PORT = "zigbee.com_port";
private static final String CONFIG_ZIGBEE_DONGLE = "zigbee.dongle";
private static final String CONFIG_ZIGBEE_DONGLE = "hal_zigbee.dongle";
private static final String CONFIG_ZIGBEE_PORT = "hal_zigbee.com_port";
private static final String CONFIG_ZIGBEE_NETWORK_CHANNEL = "hal_zigbee.network.channel";
private static final String CONFIG_ZIGBEE_NETWORK_PANID = "hal_zigbee.network.panid";
private static final String CONFIG_ZIGBEE_NETWORK_EPANID = "hal_zigbee.network.epanid";
private static final String CONFIG_ZIGBEE_NETWORK_NWKKEY = "hal_zigbee.network.nwkey";
private static final String CONFIG_ZIGBEE_NETWORK_LINKKEY = "hal_zigbee.network.linkkey";
private ZigBeePort serialPort;
protected ZigBeeNetworkManager networkManager;
@ -140,16 +145,28 @@ public class ZigbeeController implements HalSensorController,
networkManager.addSupportedServerCluster(ZclWindowCoveringCluster.CLUSTER_ID);
networkManager.addSupportedServerCluster(ZclBinaryInputBasicCluster.CLUSTER_ID);
// Prepare defaults
if (!HalContext.containsProperty(CONFIG_ZIGBEE_NETWORK_CHANNEL))
HalContext.setProperty(CONFIG_ZIGBEE_NETWORK_CHANNEL, "11");
if (!HalContext.containsProperty(CONFIG_ZIGBEE_NETWORK_PANID))
HalContext.setProperty(CONFIG_ZIGBEE_NETWORK_PANID, "" + (int) Math.floor((Math.random() * 65534)));
if (!HalContext.containsProperty(CONFIG_ZIGBEE_NETWORK_EPANID))
HalContext.setProperty(CONFIG_ZIGBEE_NETWORK_EPANID, "" + ExtendedPanId.createRandom());
if (!HalContext.containsProperty(CONFIG_ZIGBEE_NETWORK_NWKKEY))
HalContext.setProperty(CONFIG_ZIGBEE_NETWORK_NWKKEY, "" + ZigBeeKey.createRandom());
if (!HalContext.containsProperty(CONFIG_ZIGBEE_NETWORK_LINKKEY))
HalContext.setProperty(CONFIG_ZIGBEE_NETWORK_LINKKEY, "" + new ZigBeeKey(new int[] {
0x5A, 0x69, 0x67, 0x42, 0x65, 0x65, 0x41, 0x6C, 0x6C, 0x69, 0x61, 0x6E, 0x63, 0x65, 0x30, 0x39 })); // Add the default ZigBeeAlliance09 HA link key
// Configure network
networkManager.setZigBeeChannel(ZigBeeChannel.create(HalContext.getIntegerProperty(CONFIG_ZIGBEE_NETWORK_CHANNEL, 11)));
networkManager.setZigBeePanId(HalContext.getIntegerProperty(CONFIG_ZIGBEE_NETWORK_PANID));
networkManager.setZigBeeExtendedPanId(new ExtendedPanId(HalContext.getStringProperty(CONFIG_ZIGBEE_NETWORK_EPANID)));
networkManager.setZigBeeNetworkKey(new ZigBeeKey(HalContext.getStringProperty(CONFIG_ZIGBEE_NETWORK_NWKKEY)));
networkManager.setZigBeeLinkKey(new ZigBeeKey(HalContext.getStringProperty(CONFIG_ZIGBEE_NETWORK_LINKKEY)));
networkManager.setDefaultProfileId(ZigBeeProfileType.ZIGBEE_HOME_AUTOMATION.getKey());
networkManager.setZigBeeNetworkKey(ZigBeeKey.createRandom());//new ZigBeeKey("552FAAF9B5F49E75F1ADDA12215C2CA1")); // ZigBeeKey.createRandom();
networkManager.setZigBeeLinkKey(new ZigBeeKey(new int[] { // Add the default ZigBeeAlliance09 HA link key
0x5A, 0x69, 0x67, 0x42, 0x65, 0x65, 0x41, 0x6C, 0x6C, 0x69, 0x61, 0x6E, 0x63, 0x65, 0x30, 0x39 }));
networkManager.setZigBeeChannel(ZigBeeChannel.create(11));
networkManager.setZigBeePanId(65534); // (int) Math.floor((Math.random() * 65534));
networkManager.setZigBeeExtendedPanId(new ExtendedPanId("00124B001CCE1B5F")); // ExtendedPanId.createRandom();
//transportOptions.addOption(TransportConfigOption.TRUST_CENTRE_JOIN_MODE, TrustCentreJoinMode.TC_JOIN_INSECURE); // TC_JOIN_SECURE
dongle.updateTransportConfig(transportOptions);
@ -186,6 +203,24 @@ public class ZigbeeController implements HalSensorController,
serialPort.close();
}
// ------------------------------------------
// Getters
// ------------------------------------------
public ZigBeeChannel getZigbeeChannel() {
return networkManager.getZigBeeChannel();
}
public int getZigbeePanId() {
return networkManager.getZigBeePanId();
}
public ExtendedPanId getZigbeeExtendedPanId() {
return networkManager.getZigBeeExtendedPanId();
}
public Set<ZigBeeNode> getNodes() {
return networkManager.getNodes();
}
// ------------------------------------------
// Zigbee Node Methods
// ------------------------------------------
@ -237,10 +272,6 @@ public class ZigbeeController implements HalSensorController,
logger.fine("[Node: " + node.getIeeeAddress() + "]: Node registration has been removed.");
}
public Set<ZigBeeNode> getNodes() {
return networkManager.getNodes();
}
// ------------------------------------------
// Zigbee Endpoint Methods
// ------------------------------------------

View file

@ -42,15 +42,15 @@ public abstract class ZigbeeHalEventDeviceConfig extends ZigbeeHalDeviceConfig {
(CommandResult) ZclCluster.class.getMethod("sendCommand", ZclCommand.class).invoke(command);
if (result.isError() || result.isTimeout()) {
logger.warning("[Endpoint: " + cluster.getZigBeeAddress() + "] Command failed with error: " + result.isError() + " (timeout=" + result.isTimeout() + ")");
logger.warning("[Node: " + getZigbeeNodeAddress() + ", Endpoint: " + cluster.getZigBeeAddress() + "] Command failed with error: " + result.isError() + " (timeout=" + result.isTimeout() + ")");
} else {
logger.info("[Endpoint: " + cluster.getZigBeeAddress() + "] Command has been successfully sent");
logger.info("[Node: " + getZigbeeNodeAddress() + ", Endpoint: " + cluster.getZigBeeAddress() + "] Command has been successfully sent.");
}
} catch (Exception e) {
logger.warning("[Endpoint: " + cluster.getZigBeeAddress() + "] Failed to send command [" + e.getMessage() + "]");
logger.warning("[Node: " + getZigbeeNodeAddress() + ", Endpoint: " + cluster.getZigBeeAddress() + "] Failed to send command: " + e.getMessage());
}
} else {
logger.warning("[Node: " + getZigbeeNodeAddress() + "] Unable to find cluster.");
logger.warning("[Node: " + getZigbeeNodeAddress() + "] Unable to find cluster: " + getZigbeeClusterId());
}
}

View file

@ -19,8 +19,8 @@ import java.util.logging.Logger;
public class HalZWaveController implements HalSensorController, HalEventController, HalAutostartController, NotificationWatcher {
private static final Logger logger = LogUtil.getLogger();
public static final String CONFIG_ZWAVE_PORT = "zwave.com_port";
public static final String CONFIG_ZWAVE_CFG_PATH = "zwave.cfg_path";
public static final String CONFIG_ZWAVE_PORT = "hal_zwave.com_port";
public static final String CONFIG_ZWAVE_CFG_PATH = "hal_zwave.cfg_path";
private String serialPort;
private long homeId;