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.UpnpListener;
|
||||||
import com.bwssystems.HABridge.upnp.UpnpSettingsResource;
|
import com.bwssystems.HABridge.upnp.UpnpSettingsResource;
|
||||||
import com.bwssystems.NestBridge.NestHome;
|
import com.bwssystems.NestBridge.NestHome;
|
||||||
|
import com.bwssystems.hal.HalHome;
|
||||||
import com.bwssystems.harmony.HarmonyHome;
|
import com.bwssystems.harmony.HarmonyHome;
|
||||||
import com.bwssystems.hue.HueHome;
|
import com.bwssystems.hue.HueHome;
|
||||||
|
|
||||||
@@ -36,6 +37,7 @@ public class HABridge {
|
|||||||
HarmonyHome harmonyHome;
|
HarmonyHome harmonyHome;
|
||||||
NestHome nestHome;
|
NestHome nestHome;
|
||||||
HueHome hueHome;
|
HueHome hueHome;
|
||||||
|
HalHome halHome;
|
||||||
HueMulator theHueMulator;
|
HueMulator theHueMulator;
|
||||||
UpnpSettingsResource theSettingResponder;
|
UpnpSettingsResource theSettingResponder;
|
||||||
UpnpListener theUpnpListener;
|
UpnpListener theUpnpListener;
|
||||||
@@ -66,8 +68,10 @@ public class HABridge {
|
|||||||
nestHome = new NestHome(bridgeSettings.getBridgeSettingsDescriptor());
|
nestHome = new NestHome(bridgeSettings.getBridgeSettingsDescriptor());
|
||||||
//setup the hue passtrhu configuration if available
|
//setup the hue passtrhu configuration if available
|
||||||
hueHome = new HueHome(bridgeSettings.getBridgeSettingsDescriptor());
|
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
|
// 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
|
// setup the class to handle the hue emulator rest api
|
||||||
theHueMulator = new HueMulator(bridgeSettings.getBridgeSettingsDescriptor(), theResources.getDeviceRepository(), harmonyHome, nestHome, hueHome);
|
theHueMulator = new HueMulator(bridgeSettings.getBridgeSettingsDescriptor(), theResources.getDeviceRepository(), harmonyHome, nestHome, hueHome);
|
||||||
theHueMulator.setupServer();
|
theHueMulator.setupServer();
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public class DeviceResource {
|
|||||||
private HalHome halHome;
|
private HalHome halHome;
|
||||||
private static final Set<String> supportedVerbs = new HashSet<>(Arrays.asList("get", "put", "post"));
|
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());
|
this.deviceRepository = new DeviceRepository(theSettings.getUpnpDeviceDb());
|
||||||
|
|
||||||
if(theSettings.isValidVera())
|
if(theSettings.isValidVera())
|
||||||
@@ -68,7 +68,7 @@ public class DeviceResource {
|
|||||||
this.hueHome = null;
|
this.hueHome = null;
|
||||||
|
|
||||||
if(theSettings.isValidHal())
|
if(theSettings.isValidHal())
|
||||||
this.hueHome = aHueHome;
|
this.halHome = aHalHome;
|
||||||
else
|
else
|
||||||
this.halHome = null;
|
this.halHome = null;
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public class HalHome {
|
|||||||
hals = new HashMap<String, HalInfo>();
|
hals = new HashMap<String, HalInfo>();
|
||||||
if(!bridgeSettings.isValidHal())
|
if(!bridgeSettings.isValidHal())
|
||||||
return;
|
return;
|
||||||
Iterator<NamedIP> theList = bridgeSettings.getHarmonyAddress().getDevices().iterator();
|
Iterator<NamedIP> theList = bridgeSettings.getHaladdress().getDevices().iterator();
|
||||||
while(theList.hasNext()) {
|
while(theList.hasNext()) {
|
||||||
NamedIP aHal = theList.next();
|
NamedIP aHal = theList.next();
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -221,6 +221,9 @@ public final class TextStringFormatter {
|
|||||||
public static String forQuerySpace(String aURL) {
|
public static String forQuerySpace(String aURL) {
|
||||||
return aURL.replace(" ", "\u0020");
|
return aURL.replace(" ", "\u0020");
|
||||||
}
|
}
|
||||||
|
public static String forQuerySpaceUrl(String aURL) {
|
||||||
|
return aURL.replace(" ", "%20");
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Synonym for <tt>URLEncoder.encode(String, "UTF-8")</tt>.
|
* Synonym for <tt>URLEncoder.encode(String, "UTF-8")</tt>.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -48,6 +48,18 @@ app.run( function (bridgeService) {
|
|||||||
bridgeService.getHABridgeVersion();
|
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) {
|
app.service('bridgeService', function ($http, $window, ngToast) {
|
||||||
var self = this;
|
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: ""};
|
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) {
|
$scope.buildDeviceUrls = function (haldevice, dim_control) {
|
||||||
bridgeService.clearDevice();
|
bridgeService.clearDevice();
|
||||||
|
$scope.device = $scope.bridge.device;
|
||||||
$scope.device.deviceType = "switch";
|
$scope.device.deviceType = "switch";
|
||||||
$scope.device.name = haldevice.haldevicename;
|
$scope.device.name = haldevice.haldevicename;
|
||||||
$scope.device.targetDevice = haldevice.halname;
|
$scope.device.targetDevice = haldevice.halname;
|
||||||
$scope.device.mapType = "halDevice";
|
$scope.device.mapType = "halDevice";
|
||||||
$scope.device.mapId = haldevice.haldevicename + "-" + haldevice.halname;
|
$scope.device.mapId = haldevice.haldevicename + "-" + haldevice.halname;
|
||||||
if(dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0)
|
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="
|
+ "/DeviceService!DeviceName="
|
||||||
+ haldevice.haldevicename
|
+ haldevice.haldevicename.replaceAll(" ", "%20")
|
||||||
+ "!DeviceCmd=SetDevice!DeviceValue=Dim!DevicePercent="
|
+ "!DeviceCmd=SetDevice!DeviceValue=Dim!DevicePercent="
|
||||||
+ dim_control
|
+ dim_control
|
||||||
+ "?Token="
|
+ "?Token="
|
||||||
+ $scope.bridge.settings.haltoken;
|
+ $scope.bridge.settings.haltoken;
|
||||||
else
|
else
|
||||||
$scope.device.dimUrl = "http://" + veradevice.veraaddress
|
$scope.device.dimUrl = "http://" + haldevice.haladdress
|
||||||
+ "/DeviceService!DeviceName="
|
+ "/DeviceService!DeviceName="
|
||||||
+ haldevice.haldevicename
|
+ haldevice.haldevicename.replaceAll(" ", "%20")
|
||||||
+ "!DeviceCmd=SetDevice!DeviceValue=On?Token="
|
+ "!DeviceCmd=SetDevice!DeviceValue=On?Token="
|
||||||
+ $scope.bridge.settings.haltoken;
|
+ $scope.bridge.settings.haltoken;
|
||||||
$scope.device.onUrl = "http://" + veradevice.veraaddress
|
$scope.device.onUrl = "http://" + haldevice.haladdress
|
||||||
+ "/DeviceService!DeviceName="
|
+ "/DeviceService!DeviceName="
|
||||||
+ haldevice.haldevicename
|
+ haldevice.haldevicename.replaceAll(" ", "%20")
|
||||||
+ "!DeviceCmd=SetDevice!DeviceValue=On?Token="
|
+ "!DeviceCmd=SetDevice!DeviceValue=On?Token="
|
||||||
+ $scope.bridge.settings.haltoken;;
|
+ $scope.bridge.settings.haltoken;
|
||||||
$scope.device.offUrl = "http://" + veradevice.veraaddress
|
$scope.device.offUrl = "http://" + haldevice.haladdress
|
||||||
+ "/DeviceService!DeviceName="
|
+ "/DeviceService!DeviceName="
|
||||||
+ haldevice.haldevicename
|
+ haldevice.haldevicename.replaceAll(" ", "%20")
|
||||||
+ "!DeviceCmd=SetDevice!DeviceValue=Off?Token="
|
+ "!DeviceCmd=SetDevice!DeviceValue=Off?Token="
|
||||||
+ $scope.bridge.settings.haltoken;;
|
+ $scope.bridge.settings.haltoken;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.addDevice = function () {
|
$scope.addDevice = function () {
|
||||||
@@ -1373,9 +1388,9 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic
|
|||||||
$scope.bulkAddDevices = function(dim_control) {
|
$scope.bulkAddDevices = function(dim_control) {
|
||||||
var devicesList = [];
|
var devicesList = [];
|
||||||
for(var i = 0; i < $scope.bulk.devices.length; i++) {
|
for(var i = 0; i < $scope.bulk.devices.length; i++) {
|
||||||
for(var x = 0; x < bridgeService.state.veradevices.length; x++) {
|
for(var x = 0; x < bridgeService.state.haldevices.length; x++) {
|
||||||
if(bridgeService.state.veradevices[x].id == $scope.bulk.devices[i]) {
|
if(bridgeService.state.haldevices[x].id == $scope.bulk.devices[i]) {
|
||||||
$scope.buildDeviceUrls(bridgeService.state.veradevices[x],dim_control);
|
$scope.buildDeviceUrls(bridgeService.state.haldevices[x],dim_control);
|
||||||
devicesList[i] = {
|
devicesList[i] = {
|
||||||
name: $scope.device.name,
|
name: $scope.device.name,
|
||||||
mapId: $scope.device.mapId,
|
mapId: $scope.device.mapId,
|
||||||
@@ -1396,7 +1411,7 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic
|
|||||||
bridgeService.bulkAddDevice(devicesList);
|
bridgeService.bulkAddDevice(devicesList);
|
||||||
$scope.clearDevice();
|
$scope.clearDevice();
|
||||||
bridgeService.viewDevices();
|
bridgeService.viewDevices();
|
||||||
bridgeService.HalVeraDevices();
|
bridgeService.viewHalDevices();
|
||||||
$scope.bulk = { devices: [] };
|
$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() {
|
app.filter('configuredButtons', function() {
|
||||||
return function(input) {
|
return function(input) {
|
||||||
var out = [];
|
var out = [];
|
||||||
|
|||||||
@@ -199,7 +199,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>HAL Token</td>
|
<td>HAL Token</td>
|
||||||
<td><input id="bridge-settings-haltoken" class="form-control" type="password"
|
<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>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Nest Username</td>
|
<td>Nest Username</td>
|
||||||
|
|||||||
Reference in New Issue
Block a user