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

@ -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;