Finished MQTT support and some testing. Updated harmony-java-client to

v1.1.1 to fix authentication error.
This commit is contained in:
Admin
2016-11-18 15:14:58 -06:00
parent 68f38e1d95
commit 08166c0ebf
9 changed files with 49 additions and 46 deletions

View File

@@ -5,7 +5,7 @@
<groupId>com.bwssystems.HABridge</groupId>
<artifactId>ha-bridge</artifactId>
<version>3.2.2d</version>
<version>3.5.0</version>
<packaging>jar</packaging>
<name>HA Bridge</name>
@@ -32,7 +32,7 @@
<dependency>
<groupId>com.github.bwssytems</groupId>
<artifactId>harmony-java-client</artifactId>
<version>1.0.8</version>
<version>1.1.1</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>

View File

@@ -102,8 +102,6 @@ public class BridgeSettings extends BackupHandler {
}
}
theBridgeSettings.setHarmonyAddress(theHarmonyList);
theBridgeSettings.setHarmonyUser(System.getProperty("harmony.user"));
theBridgeSettings.setHarmonyPwd(System.getProperty("harmony.pwd"));
theBridgeSettings.setUpnpStrict(Boolean.parseBoolean(System.getProperty("upnp.strict", "true")));
theBridgeSettings.setTraceupnp(Boolean.parseBoolean(System.getProperty("trace.upnp", "false")));
theBridgeSettings.setButtonsleep(Integer.parseInt(System.getProperty("button.sleep", Configuration.DEFAULT_BUTTON_SLEEP)));

View File

@@ -12,8 +12,6 @@ public class BridgeSettingsDescriptor {
private String upnpdevicedb;
private IpList veraaddress;
private IpList harmonyaddress;
private String harmonyuser;
private String harmonypwd;
private Integer buttonsleep;
private boolean upnpstrict;
private boolean traceupnp;
@@ -95,18 +93,6 @@ public class BridgeSettingsDescriptor {
public void setHarmonyAddress(IpList harmonyaddress) {
this.harmonyaddress = harmonyaddress;
}
public String getHarmonyUser() {
return harmonyuser;
}
public void setHarmonyUser(String harmonyuser) {
this.harmonyuser = harmonyuser;
}
public String getHarmonyPwd() {
return harmonypwd;
}
public void setHarmonyPwd(String harmonypwd) {
this.harmonypwd = harmonypwd;
}
public boolean isUpnpStrict() {
return upnpstrict;
}
@@ -253,10 +239,6 @@ public class BridgeSettingsDescriptor {
List<NamedIP> devicesList = this.getHarmonyAddress().getDevices();
if(devicesList.get(0).getIp().contains(Configuration.DEFAULT_ADDRESS))
return false;
if(this.getHarmonyPwd() == null || this.getHarmonyPwd().equals(""))
return false;
if(this.getHarmonyUser() == null || this.getHarmonyUser().equals(""))
return false;
return true;
}
public Boolean isValidNest() {

View File

@@ -797,11 +797,13 @@ public class HueMulator implements HueErrorStringSet {
else
setCount = 1;
for(int x = 0; x < setCount; x++) {
if( x > 0) {
if( x > 0 || i > 0) {
Thread.sleep(theDelay);
}
if(deviceButtons[i].getDelay() != null &&deviceButtons[i].getDelay() > 0)
if(deviceButtons[i].getDelay() != null && deviceButtons[i].getDelay() > 0)
theDelay = deviceButtons[i].getDelay();
else
theDelay = bridgeSettings.getButtonsleep();
log.debug("pressing button: " + deviceButtons[i].getDevice() + " - " + deviceButtons[i].getButton() + " - iteration: " + String.valueOf(i) + " - count: " + String.valueOf(x));
myHarmony.pressButton(deviceButtons[i]);
}
@@ -883,11 +885,13 @@ public class HueMulator implements HueErrorStringSet {
else
setCount = 1;
for(int x = 0; x < setCount; x++) {
if( x > 0) {
if( x > 0 || i > 0) {
Thread.sleep(theDelay);
}
if(mqttMessages[i].getDelay() != null &&mqttMessages[i].getDelay() > 0)
theDelay = mqttMessages[i].getDelay();
else
theDelay = bridgeSettings.getButtonsleep();
log.debug("publishing message: " + mqttMessages[i].getClientId() + " - " + mqttMessages[i].getTopic() + " - " + mqttMessages[i].getMessage() + " - iteration: " + String.valueOf(i) + " - count: " + String.valueOf(x));
mqttHandler.publishMessage(mqttMessages[i].getTopic(), mqttMessages[i].getMessage());
}
@@ -915,11 +919,13 @@ public class HueMulator implements HueErrorStringSet {
else
setCount = 1;
for(int x = 0; x < setCount; x++) {
if( x > 0) {
if( x > 0 || i > 0) {
Thread.sleep(theDelay);
}
if(callItems[i].getDelay() != null && callItems[i].getDelay() > 0)
theDelay = callItems[i].getDelay();
else
theDelay = bridgeSettings.getButtonsleep();
String intermediate;
if(callItems[i].getItem().contains("exec://"))
intermediate = callItems[i].getItem().substring(callItems[i].getItem().indexOf("://") + 3);
@@ -950,11 +956,13 @@ public class HueMulator implements HueErrorStringSet {
else
setCount = 1;
for(int x = 0; x < setCount; x++) {
if( x > 0) {
if( x > 0 || i > 0) {
Thread.sleep(theDelay);
}
if(callItems[i].getDelay() != null && callItems[i].getDelay() > 0)
theDelay = callItems[i].getDelay();
else
theDelay = bridgeSettings.getButtonsleep();
try {
if(callItems[i].getItem().contains("udp://") || callItems[i].getItem().contains("tcp://")) {
String intermediate = callItems[i].getItem().substring(callItems[i].getItem().indexOf("://") + 3);

View File

@@ -75,7 +75,7 @@ public class HarmonyServer {
log.info(format("activity changed: [%d] %s", activity.getId(), activity.getLabel()));
}
});
harmonyClient.connect(myNameAndIP.getIp(), mySettings.getHarmonyUser(), mySettings.getHarmonyPwd());
harmonyClient.connect(myNameAndIP.getIp());
}
myHarmony = new HarmonyHandler(harmonyClient, noopCalls, devResponse);
}

View File

@@ -20,7 +20,7 @@ public class MQTTHandler {
public MQTTHandler(NamedIP aConfig) {
super();
log.debug("Setting up handler for name: " + aConfig.getName());
log.info("Setting up handler for name: " + aConfig.getName());
MemoryPersistence persistence = new MemoryPersistence();
myConfig = aConfig;
try {
@@ -30,6 +30,12 @@ public class MQTTHandler {
}
MqttConnectOptions connOpts = new MqttConnectOptions();
connOpts.setCleanSession(true);
if(aConfig.getUsername() != null && aConfig.getUsername().trim().length() > 0) {
if(aConfig.getPassword() != null && aConfig.getPassword().trim().length() > 0) {
connOpts.setUserName(aConfig.getUsername().trim());
connOpts.setPassword(aConfig.getPassword().trim().toCharArray());
}
}
try {
myClient.connect(connOpts);
} catch (MqttSecurityException e) {

View File

@@ -15,10 +15,12 @@ import com.bwssystems.HABridge.NamedIP;
public class MQTTHome {
private static final Logger log = LoggerFactory.getLogger(MQTTHome.class);
private Map<String, MQTTHandler> handlers;
private Boolean validMqtt;
public MQTTHome(BridgeSettingsDescriptor bridgeSettings) {
super();
if(!bridgeSettings.isValidMQTT())
validMqtt = bridgeSettings.isValidMQTT();
if(!validMqtt)
return;
handlers = new HashMap<String, MQTTHandler>();
@@ -32,6 +34,8 @@ public class MQTTHome {
}
public void shutdownMQTTClients() {
if(!validMqtt)
return;
log.debug("Shutting down MQTT handlers.");
if(handlers != null && !handlers.isEmpty()) {
Iterator<String> keys = handlers.keySet().iterator();
@@ -43,6 +47,8 @@ public class MQTTHome {
}
public MQTTHandler getMQTTHandler(String aName) {
if(!validMqtt)
return null;
MQTTHandler aHandler;
if(aName == null || aName.equals("")) {
aHandler = null;
@@ -56,6 +62,8 @@ public class MQTTHome {
}
public List<MQTTBroker> getBrokers() {
if(!validMqtt)
return null;
Iterator<String> keys = handlers.keySet().iterator();
ArrayList<MQTTBroker> deviceList = new ArrayList<MQTTBroker>();
while(keys.hasNext()) {

View File

@@ -702,14 +702,16 @@ app.controller('SystemController', function ($scope, $location, $http, $window,
}
}
};
$scope.addMQTTtoSettings = function (newmqttname, newmqttip) {
$scope.addMQTTtoSettings = function (newmqttname, newmqttip, newmqttusername, newmqttpassword) {
if($scope.bridge.settings.mqttaddress == null) {
$scope.bridge.settings.mqttaddress = { devices: [] };
}
var newmqtt = {name: newmqttname, ip: newmqttip }
var newmqtt = {name: newmqttname, ip: newmqttip, username: newmqttusername, password: newmqttpassword }
$scope.bridge.settings.mqttaddress.devices.push(newmqtt);
$scope.newmqttname = null;
$scope.newmqttip = null;
$scope.newmqttusername = null;
$scope.newmqttpassword = null;
};
$scope.removeMQTTtoSettings = function (mqttname, mqttip) {
for(var i = $scope.bridge.settings.mqttaddress.devices.length - 1; i >= 0; i--) {

View File

@@ -160,19 +160,6 @@
</tr>
</table></td>
</tr>
<tr>
<td>Harmony Username</td>
<td><input id="bridge-settings-harmonyuser"
class="form-control" type="text"
ng-model="bridge.settings.harmonyuser"
placeholder="someone@gmail.com"></td>
</tr>
<tr>
<td>Harmony Password</td>
<td><input id="bridge-settings-harmonypwd"
class="form-control" type="password"
ng-model="bridge.settings.harmonypwd" placeholder="thepassword"></td>
</tr>
<tr>
<td>Hue Names and IP Addresses</td>
<td><table
@@ -245,12 +232,18 @@
<tr>
<th>Client ID</th>
<th>IP</th>
<th>User (opt)</th>
<th>Password (opt)</th>
<th>Manage</th>
</tr>
</thead>
<tr ng-repeat="mqtt in bridge.settings.mqttaddress.devices">
<td>{{mqtt.name}}</td>
<td>{{mqtt.ip}}</td>
<td>{{mqtt.username}}</td>
<td ng-if="mqtt.password">*******</td>
<td ng-if="!mqtt.password"> </td>
<td><button class="btn btn-danger" type="submit"
ng-click="removeMQTTtoSettings(mqtt.name, mqtt.ip)">Del</button></td>
</tr>
@@ -261,8 +254,14 @@
<td><input id="bridge-settings-next-mqtt-ip"
class="form-control" type="text" ng-model="newmqttip"
placeholder="MQTT Broker IP and port"></td>
<td><input id="bridge-settings-next-mqtt-username"
class="form-control" type="text" ng-model="newmqttusername"
placeholder="MQTT Broker username (optional)"></td>
<td><input id="bridge-settings-next-mqtt-password"
class="form-control" type="password" ng-model="newmqttpassword"
placeholder="MQTT Broker password (opt)"></td>
<td><button class="btn btn-success" type="submit"
ng-click="addMQTTtoSettings(newmqttname, newmqttip)">Add</button></td>
ng-click="addMQTTtoSettings(newmqttname, newmqttip, newmqttusername, newmqttpassword)">Add</button></td>
</tr>
</table></td>
</tr>