mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-16 18:24:36 +00:00
Finished MQTT support and some testing. Updated harmony-java-client to
v1.1.1 to fix authentication error.
This commit is contained in:
4
pom.xml
4
pom.xml
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<groupId>com.bwssystems.HABridge</groupId>
|
<groupId>com.bwssystems.HABridge</groupId>
|
||||||
<artifactId>ha-bridge</artifactId>
|
<artifactId>ha-bridge</artifactId>
|
||||||
<version>3.2.2d</version>
|
<version>3.5.0</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>HA Bridge</name>
|
<name>HA Bridge</name>
|
||||||
@@ -32,7 +32,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.bwssytems</groupId>
|
<groupId>com.github.bwssytems</groupId>
|
||||||
<artifactId>harmony-java-client</artifactId>
|
<artifactId>harmony-java-client</artifactId>
|
||||||
<version>1.0.8</version>
|
<version>1.1.1</version>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
|
|||||||
@@ -102,8 +102,6 @@ public class BridgeSettings extends BackupHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
theBridgeSettings.setHarmonyAddress(theHarmonyList);
|
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.setUpnpStrict(Boolean.parseBoolean(System.getProperty("upnp.strict", "true")));
|
||||||
theBridgeSettings.setTraceupnp(Boolean.parseBoolean(System.getProperty("trace.upnp", "false")));
|
theBridgeSettings.setTraceupnp(Boolean.parseBoolean(System.getProperty("trace.upnp", "false")));
|
||||||
theBridgeSettings.setButtonsleep(Integer.parseInt(System.getProperty("button.sleep", Configuration.DEFAULT_BUTTON_SLEEP)));
|
theBridgeSettings.setButtonsleep(Integer.parseInt(System.getProperty("button.sleep", Configuration.DEFAULT_BUTTON_SLEEP)));
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ public class BridgeSettingsDescriptor {
|
|||||||
private String upnpdevicedb;
|
private String upnpdevicedb;
|
||||||
private IpList veraaddress;
|
private IpList veraaddress;
|
||||||
private IpList harmonyaddress;
|
private IpList harmonyaddress;
|
||||||
private String harmonyuser;
|
|
||||||
private String harmonypwd;
|
|
||||||
private Integer buttonsleep;
|
private Integer buttonsleep;
|
||||||
private boolean upnpstrict;
|
private boolean upnpstrict;
|
||||||
private boolean traceupnp;
|
private boolean traceupnp;
|
||||||
@@ -95,18 +93,6 @@ public class BridgeSettingsDescriptor {
|
|||||||
public void setHarmonyAddress(IpList harmonyaddress) {
|
public void setHarmonyAddress(IpList harmonyaddress) {
|
||||||
this.harmonyaddress = 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() {
|
public boolean isUpnpStrict() {
|
||||||
return upnpstrict;
|
return upnpstrict;
|
||||||
}
|
}
|
||||||
@@ -253,10 +239,6 @@ public class BridgeSettingsDescriptor {
|
|||||||
List<NamedIP> devicesList = this.getHarmonyAddress().getDevices();
|
List<NamedIP> devicesList = this.getHarmonyAddress().getDevices();
|
||||||
if(devicesList.get(0).getIp().contains(Configuration.DEFAULT_ADDRESS))
|
if(devicesList.get(0).getIp().contains(Configuration.DEFAULT_ADDRESS))
|
||||||
return false;
|
return false;
|
||||||
if(this.getHarmonyPwd() == null || this.getHarmonyPwd().equals(""))
|
|
||||||
return false;
|
|
||||||
if(this.getHarmonyUser() == null || this.getHarmonyUser().equals(""))
|
|
||||||
return false;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public Boolean isValidNest() {
|
public Boolean isValidNest() {
|
||||||
|
|||||||
@@ -797,11 +797,13 @@ public class HueMulator implements HueErrorStringSet {
|
|||||||
else
|
else
|
||||||
setCount = 1;
|
setCount = 1;
|
||||||
for(int x = 0; x < setCount; x++) {
|
for(int x = 0; x < setCount; x++) {
|
||||||
if( x > 0) {
|
if( x > 0 || i > 0) {
|
||||||
Thread.sleep(theDelay);
|
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();
|
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));
|
log.debug("pressing button: " + deviceButtons[i].getDevice() + " - " + deviceButtons[i].getButton() + " - iteration: " + String.valueOf(i) + " - count: " + String.valueOf(x));
|
||||||
myHarmony.pressButton(deviceButtons[i]);
|
myHarmony.pressButton(deviceButtons[i]);
|
||||||
}
|
}
|
||||||
@@ -883,11 +885,13 @@ public class HueMulator implements HueErrorStringSet {
|
|||||||
else
|
else
|
||||||
setCount = 1;
|
setCount = 1;
|
||||||
for(int x = 0; x < setCount; x++) {
|
for(int x = 0; x < setCount; x++) {
|
||||||
if( x > 0) {
|
if( x > 0 || i > 0) {
|
||||||
Thread.sleep(theDelay);
|
Thread.sleep(theDelay);
|
||||||
}
|
}
|
||||||
if(mqttMessages[i].getDelay() != null &&mqttMessages[i].getDelay() > 0)
|
if(mqttMessages[i].getDelay() != null &&mqttMessages[i].getDelay() > 0)
|
||||||
theDelay = mqttMessages[i].getDelay();
|
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));
|
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());
|
mqttHandler.publishMessage(mqttMessages[i].getTopic(), mqttMessages[i].getMessage());
|
||||||
}
|
}
|
||||||
@@ -915,11 +919,13 @@ public class HueMulator implements HueErrorStringSet {
|
|||||||
else
|
else
|
||||||
setCount = 1;
|
setCount = 1;
|
||||||
for(int x = 0; x < setCount; x++) {
|
for(int x = 0; x < setCount; x++) {
|
||||||
if( x > 0) {
|
if( x > 0 || i > 0) {
|
||||||
Thread.sleep(theDelay);
|
Thread.sleep(theDelay);
|
||||||
}
|
}
|
||||||
if(callItems[i].getDelay() != null && callItems[i].getDelay() > 0)
|
if(callItems[i].getDelay() != null && callItems[i].getDelay() > 0)
|
||||||
theDelay = callItems[i].getDelay();
|
theDelay = callItems[i].getDelay();
|
||||||
|
else
|
||||||
|
theDelay = bridgeSettings.getButtonsleep();
|
||||||
String intermediate;
|
String intermediate;
|
||||||
if(callItems[i].getItem().contains("exec://"))
|
if(callItems[i].getItem().contains("exec://"))
|
||||||
intermediate = callItems[i].getItem().substring(callItems[i].getItem().indexOf("://") + 3);
|
intermediate = callItems[i].getItem().substring(callItems[i].getItem().indexOf("://") + 3);
|
||||||
@@ -950,11 +956,13 @@ public class HueMulator implements HueErrorStringSet {
|
|||||||
else
|
else
|
||||||
setCount = 1;
|
setCount = 1;
|
||||||
for(int x = 0; x < setCount; x++) {
|
for(int x = 0; x < setCount; x++) {
|
||||||
if( x > 0) {
|
if( x > 0 || i > 0) {
|
||||||
Thread.sleep(theDelay);
|
Thread.sleep(theDelay);
|
||||||
}
|
}
|
||||||
if(callItems[i].getDelay() != null && callItems[i].getDelay() > 0)
|
if(callItems[i].getDelay() != null && callItems[i].getDelay() > 0)
|
||||||
theDelay = callItems[i].getDelay();
|
theDelay = callItems[i].getDelay();
|
||||||
|
else
|
||||||
|
theDelay = bridgeSettings.getButtonsleep();
|
||||||
try {
|
try {
|
||||||
if(callItems[i].getItem().contains("udp://") || callItems[i].getItem().contains("tcp://")) {
|
if(callItems[i].getItem().contains("udp://") || callItems[i].getItem().contains("tcp://")) {
|
||||||
String intermediate = callItems[i].getItem().substring(callItems[i].getItem().indexOf("://") + 3);
|
String intermediate = callItems[i].getItem().substring(callItems[i].getItem().indexOf("://") + 3);
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ public class HarmonyServer {
|
|||||||
log.info(format("activity changed: [%d] %s", activity.getId(), activity.getLabel()));
|
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);
|
myHarmony = new HarmonyHandler(harmonyClient, noopCalls, devResponse);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public class MQTTHandler {
|
|||||||
|
|
||||||
public MQTTHandler(NamedIP aConfig) {
|
public MQTTHandler(NamedIP aConfig) {
|
||||||
super();
|
super();
|
||||||
log.debug("Setting up handler for name: " + aConfig.getName());
|
log.info("Setting up handler for name: " + aConfig.getName());
|
||||||
MemoryPersistence persistence = new MemoryPersistence();
|
MemoryPersistence persistence = new MemoryPersistence();
|
||||||
myConfig = aConfig;
|
myConfig = aConfig;
|
||||||
try {
|
try {
|
||||||
@@ -30,6 +30,12 @@ public class MQTTHandler {
|
|||||||
}
|
}
|
||||||
MqttConnectOptions connOpts = new MqttConnectOptions();
|
MqttConnectOptions connOpts = new MqttConnectOptions();
|
||||||
connOpts.setCleanSession(true);
|
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 {
|
try {
|
||||||
myClient.connect(connOpts);
|
myClient.connect(connOpts);
|
||||||
} catch (MqttSecurityException e) {
|
} catch (MqttSecurityException e) {
|
||||||
|
|||||||
@@ -15,10 +15,12 @@ import com.bwssystems.HABridge.NamedIP;
|
|||||||
public class MQTTHome {
|
public class MQTTHome {
|
||||||
private static final Logger log = LoggerFactory.getLogger(MQTTHome.class);
|
private static final Logger log = LoggerFactory.getLogger(MQTTHome.class);
|
||||||
private Map<String, MQTTHandler> handlers;
|
private Map<String, MQTTHandler> handlers;
|
||||||
|
private Boolean validMqtt;
|
||||||
|
|
||||||
public MQTTHome(BridgeSettingsDescriptor bridgeSettings) {
|
public MQTTHome(BridgeSettingsDescriptor bridgeSettings) {
|
||||||
super();
|
super();
|
||||||
if(!bridgeSettings.isValidMQTT())
|
validMqtt = bridgeSettings.isValidMQTT();
|
||||||
|
if(!validMqtt)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
handlers = new HashMap<String, MQTTHandler>();
|
handlers = new HashMap<String, MQTTHandler>();
|
||||||
@@ -32,6 +34,8 @@ public class MQTTHome {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void shutdownMQTTClients() {
|
public void shutdownMQTTClients() {
|
||||||
|
if(!validMqtt)
|
||||||
|
return;
|
||||||
log.debug("Shutting down MQTT handlers.");
|
log.debug("Shutting down MQTT handlers.");
|
||||||
if(handlers != null && !handlers.isEmpty()) {
|
if(handlers != null && !handlers.isEmpty()) {
|
||||||
Iterator<String> keys = handlers.keySet().iterator();
|
Iterator<String> keys = handlers.keySet().iterator();
|
||||||
@@ -43,6 +47,8 @@ public class MQTTHome {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MQTTHandler getMQTTHandler(String aName) {
|
public MQTTHandler getMQTTHandler(String aName) {
|
||||||
|
if(!validMqtt)
|
||||||
|
return null;
|
||||||
MQTTHandler aHandler;
|
MQTTHandler aHandler;
|
||||||
if(aName == null || aName.equals("")) {
|
if(aName == null || aName.equals("")) {
|
||||||
aHandler = null;
|
aHandler = null;
|
||||||
@@ -56,6 +62,8 @@ public class MQTTHome {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<MQTTBroker> getBrokers() {
|
public List<MQTTBroker> getBrokers() {
|
||||||
|
if(!validMqtt)
|
||||||
|
return null;
|
||||||
Iterator<String> keys = handlers.keySet().iterator();
|
Iterator<String> keys = handlers.keySet().iterator();
|
||||||
ArrayList<MQTTBroker> deviceList = new ArrayList<MQTTBroker>();
|
ArrayList<MQTTBroker> deviceList = new ArrayList<MQTTBroker>();
|
||||||
while(keys.hasNext()) {
|
while(keys.hasNext()) {
|
||||||
|
|||||||
@@ -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) {
|
if($scope.bridge.settings.mqttaddress == null) {
|
||||||
$scope.bridge.settings.mqttaddress = { devices: [] };
|
$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.bridge.settings.mqttaddress.devices.push(newmqtt);
|
||||||
$scope.newmqttname = null;
|
$scope.newmqttname = null;
|
||||||
$scope.newmqttip = null;
|
$scope.newmqttip = null;
|
||||||
|
$scope.newmqttusername = null;
|
||||||
|
$scope.newmqttpassword = null;
|
||||||
};
|
};
|
||||||
$scope.removeMQTTtoSettings = function (mqttname, mqttip) {
|
$scope.removeMQTTtoSettings = function (mqttname, mqttip) {
|
||||||
for(var i = $scope.bridge.settings.mqttaddress.devices.length - 1; i >= 0; i--) {
|
for(var i = $scope.bridge.settings.mqttaddress.devices.length - 1; i >= 0; i--) {
|
||||||
|
|||||||
@@ -160,19 +160,6 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table></td>
|
</table></td>
|
||||||
</tr>
|
</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>
|
<tr>
|
||||||
<td>Hue Names and IP Addresses</td>
|
<td>Hue Names and IP Addresses</td>
|
||||||
<td><table
|
<td><table
|
||||||
@@ -245,12 +232,18 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>Client ID</th>
|
<th>Client ID</th>
|
||||||
<th>IP</th>
|
<th>IP</th>
|
||||||
|
<th>User (opt)</th>
|
||||||
|
<th>Password (opt)</th>
|
||||||
<th>Manage</th>
|
<th>Manage</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tr ng-repeat="mqtt in bridge.settings.mqttaddress.devices">
|
<tr ng-repeat="mqtt in bridge.settings.mqttaddress.devices">
|
||||||
<td>{{mqtt.name}}</td>
|
<td>{{mqtt.name}}</td>
|
||||||
<td>{{mqtt.ip}}</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"
|
<td><button class="btn btn-danger" type="submit"
|
||||||
ng-click="removeMQTTtoSettings(mqtt.name, mqtt.ip)">Del</button></td>
|
ng-click="removeMQTTtoSettings(mqtt.name, mqtt.ip)">Del</button></td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -261,8 +254,14 @@
|
|||||||
<td><input id="bridge-settings-next-mqtt-ip"
|
<td><input id="bridge-settings-next-mqtt-ip"
|
||||||
class="form-control" type="text" ng-model="newmqttip"
|
class="form-control" type="text" ng-model="newmqttip"
|
||||||
placeholder="MQTT Broker IP and port"></td>
|
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"
|
<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>
|
</tr>
|
||||||
</table></td>
|
</table></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user