mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-19 00:20:26 +00:00
Finished draft HAL integration for lights type only
This commit is contained in:
@@ -10,6 +10,7 @@ import com.bwssystems.HABridge.hue.HueMulator;
|
||||
import com.bwssystems.HABridge.upnp.UpnpListener;
|
||||
import com.bwssystems.HABridge.upnp.UpnpSettingsResource;
|
||||
import com.bwssystems.NestBridge.NestHome;
|
||||
import com.bwssystems.hal.HalHome;
|
||||
import com.bwssystems.harmony.HarmonyHome;
|
||||
import com.bwssystems.hue.HueHome;
|
||||
|
||||
@@ -36,6 +37,7 @@ public class HABridge {
|
||||
HarmonyHome harmonyHome;
|
||||
NestHome nestHome;
|
||||
HueHome hueHome;
|
||||
HalHome halHome;
|
||||
HueMulator theHueMulator;
|
||||
UpnpSettingsResource theSettingResponder;
|
||||
UpnpListener theUpnpListener;
|
||||
@@ -66,8 +68,10 @@ public class HABridge {
|
||||
nestHome = new NestHome(bridgeSettings.getBridgeSettingsDescriptor());
|
||||
//setup the hue passtrhu configuration if available
|
||||
hueHome = new HueHome(bridgeSettings.getBridgeSettingsDescriptor());
|
||||
//setup the hal configuration if available
|
||||
halHome = new HalHome(bridgeSettings.getBridgeSettingsDescriptor());
|
||||
// setup the class to handle the resource setup rest api
|
||||
theResources = new DeviceResource(bridgeSettings.getBridgeSettingsDescriptor(), harmonyHome, nestHome, hueHome);
|
||||
theResources = new DeviceResource(bridgeSettings.getBridgeSettingsDescriptor(), harmonyHome, nestHome, hueHome, halHome);
|
||||
// setup the class to handle the hue emulator rest api
|
||||
theHueMulator = new HueMulator(bridgeSettings.getBridgeSettingsDescriptor(), theResources.getDeviceRepository(), harmonyHome, nestHome, hueHome);
|
||||
theHueMulator.setupServer();
|
||||
|
||||
@@ -44,7 +44,7 @@ public class DeviceResource {
|
||||
private HalHome halHome;
|
||||
private static final Set<String> supportedVerbs = new HashSet<>(Arrays.asList("get", "put", "post"));
|
||||
|
||||
public DeviceResource(BridgeSettingsDescriptor theSettings, HarmonyHome theHarmonyHome, NestHome aNestHome, HueHome aHueHome) {
|
||||
public DeviceResource(BridgeSettingsDescriptor theSettings, HarmonyHome theHarmonyHome, NestHome aNestHome, HueHome aHueHome, HalHome aHalHome) {
|
||||
this.deviceRepository = new DeviceRepository(theSettings.getUpnpDeviceDb());
|
||||
|
||||
if(theSettings.isValidVera())
|
||||
@@ -68,7 +68,7 @@ public class DeviceResource {
|
||||
this.hueHome = null;
|
||||
|
||||
if(theSettings.isValidHal())
|
||||
this.hueHome = aHueHome;
|
||||
this.halHome = aHalHome;
|
||||
else
|
||||
this.halHome = null;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public class HalHome {
|
||||
hals = new HashMap<String, HalInfo>();
|
||||
if(!bridgeSettings.isValidHal())
|
||||
return;
|
||||
Iterator<NamedIP> theList = bridgeSettings.getHarmonyAddress().getDevices().iterator();
|
||||
Iterator<NamedIP> theList = bridgeSettings.getHaladdress().getDevices().iterator();
|
||||
while(theList.hasNext()) {
|
||||
NamedIP aHal = theList.next();
|
||||
try {
|
||||
|
||||
@@ -221,6 +221,9 @@ public final class TextStringFormatter {
|
||||
public static String forQuerySpace(String aURL) {
|
||||
return aURL.replace(" ", "\u0020");
|
||||
}
|
||||
public static String forQuerySpaceUrl(String aURL) {
|
||||
return aURL.replace(" ", "%20");
|
||||
}
|
||||
/**
|
||||
* Synonym for <tt>URLEncoder.encode(String, "UTF-8")</tt>.
|
||||
*
|
||||
|
||||
@@ -48,6 +48,18 @@ app.run( function (bridgeService) {
|
||||
bridgeService.getHABridgeVersion();
|
||||
});
|
||||
|
||||
String.prototype.replaceAll = function(search, replace)
|
||||
{
|
||||
//if replace is not sent, return original string otherwise it will
|
||||
//replace search string with 'undefined'.
|
||||
if (replace === undefined) {
|
||||
return this.toString();
|
||||
}
|
||||
|
||||
return this.replace(new RegExp('[' + search + ']', 'g'), replace);
|
||||
};
|
||||
|
||||
|
||||
app.service('bridgeService', function ($http, $window, ngToast) {
|
||||
var self = this;
|
||||
this.state = {base: window.location.origin + "/api/devices", bridgelocation: window.location.origin, systemsbase: window.location.origin + "/system", huebase: window.location.origin + "/api", configs: [], backups: [], devices: [], device: [], mapandid: [], type: "", settings: [], myToastMsg: [], logMsgs: [], loggerInfo: [], olddevicename: "", logShowAll: false, isInControl: false, showVera: false, showHarmony: false, showNest: false, showHue: false, showHal: false, habridgeversion: ""};
|
||||
@@ -1323,35 +1335,38 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic
|
||||
|
||||
$scope.buildDeviceUrls = function (haldevice, dim_control) {
|
||||
bridgeService.clearDevice();
|
||||
$scope.device = $scope.bridge.device;
|
||||
$scope.device.deviceType = "switch";
|
||||
$scope.device.name = haldevice.haldevicename;
|
||||
$scope.device.targetDevice = haldevice.halname;
|
||||
$scope.device.mapType = "halDevice";
|
||||
$scope.device.mapId = haldevice.haldevicename + "-" + haldevice.halname;
|
||||
if(dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0)
|
||||
$scope.device.dimUrl = "http://" + haldevice.veraaddress
|
||||
$scope.device.dimUrl = "http://" + haldevice.haladdress
|
||||
+ "/DeviceService!DeviceName="
|
||||
+ haldevice.haldevicename
|
||||
+ haldevice.haldevicename.replaceAll(" ", "%20")
|
||||
+ "!DeviceCmd=SetDevice!DeviceValue=Dim!DevicePercent="
|
||||
+ dim_control
|
||||
+ "?Token="
|
||||
+ $scope.bridge.settings.haltoken;
|
||||
else
|
||||
$scope.device.dimUrl = "http://" + veradevice.veraaddress
|
||||
$scope.device.dimUrl = "http://" + haldevice.haladdress
|
||||
+ "/DeviceService!DeviceName="
|
||||
+ haldevice.haldevicename
|
||||
+ haldevice.haldevicename.replaceAll(" ", "%20")
|
||||
+ "!DeviceCmd=SetDevice!DeviceValue=On?Token="
|
||||
+ $scope.bridge.settings.haltoken;
|
||||
$scope.device.onUrl = "http://" + veradevice.veraaddress
|
||||
$scope.device.onUrl = "http://" + haldevice.haladdress
|
||||
+ "/DeviceService!DeviceName="
|
||||
+ haldevice.haldevicename
|
||||
+ haldevice.haldevicename.replaceAll(" ", "%20")
|
||||
+ "!DeviceCmd=SetDevice!DeviceValue=On?Token="
|
||||
+ $scope.bridge.settings.haltoken;;
|
||||
$scope.device.offUrl = "http://" + veradevice.veraaddress
|
||||
+ $scope.bridge.settings.haltoken;
|
||||
$scope.device.offUrl = "http://" + haldevice.haladdress
|
||||
+ "/DeviceService!DeviceName="
|
||||
+ haldevice.haldevicename
|
||||
+ haldevice.haldevicename.replaceAll(" ", "%20")
|
||||
+ "!DeviceCmd=SetDevice!DeviceValue=Off?Token="
|
||||
+ $scope.bridge.settings.haltoken;;
|
||||
+ $scope.bridge.settings.haltoken;
|
||||
|
||||
|
||||
};
|
||||
|
||||
$scope.addDevice = function () {
|
||||
@@ -1373,9 +1388,9 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic
|
||||
$scope.bulkAddDevices = function(dim_control) {
|
||||
var devicesList = [];
|
||||
for(var i = 0; i < $scope.bulk.devices.length; i++) {
|
||||
for(var x = 0; x < bridgeService.state.veradevices.length; x++) {
|
||||
if(bridgeService.state.veradevices[x].id == $scope.bulk.devices[i]) {
|
||||
$scope.buildDeviceUrls(bridgeService.state.veradevices[x],dim_control);
|
||||
for(var x = 0; x < bridgeService.state.haldevices.length; x++) {
|
||||
if(bridgeService.state.haldevices[x].id == $scope.bulk.devices[i]) {
|
||||
$scope.buildDeviceUrls(bridgeService.state.haldevices[x],dim_control);
|
||||
devicesList[i] = {
|
||||
name: $scope.device.name,
|
||||
mapId: $scope.device.mapId,
|
||||
@@ -1396,7 +1411,7 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic
|
||||
bridgeService.bulkAddDevice(devicesList);
|
||||
$scope.clearDevice();
|
||||
bridgeService.viewDevices();
|
||||
bridgeService.HalVeraDevices();
|
||||
bridgeService.viewHalDevices();
|
||||
$scope.bulk = { devices: [] };
|
||||
};
|
||||
|
||||
@@ -1664,6 +1679,34 @@ app.filter('unavailableHueDeviceId', function(bridgeService) {
|
||||
}
|
||||
});
|
||||
|
||||
app.filter('availableHalDeviceId', function(bridgeService) {
|
||||
return function(input) {
|
||||
var out = [];
|
||||
if(input == null)
|
||||
return out;
|
||||
for (var i = 0; i < input.length; i++) {
|
||||
if(!bridgeService.findDeviceByMapId(input[i].id, input[i].haldevicename, "halDevice")){
|
||||
out.push(input[i]);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
});
|
||||
|
||||
app.filter('unavailableHalDeviceId', function(bridgeService) {
|
||||
return function(input) {
|
||||
var out = [];
|
||||
if(input == null)
|
||||
return out;
|
||||
for (var i = 0; i < input.length; i++) {
|
||||
if(bridgeService.findDeviceByMapId(input[i].id, input[i].haldevicename, "halDevice")){
|
||||
out.push(input[i]);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
});
|
||||
|
||||
app.filter('configuredButtons', function() {
|
||||
return function(input) {
|
||||
var out = [];
|
||||
|
||||
@@ -199,7 +199,7 @@
|
||||
<tr>
|
||||
<td>HAL Token</td>
|
||||
<td><input id="bridge-settings-haltoken" class="form-control" type="password"
|
||||
ng-model="bridge.settings.halpwd" placeholder="thetoken"></td>
|
||||
ng-model="bridge.settings.haltoken" placeholder="thetoken"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Nest Username</td>
|
||||
|
||||
Reference in New Issue
Block a user