mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-16 18:24:36 +00:00
Fix small issues and add pct check for FHEM
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>com.bwssystems.HABridge</groupId>
|
||||
<artifactId>ha-bridge</artifactId>
|
||||
<version>5.2.0RC8</version>
|
||||
<version>5.2.0RC9</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>HA Bridge</name>
|
||||
|
||||
@@ -49,14 +49,12 @@ public class HABridge {
|
||||
// Singleton initialization
|
||||
thePool = new HttpClientPool();
|
||||
|
||||
log.info("HA Bridge (v" + theVersion.getVersion() + ") starting....");
|
||||
|
||||
bridgeSettings = new BridgeSettings();
|
||||
// sparkjava config directive to set html static file location for Jetty
|
||||
while(!bridgeSettings.getBridgeControl().isStop()) {
|
||||
bridgeSettings.buildSettings();
|
||||
bridgeSettings.getBridgeSecurity().removeTestUsers();
|
||||
log.info("HA Bridge initializing....");
|
||||
log.info("HA Bridge (v" + theVersion.getVersion() + ") initializing....");
|
||||
// sparkjava config directive to set ip address for the web server to listen on
|
||||
ipAddress(bridgeSettings.getBridgeSettingsDescriptor().getWebaddress());
|
||||
// sparkjava config directive to set port for the web server to listen on
|
||||
@@ -91,7 +89,7 @@ public class HABridge {
|
||||
bridgeSettings.getBridgeSettingsDescriptor().isUseupnpiface() + " on web server: " +
|
||||
bridgeSettings.getBridgeSettingsDescriptor().getWebaddress() + ":" + bridgeSettings.getBridgeSettingsDescriptor().getServerPort());
|
||||
// setup the class to handle the upnp response rest api
|
||||
theSettingResponder = new UpnpSettingsResource(bridgeSettings.getBridgeSettingsDescriptor());
|
||||
theSettingResponder = new UpnpSettingsResource(bridgeSettings);
|
||||
theSettingResponder.setupServer();
|
||||
|
||||
// start the upnp ssdp discovery listener
|
||||
@@ -127,12 +125,12 @@ public class HABridge {
|
||||
bridgeSettings.updateConfigFile();
|
||||
try {
|
||||
HttpClientPool.shutdown();
|
||||
thePool = null;
|
||||
} catch (InterruptedException e) {
|
||||
log.warn("Error shutting down http pool: " + e.getMessage());;
|
||||
} catch (IOException e) {
|
||||
log.warn("Error shutting down http pool: " + e.getMessage());;
|
||||
}
|
||||
thePool = null;
|
||||
log.info("HA Bridge (v" + theVersion.getVersion() + ") exiting....");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
@@ -42,6 +42,14 @@ public class HomeManager {
|
||||
// factory method
|
||||
public void buildHomes(BridgeSettings bridgeSettings, UDPDatagramSender aUdpDatagramSender) {
|
||||
Home aHome = null;
|
||||
//setup the http handler Home - This must be the first home created for devMode
|
||||
aHome = new HTTPHome(bridgeSettings);
|
||||
homeList.put(DeviceMapTypes.HTTP_DEVICE[DeviceMapTypes.typeIndex], aHome);
|
||||
homeList.put(DeviceMapTypes.CUSTOM_DEVICE[DeviceMapTypes.typeIndex], aHome);
|
||||
homeList.put(DeviceMapTypes.VERA_DEVICE[DeviceMapTypes.typeIndex], aHome);
|
||||
homeList.put(DeviceMapTypes.VERA_SCENE[DeviceMapTypes.typeIndex], aHome);
|
||||
homeList.put(DeviceMapTypes.FIBARO_DEVICE[DeviceMapTypes.typeIndex], aHome);
|
||||
homeList.put(DeviceMapTypes.FIBARO_SCENE[DeviceMapTypes.typeIndex], aHome);
|
||||
//setup the harmony connection if available
|
||||
aHome = new HarmonyHome(bridgeSettings);
|
||||
resourceList.put(DeviceMapTypes.HARMONY_ACTIVITY[DeviceMapTypes.typeIndex], aHome);
|
||||
@@ -80,14 +88,6 @@ public class HomeManager {
|
||||
aHome = new CommandHome(bridgeSettings);
|
||||
homeList.put(DeviceMapTypes.EXEC_DEVICE_COMPAT[DeviceMapTypes.typeIndex], aHome);
|
||||
homeList.put(DeviceMapTypes.CMD_DEVICE[DeviceMapTypes.typeIndex], aHome);
|
||||
//setup the http handler Home
|
||||
aHome = new HTTPHome(bridgeSettings);
|
||||
homeList.put(DeviceMapTypes.HTTP_DEVICE[DeviceMapTypes.typeIndex], aHome);
|
||||
homeList.put(DeviceMapTypes.CUSTOM_DEVICE[DeviceMapTypes.typeIndex], aHome);
|
||||
homeList.put(DeviceMapTypes.VERA_DEVICE[DeviceMapTypes.typeIndex], aHome);
|
||||
homeList.put(DeviceMapTypes.VERA_SCENE[DeviceMapTypes.typeIndex], aHome);
|
||||
homeList.put(DeviceMapTypes.FIBARO_DEVICE[DeviceMapTypes.typeIndex], aHome);
|
||||
homeList.put(DeviceMapTypes.FIBARO_SCENE[DeviceMapTypes.typeIndex], aHome);
|
||||
//setup the tcp handler Home
|
||||
aHome = new TCPHome(bridgeSettings);
|
||||
homeList.put(DeviceMapTypes.TCP_DEVICE[DeviceMapTypes.typeIndex], aHome);
|
||||
|
||||
@@ -111,11 +111,7 @@ public class BrightnessDecode {
|
||||
|
||||
Integer endResult = calculateMath(variables, mathDescriptor);
|
||||
if(endResult != null) {
|
||||
if (isHex) {
|
||||
replaceValue = convertToHex(endResult);
|
||||
} else {
|
||||
replaceValue = endResult.toString();
|
||||
}
|
||||
replaceValue = convertToHex(endResult);
|
||||
replaceTarget = INTENSITY_MATH + mathDescriptor + INTENSITY_MATH_CLOSE_HEX;
|
||||
notDone = true;
|
||||
}
|
||||
|
||||
@@ -45,14 +45,21 @@ public class HttpTestHandler extends HTTPHandler {
|
||||
log.info("header index " + i + " name: <<<" + headers[i].getName() + ">>>, value: <<<" + headers[i].getValue() + ">>>");
|
||||
String responseData = null;
|
||||
for(NameValue aTest:theData) {
|
||||
if(url.contains(aTest.getName()))
|
||||
responseData = aTest.getValue();
|
||||
else if(aTest.getName() == null || aTest.getName().isEmpty())
|
||||
if(aTest.getName() == null)
|
||||
responseData = aTest.getValue();
|
||||
else {
|
||||
if(url.contains(aTest.getName()))
|
||||
responseData = aTest.getValue();
|
||||
else if(aTest.getName() == null || aTest.getName().isEmpty())
|
||||
responseData = aTest.getValue();
|
||||
}
|
||||
|
||||
if(responseData != null)
|
||||
break;
|
||||
}
|
||||
|
||||
if(responseData == null)
|
||||
responseData = "No data was set for HttpTestHandler for your request url.";
|
||||
return responseData;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,22 +66,26 @@ public class OpenHABInstance {
|
||||
theData = httpClient.doHttpRequest(theUrl, HttpGet.METHOD_NAME, "application/json", null, headers);
|
||||
if(theData != null) {
|
||||
log.debug("GET OpenHAB States - data: " + theData);
|
||||
theOpenhabStates = new Gson().fromJson(theData, OpenHABItem[].class);
|
||||
if(theOpenhabStates == null) {
|
||||
log.warn("Cannot get any devices for OpenHAB " + theOpenHAB.getName() + " as response is not parsable.");
|
||||
}
|
||||
else {
|
||||
deviceList = new ArrayList<OpenHABDevice>();
|
||||
|
||||
for (int i = 0; i < theOpenhabStates.length; i++) {
|
||||
OpenHABDevice aNewOpenHABDeviceDevice = new OpenHABDevice();
|
||||
aNewOpenHABDeviceDevice.setItem(theOpenhabStates[i]);
|
||||
aNewOpenHABDeviceDevice.setAddress(theOpenHAB.getIp() + ":" + theOpenHAB.getPort());
|
||||
aNewOpenHABDeviceDevice.setName(theOpenHAB.getName());
|
||||
deviceList.add(aNewOpenHABDeviceDevice);
|
||||
|
||||
}
|
||||
}
|
||||
try {
|
||||
theOpenhabStates = new Gson().fromJson(theData, OpenHABItem[].class);
|
||||
if(theOpenhabStates == null) {
|
||||
log.warn("Cannot get any devices for OpenHAB " + theOpenHAB.getName() + " as response is not parsable.");
|
||||
}
|
||||
else {
|
||||
deviceList = new ArrayList<OpenHABDevice>();
|
||||
|
||||
for (int i = 0; i < theOpenhabStates.length; i++) {
|
||||
OpenHABDevice aNewOpenHABDeviceDevice = new OpenHABDevice();
|
||||
aNewOpenHABDeviceDevice.setItem(theOpenhabStates[i]);
|
||||
aNewOpenHABDeviceDevice.setAddress(theOpenHAB.getIp() + ":" + theOpenHAB.getPort());
|
||||
aNewOpenHABDeviceDevice.setName(theOpenHAB.getName());
|
||||
deviceList.add(aNewOpenHABDeviceDevice);
|
||||
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("Cannot get an devices for OpenHAB " + theOpenHAB.getName() + " Gson Parse Error.");
|
||||
}
|
||||
}
|
||||
else
|
||||
log.warn("Cannot get an devices for OpenHAB " + theOpenHAB.getName() + " http call failed.");
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.bwssystems.HABridge.upnp;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.bwssystems.HABridge.BridgeSettings;
|
||||
import com.bwssystems.HABridge.BridgeSettingsDescriptor;
|
||||
import com.bwssystems.HABridge.api.hue.HueConstants;
|
||||
import com.bwssystems.HABridge.api.hue.HuePublicConfig;
|
||||
@@ -16,6 +17,7 @@ public class UpnpSettingsResource {
|
||||
private Logger log = LoggerFactory.getLogger(UpnpSettingsResource.class);
|
||||
|
||||
private BridgeSettingsDescriptor theSettings;
|
||||
private BridgeSettings bridgeSettings;
|
||||
|
||||
private String hueTemplate = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
|
||||
+ "<root xmlns=\"urn:schemas-upnp-org:device-1-0\">\n"
|
||||
@@ -55,15 +57,22 @@ public class UpnpSettingsResource {
|
||||
+ "</device>\n"
|
||||
+ "</root>\n";
|
||||
|
||||
public UpnpSettingsResource(BridgeSettingsDescriptor theBridgeSettings) {
|
||||
public UpnpSettingsResource(BridgeSettings theBridgeSettings) {
|
||||
super();
|
||||
this.theSettings = theBridgeSettings;
|
||||
this.bridgeSettings = theBridgeSettings;
|
||||
this.theSettings = theBridgeSettings.getBridgeSettingsDescriptor();
|
||||
}
|
||||
|
||||
public void setupServer() {
|
||||
log.info("Description xml service started....");
|
||||
// http://ip_adress:port/description.xml which returns the xml configuration for the hue emulator
|
||||
get("/description.xml", "application/xml; charset=utf-8", (request, response) -> {
|
||||
if(bridgeSettings.getBridgeControl().isReinit() || bridgeSettings.getBridgeControl().isStop()) {
|
||||
log.info("Get description.xml called while in re-init or stop state");
|
||||
response.status(503);
|
||||
return null;
|
||||
}
|
||||
|
||||
String portNumber = Integer.toString(request.port());
|
||||
String filledTemplate = null;
|
||||
String bridgeIdMac = HuePublicConfig.createConfig("temp", theSettings.getUpnpConfigAddress(), HueConstants.HUB_VERSION, theSettings.getHubmac()).getSNUUIDFromMac();
|
||||
|
||||
@@ -3049,6 +3049,8 @@ app.controller('MQTTController', function ($scope, $location, bridgeService, ngD
|
||||
bridgeService.viewMQTTDevices();
|
||||
$scope.imgButtonsUrl = "glyphicon glyphicon-plus";
|
||||
$scope.buttonsVisible = false;
|
||||
$scope.mqttretain = false;
|
||||
$scope.mqttqos = 1;
|
||||
|
||||
$scope.clearDevice = function () {
|
||||
bridgeService.clearDevice();
|
||||
@@ -3056,6 +3058,10 @@ app.controller('MQTTController', function ($scope, $location, bridgeService, ngD
|
||||
};
|
||||
|
||||
$scope.buildMQTTPublish = function (mqttbroker, mqtttopic, mqttmessage, mqttqos, mqttretain) {
|
||||
if(mqttretain === 'undefined')
|
||||
mqttretain = false;
|
||||
if(mqttqos === 'undefined')
|
||||
mqttqos = 1;
|
||||
onpayload = "{\"clientId\":\"" + mqttbroker.clientId + "\",\"topic\":\"" + mqtttopic + "\",\"message\":\"" + mqttmessage + "\",\"qos\":\"" + mqttqos + "\",\"retain\":\"" + mqttretain + "\"}";
|
||||
offpayload = "{\"clientId\":\"" + mqttbroker.clientId + "\",\"topic\":\"" + mqtttopic + "\",\"message\":\"" + mqttmessage + "\",\"qos\":\"" + mqttqos + "\",\"retain\":\"" + mqttretain + "\"}";
|
||||
|
||||
@@ -3926,16 +3932,23 @@ app.controller('FhemController', function ($scope, $location, bridgeService, ngD
|
||||
|
||||
$scope.buildDeviceUrls = function (fhemdevice, dim_control, buildonly) {
|
||||
var preCmd = "/fhem?cmd=set%20" + fhemdevice.item.Name + "%20";
|
||||
if(fhemdevice.item.PossibleSets.indexOf("dim") >= 0) {
|
||||
if(fhemdevice.item.PossibleSets.toLowerCase().indexOf("dim") >= 0) {
|
||||
if((dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0)) {
|
||||
dimpayload = "{\"url\":\"http://" + fhemdevice.address + preCmd + "\",\"command\":\"dim%20" + dim_control + "\"}";
|
||||
}
|
||||
else
|
||||
dimpayload = "{\"url\":\"http://" + fhemdevice.address + preCmd + "\",\"command\":\"dim%20${intensity.percent}\"}";
|
||||
}
|
||||
else if(fhemdevice.item.PossibleSets.toLowerCase().indexOf("pct") >= 0) {
|
||||
if((dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0)) {
|
||||
dimpayload = "{\"url\":\"http://" + fhemdevice.address + preCmd + "\",\"command\":\"pct%20" + dim_control + "\"}";
|
||||
}
|
||||
else
|
||||
dimpayload = "{\"url\":\"http://" + fhemdevice.address + preCmd + "\",\"command\":\"pct%20${intensity.percent}\"}";
|
||||
}
|
||||
else
|
||||
dimpayload = null;
|
||||
if(fhemdevice.item.PossibleSets.indexOf("RGB") >= 0) {
|
||||
if(fhemdevice.item.PossibleSets.toLowerCase().indexOf("rgb") >= 0) {
|
||||
colorpayload = "{\"url\":\"http://" + fhemdevice.address + preCmd + "\",\"command\":\"RGB%20${color.rgbx}\"}";
|
||||
}
|
||||
else
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<li ng-if="bridge.showSomfy" role="presentation"><a href="#!/somfydevices">Somfy Devices</a></li>
|
||||
<li ng-if="bridge.showLifx" role="presentation"><a href="#!/lifxdevices">LIFX Devices</a></li>
|
||||
<li ng-if="bridge.showHomeWizard" role="presentation"><a href="#!/homewizarddevices">HomeWizard Devices</a></li>
|
||||
<li ng-if="bridge.showbroadlink" role="presentation"><a href="#!/broadlinkdevices">broadlink Devices</a></li>
|
||||
<li ng-if="bridge.showOpenHAB" role="presentation"><a href="#!/openhabdevices">OpenHAB Devices</a></li>
|
||||
<li ng-if="bridge.showFHEM" role="presentation"><a href="#!/fhemdevices">FHEM Devices</a></li>
|
||||
<li ng-if="bridge.showBroadlink" role="presentation" class="active"><a href="#!/broadlinkdevices">Broadlink Devices</a></li>
|
||||
<li role="presentation"><a href="#!/editdevice">Add/Edit</a></li>
|
||||
|
||||
@@ -71,8 +71,9 @@
|
||||
ng-model="mqttqos" placeholder="1"/>
|
||||
</td>
|
||||
<td>
|
||||
<input type="checkbox" rows="1" class="form-control" id="mqtt-retain"
|
||||
ng-model="mqttretain"/>
|
||||
<input type="checkbox" id="mqtt-retain"
|
||||
ng-model="mqttretain" ng-true-value=true
|
||||
ng-false-value=false>{{mqttretain}}</td>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn btn-success" type="submit"
|
||||
|
||||
Reference in New Issue
Block a user