Cleanup of property names
This commit is contained in:
parent
467a5ff068
commit
c3731ca4b4
5 changed files with 43 additions and 29 deletions
BIN
hal-default.db
BIN
hal-default.db
Binary file not shown.
|
|
@ -1,8 +1,13 @@
|
||||||
### Core settings
|
# ------------------------------------
|
||||||
http_port=8080
|
# Core settings
|
||||||
sync_port=6666
|
# ------------------------------------
|
||||||
|
|
||||||
|
hal.http_port=8080
|
||||||
|
|
||||||
|
# ------------------------------------
|
||||||
|
# Plugin configurations
|
||||||
|
# ------------------------------------
|
||||||
|
|
||||||
### Plugin configurations
|
|
||||||
## Tellstick plugin
|
## Tellstick plugin
|
||||||
#tellstick.com_port=COM5
|
#tellstick.com_port=COM5
|
||||||
#tellstick.com_port=/dev/serial/by-id/usb-Telldus_TellStick_Duo_A6XNNE6Z-if00-port0
|
#tellstick.com_port=/dev/serial/by-id/usb-Telldus_TellStick_Duo_A6XNNE6Z-if00-port0
|
||||||
|
|
@ -17,3 +22,6 @@ sync_port=6666
|
||||||
|
|
||||||
## ZWave plugin
|
## ZWave plugin
|
||||||
#zwave.com_port=COM4
|
#zwave.com_port=COM4
|
||||||
|
|
||||||
|
## Power Challenge Plugin
|
||||||
|
powerchallenge.sync_port=6666
|
||||||
|
|
@ -53,11 +53,13 @@ import java.util.logging.Logger;
|
||||||
|
|
||||||
public class PCDataSynchronizationDaemon extends ThreadedTCPNetworkServer implements HalDaemon {
|
public class PCDataSynchronizationDaemon extends ThreadedTCPNetworkServer implements HalDaemon {
|
||||||
private static final Logger logger = LogUtil.getLogger();
|
private static final Logger logger = LogUtil.getLogger();
|
||||||
|
|
||||||
|
public static final String PROPERTY_SYNC_PORT = "powerchallenge.sync_port";
|
||||||
public static final int PROTOCOL_VERSION = 5; // Increment for protocol changes
|
public static final int PROTOCOL_VERSION = 5; // Increment for protocol changes
|
||||||
|
|
||||||
|
|
||||||
public PCDataSynchronizationDaemon() {
|
public PCDataSynchronizationDaemon() {
|
||||||
super(HalContext.getIntegerProperty("sync_port"));
|
super(HalContext.getIntegerProperty(PROPERTY_SYNC_PORT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package se.hal;
|
package se.hal;
|
||||||
|
|
||||||
import se.hal.struct.User;
|
import se.hal.struct.User;
|
||||||
|
import zutil.ObjectUtil;
|
||||||
import zutil.db.DBConnection;
|
import zutil.db.DBConnection;
|
||||||
import zutil.db.DBUpgradeHandler;
|
import zutil.db.DBUpgradeHandler;
|
||||||
import zutil.db.SQLResultHandler;
|
import zutil.db.SQLResultHandler;
|
||||||
|
|
@ -14,11 +15,13 @@ import java.sql.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
|
||||||
public class HalContext {
|
public class HalContext {
|
||||||
private static final Logger logger = LogUtil.getLogger();
|
private static final Logger logger = LogUtil.getLogger();
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
private static final String PROPERTY_DB_VERSION = "db_version";
|
public static final String PROPERTY_DB_VERSION = "hal.db_version";
|
||||||
|
public static final String PROPERTY_HTTP_PORT = "hal.http_port";
|
||||||
|
|
||||||
private static final String CONF_FILE = "hal.conf";
|
private static final String CONF_FILE = "hal.conf";
|
||||||
private static final String DB_FILE = "hal.db";
|
private static final String DB_FILE = "hal.db";
|
||||||
|
|
@ -27,28 +30,27 @@ public class HalContext {
|
||||||
// Variables
|
// Variables
|
||||||
private static DBConnection db; // TODO: Should probably be a db pool as we have multiple threads accessing the DB
|
private static DBConnection db; // TODO: Should probably be a db pool as we have multiple threads accessing the DB
|
||||||
|
|
||||||
private static Properties defaultFileConf;
|
private static HashMap<String,String> registeredConf = new HashMap<>();
|
||||||
private static Properties fileConf;
|
private static Properties fileConf = new Properties();
|
||||||
private static Properties dbConf;
|
private static Properties dbConf = new Properties();;
|
||||||
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
defaultFileConf = new Properties();
|
// Set default values to get Hal up and running
|
||||||
defaultFileConf.setProperty("http_port", ""+8080);
|
fileConf.setProperty(PROPERTY_HTTP_PORT, "" + 8080);
|
||||||
defaultFileConf.setProperty("sync_port", ""+6666);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void initialize(){
|
public static void initialize(){
|
||||||
try {
|
try {
|
||||||
// Read conf
|
// Read conf
|
||||||
fileConf = new Properties(defaultFileConf);
|
|
||||||
if (FileUtil.find(CONF_FILE) != null) {
|
if (FileUtil.find(CONF_FILE) != null) {
|
||||||
FileReader in = new FileReader(CONF_FILE);
|
FileReader in = new FileReader(CONF_FILE);
|
||||||
fileConf.load(in);
|
fileConf.load(in);
|
||||||
in.close();
|
in.close();
|
||||||
|
} else {
|
||||||
|
logger.info("No hal.conf file found");
|
||||||
}
|
}
|
||||||
else logger.info("No hal.conf file found");
|
|
||||||
|
|
||||||
if (FileUtil.find(DEFAULT_DB_FILE) == null){
|
if (FileUtil.find(DEFAULT_DB_FILE) == null){
|
||||||
logger.severe("Unable to find default DB: " + DEFAULT_DB_FILE);
|
logger.severe("Unable to find default DB: " + DEFAULT_DB_FILE);
|
||||||
|
|
@ -58,11 +60,10 @@ public class HalContext {
|
||||||
// Init DB
|
// Init DB
|
||||||
File dbFile = FileUtil.find(DB_FILE);
|
File dbFile = FileUtil.find(DB_FILE);
|
||||||
db = new DBConnection(DBConnection.DBMS.SQLite, DB_FILE);
|
db = new DBConnection(DBConnection.DBMS.SQLite, DB_FILE);
|
||||||
|
|
||||||
if(dbFile == null){
|
if(dbFile == null){
|
||||||
logger.info("No database file found, creating new DB...");
|
logger.info("No database file found, creating new DB...");
|
||||||
dbConf = new Properties();
|
} else {
|
||||||
}
|
|
||||||
else{
|
|
||||||
dbConf = db.exec("SELECT * FROM conf", new PropertiesSQLResult());
|
dbConf = db.exec("SELECT * FROM conf", new PropertiesSQLResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -70,6 +71,7 @@ public class HalContext {
|
||||||
DBConnection referenceDB = new DBConnection(DBConnection.DBMS.SQLite, DEFAULT_DB_FILE);
|
DBConnection referenceDB = new DBConnection(DBConnection.DBMS.SQLite, DEFAULT_DB_FILE);
|
||||||
Properties defaultDBConf =
|
Properties defaultDBConf =
|
||||||
referenceDB.exec("SELECT * FROM conf", new PropertiesSQLResult());
|
referenceDB.exec("SELECT * FROM conf", new PropertiesSQLResult());
|
||||||
|
|
||||||
// Check DB version
|
// Check DB version
|
||||||
final int defaultDBVersion = Integer.parseInt(defaultDBConf.getProperty(PROPERTY_DB_VERSION));
|
final int defaultDBVersion = Integer.parseInt(defaultDBConf.getProperty(PROPERTY_DB_VERSION));
|
||||||
final int dbVersion = (dbConf.getProperty(PROPERTY_DB_VERSION) != null ?
|
final int dbVersion = (dbConf.getProperty(PROPERTY_DB_VERSION) != null ?
|
||||||
|
|
@ -93,7 +95,7 @@ public class HalContext {
|
||||||
|
|
||||||
logger.fine("Performing pre-upgrade activities");
|
logger.fine("Performing pre-upgrade activities");
|
||||||
|
|
||||||
//read upgrade path preferences from the reference database
|
// Read upgrade path preferences from the reference database
|
||||||
referenceDB.exec("SELECT * FROM db_version_history"
|
referenceDB.exec("SELECT * FROM db_version_history"
|
||||||
+ " WHERE db_version <= " + defaultDBVersion
|
+ " WHERE db_version <= " + defaultDBVersion
|
||||||
+ " AND db_version > " + dbVersion,
|
+ " AND db_version > " + dbVersion,
|
||||||
|
|
@ -114,7 +116,7 @@ public class HalContext {
|
||||||
|
|
||||||
logger.fine("Performing post-upgrade activities");
|
logger.fine("Performing post-upgrade activities");
|
||||||
|
|
||||||
//read upgrade path preferences from the reference database
|
// Read upgrade path preferences from the reference database
|
||||||
referenceDB.exec("SELECT * FROM db_version_history"
|
referenceDB.exec("SELECT * FROM db_version_history"
|
||||||
+ " WHERE db_version <= " + defaultDBVersion
|
+ " WHERE db_version <= " + defaultDBVersion
|
||||||
+ " AND db_version > " + dbVersion,
|
+ " AND db_version > " + dbVersion,
|
||||||
|
|
@ -123,6 +125,7 @@ public class HalContext {
|
||||||
public Object handleQueryResult(Statement stmt, ResultSet result) throws SQLException {
|
public Object handleQueryResult(Statement stmt, ResultSet result) throws SQLException {
|
||||||
boolean clearExternalAggrData = false;
|
boolean clearExternalAggrData = false;
|
||||||
boolean clearInternalAggrData = false;
|
boolean clearInternalAggrData = false;
|
||||||
|
|
||||||
while(result.next()){
|
while(result.next()){
|
||||||
if(result.getBoolean("clear_external_aggr_data"))
|
if(result.getBoolean("clear_external_aggr_data"))
|
||||||
clearExternalAggrData = true;
|
clearExternalAggrData = true;
|
||||||
|
|
@ -146,11 +149,6 @@ public class HalContext {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (dbVersion < 9) { // tellstick code has changed package
|
|
||||||
db.exec("UPDATE sensor SET type = 'se.hal.plugin.tellstick.device.Oregon0x1A2D' WHERE type = 'se.hal.plugin.tellstick.protocols.Oregon0x1A2D'");
|
|
||||||
db.exec("UPDATE event SET type = 'se.hal.plugin.tellstick.device.NexaSelfLearning' WHERE type = 'se.hal.plugin.tellstick.protocols.NexaSelfLearning'");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Check if there is a local user
|
// Check if there is a local user
|
||||||
User localUser = User.getLocalUser(db);
|
User localUser = User.getLocalUser(db);
|
||||||
|
|
@ -174,16 +172,22 @@ public class HalContext {
|
||||||
|
|
||||||
public static Map<String,String> getProperties() {
|
public static Map<String,String> getProperties() {
|
||||||
HashMap map = new HashMap();
|
HashMap map = new HashMap();
|
||||||
map.putAll(fileConf);
|
map.putAll(registeredConf);
|
||||||
map.putAll(dbConf);
|
map.putAll(dbConf);
|
||||||
|
map.putAll(fileConf);
|
||||||
return map;
|
return map;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public static void registerProperty(String key) {
|
||||||
|
registeredConf.put(key, "");
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean containsProperty(String key) {
|
public static boolean containsProperty(String key) {
|
||||||
return getStringProperty(key) != null;
|
return !ObjectUtil.isEmpty(getStringProperty(key));
|
||||||
}
|
}
|
||||||
public static String getStringProperty(String key){
|
public static String getStringProperty(String key){
|
||||||
|
registerProperty(key);
|
||||||
|
|
||||||
String value = null;
|
String value = null;
|
||||||
if (fileConf != null)
|
if (fileConf != null)
|
||||||
value = fileConf.getProperty(key);
|
value = fileConf.getProperty(key);
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ public class HalServer {
|
||||||
HalWebPage.getRootNav().createSubNav("Events").setWeight(100);
|
HalWebPage.getRootNav().createSubNav("Events").setWeight(100);
|
||||||
HalWebPage.getRootNav().createSubNav("Settings").setWeight(200);
|
HalWebPage.getRootNav().createSubNav("Settings").setWeight(200);
|
||||||
|
|
||||||
http = new HttpServer(HalContext.getIntegerProperty("http_port"));
|
http = new HttpServer(HalContext.getIntegerProperty(HalContext.PROPERTY_HTTP_PORT));
|
||||||
http.setDefaultPage(new HttpFilePage(FileUtil.find("resource/web/")));
|
http.setDefaultPage(new HttpFilePage(FileUtil.find("resource/web/")));
|
||||||
http.setPage("/", new HttpRedirectPage("/map"));
|
http.setPage("/", new HttpRedirectPage("/map"));
|
||||||
http.setPage(HalAlertManager.getInstance().getUrl(), HalAlertManager.getInstance());
|
http.setPage(HalAlertManager.getInstance().getUrl(), HalAlertManager.getInstance());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue