mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-18 00:10:20 +00:00
refactoring....
This commit is contained in:
2
pom.xml
2
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.5.1q</version>
|
<version>3.5.1r</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>HA Bridge</name>
|
<name>HA Bridge</name>
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public class UDPHome implements Home {
|
|||||||
sendData = theUrlBody.getBytes();
|
sendData = theUrlBody.getBytes();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
theUDPDatagramSender.sendUDPResponse(new String(sendData), IPAddress,
|
theUDPDatagramSender.sendUDPResponse(sendData, IPAddress,
|
||||||
Integer.parseInt(port));
|
Integer.parseInt(port));
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
// noop
|
// noop
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ public class UpnpListener {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
log.debug("sendUpnpResponse discovery responseTemplate1 is <<<" + discoveryResponse + ">>>");
|
log.debug("sendUpnpResponse discovery responseTemplate1 is <<<" + discoveryResponse + ">>>");
|
||||||
theUDPDatagramSender.sendUDPResponse(discoveryResponse, requester, sourcePort);
|
theUDPDatagramSender.sendUDPResponse(discoveryResponse.getBytes(), requester, sourcePort);
|
||||||
|
|
||||||
discoveryResponse = String.format(responseTemplate2, Configuration.UPNP_MULTICAST_ADDRESS, Configuration.UPNP_DISCOVERY_PORT, responseAddress, httpServerPort, bridgeId, bridgeSNUUID, bridgeSNUUID);
|
discoveryResponse = String.format(responseTemplate2, Configuration.UPNP_MULTICAST_ADDRESS, Configuration.UPNP_DISCOVERY_PORT, responseAddress, httpServerPort, bridgeId, bridgeSNUUID, bridgeSNUUID);
|
||||||
if(traceupnp) {
|
if(traceupnp) {
|
||||||
@@ -217,7 +217,7 @@ public class UpnpListener {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
log.debug("sendUpnpResponse discovery responseTemplate2 is <<<" + discoveryResponse + ">>>");
|
log.debug("sendUpnpResponse discovery responseTemplate2 is <<<" + discoveryResponse + ">>>");
|
||||||
theUDPDatagramSender.sendUDPResponse(discoveryResponse, requester, sourcePort);
|
theUDPDatagramSender.sendUDPResponse(discoveryResponse.getBytes(), requester, sourcePort);
|
||||||
|
|
||||||
discoveryResponse = String.format(responseTemplate3, Configuration.UPNP_MULTICAST_ADDRESS, Configuration.UPNP_DISCOVERY_PORT, responseAddress, httpServerPort, bridgeId, bridgeSNUUID);
|
discoveryResponse = String.format(responseTemplate3, Configuration.UPNP_MULTICAST_ADDRESS, Configuration.UPNP_DISCOVERY_PORT, responseAddress, httpServerPort, bridgeId, bridgeSNUUID);
|
||||||
if(traceupnp) {
|
if(traceupnp) {
|
||||||
@@ -225,6 +225,6 @@ public class UpnpListener {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
log.debug("sendUpnpResponse discovery responseTemplate3 is <<<" + discoveryResponse + ">>>");
|
log.debug("sendUpnpResponse discovery responseTemplate3 is <<<" + discoveryResponse + ">>>");
|
||||||
theUDPDatagramSender.sendUDPResponse(discoveryResponse, requester, sourcePort);
|
theUDPDatagramSender.sendUDPResponse(discoveryResponse.getBytes(), requester, sourcePort);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,11 +62,11 @@ public class UDPDatagramSender {
|
|||||||
responseSocket.close();
|
responseSocket.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendUDPResponse(String udpResponse, InetAddress requester, int sourcePort) throws IOException {
|
public void sendUDPResponse(byte[] udpMessage, InetAddress requester, int sourcePort) throws IOException {
|
||||||
log.debug("Sending response string: <<<" + udpResponse + ">>>");
|
log.debug("Sending response string: <<<" + new String(udpMessage) + ">>>");
|
||||||
if(responseSocket == null)
|
if(responseSocket == null)
|
||||||
throw new IOException("Socket not initialized");
|
throw new IOException("Socket not initialized");
|
||||||
DatagramPacket response = new DatagramPacket(udpResponse.getBytes(), udpResponse.length(), requester, sourcePort);
|
DatagramPacket response = new DatagramPacket(udpMessage, udpMessage.length, requester, sourcePort);
|
||||||
responseSocket.send(response);
|
responseSocket.send(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1036,7 +1036,7 @@ app.controller('VeraController', function ($scope, $location, $http, bridgeServi
|
|||||||
$scope.device.dimUrl = "[{\"item\":\"http://" + veradevice.veraaddress + ":" + $scope.vera.port
|
$scope.device.dimUrl = "[{\"item\":\"http://" + veradevice.veraaddress + ":" + $scope.vera.port
|
||||||
+ "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum="
|
+ "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum="
|
||||||
+ veradevice.id + "\"},\"type\":\"veraDevice\"}]";
|
+ veradevice.id + "\"},\"type\":\"veraDevice\"}]";
|
||||||
$scope.device.onUrl = "[{\"item\":{\"clientId\":\"http://" + veradevice.veraaddress + ":" + $scope.vera.port
|
$scope.device.onUrl = "[{\"item\":\"http://" + veradevice.veraaddress + ":" + $scope.vera.port
|
||||||
+ "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum="
|
+ "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum="
|
||||||
+ veradevice.id + "\"},\"type\":\"veraDevice\"}]";
|
+ veradevice.id + "\"},\"type\":\"veraDevice\"}]";
|
||||||
$scope.device.offUrl = "[{\"item\":\"http://" + veradevice.veraaddress + ":" + $scope.vera.port
|
$scope.device.offUrl = "[{\"item\":\"http://" + veradevice.veraaddress + ":" + $scope.vera.port
|
||||||
@@ -1052,10 +1052,10 @@ app.controller('VeraController', function ($scope, $location, $http, bridgeServi
|
|||||||
$scope.device.mapId = $scope.device.mapId + "-" + verascene.id;
|
$scope.device.mapId = $scope.device.mapId + "-" + verascene.id;
|
||||||
$scope.device.onUrl = currentOn.substr(0, currentOn.indexOf("]")) + ",{\"item\":\"http://" + verascene.veraaddress + ":" + $scope.vera.port
|
$scope.device.onUrl = currentOn.substr(0, currentOn.indexOf("]")) + ",{\"item\":\"http://" + verascene.veraaddress + ":" + $scope.vera.port
|
||||||
+ "/data_request?id=action&output_format=json&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum="
|
+ "/data_request?id=action&output_format=json&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum="
|
||||||
+ verascene.id+ "\"},\"type\":\"veraDevice\"}]";
|
+ verascene.id + "\"},\"type\":\"veraScene\"}]";
|
||||||
$scope.device.offUrl = currentOff.substr(0, currentOff.indexOf("]")) + ",{\"item\":\"http://" + verascene.veraaddress + ":" + $scope.vera.port
|
$scope.device.offUrl = currentOff.substr(0, currentOff.indexOf("]")) + ",{\"item\":\"http://" + verascene.veraaddress + ":" + $scope.vera.port
|
||||||
+ "/data_request?id=action&output_format=json&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum="
|
+ "/data_request?id=action&output_format=json&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum="
|
||||||
+ verascene.id+ "\"},\"type\":\"veraDevice\"}]";
|
+ verascene.id + "\"},\"type\":\"veraScene\"}]";
|
||||||
}
|
}
|
||||||
else if ($scope.device.mapType === undefined || $scope.device.mapType == null || $scope.device.mapType == "") {
|
else if ($scope.device.mapType === undefined || $scope.device.mapType == null || $scope.device.mapType == "") {
|
||||||
bridgeService.clearDevice();
|
bridgeService.clearDevice();
|
||||||
@@ -1066,10 +1066,10 @@ app.controller('VeraController', function ($scope, $location, $http, bridgeServi
|
|||||||
$scope.device.mapId = verascene.id;
|
$scope.device.mapId = verascene.id;
|
||||||
$scope.device.onUrl = "[{\"item\":\"http://" + verascene.veraaddress + ":" + $scope.vera.port
|
$scope.device.onUrl = "[{\"item\":\"http://" + verascene.veraaddress + ":" + $scope.vera.port
|
||||||
+ "/data_request?id=action&output_format=json&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum="
|
+ "/data_request?id=action&output_format=json&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum="
|
||||||
+ verascene.id+ "\"},\"type\":\"veraDevice\"}]";
|
+ verascene.id + "\"},\"type\":\"veraScene\"}]";
|
||||||
$scope.device.offUrl = "[{\"item\":\"http://" + verascene.veraaddress + ":" + $scope.vera.port
|
$scope.device.offUrl = "[{\"item\":\"http://" + verascene.veraaddress + ":" + $scope.vera.port
|
||||||
+ "/data_request?id=action&output_format=json&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum="
|
+ "/data_request?id=action&output_format=json&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum="
|
||||||
+ verascene.id+ "\"},\"type\":\"veraDevice\"}]";
|
+ verascene.id + "\"},\"type\":\"veraScene\"}]";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1194,13 +1194,22 @@ app.controller('HarmonyController', function ($scope, $location, $http, bridgeSe
|
|||||||
|
|
||||||
$scope.buildActivityUrls = function (harmonyactivity) {
|
$scope.buildActivityUrls = function (harmonyactivity) {
|
||||||
bridgeService.clearDevice();
|
bridgeService.clearDevice();
|
||||||
$scope.device.deviceType = "activity";
|
var currentOn = $scope.device.onUrl;
|
||||||
$scope.device.targetDevice = harmonyactivity.hub;
|
var currentOff = $scope.device.offUrl;
|
||||||
$scope.device.name = harmonyactivity.activity.label;
|
if($scope.device.mapType !== undefined && $scope.device.mapType != null && $scope.device.mapType != "") {
|
||||||
$scope.device.mapType = "harmonyActivity";
|
$scope.device.mapId = $scope.device.mapId + "-" + harmonyactivity.activity.id;
|
||||||
$scope.device.mapId = harmonyactivity.activity.id;
|
$scope.device.onUrl = currentOn.substr(0, currentOn.indexOf("]")) + ",{\"item\":{\"name\":\"" + harmonyactivity.activity.id + "\"}" + "\"},\"type\":\"harmonyActivity\"}]";
|
||||||
$scope.device.onUrl = "{\"name\":\"" + harmonyactivity.activity.id + "\"}";
|
$scope.device.offUrl = currentOn.substr(0, currentOn.indexOf("]")) + ",{\"item\":{\"name\":\"-1\"}" + "\"},\"type\":\"harmonyActivity\"}]";
|
||||||
$scope.device.offUrl = "{\"name\":\"-1\"}";
|
}
|
||||||
|
else if ($scope.device.mapType == null || $scope.device.mapType == "") {
|
||||||
|
$scope.device.deviceType = "activity";
|
||||||
|
$scope.device.targetDevice = harmonyactivity.hub;
|
||||||
|
$scope.device.name = harmonyactivity.activity.label;
|
||||||
|
$scope.device.mapType = "harmonyActivity";
|
||||||
|
$scope.device.mapId = harmonyactivity.activity.id;
|
||||||
|
$scope.device.onUrl = "[{\"item\":{\"name\":\"" + harmonyactivity.activity.id + "\"}" + "\"},\"type\":\"harmonyActivity\"}]";
|
||||||
|
$scope.device.offUrl = "[{\"item\":{\"name\":\"-1\"}" + "\"},\"type\":\"harmonyActivity\"}]";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.buildButtonUrls = function (harmonydevice, onbutton, offbutton) {
|
$scope.buildButtonUrls = function (harmonydevice, onbutton, offbutton) {
|
||||||
@@ -1208,10 +1217,10 @@ app.controller('HarmonyController', function ($scope, $location, $http, bridgeSe
|
|||||||
var currentOff = $scope.device.offUrl;
|
var currentOff = $scope.device.offUrl;
|
||||||
var actionOn = angular.fromJson(onbutton);
|
var actionOn = angular.fromJson(onbutton);
|
||||||
var actionOff = angular.fromJson(offbutton);
|
var actionOff = angular.fromJson(offbutton);
|
||||||
if( $scope.device.mapType == "harmonyButton") {
|
if($scope.device.mapType !== undefined && $scope.device.mapType != null && $scope.device.mapType != "") {
|
||||||
$scope.device.mapId = $scope.device.mapId + "-" + actionOn.command;
|
$scope.device.mapId = $scope.device.mapId + "-" + actionOn.command;
|
||||||
$scope.device.onUrl = currentOn.substr(0, currentOn.indexOf("]")) + ",{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + actionOn.command + "\"}]";
|
$scope.device.onUrl = currentOn.substr(0, currentOn.indexOf("]")) + ",{\"item\":{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + actionOn.command + "\"}]";
|
||||||
$scope.device.offUrl = currentOff.substr(0, currentOff.indexOf("]")) + ",{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + actionOff.command + "\"}]";
|
$scope.device.offUrl = currentOff.substr(0, currentOff.indexOf("]")) + ",{\"item\":{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + actionOff.command + "\"}]";
|
||||||
}
|
}
|
||||||
else if ($scope.device.mapType == null || $scope.device.mapType == "") {
|
else if ($scope.device.mapType == null || $scope.device.mapType == "") {
|
||||||
bridgeService.clearDevice();
|
bridgeService.clearDevice();
|
||||||
@@ -1220,8 +1229,8 @@ app.controller('HarmonyController', function ($scope, $location, $http, bridgeSe
|
|||||||
$scope.device.name = harmonydevice.device.label;
|
$scope.device.name = harmonydevice.device.label;
|
||||||
$scope.device.mapType = "harmonyButton";
|
$scope.device.mapType = "harmonyButton";
|
||||||
$scope.device.mapId = harmonydevice.device.id + "-" + actionOn.command;
|
$scope.device.mapId = harmonydevice.device.id + "-" + actionOn.command;
|
||||||
$scope.device.onUrl = "[{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + actionOn.command + "\"}]";
|
$scope.device.onUrl = "[{\"item\":{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + actionOn.command + "\"}]";
|
||||||
$scope.device.offUrl = "[{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + actionOff.command + "\"}]";
|
$scope.device.offUrl = "[{\"item\":{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + actionOff.command + "\"}]";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user