From f27d90586921a524ae4f2c1b494fe830dba65e27 Mon Sep 17 00:00:00 2001 From: bsamuels Date: Tue, 2 Jan 2018 16:20:51 -0600 Subject: [PATCH] Updated FHEM integration for testing --- pom.xml | 2 +- .../bwssystems/HABridge/BridgeSettings.java | 1 + .../HABridge/BridgeSettingsDescriptor.java | 26 +++ .../bwssystems/HABridge/DeviceMapTypes.java | 2 + .../com/bwssystems/HABridge/HomeManager.java | 7 +- .../devicemanagmeent/DeviceResource.java | 6 + .../HABridge/plugins/fhem/FHEMDevice.java | 7 +- .../HABridge/plugins/fhem/FHEMHome.java | 6 +- .../HABridge/plugins/fhem/FHEMInstance.java | 18 +- .../plugins/openhab/OpenHABInstance.java | 2 +- src/main/resources/public/scripts/app.js | 204 +++++++++++++++++- .../resources/public/views/configuration.html | 1 + .../public/views/domoticzdevice.html | 1 + .../resources/public/views/editdevice.html | 1 + .../resources/public/views/fhemdevice.html | 142 ++++++++++++ .../resources/public/views/fibarodevice.html | 1 + .../resources/public/views/fibaroscene.html | 1 + .../resources/public/views/haldevice.html | 1 + .../public/views/harmonyactivity.html | 1 + .../resources/public/views/harmonydevice.html | 1 + .../resources/public/views/hassdevice.html | 1 + .../public/views/homewizarddevice.html | 1 + .../resources/public/views/huedevice.html | 1 + .../resources/public/views/lifxdevice.html | 1 + src/main/resources/public/views/logs.html | 1 + .../resources/public/views/mqttpublish.html | 1 + .../resources/public/views/nestactions.html | 1 + .../resources/public/views/openhabdevice.html | 1 + .../resources/public/views/somfydevice.html | 1 + src/main/resources/public/views/system.html | 9 +- .../resources/public/views/veradevice.html | 1 + .../resources/public/views/verascene.html | 1 + .../fhem/test/FHEMInstanceConstructor.java | 7 +- 33 files changed, 434 insertions(+), 24 deletions(-) create mode 100644 src/main/resources/public/views/fhemdevice.html diff --git a/pom.xml b/pom.xml index 8658c18..67a7724 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.bwssystems.HABridge ha-bridge - 5.1.0d + 5.1.0e jar HA Bridge diff --git a/src/main/java/com/bwssystems/HABridge/BridgeSettings.java b/src/main/java/com/bwssystems/HABridge/BridgeSettings.java index 9ae4d7f..eef0d7e 100644 --- a/src/main/java/com/bwssystems/HABridge/BridgeSettings.java +++ b/src/main/java/com/bwssystems/HABridge/BridgeSettings.java @@ -211,6 +211,7 @@ public class BridgeSettings extends BackupHandler { theBridgeSettings.setSomfyconfigured(theBridgeSettings.isValidSomfy()); theBridgeSettings.setHomeWizardConfigured(theBridgeSettings.isValidHomeWizard()); theBridgeSettings.setOpenhabconfigured(theBridgeSettings.isValidOpenhab()); + theBridgeSettings.setFhemconfigured(theBridgeSettings.isValidFhem()); // Lifx is either configured or not, so it does not need an update. if(serverPortOverride != null) theBridgeSettings.setServerPort(serverPortOverride); diff --git a/src/main/java/com/bwssystems/HABridge/BridgeSettingsDescriptor.java b/src/main/java/com/bwssystems/HABridge/BridgeSettingsDescriptor.java index db96433..2549e68 100644 --- a/src/main/java/com/bwssystems/HABridge/BridgeSettingsDescriptor.java +++ b/src/main/java/com/bwssystems/HABridge/BridgeSettingsDescriptor.java @@ -105,6 +105,9 @@ public class BridgeSettingsDescriptor { @SerializedName("upnpsenddelay") @Expose private Integer upnpsenddelay; + @SerializedName("fhemaddress") + @Expose + private IpList fhemaddress; private boolean settingsChanged; private boolean veraconfigured; @@ -120,6 +123,7 @@ public class BridgeSettingsDescriptor { private boolean lifxconfigured; private boolean homewizardconfigured; private boolean openhabconfigured; + private boolean fhemconfigured; // Deprecated settings private String haltoken; @@ -447,6 +451,18 @@ public class BridgeSettingsDescriptor { public void setUpnpsenddelay(Integer upnpsenddelay) { this.upnpsenddelay = upnpsenddelay; } + public IpList getFhemaddress() { + return fhemaddress; + } + public void setFhemaddress(IpList fhemaddress) { + this.fhemaddress = fhemaddress; + } + public boolean isFhemconfigured() { + return fhemconfigured; + } + public void setFhemconfigured(boolean fhemconfigured) { + this.fhemconfigured = fhemconfigured; + } public Boolean isValidVera() { if(this.getVeraAddress() == null || this.getVeraAddress().getDevices().size() <= 0) return false; @@ -564,4 +580,14 @@ public class BridgeSettingsDescriptor { return true; } + public Boolean isValidFhem() { + if(this.getFhemaddress() == null || this.getFhemaddress().getDevices().size() <= 0) + return false; + + List devicesList = this.getFhemaddress().getDevices(); + if(devicesList.get(0).getIp().contains(Configuration.DEFAULT_ADDRESS)) + return false; + + return true; + } } diff --git a/src/main/java/com/bwssystems/HABridge/DeviceMapTypes.java b/src/main/java/com/bwssystems/HABridge/DeviceMapTypes.java index 9167437..80b1f33 100644 --- a/src/main/java/com/bwssystems/HABridge/DeviceMapTypes.java +++ b/src/main/java/com/bwssystems/HABridge/DeviceMapTypes.java @@ -32,6 +32,7 @@ public class DeviceMapTypes { public final static String[] SOMFY_DEVICE = { "somfyDevice", "Somfy Device"}; public final static String[] LIFX_DEVICE = { "lifxDevice", "LIFX Device"}; public final static String[] OPENHAB_DEVICE = { "openhabDevice", "OpenHAB Device"}; + public final static String[] FHEM_DEVICE = { "fhemDevice", "FHEM Device"}; public final static int typeIndex = 0; public final static int displayIndex = 1; @@ -65,6 +66,7 @@ public class DeviceMapTypes { deviceMapTypes.add(FIBARO_SCENE); deviceMapTypes.add(SOMFY_DEVICE); deviceMapTypes.add(OPENHAB_DEVICE); + deviceMapTypes.add(FHEM_DEVICE); } public static int getTypeIndex() { return typeIndex; diff --git a/src/main/java/com/bwssystems/HABridge/HomeManager.java b/src/main/java/com/bwssystems/HABridge/HomeManager.java index 6dbd3dd..5fcc3e3 100644 --- a/src/main/java/com/bwssystems/HABridge/HomeManager.java +++ b/src/main/java/com/bwssystems/HABridge/HomeManager.java @@ -11,6 +11,7 @@ import com.bwssystems.HABridge.devicemanagmeent.ResourceHandler; import com.bwssystems.HABridge.plugins.NestBridge.NestHome; import com.bwssystems.HABridge.plugins.domoticz.DomoticzHome; import com.bwssystems.HABridge.plugins.exec.CommandHome; +import com.bwssystems.HABridge.plugins.fhem.FHEMHome; import com.bwssystems.HABridge.plugins.hal.HalHome; import com.bwssystems.HABridge.plugins.harmony.HarmonyHome; import com.bwssystems.HABridge.plugins.hass.HassHome; @@ -106,7 +107,7 @@ public class HomeManager { aHome = new DomoticzHome(bridgeSettings); homeList.put(DeviceMapTypes.DOMOTICZ_DEVICE[DeviceMapTypes.typeIndex], aHome); resourceList.put(DeviceMapTypes.DOMOTICZ_DEVICE[DeviceMapTypes.typeIndex], aHome); - //setup the Somfy configuration if available + //setup the Somfy configuration if availableOPENHAB aHome = new SomfyHome(bridgeSettings); homeList.put(DeviceMapTypes.SOMFY_DEVICE[DeviceMapTypes.typeIndex], aHome); resourceList.put(DeviceMapTypes.SOMFY_DEVICE[DeviceMapTypes.typeIndex], aHome); @@ -118,6 +119,10 @@ public class HomeManager { aHome = new OpenHABHome(bridgeSettings); resourceList.put(DeviceMapTypes.OPENHAB_DEVICE[DeviceMapTypes.typeIndex], aHome); homeList.put(DeviceMapTypes.OPENHAB_DEVICE[DeviceMapTypes.typeIndex], aHome); + //setup the OpenHAB configuration if available + aHome = new FHEMHome(bridgeSettings); + resourceList.put(DeviceMapTypes.FHEM_DEVICE[DeviceMapTypes.typeIndex], aHome); + homeList.put(DeviceMapTypes.FHEM_DEVICE[DeviceMapTypes.typeIndex], aHome); } public Home findHome(String type) { diff --git a/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java b/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java index cca67ad..ed598c6 100644 --- a/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java +++ b/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java @@ -321,6 +321,12 @@ public class DeviceResource { return homeManager.findResource(DeviceMapTypes.OPENHAB_DEVICE[DeviceMapTypes.typeIndex]).getItems(DeviceMapTypes.OPENHAB_DEVICE[DeviceMapTypes.typeIndex]); }, new JsonTransformer()); + get (API_CONTEXT + "/fhem/devices", "application/json", (request, response) -> { + log.debug("Get FHEM devices"); + response.status(HttpStatus.SC_OK); + return homeManager.findResource(DeviceMapTypes.FHEM_DEVICE[DeviceMapTypes.typeIndex]).getItems(DeviceMapTypes.FHEM_DEVICE[DeviceMapTypes.typeIndex]); + }, new JsonTransformer()); + get (API_CONTEXT + "/map/types", "application/json", (request, response) -> { log.debug("Get map types"); return new DeviceMapTypes().getDeviceMapTypes(); diff --git a/src/main/java/com/bwssystems/HABridge/plugins/fhem/FHEMDevice.java b/src/main/java/com/bwssystems/HABridge/plugins/fhem/FHEMDevice.java index 7d64389..aa68ae0 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/fhem/FHEMDevice.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/fhem/FHEMDevice.java @@ -4,7 +4,7 @@ public class FHEMDevice { private String address; private String name; - private FHEMItem item; + private Result item; public String getAddress() { return address; } @@ -17,11 +17,10 @@ public class FHEMDevice { public void setName(String name) { this.name = name; } - public FHEMItem getItem() { + public Result getItem() { return item; } - public void setItem(FHEMItem item) { + public void setItem(Result item) { this.item = item; } - } diff --git a/src/main/java/com/bwssystems/HABridge/plugins/fhem/FHEMHome.java b/src/main/java/com/bwssystems/HABridge/plugins/fhem/FHEMHome.java index 8850c7d..a26a818 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/fhem/FHEMHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/fhem/FHEMHome.java @@ -131,7 +131,7 @@ public class FHEMHome implements Home { if(!validFhem) return null; - log.debug("consolidating devices for java.lang.String"); + log.debug("consolidating devices for FHEM"); List theResponse = null; Iterator keys = fhemMap.keySet().iterator(); List deviceList = new ArrayList(); @@ -160,12 +160,12 @@ public class FHEMHome implements Home { @Override public Home createHome(BridgeSettings bridgeSettings) { fhemMap = null; - validFhem = bridgeSettings.getBridgeSettingsDescriptor().isValidOpenhab(); + validFhem = bridgeSettings.getBridgeSettingsDescriptor().isValidFhem(); log.info("FHEM Home created." + (validFhem ? "" : " No FHEMs configured.")); if(validFhem) { fhemMap = new HashMap(); httpClient = HTTPHome.getHandler(); - Iterator theList = bridgeSettings.getBridgeSettingsDescriptor().getOpenhabaddress().getDevices().iterator(); + Iterator theList = bridgeSettings.getBridgeSettingsDescriptor().getFhemaddress().getDevices().iterator(); while(theList.hasNext() && validFhem) { NamedIP aFhem = theList.next(); try { diff --git a/src/main/java/com/bwssystems/HABridge/plugins/fhem/FHEMInstance.java b/src/main/java/com/bwssystems/HABridge/plugins/fhem/FHEMInstance.java index 60dc722..85a1f72 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/fhem/FHEMInstance.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/fhem/FHEMInstance.java @@ -49,7 +49,7 @@ public class FHEMInstance { public List getDevices(HTTPHandler httpClient) { List deviceList = null; - FHEMItem[] theFhemStates; + FHEMItem theFhemStates; String theUrl = null; String theData; NameValue[] headers = null; @@ -61,24 +61,25 @@ public class FHEMInstance { theUrl = theUrl + theFhem.getUsername() + ":" + theFhem.getPassword() + "@"; } theUrl = theUrl + theFhem.getIp() + ":" + theFhem.getPort() + "/fhem?cmd=jsonlist2"; + if(theFhem.getWebhook() != null && !theFhem.getWebhook().trim().isEmpty()) + theUrl = theUrl + "%20room=" + theFhem.getWebhook().trim(); theData = httpClient.doHttpRequest(theUrl, HttpGet.METHOD_NAME, "application/json", null, headers); if(theData != null) { log.debug("GET FHEM States - data: " + theData); theData = getJSONData(theData); - theFhemStates = new Gson().fromJson(theData, FHEMItem[].class); + theFhemStates = new Gson().fromJson(theData, FHEMItem.class); if(theFhemStates == null) { - log.warn("Cannot get an devices for FHEM " + theFhem.getName() + " as response is not parsable."); + log.warn("Cannot get any devices for FHEM " + theFhem.getName() + " as response is not parsable."); } else { deviceList = new ArrayList(); - for (int i = 0; i < theFhemStates.length; i++) { + for (Result aResult:theFhemStates.getResults()) { FHEMDevice aNewFhemDeviceDevice = new FHEMDevice(); - aNewFhemDeviceDevice.setItem(theFhemStates[i]); + aNewFhemDeviceDevice.setItem(aResult); aNewFhemDeviceDevice.setAddress(theFhem.getIp() + ":" + theFhem.getPort()); aNewFhemDeviceDevice.setName(theFhem.getName()); deviceList.add(aNewFhemDeviceDevice); - } } } @@ -91,7 +92,10 @@ public class FHEMInstance { String theData; theData = response.substring(response.indexOf("
") + 4);
 		theData = theData.substring(1, theData.indexOf("
") - 1); - // TODO Fix stripping out new line chars + theData = theData.replace("\n", ""); + theData = theData.replace("\r", ""); + theData = theData.replace("", "\\\">"); return theData; } diff --git a/src/main/java/com/bwssystems/HABridge/plugins/openhab/OpenHABInstance.java b/src/main/java/com/bwssystems/HABridge/plugins/openhab/OpenHABInstance.java index 8e5c295..08831d1 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/openhab/OpenHABInstance.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/openhab/OpenHABInstance.java @@ -66,7 +66,7 @@ public class OpenHABInstance { log.debug("GET OpenHAB States - data: " + theData); theOpenhabStates = new Gson().fromJson(theData, OpenHABItem[].class); if(theOpenhabStates == null) { - log.warn("Cannot get an devices for OpenHAB " + theOpenHAB.getName() + " as response is not parsable."); + log.warn("Cannot get any devices for OpenHAB " + theOpenHAB.getName() + " as response is not parsable."); } else { deviceList = new ArrayList(); diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index e42740a..3744aa1 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -83,6 +83,10 @@ app.config (function ($locationProvider, $routeProvider) { templateUrl: 'views/openhabdevice.html', controller: 'OpenHABController', requiresAuthentication: true + }).when ('/fhemdevices', { + templateUrl: 'views/fhemdevice.html', + controller: 'FhemController', + requiresAuthentication: true }).when ('/login', { templateUrl: 'views/login.html', controller: 'LoginController' @@ -151,7 +155,7 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n this.state = {base: "./api/devices", bridgelocation: ".", systemsbase: "./system", huebase: "./api", configs: [], backups: [], devices: [], device: {}, mapandid: [], type: "", settings: [], myToastMsg: [], logMsgs: [], loggerInfo: [], mapTypes: [], olddevicename: "", logShowAll: false, isInControl: false, showVera: false, showFibaro: false, showHarmony: false, showNest: false, showHue: false, showHal: false, showMqtt: false, showHass: false, - showHomeWizard: false, showDomoticz: false, showSomfy: false, showLifx: false, showOpenHAB: false, habridgeversion: {}, viewDevId: "", queueDevId: "", securityInfo: {}, filterDevicesByIpAddress: null, + showHomeWizard: false, showDomoticz: false, showSomfy: false, showLifx: false, showOpenHAB: false, showFHEM: false, habridgeversion: {}, viewDevId: "", queueDevId: "", securityInfo: {}, filterDevicesByIpAddress: null, filterDevicesOnlyFiltered: false, filterDeviceType: null}; this.displayWarn = function(errorTitle, error) { @@ -567,6 +571,11 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n return; } + this.updateShowFhem = function () { + this.state.showFHEM = self.state.settings.fhemconfigured; + return; + } + this.loadBridgeSettings = function () { return $http.get(this.state.systemsbase + "/settings").then( function (response) { @@ -584,6 +593,7 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n self.updateShowSomfy(); self.updateShowLifx(); self.updateShowOpenHAB(); + self.updateShowFhem(); }, function (error) { if (error.status === 401) @@ -907,6 +917,22 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n ); }; + this.viewFhemDevices = function () { + if (!this.state.showFHEM) + return; + return $http.get(this.state.base + "/fhem/devices").then( + function (response) { + self.state.fhemdevices = response.data; + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else + self.displayWarn("Get FHEM Devices Error: ", error); + } + ); + }; + this.formatCallItem = function (currentItem) { if(!currentItem.startsWith("{\"item") && !currentItem.startsWith("[{\"item")) { if (currentItem.startsWith("[") || currentItem.startsWith("{")) @@ -1631,6 +1657,27 @@ app.controller ('SystemController', function ($scope, $location, bridgeService, } }; + $scope.addFhemtoSettings = function (newfhemname, newfhemip, newfhemport, newfhemusername, newfhempassword, newfhemwebhook, newfhemsecure) { + if($scope.bridge.settings.fhemaddress === undefined || $scope.bridge.settings.fhemaddress === null) { + $scope.bridge.settings.fhemaddress = { devices: [] }; + } + var newfhem = {name: newfhemname, ip: newfhemip, port: newfhemport, username: newfhemusername, password: newfhempassword, secure: newfhemsecure, webhook: newfhemwebhook } + $scope.bridge.settings.fhemaddress.devices.push(newfhem); + $scope.newfhemname = null; + $scope.newfhemip = null; + $scope.newfhemport = null; + $scope.newfhemusername = null; + $scope.newfhempassword = null; + $scope.newfhemwebhook = null; + }; + $scope.removeFhemtoSettings = function (fhemname, fhemip) { + for(var i = $scope.bridge.settings.fhemaddress.devices.length - 1; i >= 0; i--) { + if($scope.bridge.settings.fhemaddress.devices[i].name === fhemname && $scope.bridge.settings.fhemaddress.devices[i].ip === fhemip) { + $scope.bridge.settings.fhemaddress.devices.splice(i, 1); + } + } + }; + $scope.bridgeReinit = function () { bridgeService.reinit(); }; @@ -3737,6 +3784,147 @@ app.controller('OpenHABController', function ($scope, $location, bridgeService, }; }); +app.controller('FhemController', function ($scope, $location, bridgeService, ngDialog) { + $scope.bridge = bridgeService.state; + $scope.device = bridgeService.state.device; + $scope.device_dim_control = ""; + $scope.bulk = { devices: [] }; + $scope.selectAll = false; + bridgeService.viewFhemDevices(); + $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; + $scope.buttonsVisible = false; + + $scope.clearDevice = function () { + bridgeService.clearDevice(); + $scope.device = bridgeService.state.device; + }; + + $scope.buildDeviceUrls = function (fhemdevice, dim_control, ondeviceaction, oninputdeviceaction, offdeviceaction, offinputdeviceaction, buildonly) { + var preCmd = "/fhem?cmd=set%20" + fhemdevice.item.name + "%20"; + if(fhemdevice.item.possibleSets.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 = null; + } + else + dimpayload = null; + if(fhemdevice.item.possibleSets.indexOf("RGB" >= 0)) { + if((dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0)) { + colorpayload = "{\"url\":\"http://" + fhemdevice.address + preCmd + "\",\"command\":\"RGB%20${color.rgbx}\"}"; + } + else + colorpayload = null; + } + else + colorpayload = null; + onpayload = "{\"url\":\"http://" + fhemdevice.address + preCmd + "\",\"command\":\"on\"}"; + offpayload = "{\"url\":\"http://" + fhemdevice.address + preCmd + "\",\"command\":\"off\"}"; + bridgeService.buildUrls(onpayload, dimpayload, offpayload, colorpayload, true, fhemdevice.item.name + "-" + fhemdevice.name, fhemdevice.item.name, fhemdevice.name, fhemdevice.item.type, "fhemDevice", null, null); + $scope.device = bridgeService.state.device; + if (!buildonly) { + bridgeService.editNewDevice($scope.device); + $location.path('/editdevice'); + } + }; + + $scope.bulkAddDevices = function(dim_control) { + var devicesList = []; + $scope.clearDevice(); + for(var i = 0; i < $scope.bulk.devices.length; i++) { + for(var x = 0; x < bridgeService.state.fhemdevices.length; x++) { + if(bridgeService.state.fhemdevices[x].devicename === $scope.bulk.devices[i]) { + $scope.buildDeviceUrls(bridgeService.state.fhemdevices[x],dim_control,true); + devicesList[i] = { + name: $scope.device.name, + mapId: $scope.device.mapId, + mapType: $scope.device.mapType, + deviceType: $scope.device.deviceType, + targetDevice: $scope.device.targetDevice, + onUrl: $scope.device.onUrl, + dimUrl: $scope.device.dimUrl, + offUrl: $scope.device.offUrl, + colorUrl: $scope.device.colorUrl, + headers: $scope.device.headers, + httpVerb: $scope.device.httpVerb, + contentType: $scope.device.contentType, + contentBody: $scope.device.contentBody, + contentBodyDim: $scope.device.contentBodyDim, + contentBodyOff: $scope.device.contentBodyOff + }; + $scope.clearDevice(); + } + } + } + bridgeService.bulkAddDevice(devicesList).then( + function () { + $scope.clearDevice(); + bridgeService.viewDevices(); + bridgeService.viewHalDevices(); + }, + function (error) { + bridgeService.displayWarn("Error adding fhem devices in bulk.", error) + } + ); + $scope.bulk = { devices: [] }; + $scope.selectAll = false; + }; + + $scope.toggleSelection = function toggleSelection(deviceId) { + var idx = $scope.bulk.devices.indexOf(deviceId); + + // is currently selected + if (idx > -1) { + $scope.bulk.devices.splice(idx, 1); + if($scope.bulk.devices.length === 0 && $scope.selectAll) + $scope.selectAll = false; + } + + // is newly selected + else { + $scope.bulk.devices.push(deviceId); + $scope.selectAll = true; + } + }; + + $scope.toggleSelectAll = function toggleSelectAll() { + if($scope.selectAll) { + $scope.selectAll = false; + $scope.bulk = { devices: [] }; + } + else { + $scope.selectAll = true; + for(var x = 0; x < bridgeService.state.fhemdevices.length; x++) { + if($scope.bulk.devices.indexOf(bridgeService.state.fhemdevices[x]) < 0) + $scope.bulk.devices.push(bridgeService.state.fhemdevices[x].devicename); + } + } + }; + + $scope.toggleButtons = function () { + $scope.buttonsVisible = !$scope.buttonsVisible; + if($scope.buttonsVisible) + $scope.imgButtonsUrl = "glyphicon glyphicon-minus"; + else + $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; + }; + + $scope.deleteDevice = function (device) { + $scope.bridge.device = device; + ngDialog.open({ + template: 'deleteDialog', + controller: 'DeleteDialogCtrl', + className: 'ngdialog-theme-default' + }); + }; + + $scope.editDevice = function (device) { + bridgeService.editDevice(device); + $location.path('/editdevice'); + }; +}); + app.controller('EditController', function ($scope, $location, bridgeService) { $scope.bridge = bridgeService.state; $scope.device = bridgeService.state.device; @@ -4168,6 +4356,20 @@ app.filter('configuredOpenHABItems', function (bridgeService) { } }); +app.filter('configuredFhemItems', function (bridgeService) { + return function(input) { + var out = []; + if(input === undefined || input === null || input.length === undefined) + return out; + for (var i = 0; i < input.length; i++) { + if (bridgeService.deviceContainsType(input[i], "fhem")) { + out.push(input[i]); + } + } + return out; + } +}); + app.filter('filterDevicesByRequester', function () { return function(input,search,mustContain,deviceType) { var out = []; diff --git a/src/main/resources/public/views/configuration.html b/src/main/resources/public/views/configuration.html index 5456ddd..6f59895 100644 --- a/src/main/resources/public/views/configuration.html +++ b/src/main/resources/public/views/configuration.html @@ -19,6 +19,7 @@
  • LIFX Devices
  • HomeWizard Devices
  • OpenHAB Devices
  • +
  • FHEM Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/domoticzdevice.html b/src/main/resources/public/views/domoticzdevice.html index bb3dbfe..829f0da 100644 --- a/src/main/resources/public/views/domoticzdevice.html +++ b/src/main/resources/public/views/domoticzdevice.html @@ -18,6 +18,7 @@
  • LIFX Devices
  • HomeWizard Devices
  • OpenHAB Devices
  • +
  • FHEM Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/editdevice.html b/src/main/resources/public/views/editdevice.html index 8fe6139..bdb0733 100644 --- a/src/main/resources/public/views/editdevice.html +++ b/src/main/resources/public/views/editdevice.html @@ -19,6 +19,7 @@
  • LIFX Devices
  • HomeWizard Devices
  • OpenHAB Devices
  • +
  • FHEM Devices
  • diff --git a/src/main/resources/public/views/fhemdevice.html b/src/main/resources/public/views/fhemdevice.html new file mode 100644 index 0000000..4ade752 --- /dev/null +++ b/src/main/resources/public/views/fhemdevice.html @@ -0,0 +1,142 @@ + + +
    +
    +

    FHEM Device List + ({{bridge.fhemdevices.length}})

    +
    +
    +

    For any FHEM Device, use the build action buttons + to generate the item addition information into the ha-bridge device and this will put you into the edit screen. Then + you can modify the name to anything you want that will be the keyword + for the Echo or Google Home. Also, you can go back to any helper tab and click a build + action button to add another item for a multi-command. After you are + done in the edit tab, click the 'Add Bridge Device' to finish that selection + setup. The 'Already Configured FHEM Devices' list below will show what + is already setup for your FHEM.

    +

    + Also, use this select menu for which type of dim control you would + like to be generated: +

    +

    Use the check boxes by the names to use the bulk addition + feature. Select your items and dim control type if wanted, then click + bulk add below. Your items will be added with on and off or dim and + off if selected with the name of the device from the FHEM.

    + + + + + + + + + + + + + + + + + + +
    Row + NameFHEMCapabilitiesBuild Actions
    {{$index+1}} + {{fhemdevice.item.name}}{{fhemdevice.name}}{{fhemdevice.item.possibleSets}} + +
    +
    + +
    +
    +
    +
    +

    + Already Configured FHEM Devices +

    +
    +
    + + + + + + + + + + + + + + + + + + + + + +
    RowNameCategoryFHEMMap IdActions
    {{$index+1}}{{device.name}}{{device.deviceType}}{{device.targetDevice}}{{device.mapId}} +

    + + +

    +
    +
    +
    +
    + diff --git a/src/main/resources/public/views/fibarodevice.html b/src/main/resources/public/views/fibarodevice.html index 881ff78..1ed4a29 100644 --- a/src/main/resources/public/views/fibarodevice.html +++ b/src/main/resources/public/views/fibarodevice.html @@ -18,6 +18,7 @@
  • LIFX Devices
  • HomeWizard Devices
  • OpenHAB Devices
  • +
  • FHEM Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/fibaroscene.html b/src/main/resources/public/views/fibaroscene.html index aa688ca..43d8759 100644 --- a/src/main/resources/public/views/fibaroscene.html +++ b/src/main/resources/public/views/fibaroscene.html @@ -18,6 +18,7 @@
  • LIFX Devices
  • HomeWizard Devices
  • OpenHAB Devices
  • +
  • FHEM Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/haldevice.html b/src/main/resources/public/views/haldevice.html index a5e5012..d0121bb 100644 --- a/src/main/resources/public/views/haldevice.html +++ b/src/main/resources/public/views/haldevice.html @@ -18,6 +18,7 @@
  • LIFX Devices
  • HomeWizard Devices
  • OpenHAB Devices
  • +
  • FHEM Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/harmonyactivity.html b/src/main/resources/public/views/harmonyactivity.html index ac7ea6d..94fd1dc 100644 --- a/src/main/resources/public/views/harmonyactivity.html +++ b/src/main/resources/public/views/harmonyactivity.html @@ -18,6 +18,7 @@
  • LIFX Devices
  • HomeWizard Devices
  • OpenHAB Devices
  • +
  • FHEM Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/harmonydevice.html b/src/main/resources/public/views/harmonydevice.html index a6a4723..84131e1 100644 --- a/src/main/resources/public/views/harmonydevice.html +++ b/src/main/resources/public/views/harmonydevice.html @@ -18,6 +18,7 @@
  • LIFX Devices
  • HomeWizard Devices
  • OpenHAB Devices
  • +
  • FHEM Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/hassdevice.html b/src/main/resources/public/views/hassdevice.html index b4ad7eb..26a39bd 100644 --- a/src/main/resources/public/views/hassdevice.html +++ b/src/main/resources/public/views/hassdevice.html @@ -18,6 +18,7 @@
  • LIFX Devices
  • HomeWizard Devices
  • OpenHAB Devices
  • +
  • FHEM Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/homewizarddevice.html b/src/main/resources/public/views/homewizarddevice.html index d6d858a..a683000 100644 --- a/src/main/resources/public/views/homewizarddevice.html +++ b/src/main/resources/public/views/homewizarddevice.html @@ -18,6 +18,7 @@
  • LIFX Devices
  • OpenHAB Devices
  • +
  • FHEM Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/huedevice.html b/src/main/resources/public/views/huedevice.html index d48fb2c..ed2eed3 100644 --- a/src/main/resources/public/views/huedevice.html +++ b/src/main/resources/public/views/huedevice.html @@ -18,6 +18,7 @@
  • LIFX Devices
  • HomeWizard Devices
  • OpenHAB Devices
  • +
  • FHEM Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/lifxdevice.html b/src/main/resources/public/views/lifxdevice.html index 35042c9..1fe1217 100644 --- a/src/main/resources/public/views/lifxdevice.html +++ b/src/main/resources/public/views/lifxdevice.html @@ -18,6 +18,7 @@
  • HomeWizard Devices
  • OpenHAB Devices
  • +
  • FHEM Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/logs.html b/src/main/resources/public/views/logs.html index b080e62..6be2fa9 100644 --- a/src/main/resources/public/views/logs.html +++ b/src/main/resources/public/views/logs.html @@ -18,6 +18,7 @@
  • LIFX Devices
  • HomeWizard Devices
  • OpenHAB Devices
  • +
  • FHEM Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/mqttpublish.html b/src/main/resources/public/views/mqttpublish.html index 034d9e5..14a9de5 100644 --- a/src/main/resources/public/views/mqttpublish.html +++ b/src/main/resources/public/views/mqttpublish.html @@ -18,6 +18,7 @@
  • LIFX Devices
  • HomeWizard Devices
  • OpenHAB Devices
  • +
  • FHEM Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/nestactions.html b/src/main/resources/public/views/nestactions.html index acd713b..ade8efa 100644 --- a/src/main/resources/public/views/nestactions.html +++ b/src/main/resources/public/views/nestactions.html @@ -18,6 +18,7 @@
  • LIFX Devices
  • HomeWizard Devices
  • OpenHAB Devices
  • +
  • FHEM Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/openhabdevice.html b/src/main/resources/public/views/openhabdevice.html index 993ba89..dacff76 100644 --- a/src/main/resources/public/views/openhabdevice.html +++ b/src/main/resources/public/views/openhabdevice.html @@ -18,6 +18,7 @@
  • LIFX Devices
  • HomeWizard Devices
  • +
  • FHEM Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/somfydevice.html b/src/main/resources/public/views/somfydevice.html index 651b206..06005f6 100644 --- a/src/main/resources/public/views/somfydevice.html +++ b/src/main/resources/public/views/somfydevice.html @@ -18,6 +18,7 @@
  • LIFX Devices
  • HomeWizard Devices
  • OpenHAB Devices
  • +
  • FHEM Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/system.html b/src/main/resources/public/views/system.html index 6452015..77853cd 100644 --- a/src/main/resources/public/views/system.html +++ b/src/main/resources/public/views/system.html @@ -637,6 +637,7 @@ Port Username (opt) Password (opt) + Room (opt) Use SSL Manage @@ -657,6 +658,9 @@ + @@ -679,11 +683,14 @@ + + ng-click="addFhemtoSettings(newfhemname, newfhemip, newfhemport, newsfhemusername, newfhempassword, newfhemwebhook, newfhemsecure)">Add diff --git a/src/main/resources/public/views/veradevice.html b/src/main/resources/public/views/veradevice.html index 9657971..cde55e8 100644 --- a/src/main/resources/public/views/veradevice.html +++ b/src/main/resources/public/views/veradevice.html @@ -18,6 +18,7 @@
  • LIFX Devices
  • HomeWizard Devices
  • OpenHAB Devices
  • +
  • FHEM Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/verascene.html b/src/main/resources/public/views/verascene.html index a775a9c..697eff9 100644 --- a/src/main/resources/public/views/verascene.html +++ b/src/main/resources/public/views/verascene.html @@ -18,6 +18,7 @@
  • LIFX Devices
  • HomeWizard Devices
  • OpenHAB Devices
  • +
  • FHEM Devices
  • Add/Edit
  • diff --git a/src/test/java/com/bwssystems/fhem/test/FHEMInstanceConstructor.java b/src/test/java/com/bwssystems/fhem/test/FHEMInstanceConstructor.java index 98acd94..53cc2e1 100644 --- a/src/test/java/com/bwssystems/fhem/test/FHEMInstanceConstructor.java +++ b/src/test/java/com/bwssystems/fhem/test/FHEMInstanceConstructor.java @@ -248,14 +248,11 @@ public class FHEMInstanceConstructor { aGson = new GsonBuilder() .create(); - FHEMItem[] aService = aGson.fromJson(decodeData, FHEMItem[].class); - for(int i = 0; i < aService.length; i++) { - System.out.println(aService[i].getTotalResultsReturned()); - List services = aService[i].getResults(); + FHEMItem aService = aGson.fromJson(decodeData, FHEMItem.class); + List services = aService.getResults(); for(Result aResult:services) { System.out.println(" " + aResult.getName()); } - } } catch (Exception e) { return false; }