diff --git a/pom.xml b/pom.xml index f63ebbf..0db4b1e 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.bwssystems.HABridge ha-bridge - 5.2.next_a + 5.2.next_b jar HA Bridge diff --git a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java index 5350a96..00953ad 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java +++ b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java @@ -1431,7 +1431,7 @@ public class HueMulator { anHSL.setSat(sat); else anHSL.setSat(state.getSat()); - log.info("hue/sat request - " + anHSL); + log.debug("hue/sat request - " + anHSL); colorData = new ColorData(ColorData.ColorMode.HS, anHSL); } else if (hueInc != null || satInc != null) { anHSL = new HueSatBri(); diff --git a/src/main/java/com/bwssystems/HABridge/plugins/http/HTTPHandler.java b/src/main/java/com/bwssystems/HABridge/plugins/http/HTTPHandler.java index 00b0acc..f52e26c 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/http/HTTPHandler.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/http/HTTPHandler.java @@ -5,8 +5,6 @@ import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.Charset; -import javax.net.ssl.SSLContext; - import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; @@ -154,7 +152,7 @@ public class HTTPHandler { } catch (ClientProtocolException e) { log.warn("Client Protocol Exception received, retyring...."); } catch (IOException e) { - log.warn("Error calling out to HA gateway: IOException in log: " + e.getMessage()); + log.warn("Error calling out to HA gateway: IOException in log: " + e.getMessage(), e); retryCount = 2; } diff --git a/src/main/java/com/bwssystems/HABridge/plugins/http/HttpClientPool.java b/src/main/java/com/bwssystems/HABridge/plugins/http/HttpClientPool.java index b1790f2..0f80dfd 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/http/HttpClientPool.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/http/HttpClientPool.java @@ -62,9 +62,9 @@ public final class HttpClientPool { // Just one of me so constructor will be called once. SSLClient; // The thread-safe client. - private final CloseableHttpClient threadSafeClient; + private CloseableHttpClient threadSafeClient; // The pool monitor. - private final IdleConnectionMonitorThread monitor; + private IdleConnectionMonitorThread monitor = null; private TrustStrategy acceptingTrustStrategy = null; private SSLContext sslContext = null; private SSLConnectionSocketFactory sslsf = null; @@ -73,27 +73,33 @@ public final class HttpClientPool { // The constructor creates it - thus late private SingletonSSL() { - PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); - // Increase max total connection to 200 - cm.setMaxTotal(200); - // Increase default max connection per route to 20 - cm.setDefaultMaxPerRoute(20); try { acceptingTrustStrategy = (cert, authType) -> true; hostnameVerifier = new NoopHostnameVerifier(); sslContext = SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build(); sslsf = new SSLConnectionSocketFactory(sslContext, hostnameVerifier); + HttpClientPool.log.info("Instantiated SSL components."); + final Registry socketFactoryRegistry = RegistryBuilder.create() + .register("http", new PlainConnectionSocketFactory()) + .register("https", sslsf) + .build(); + PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(socketFactoryRegistry); + // Increase max total connection to 200 + cm.setMaxTotal(200); + // Increase default max connection per route to 20 + cm.setDefaultMaxPerRoute(20); + + // Build the client. + threadSafeClient = HttpClients.custom().setSSLSocketFactory(sslsf).setConnectionManager(cm).build(); + // Start up an eviction thread. + monitor = new IdleConnectionMonitorThread(cm); + // Don't stop quitting. + monitor.setDaemon(true); + monitor.start(); } catch (Exception e) { HttpClientPool.log.warn("SingletonSSL failed on SSL init"); + threadSafeClient = null; } - // Build the client. - threadSafeClient = HttpClients.custom().setConnectionManager(cm).setSSLSocketFactory(sslsf) - .setSSLHostnameVerifier(hostnameVerifier).build(); - // Start up an eviction thread. - monitor = new IdleConnectionMonitorThread(cm); - // Don't stop quitting. - monitor.setDaemon(true); - monitor.start(); } public CloseableHttpClient get() { diff --git a/src/main/java/com/bwssystems/HABridge/plugins/moziot/MozIotCommand.java b/src/main/java/com/bwssystems/HABridge/plugins/moziot/MozIotCommand.java index acb78fe..1c86ce0 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/moziot/MozIotCommand.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/moziot/MozIotCommand.java @@ -1,18 +1,25 @@ package com.bwssystems.HABridge.plugins.moziot; +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + public class MozIotCommand { + @SerializedName("url") + @Expose private String url; - private String command; + @SerializedName("command") + @Expose + private MozIotCommandDetail command; public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } - public String getCommand() { + public MozIotCommandDetail getCommand() { return command; } - public void setCommand(String command) { + public void setCommand(MozIotCommandDetail command) { this.command = command; } diff --git a/src/main/java/com/bwssystems/HABridge/plugins/moziot/MozIotCommandDetail.java b/src/main/java/com/bwssystems/HABridge/plugins/moziot/MozIotCommandDetail.java new file mode 100644 index 0000000..ca04074 --- /dev/null +++ b/src/main/java/com/bwssystems/HABridge/plugins/moziot/MozIotCommandDetail.java @@ -0,0 +1,54 @@ +package com.bwssystems.HABridge.plugins.moziot; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class MozIotCommandDetail { + @SerializedName("on") + @Expose + private boolean on; + @SerializedName("level") + @Expose + private String level; + @SerializedName("color") + @Expose + private String color; + + public boolean isOn() { + return on; + } + + public void setOn(boolean on) { + this.on = on; + } + + public String getLevel() { + return level; + } + + public void setLevel(String level) { + this.level = level; + } + + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } + + public String getBody() { + String theBody = ""; + + if(level != null && level != "") { + theBody = "{\"level\":" + level + "}"; + } + else if(color != null && color != "") { + theBody = "{\"color\":\"" + color + "\"}"; + } else { + theBody = "{\"on\":" + on + "}"; + } + return theBody; + } +} \ No newline at end of file diff --git a/src/main/java/com/bwssystems/HABridge/plugins/moziot/MozIotDevice.java b/src/main/java/com/bwssystems/HABridge/plugins/moziot/MozIotDevice.java new file mode 100644 index 0000000..2196d56 --- /dev/null +++ b/src/main/java/com/bwssystems/HABridge/plugins/moziot/MozIotDevice.java @@ -0,0 +1,29 @@ +package com.bwssystems.HABridge.plugins.moziot; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class MozIotDevice { + @SerializedName("gatewayName") + @Expose + private String gatewayName; + @SerializedName("deviceDetail") + @Expose + private MozillaThing deviceDetail; + + public String getGatewayName() { + return gatewayName; + } + + public void setGatewayName(String gatewayName) { + this.gatewayName = gatewayName; + } + + public MozillaThing getDeviceDetail() { + return deviceDetail; + } + + public void setDeviceDetail(MozillaThing deviceDetail) { + this.deviceDetail = deviceDetail; + } +} \ No newline at end of file diff --git a/src/main/java/com/bwssystems/HABridge/plugins/moziot/MozIotHome.java b/src/main/java/com/bwssystems/HABridge/plugins/moziot/MozIotHome.java index 0510adf..082e8a0 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/moziot/MozIotHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/moziot/MozIotHome.java @@ -26,13 +26,13 @@ import com.bwssystems.HABridge.plugins.http.HTTPHandler; import com.bwssystems.HABridge.plugins.http.HTTPHome; import com.google.gson.Gson; -public class MozIotHome implements Home { - private static final Logger log = LoggerFactory.getLogger(MozIotHome.class); +public class MozIotHome implements Home { + private static final Logger log = LoggerFactory.getLogger(MozIotHome.class); private Map moziotMap; private Boolean validMoziot; - private HTTPHandler httpClient; + private HTTPHandler httpClient; private boolean closed; - + public MozIotHome(BridgeSettings bridgeSettings) { super(); closed = true; @@ -47,71 +47,68 @@ public class MozIotHome implements Home { String theUrl = anItem.getItem().getAsString(); String responseString = null; - if(theUrl != null && !theUrl.isEmpty()) { + if (theUrl != null && !theUrl.isEmpty()) { + String anUrl = BrightnessDecode.calculateReplaceIntensityValue(theUrl, intensity, targetBri, targetBriInc, + false); + if (colorData != null) { + anUrl = ColorDecode.replaceColorData(anUrl, colorData, + BrightnessDecode.calculateIntensity(intensity, targetBri, targetBriInc), true); + } + anUrl = DeviceDataDecode.replaceDeviceData(anUrl, device); + anUrl = TimeDecode.replaceTimeValue(anUrl); + + anUrl = BrightnessDecode.calculateReplaceIntensityValue(anUrl, intensity, targetBri, targetBriInc, false); + if (colorData != null) { + anUrl = ColorDecode.replaceColorData(anUrl, colorData, + BrightnessDecode.calculateIntensity(intensity, targetBri, targetBriInc), false); + } + anUrl = DeviceDataDecode.replaceDeviceData(anUrl, device); + anUrl = TimeDecode.replaceTimeValue(anUrl); + MozIotCommand theCommand = null; try { theUrl = theUrl.replaceAll("^\"|\"$", ""); - theCommand = new Gson().fromJson(theUrl, MozIotCommand.class); - } catch(Exception e) { - log.warn("Cannot parse command to Mozilla IOT <<<" + theUrl + ">>>", e); + theCommand = new Gson().fromJson(anUrl, MozIotCommand.class); + } catch (Exception e) { + log.warn("Cannot parse command to Mozilla IOT <<<" + theUrl + ">>>", e); responseString = new Gson().toJson(HueErrorResponse.createResponse("6", "/lights/" + lightId, - "Error on calling url to change device state", "/lights/" - + lightId + "/state", null, null).getTheErrors(), HueError[].class); + "Error on calling url to change device state", "/lights/" + lightId + "/state", null, null) + .getTheErrors(), HueError[].class); return responseString; } - String intermediate = theCommand.getUrl().substring(theCommand.getUrl().indexOf("://") + 3); - String hostPortion = intermediate.substring(0, intermediate.indexOf('/')); - String theUrlBody = intermediate.substring(intermediate.indexOf('/') + 1); - String hostAddr = null; - if (hostPortion.contains(":")) { - hostAddr = hostPortion.substring(0, intermediate.indexOf(':')); - } else - hostAddr = hostPortion; - MozIotInstance theHandler = findHandlerByAddress(hostAddr); - if(theHandler != null) { - String anUrl = BrightnessDecode.calculateReplaceIntensityValue(theUrlBody, - intensity, targetBri, targetBriInc, false); - if (colorData != null) { - anUrl = ColorDecode.replaceColorData(anUrl, colorData, BrightnessDecode.calculateIntensity(intensity, targetBri, targetBriInc), false); - } - anUrl = DeviceDataDecode.replaceDeviceData(anUrl, device); - anUrl = TimeDecode.replaceTimeValue(anUrl); - - String aCommand = null; - if(theCommand.getCommand() != null && !theCommand.getCommand().isEmpty()) { - aCommand = BrightnessDecode.calculateReplaceIntensityValue(theCommand.getCommand(), - intensity, targetBri, targetBriInc, false); - if (colorData != null) { - aCommand = ColorDecode.replaceColorData(aCommand, colorData, BrightnessDecode.calculateIntensity(intensity, targetBri, targetBriInc), false); - } - aCommand = DeviceDataDecode.replaceDeviceData(aCommand, device); - aCommand = TimeDecode.replaceTimeValue(aCommand); - } - try { - boolean success = theHandler.callCommand(anUrl, aCommand, httpClient); - if(!success) { - log.warn("Comand had error to Mozilla IOT"); + + String intermediate = theCommand.getUrl().substring(theCommand.getUrl().indexOf("/things/") + 8); + String devicePortion = intermediate.substring(0, intermediate.indexOf('/')); + String theUrlCommand = intermediate.substring(intermediate.indexOf('/') + 1); + MozIotInstance theHandler = moziotMap.get(device.getTargetDevice()); + if (theHandler != null) { + try { + boolean success = theHandler.callCommand(devicePortion, theUrlCommand, theCommand.getCommand(), httpClient); + if (!success) { + log.warn("Comand had error to Mozilla IOT"); responseString = new Gson().toJson(HueErrorResponse.createResponse("6", "/lights/" + lightId, - "Error on calling url to change device state", "/lights/" - + lightId + "state", null, null).getTheErrors(), HueError[].class); - } - } catch (Exception e) { - log.warn("Cannot send comand to Mozilla IOT", e); + "Error on calling url to change device state", "/lights/" + lightId + "/state", null, + null).getTheErrors(), HueError[].class); + } + } catch (Exception e) { + log.warn("Cannot send comand to Mozilla IOT", e); responseString = new Gson().toJson(HueErrorResponse.createResponse("6", "/lights/" + lightId, - "Error on calling url to change device state", "/lights/" - + lightId + "state", null, null).getTheErrors(), HueError[].class); - } + "Error on calling url to change device state", "/lights/" + lightId + "/state", null, null) + .getTheErrors(), HueError[].class); + } } else { log.warn("Mozilla IOT Call could not complete, no address found: " + theUrl); responseString = new Gson().toJson(HueErrorResponse.createResponse("6", "/lights/" + lightId, - "Error on calling url to change device state", "/lights/" - + lightId + "state", null, null).getTheErrors(), HueError[].class); + "Error on calling url to change device state", "/lights/" + lightId + "/state", null, null) + .getTheErrors(), HueError[].class); } } else { - log.warn("Mozilla IOT Call to be presented as http(s)://(:)/payload, format of request unknown: " + theUrl); + log.warn( + "Mozilla IOT Call to be presented as http(s)://(:)/payload, format of request unknown: " + + theUrl); responseString = new Gson().toJson(HueErrorResponse.createResponse("6", "/lights/" + lightId, - "Error on calling url to change device state", "/lights/" - + lightId + "state", null, null).getTheErrors(), HueError[].class); + "Error on calling url to change device state", "/lights/" + lightId + "/state", null, null) + .getTheErrors(), HueError[].class); } return responseString; } @@ -119,16 +116,16 @@ public class MozIotHome implements Home { @Override public Object getItems(String type) { - if(!validMoziot) + if (!validMoziot) return null; log.debug("consolidating devices for Mozilla IOT"); List theResponse = null; Iterator keys = moziotMap.keySet().iterator(); - List deviceList = new ArrayList(); - while(keys.hasNext()) { + List deviceList = new ArrayList(); + while (keys.hasNext()) { String key = keys.next(); theResponse = moziotMap.get(key).getDevices(httpClient); - if(theResponse != null) + if (theResponse != null) addMozIotDevices(deviceList, theResponse, key); else { log.warn("Cannot get devices for Mozilla IOT with name: " + key + ", skipping this Mozilla IOT."); @@ -137,11 +134,15 @@ public class MozIotHome implements Home { } return deviceList; } - - private Boolean addMozIotDevices(List theDeviceList, List theSourceList, String theKey) { - Iterator devices = theSourceList.iterator(); - while(devices.hasNext()) { - MozillaThing theDevice = devices.next(); + + private Boolean addMozIotDevices(List theDeviceList, List theSourceList, + String theKey) { + Iterator things = theSourceList.iterator(); + while (things.hasNext()) { + MozillaThing theThing = things.next(); + MozIotDevice theDevice = new MozIotDevice(); + theDevice.setDeviceDetail(theThing); + theDevice.setGatewayName(theKey); theDeviceList.add(theDevice); } return true; @@ -152,57 +153,42 @@ public class MozIotHome implements Home { moziotMap = null; validMoziot = bridgeSettings.getBridgeSettingsDescriptor().isValidMozIot(); log.info("Mozilla IOT Home created." + (validMoziot ? "" : " No Mozilla IOTs configured.")); - if(validMoziot) { - moziotMap = new HashMap(); - httpClient = HTTPHome.getHandler(); - Iterator theList = bridgeSettings.getBridgeSettingsDescriptor().getMoziotaddress().getDevices().iterator(); - while(theList.hasNext() && validMoziot) { + if (validMoziot) { + moziotMap = new HashMap(); + httpClient = HTTPHome.getHandler(); + Iterator theList = bridgeSettings.getBridgeSettingsDescriptor().getMoziotaddress().getDevices() + .iterator(); + while (theList.hasNext() && validMoziot) { NamedIP aMoziot = theList.next(); - try { - moziotMap.put(aMoziot.getName(), new MozIotInstance(aMoziot, httpClient)); + try { + moziotMap.put(aMoziot.getName(), new MozIotInstance(aMoziot, httpClient)); } catch (Exception e) { - log.error("Cannot get Mozilla IOT (" + aMoziot.getName() + ") setup, Exiting with message: " + e.getMessage(), e); - validMoziot = false; + log.error("Cannot get Mozilla IOT (" + aMoziot.getName() + ") setup, Exiting with message: " + + e.getMessage(), e); + validMoziot = false; } } - } - return this; - } - - private MozIotInstance findHandlerByAddress(String hostAddress) { - MozIotInstance aHandler = null; - boolean found = false; - Iterator keys = moziotMap.keySet().iterator(); - while(keys.hasNext()) { - String key = keys.next(); - aHandler = moziotMap.get(key); - if(aHandler != null && aHandler.getMozIotIP().getIp().equals(hostAddress)) { - found = true; - break; - } } - if(!found) - aHandler = null; - return aHandler; + return this; } @Override public void closeHome() { log.debug("Closing Home."); - if(!closed && validMoziot) { + if (!closed && validMoziot) { log.debug("Home is already closed...."); return; } - if(httpClient != null) + if (httpClient != null) httpClient.closeHandler(); moziotMap = null; - closed = true; + closed = true; } - + @Override public void refresh() { - // noop + // noop } } diff --git a/src/main/java/com/bwssystems/HABridge/plugins/moziot/MozIotInstance.java b/src/main/java/com/bwssystems/HABridge/plugins/moziot/MozIotInstance.java index 117fca5..bd336b6 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/moziot/MozIotInstance.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/moziot/MozIotInstance.java @@ -26,8 +26,8 @@ public class MozIotInstance { gatewayLogin(httpClient); } - public Boolean callCommand(String aCommand, String commandData, HTTPHandler httpClient) { - log.debug("calling Mozilla IOT: " + mozIotIP.getIp() + ":" + mozIotIP.getPort() + aCommand); + public Boolean callCommand(String deviceId, String aCommand, MozIotCommandDetail commandData, HTTPHandler httpClient) { + log.debug("calling Mozilla IOT: {}:{}{}{}", mozIotIP.getIp(), mozIotIP.getPort(), aCommand, commandData.getBody()); String aUrl = null; if (mozIotIP.getSecure() != null && mozIotIP.getSecure()) @@ -36,9 +36,9 @@ public class MozIotInstance { aUrl = "http://"; headers = getAuthHeader(); - aUrl = aUrl + mozIotIP.getIp() + ":" + mozIotIP.getPort() + "/" + aCommand; - String theData = httpClient.doHttpRequest(aUrl, HttpPut.METHOD_NAME, "application/json", commandData, headers); - log.debug("call Command return is: <" + theData + ">"); + aUrl = aUrl + mozIotIP.getIp() + ":" + mozIotIP.getPort() + "/things/" + deviceId + "/" + aCommand; + String theData = httpClient.doHttpRequest(aUrl, HttpPut.METHOD_NAME, "application/json", commandData.getBody(), headers); + log.debug("call Command return is: <<<{}>>>", theData); if (theData.contains("error") || theData.contains("ERROR") || theData.contains("Error")) return false; return true; @@ -70,7 +70,7 @@ public class MozIotInstance { } } } catch (Exception e) { - log.warn("Cannot get an devices for Mozilla IOT " + mozIotIP.getName() + " Gson Parse Error."); + log.warn("Cannot get an devices for Mozilla IOT {} Gson Parse Error.", mozIotIP.getName()); } } return deviceList; @@ -78,11 +78,17 @@ public class MozIotInstance { private NameValue[] getAuthHeader() { if (headers == null) { - headers = new NameValue[1]; + headers = new NameValue[3]; headers[0] = new NameValue(); headers[0].setName("Authorization"); headers[0].setValue("Bearer " + moziotToken.getJwt()); - } + headers[1] = new NameValue(); + headers[1].setName("Content-Type"); + headers[1].setValue("application/json"); + headers[2] = new NameValue(); + headers[2].setName("Accept"); + headers[2].setValue("application/json"); + } return headers; } @@ -102,20 +108,20 @@ public class MozIotInstance { headers[1].setName("Accept"); headers[1].setValue("application/json"); aUrl = aUrl + mozIotIP.getIp() + ":" + mozIotIP.getPort() + "/login"; - log.info("gateway login URL: " + aUrl); + log.debug("gateway login URL: {}", aUrl); String commandData = "{\"email\": \"" + mozIotIP.getUsername() + "\", \"password\":\"" + mozIotIP.getPassword() + "\"}"; - log.info("The login body: " + commandData); + log.debug("The login body: {}", commandData); String theData = httpClient.doHttpRequest(aUrl, HttpPost.METHOD_NAME, "application/json", commandData, headers); if (theData != null) { - log.info("GET Mozilla login - data: " + theData); + log.debug("GET Mozilla login - data: {}", theData); try { moziotToken = new Gson().fromJson(theData, JWT.class); } catch (Exception e) { - log.warn("Cannot get login for Mozilla IOT " + mozIotIP.getName() + " Gson Parse Error."); + log.warn("Cannot get login for Mozilla IOT {} Gson Parse Error.", mozIotIP.getName()); } } else { - log.warn("Could not login " + mozIotIP.getName() + " error: <<<" + theData + ">>>"); + log.warn("Could not login {} error: <<<{}>>>", mozIotIP.getName(), theData); } headers = null; diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index b9823f0..de16a17 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -1,106 +1,106 @@ -var app = angular.module ('habridge', ['ngRoute', 'ngToast', 'rzModule', 'ngDialog', 'base64', 'scrollable-table', 'ngResource', 'ngStorage', 'colorpicker.module']); +var app = angular.module('habridge', ['ngRoute', 'ngToast', 'rzModule', 'ngDialog', 'base64', 'scrollable-table', 'ngResource', 'ngStorage', 'colorpicker.module']); -app.config (function ($locationProvider, $routeProvider) { - $locationProvider.hashPrefix('!'); +app.config(function ($locationProvider, $routeProvider) { + $locationProvider.hashPrefix('!'); - $routeProvider.when ('/', { + $routeProvider.when('/', { templateUrl: 'views/configuration.html', controller: 'ViewingController', - requiresAuthentication: true - }).when ('/system', { + requiresAuthentication: true + }).when('/system', { templateUrl: 'views/system.html', - controller: 'SystemController', + controller: 'SystemController', requiresAuthentication: true - }).when ('/logs', { + }).when('/logs', { templateUrl: 'views/logs.html', - controller: 'LogsController', + controller: 'LogsController', requiresAuthentication: true - }).when ('/editdevice', { + }).when('/editdevice', { templateUrl: 'views/editdevice.html', - controller: 'EditController', - requiresAuthentication: true - }).when ('/veradevices', { + controller: 'EditController', + requiresAuthentication: true + }).when('/veradevices', { templateUrl: 'views/veradevice.html', - controller: 'VeraController', - requiresAuthentication: true - }).when ('/verascenes', { + controller: 'VeraController', + requiresAuthentication: true + }).when('/verascenes', { templateUrl: 'views/verascene.html', - controller: 'VeraController', + controller: 'VeraController', requiresAuthentication: true - }).when ('/fibarodevices', { + }).when('/fibarodevices', { templateUrl: 'views/fibarodevice.html', - controller: 'FibaroController', - requiresAuthentication: true - }).when ('/fibaroscenes', { + controller: 'FibaroController', + requiresAuthentication: true + }).when('/fibaroscenes', { templateUrl: 'views/fibaroscene.html', - controller: 'FibaroController', + controller: 'FibaroController', requiresAuthentication: true - }).when ('/harmonydevices', { + }).when('/harmonydevices', { templateUrl: 'views/harmonydevice.html', - controller: 'HarmonyController', - requiresAuthentication: true - }).when ('/harmonyactivities', { - templateUrl: 'views/harmonyactivity.html', - controller: 'HarmonyController', - requiresAuthentication: true - }).when ('/nest', { - templateUrl: 'views/nestactions.html', - controller: 'NestController', - requiresAuthentication: true - }).when ('/huedevices', { - templateUrl: 'views/huedevice.html', - controller: 'HueController', - requiresAuthentication: true - }).when ('/haldevices', { - templateUrl: 'views/haldevice.html', - controller: 'HalController', - requiresAuthentication: true - }).when ('/mqttmessages', { - templateUrl: 'views/mqttpublish.html', - controller: 'MQTTController', - requiresAuthentication: true - }).when ('/hassdevices', { - templateUrl: 'views/hassdevice.html', - controller: 'HassController', + controller: 'HarmonyController', requiresAuthentication: true - }).when ('/homewizarddevices', { - templateUrl: 'views/homewizarddevice.html', - controller: 'HomeWizardController', - requiresAuthentication: true - }).when ('/domoticzdevices', { + }).when('/harmonyactivities', { + templateUrl: 'views/harmonyactivity.html', + controller: 'HarmonyController', + requiresAuthentication: true + }).when('/nest', { + templateUrl: 'views/nestactions.html', + controller: 'NestController', + requiresAuthentication: true + }).when('/huedevices', { + templateUrl: 'views/huedevice.html', + controller: 'HueController', + requiresAuthentication: true + }).when('/haldevices', { + templateUrl: 'views/haldevice.html', + controller: 'HalController', + requiresAuthentication: true + }).when('/mqttmessages', { + templateUrl: 'views/mqttpublish.html', + controller: 'MQTTController', + requiresAuthentication: true + }).when('/hassdevices', { + templateUrl: 'views/hassdevice.html', + controller: 'HassController', + requiresAuthentication: true + }).when('/homewizarddevices', { + templateUrl: 'views/homewizarddevice.html', + controller: 'HomeWizardController', + requiresAuthentication: true + }).when('/domoticzdevices', { templateUrl: 'views/domoticzdevice.html', - controller: 'DomoticzController', + controller: 'DomoticzController', requiresAuthentication: true }).when('/somfydevices', { - templateUrl: 'views/somfydevice.html', - controller: 'SomfyController', - requiresAuthentication: true - }).when ('/lifxdevices', { + templateUrl: 'views/somfydevice.html', + controller: 'SomfyController', + requiresAuthentication: true + }).when('/lifxdevices', { templateUrl: 'views/lifxdevice.html', - controller: 'LifxController', - requiresAuthentication: true - }).when ('/openhabdevices', { + controller: 'LifxController', + requiresAuthentication: true + }).when('/openhabdevices', { templateUrl: 'views/openhabdevice.html', controller: 'OpenHABController', requiresAuthentication: true - }).when ('/moziotdevices', { + }).when('/moziotdevices', { templateUrl: 'views/moziotdevice.html', controller: 'MozIotController', requiresAuthentication: true - }).when ('/fhemdevices', { + }).when('/fhemdevices', { templateUrl: 'views/fhemdevice.html', controller: 'FhemController', requiresAuthentication: true - }).when ('/broadlinkdevices', { + }).when('/broadlinkdevices', { templateUrl: 'views/broadlinkdevice.html', controller: 'BroadlinkController', requiresAuthentication: true - }).when ('/login', { + }).when('/login', { templateUrl: 'views/login.html', - controller: 'LoginController' - }).otherwise ({ + controller: 'LoginController' + }).otherwise({ templateUrl: 'views/configuration.html', - controller: 'ViewingController', + controller: 'ViewingController', requiresAuthentication: true }); }); @@ -108,70 +108,106 @@ app.config (function ($locationProvider, $routeProvider) { app.run(function ($rootScope, $location, Auth, bridgeService) { bridgeService.getHABridgeVersion(); - $rootScope.$on('securitySetupReceived', function(event, data) { - Auth.init(); - if(Auth.isLoggedIn()) { - bridgeService.loadBridgeSettings(); - bridgeService.getSecurityInfo(); - bridgeService.viewMapTypes(); - $location.path("/"); - } else { - event.preventDefault(); - $location.path("/login"); - } - }); - - $rootScope.$on('securityError', function(event, data) { - Auth.logout(); - event.preventDefault(); - $location.path("/login"); - }); - - $rootScope.$on('securityReinit', function(event, data) { - event.preventDefault(); - bridgeService.state.testuser = ""; - Auth.logout(); + $rootScope.$on('securitySetupReceived', function (event, data) { + Auth.init(); + if (Auth.isLoggedIn()) { + bridgeService.loadBridgeSettings(); + bridgeService.getSecurityInfo(); + bridgeService.viewMapTypes(); + $location.path("/"); + } else { + event.preventDefault(); + $location.path("/login"); + } + }); + + $rootScope.$on('securityError', function (event, data) { + Auth.logout(); + event.preventDefault(); + $location.path("/login"); + }); + + $rootScope.$on('securityReinit', function (event, data) { + event.preventDefault(); + bridgeService.state.testuser = ""; + Auth.logout(); $location.path("/"); - }); - - $rootScope.$on('$routeChangeStart', function (event, next) { - if (!Auth.checkPermissionForView(next)){ - event.preventDefault(); - $location.path("/login"); - } else { - $location.path(next.originalPath); - - } - }); + }); + + $rootScope.$on('$routeChangeStart', function (event, next) { + if (!Auth.checkPermissionForView(next)) { + event.preventDefault(); + $location.path("/login"); + } else { + $location.path(next.originalPath); + + } + }); }); -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(); - } +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); + return this.replace(new RegExp('[' + search + ']', 'g'), replace); }; -app.service ('bridgeService', function ($rootScope, $http, $base64, $location, ngToast) { +app.service('bridgeService', function ($rootScope, $http, $base64, $location, ngToast) { var self = this; - 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, showMozIot: false, showFHEM: false, showBroadlink: false, habridgeversion: {}, - viewDevId: "", queueDevId: "", securityInfo: {}, filterDevicesByIpAddress: null, - filterDevicesOnlyFiltered: false, filterDeviceType: null}; + 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, + showMozIot: false, + showFHEM: false, + showBroadlink: false, + habridgeversion: {}, + viewDevId: "", + queueDevId: "", + securityInfo: {}, + filterDevicesByIpAddress: null, + filterDevicesOnlyFiltered: false, + filterDeviceType: null + }; - this.displayWarn = function(errorTitle, error) { + this.displayWarn = function (errorTitle, error) { var toastContent = errorTitle; - if (error !== null && typeof(error) !== 'undefined') { + if (error !== null && typeof (error) !== 'undefined') { if (error.data !== null) - toastContent = toastContent + " " + error.data.message + " with status: " + error.statusText + " - " + error.status; + toastContent = toastContent + " " + error.data.message + " with status: " + error.statusText + " - " + error.status; else toastContent = error; } @@ -179,74 +215,79 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n className: "warning", dismissButton: true, dismissOnTimeout: false, - content: toastContent}); + content: toastContent + }); }; - - this.displayError = function(errorTitle, error) { + + this.displayError = function (errorTitle, error) { var toastContent = errorTitle; - if (error !== null && typeof(error) !== 'undefined') - toastContent = toastContent + " " + error.data.message + " with status: " + error.statusText + " - " + error.status; + if (error !== null && typeof (error) !== 'undefined') + toastContent = toastContent + " " + error.data.message + " with status: " + error.statusText + " - " + error.status; ngToast.create({ className: "danger", dismissButton: true, dismissOnTimeout: false, - content: toastContent}); + content: toastContent + }); }; - + this.displayErrorMessage = function (errorTitle, errorMessage) { ngToast.create({ className: "danger", dismissButton: true, dismissOnTimeout: false, - content: errorTitle + errorMessage}); + content: errorTitle + errorMessage + }); }; - + this.displaySuccess = function (theTitle) { ngToast.create({ className: "success", - content: theTitle}); + content: theTitle + }); }; - + this.displayTimer = function (theTitle, timeMillis) { ngToast.create({ className: "success", timeout: timeMillis, dismissOnClick: false, - content: theTitle + " in " + timeMillis/1000 + " seconds"}); + content: theTitle + " in " + timeMillis / 1000 + " seconds" + }); }; - + this.viewDevices = function () { return $http.get(this.state.base).then( - function (response) { - self.state.devices = response.data; - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else - self.displayError("Cannot get devices from habridge: ", error); - } + function (response) { + self.state.devices = response.data; + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else + self.displayError("Cannot get devices from habridge: ", error); + } ); }; this.renumberDevices = function () { return $http.post(this.state.base + "/exec/renumber").then( - function (response) { - self.viewDevices(); - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else - self.displayError("Cannot renumber devices from habridge: ", error); - } + function (response) { + self.viewDevices(); + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else + self.displayError("Cannot renumber devices from habridge: ", error); + } ); }; - this.compareUniqueId = function(r1, r2) { - if (r1.id === r2.id) - return 0; - return parseInt(r1.id) > parseInt(r2.id) ? 1 : -1; + this.compareUniqueId = function (r1, r2) { + if (r1.id === r2.id) + return 0; + return parseInt(r1.id) > parseInt(r2.id) ? 1 : -1; }; this.clearDevice = function () { @@ -256,198 +297,198 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n this.getHABridgeVersion = function () { return $http.get(this.state.systemsbase + "/habridge/version").then( - function (response) { - self.state.habridgeversion = { - version: response.data.version, - isSecure: response.data.isSecure - }; - $rootScope.$broadcast('securitySetupReceived', 'done'); - }, - function (error) { - self.displayWarn("Cannot get version: ", error); - } + function (response) { + self.state.habridgeversion = { + version: response.data.version, + isSecure: response.data.isSecure + }; + $rootScope.$broadcast('securitySetupReceived', 'done'); + }, + function (error) { + self.displayWarn("Cannot get version: ", error); + } ); }; this.getTestUser = function () { - if(self.state.testuser === undefined || self.state.testuser === "") { + if (self.state.testuser === undefined || self.state.testuser === "") { var linkParams = {}; linkParams = { - seconds: 3, - silent: true - }; + seconds: 3, + silent: true + }; return $http.put(this.state.systemsbase + "/presslinkbutton", linkParams).then( - function (response) { - self.getAUser(); - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else - self.displayWarn("Cannot get testuser: ", error); - } + function (response) { + self.getAUser(); + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else + self.displayWarn("Cannot get testuser: ", error); + } ); } }; this.getAUser = function () { return $http.post(this.state.huebase, "{\"devicetype\":\"test_ha_bridge\"}").then( - function (response) { - self.state.testuser = response.data[0].success.username; - self.getWhitelist(); - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else - self.displayWarn("Cannot get a user: ", error); - } + function (response) { + self.state.testuser = response.data[0].success.username; + self.getWhitelist(); + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else + self.displayWarn("Cannot get a user: ", error); + } ); }; this.getSecurityInfo = function () { return $http.get(this.state.systemsbase + "/securityinfo").then( - function (response) { - self.state.securityInfo = response.data; - self.getTestUser(); - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else - self.displayWarn("Cannot get security info: ", error); - } + function (response) { + self.state.securityInfo = response.data; + self.getTestUser(); + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else + self.displayWarn("Cannot get security info: ", error); + } ); }; - + this.changeSecuritySettings = function (useLinkButton, secureHueApi, execGarden) { var newSecurityInfo = {}; newSecurityInfo = { - useLinkButton: useLinkButton, - secureHueApi: secureHueApi, - execGarden: execGarden - }; - return $http.post(this.state.systemsbase + "/changesecurityinfo", newSecurityInfo ).then( - function (response) { - self.state.securityInfo = response.data; - self.displaySuccess("Updated security settings."); - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else + useLinkButton: useLinkButton, + secureHueApi: secureHueApi, + execGarden: execGarden + }; + return $http.post(this.state.systemsbase + "/changesecurityinfo", newSecurityInfo).then( + function (response) { + self.state.securityInfo = response.data; + self.displaySuccess("Updated security settings."); + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else self.displayWarn("Update security settings Error: ", error); - } + } ); }; this.isSecure = function () { - if(self.state.habridgeversion === undefined) + if (self.state.habridgeversion === undefined) return true; - if(self.state.habridgeversion.isSecure === undefined) + if (self.state.habridgeversion.isSecure === undefined) return true; - + return self.state.habridgeversion.isSecure; }; this.changePassword = function (aPassword, aPassword2) { var newUserInfo = {}; newUserInfo = { - username: self.state.loggedInUser, - password: aPassword, - password2: aPassword2 - }; + username: self.state.loggedInUser, + password: aPassword, + password2: aPassword2 + }; var theEncodedPayload = $base64.encode(angular.toJson(newUserInfo)); - return $http.post(this.state.systemsbase + "/setpassword", theEncodedPayload ).then( - function (response) { - self.displaySuccess("Password updated"); - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else + return $http.post(this.state.systemsbase + "/setpassword", theEncodedPayload).then( + function (response) { + self.displaySuccess("Password updated"); + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else self.displayWarn("Update password Error: ", error); - } + } ); }; this.addUser = function (username, aPassword, aPassword2) { var newUserInfo = {}; newUserInfo = { - username: username, - password: aPassword, - password2: aPassword2 - }; + username: username, + password: aPassword, + password2: aPassword2 + }; var theEncodedPayload = $base64.encode(angular.toJson(newUserInfo)); - return $http.put(this.state.systemsbase + "/adduser", theEncodedPayload ).then( - function (response) { - self.displaySuccess("User added"); - if(!self.isSecure()) { - self.getHABridgeVersion(); - } - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else - self.displayWarn("User add Error: ", error); + return $http.put(this.state.systemsbase + "/adduser", theEncodedPayload).then( + function (response) { + self.displaySuccess("User added"); + if (!self.isSecure()) { + self.getHABridgeVersion(); } + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else + self.displayWarn("User add Error: ", error); + } ); }; this.delUser = function (username) { var newUserInfo = {}; newUserInfo = { - username: username - }; + username: username + }; var theEncodedPayload = $base64.encode(angular.toJson(newUserInfo)); - return $http.put(this.state.systemsbase + "/deluser", theEncodedPayload ).then( - function (response) { - self.displaySuccess("User deleted"); - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else + return $http.put(this.state.systemsbase + "/deluser", theEncodedPayload).then( + function (response) { + self.displaySuccess("User deleted"); + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else self.displayWarn("User add Error: ", error); - } + } ); }; this.pushLinkButton = function () { return $http.put(this.state.systemsbase + "/presslinkbutton").then( - function (response) { - self.displayTimer("Link your device", 30000); - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else + function (response) { + self.displayTimer("Link your device", 30000); + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else self.displayWarn("Cannot get security info: ", error); - } + } ); }; this.getWhitelist = function () { return $http.get(this.state.systemsbase + "/whitelist").then( - function (response) { - self.state.whitelist = response.data; - }, - function (error) { - self.displayWarn("Cannot get swhitelist: ", error); - } + function (response) { + self.state.whitelist = response.data; + }, + function (error) { + self.displayWarn("Cannot get swhitelist: ", error); + } ); }; - + this.setWhitelist = function (whitelist) { - return $http.post(this.state.systemsbase + "/setwhitelist", whitelist ).then( - function (response) { - self.state.whitelist = response.data; - self.displaySuccess("Updated whitelist."); - }, - function (error) { - self.displayWarn("Update whitelist Error: ", error); - } + return $http.post(this.state.systemsbase + "/setwhitelist", whitelist).then( + function (response) { + self.state.whitelist = response.data; + self.displaySuccess("Updated whitelist."); + }, + function (error) { + self.displayWarn("Update whitelist Error: ", error); + } ); }; @@ -456,61 +497,61 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n }; this.deviceContainsType = function (device, aType) { - if(device.mapType !== undefined && device.mapType !== null && device.mapType.indexOf(aType) >= 0) - return true; - - if(device.deviceType !== undefined && device.deviceType !== null && device.deviceType.indexOf(aType) >= 0) - return true; - - if(device.onUrl !== undefined && device.onUrl !== null && device.onUrl.indexOf(aType) >= 0) - return true; - - if(device.dimUrl !== undefined && device.dimUrl !== null && device.dimUrl.indexOf(aType) >= 0) - return true; - - if(device.offUrl !== undefined && device.offUrl !== null && device.offUrl.indexOf(aType) >= 0) + if (device.mapType !== undefined && device.mapType !== null && device.mapType.indexOf(aType) >= 0) return true; - if(device.colorUrl !== undefined && device.colorUrl !== null && device.colorUrl.indexOf(aType) >= 0) + if (device.deviceType !== undefined && device.deviceType !== null && device.deviceType.indexOf(aType) >= 0) return true; - - + + if (device.onUrl !== undefined && device.onUrl !== null && device.onUrl.indexOf(aType) >= 0) + return true; + + if (device.dimUrl !== undefined && device.dimUrl !== null && device.dimUrl.indexOf(aType) >= 0) + return true; + + if (device.offUrl !== undefined && device.offUrl !== null && device.offUrl.indexOf(aType) >= 0) + return true; + + if (device.colorUrl !== undefined && device.colorUrl !== null && device.colorUrl.indexOf(aType) >= 0) + return true; + + return false; }; - this.compareHarmonyNumber = function(r1, r2) { + this.compareHarmonyNumber = function (r1, r2) { if (r1.device !== undefined) { - if (r1.device.id === r2.device.id) - return 0; - return r1.device.id > r2.device.id ? 1 : -1; + if (r1.device.id === r2.device.id) + return 0; + return r1.device.id > r2.device.id ? 1 : -1; } if (r1.activity !== undefined) { - if (r1.activity.id === r2.activity.id) - return 0; - return r1.activity.id > r2.activity.id ? 1 : -1; + if (r1.activity.id === r2.activity.id) + return 0; + return r1.activity.id > r2.activity.id ? 1 : -1; } return 0; }; - this.compareHarmonyLabel = function(r1, r2) { + this.compareHarmonyLabel = function (r1, r2) { if (r1.device !== undefined) { - if (r1.device.label === r2.device.label) - return 0; - return r1.device.label > r2.device.label ? 1 : -1; + if (r1.device.label === r2.device.label) + return 0; + return r1.device.label > r2.device.label ? 1 : -1; } if (r1.activity !== undefined) { - if (r1.activity.label === r2.activity.label) - return 0; - return r1.activity.label > r2.activity.label ? 1 : -1; + if (r1.activity.label === r2.activity.label) + return 0; + return r1.activity.label > r2.activity.label ? 1 : -1; } return 0; }; - this.compareHarmonyHub = function(r1, r2) { + this.compareHarmonyHub = function (r1, r2) { if (r1.hub !== undefined) { - if (r1.hub === r2.hub) - return 0; - return r1.hub > r2.hub ? 1 : -1; + if (r1.hub === r2.hub) + return 0; + return r1.hub > r2.hub ? 1 : -1; } return 0; }; @@ -519,7 +560,7 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n this.state.showVera = self.state.settings.veraconfigured; return; }; - + this.updateShowFibaro = function () { this.state.showFibaro = self.state.settings.fibaroconfigured; return; @@ -556,19 +597,19 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n }; this.updateShowHass = function () { - this.state.showHass = self.state.settings.hassconfigured; - return; - }; - + this.state.showHass = self.state.settings.hassconfigured; + return; + }; + this.updateShowDomoticz = function () { this.state.showDomoticz = self.state.settings.domoticzconfigured; return; }; - this.updateShowSomfy = function () { - this.state.showSomfy = self.state.settings.somfyconfigured; - return; - }; + this.updateShowSomfy = function () { + this.state.showSomfy = self.state.settings.somfyconfigured; + return; + }; this.updateShowLifx = function () { this.state.showLifx = self.state.settings.lifxconfigured; @@ -597,183 +638,183 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n this.loadBridgeSettings = function () { return $http.get(this.state.systemsbase + "/settings").then( - function (response) { - self.state.settings = response.data; - self.updateShowVera(); - self.updateShowFibaro(); - self.updateShowHarmony(); - self.updateShowNest(); - self.updateShowHue(); - self.updateShowHal(); - self.updateShowMqtt(); - self.updateShowHass(); - self.updateShowHomeWizard(); - self.updateShowDomoticz(); - self.updateShowSomfy(); - self.updateShowLifx(); - self.updateShowOpenHAB(); - self.updateShowMozIot(); - self.updateShowFhem(); - self.updateShowBroadlink(); - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else + function (response) { + self.state.settings = response.data; + self.updateShowVera(); + self.updateShowFibaro(); + self.updateShowHarmony(); + self.updateShowNest(); + self.updateShowHue(); + self.updateShowHal(); + self.updateShowMqtt(); + self.updateShowHass(); + self.updateShowHomeWizard(); + self.updateShowDomoticz(); + self.updateShowSomfy(); + self.updateShowLifx(); + self.updateShowOpenHAB(); + self.updateShowMozIot(); + self.updateShowFhem(); + self.updateShowBroadlink(); + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else self.displayWarn("Load Bridge Settings Error: ", error); - } + } ); }; this.viewBackups = function () { return $http.get(this.state.base + "/backup/available").then( - function (response) { - self.state.backups = response.data; - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else + function (response) { + self.state.backups = response.data; + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else self.displayWarn("Get Backups Error: ", error); - } + } ); }; this.viewConfigs = function () { return $http.get(this.state.systemsbase + "/backup/available").then( - function (response) { - self.state.configs = response.data; - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else + function (response) { + self.state.configs = response.data; + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else self.displayWarn("Get Configs Error: ", error); - } + } ); }; this.viewLogs = function () { return $http.get(this.state.systemsbase + "/logmsgs").then( - function (response) { - self.state.logMsgs = response.data; - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else + function (response) { + self.state.logMsgs = response.data; + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else self.displayWarn("Get log messages Error: ", error); - } + } ); }; this.viewLoggerInfo = function () { return $http.get(this.state.systemsbase + "/logmgmt/loggers/" + self.state.logShowAll).then( - function (response) { - self.state.loggerInfo = response.data; - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else + function (response) { + self.state.loggerInfo = response.data; + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else self.displayWarn("Get logger info Error: ", error); - } + } ); }; this.viewNestItems = function () { - if(!this.state.showNest) + if (!this.state.showNest) return; return $http.get(this.state.base + "/nest/items").then( - function (response) { - self.state.nestitems = response.data; - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else + function (response) { + self.state.nestitems = response.data; + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else self.displayWarn("Get Nest Items Error: ", error); - } + } ); }; this.viewHueDevices = function () { - if(!this.state.showHue) + if (!this.state.showHue) return; return $http.get(this.state.base + "/hue/devices").then( - function (response) { - self.state.huedevices = response.data; - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else + function (response) { + self.state.huedevices = response.data; + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else self.displayWarn("Get Hue Items Error: ", error); - } + } ); }; this.viewVeraDevices = function () { - if(!this.state.showVera) + if (!this.state.showVera) return; return $http.get(this.state.base + "/vera/devices").then( - function (response) { - self.state.veradevices = response.data; - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else + function (response) { + self.state.veradevices = response.data; + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else self.displayWarn("Get Vera Devices Error: ", error); - } + } ); }; this.viewVeraScenes = function () { - if(!this.state.showVera) + if (!this.state.showVera) return; return $http.get(this.state.base + "/vera/scenes").then( - function (response) { - self.state.verascenes = response.data; - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else + function (response) { + self.state.verascenes = response.data; + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else self.displayWarn("Get Vera Scenes Error: ", error); - } + } ); }; - + this.viewFibaroDevices = function () { - if(!this.state.showFibaro) + if (!this.state.showFibaro) return; return $http.get(this.state.base + "/fibaro/devices").then( - function (response) { - self.state.fibarodevices = response.data; - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else + function (response) { + self.state.fibarodevices = response.data; + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else self.displayWarn("Get Fibaro Devices Error: ", error); - } + } ); }; this.viewFibaroScenes = function () { - if(!this.state.showFibaro) + if (!this.state.showFibaro) return; return $http.get(this.state.base + "/fibaro/scenes").then( - function (response) { - self.state.fibaroscenes = response.data; - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else + function (response) { + self.state.fibaroscenes = response.data; + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else self.displayWarn("Get Fibaro Scenes Error: ", error); - } + } ); }; @@ -781,15 +822,15 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n if (!this.state.showHarmony) return; return $http.get(this.state.base + "/harmony/activities").then( - function (response) { - self.state.harmonyactivities = response.data; - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else + function (response) { + self.state.harmonyactivities = response.data; + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else self.displayWarn("Get Harmony Activities Error: ", error); - } + } ); }; @@ -797,15 +838,15 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n if (!this.state.showHarmony) return; return $http.get(this.state.base + "/harmony/devices").then( - function (response) { - self.state.harmonydevices = response.data; - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else + function (response) { + self.state.harmonydevices = response.data; + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else self.displayWarn("Get Harmony Devices Error: ", error); - } + } ); }; @@ -813,15 +854,15 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n if (!this.state.showHal) return; return $http.get(this.state.base + "/hal/devices").then( - function (response) { - self.state.haldevices = response.data; - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else + function (response) { + self.state.haldevices = response.data; + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else self.displayWarn("Get Hal Devices Error: ", error); - } + } ); }; @@ -829,15 +870,15 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n if (!this.state.showMqtt) return; return $http.get(this.state.base + "/mqtt/devices").then( - function (response) { - self.state.mqttbrokers = response.data; - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else + function (response) { + self.state.mqttbrokers = response.data; + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else self.displayWarn("Get MQTT Devices Error: ", error); - } + } ); }; @@ -845,80 +886,80 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n if (!this.state.showHass) return; return $http.get(this.state.base + "/hass/devices").then( - function (response) { - self.state.hassdevices = response.data; - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else + function (response) { + self.state.hassdevices = response.data; + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else self.displayWarn("Get Hass Devices Error: ", error); - } + } + ); + }; + + this.viewHomeWizardDevices = function () { + if (!this.state.showHomeWizard) + return; + return $http.get(this.state.base + "/homewizard/devices").then( + function (response) { + self.state.homewizarddevices = response.data; + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else + self.displayWarn("Get HomeWizard Devices Error: ", error); + } ); }; - this.viewHomeWizardDevices = function () { - if (!this.state.showHomeWizard) - return; - return $http.get(this.state.base + "/homewizard/devices").then( - function (response) { - self.state.homewizarddevices = response.data; - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else - self.displayWarn("Get HomeWizard Devices Error: ", error); - } - ); - }; - this.viewDomoticzDevices = function () { if (!this.state.showDomoticz) return; return $http.get(this.state.base + "/domoticz/devices").then( - function (response) { - self.state.domoticzdevices = response.data; - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else + function (response) { + self.state.domoticzdevices = response.data; + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else self.displayWarn("Get Domoticz Devices Error: ", error); - } + } ); }; this.viewSomfyDevices = function () { - if(!this.state.showSomfy) - return; - return $http.get(this.state.base + "/somfy/devices").then( - function (response) { - self.state.somfydevices = response.data; - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else - self.displayWarn("Get Somfy Devices Error: ", error); - } - ); - }; + if (!this.state.showSomfy) + return; + return $http.get(this.state.base + "/somfy/devices").then( + function (response) { + self.state.somfydevices = response.data; + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else + self.displayWarn("Get Somfy Devices Error: ", error); + } + ); + }; this.viewLifxDevices = function () { if (!this.state.showLifx) return; return $http.get(this.state.base + "/lifx/devices").then( - function (response) { - self.state.lifxdevices = response.data; - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else + function (response) { + self.state.lifxdevices = response.data; + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else self.displayWarn("Get Lifx Devices Error: ", error); - } + } ); }; @@ -926,15 +967,15 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n if (!this.state.showOpenHAB) return; return $http.get(this.state.base + "/openhab/devices").then( - function (response) { - self.state.openhabdevices = response.data; - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else - self.displayWarn("Get OpenHAB Devices Error: ", error); - } + function (response) { + self.state.openhabdevices = response.data; + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else + self.displayWarn("Get OpenHAB Devices Error: ", error); + } ); }; @@ -942,15 +983,15 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n if (!this.state.showMozIot) return; return $http.get(this.state.base + "/moziot/devices").then( - function (response) { - self.state.moziotdevices = response.data; - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else - self.displayWarn("Get Mozilla IOT Devices Error: ", error); - } + function (response) { + self.state.moziotdevices = response.data; + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else + self.displayWarn("Get Mozilla IOT Devices Error: ", error); + } ); }; @@ -958,15 +999,15 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n 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); - } + 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); + } ); }; @@ -974,41 +1015,41 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n if (!this.state.showBroadlink) return; return $http.get(this.state.base + "/broadlink/devices").then( - function (response) { - self.state.broadlinkdevices = response.data; - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else - self.displayWarn("Get broadlink Devices Error: ", error); - } + function (response) { + self.state.broadlinkdevices = response.data; + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else + self.displayWarn("Get broadlink Devices Error: ", error); + } ); }; this.refreshDevices = function (typeIndex) { return $http.get(this.state.base + "/refresh/" + typeIndex).then( - function (response) { - self.displaySuccess("Refresh devices request complete"); - }, - function (error) { - self.displayWarn("Refresh devices request Error: ", error); - } + function (response) { + self.displaySuccess("Refresh devices request complete"); + }, + function (error) { + self.displayWarn("Refresh devices request Error: ", error); + } ); }; this.formatCallItem = function (currentItem) { - if(currentItem.indexOf("item") < 0) { + if (currentItem.indexOf("item") < 0) { if (currentItem.startsWith("[") || currentItem.startsWith("{")) currentItem = "[{\"item\":" + currentItem + "}]"; else currentItem = "[{\"item\":\"" + currentItem + "\"}]"; - } else if(currentItem.startsWith("{")) + } else if (currentItem.startsWith("{")) currentItem = "[" + currentItem + "]"; return currentItem; }; - + this.getCallObjects = function (deviceString) { if (deviceString === undefined || deviceString === "") return null; @@ -1017,88 +1058,88 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n var newDevices = angular.fromJson(deviceString); var i, s, len = newDevices.length; - for (i=0; i 0.04045) ? Math.pow((red + 0.055) / (1.0 + 0.055), 2.4) : (red / 12.92); - green = (green > 0.04045) ? Math.pow((green + 0.055) / (1.0 + 0.055), 2.4) : (green / 12.92); - blue = (blue > 0.04045) ? Math.pow((blue + 0.055) / (1.0 + 0.055), 2.4) : (blue / 12.92); - - //Apply wide gamut conversion D65 - var X = red * 0.664511 + green * 0.154324 + blue * 0.162028; - var Y = red * 0.283881 + green * 0.668433 + blue * 0.047685; - var Z = red * 0.000088 + green * 0.072310 + blue * 0.986039; - - var fx = X / (X + Y + Z); - var fy = Y / (X + Y + Z); - if (isNaN(fx)) { - fx = 0.0; - } - if (isNaN(fy)) { - fy = 0.0; - } - - return [fx.toPrecision(4),fy.toPrecision(4)]; - }; + //Gamma corrective + red = (red > 0.04045) ? Math.pow((red + 0.055) / (1.0 + 0.055), 2.4) : (red / 12.92); + green = (green > 0.04045) ? Math.pow((green + 0.055) / (1.0 + 0.055), 2.4) : (green / 12.92); + blue = (blue > 0.04045) ? Math.pow((blue + 0.055) / (1.0 + 0.055), 2.4) : (blue / 12.92); + + //Apply wide gamut conversion D65 + var X = red * 0.664511 + green * 0.154324 + blue * 0.162028; + var Y = red * 0.283881 + green * 0.668433 + blue * 0.047685; + var Z = red * 0.000088 + green * 0.072310 + blue * 0.986039; + + var fx = X / (X + Y + Z); + var fy = Y / (X + Y + Z); + if (isNaN(fx)) { + fx = 0.0; + } + if (isNaN(fy)) { + fy = 0.0; + } + + return [fx.toPrecision(4), fy.toPrecision(4)]; + }; this.testUrl = function (device, type, value, valueType) { var msgDescription = "unknown"; @@ -1405,50 +1445,49 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n addComma = true; } if (valueType === "dim" && value) { - if(addComma) + if (addComma) testBody = testBody + ","; testBody = testBody + "\"bri\":" + value; addComma = true; } if (valueType === "color" && value) { - if(addComma) + if (addComma) testBody = testBody + ","; - testBody = testBody + "\"xy\": [" + value[0] +"," + value[1] + "]"; + testBody = testBody + "\"xy\": [" + value[0] + "," + value[1] + "]"; } testBody = testBody + "}"; if (testBody === "{}") { self.displayWarn("No value available for test call...", null); return; } - + $http.put(testUrl, testBody).then( - function (response) { - if (typeof(response.data[0].success) !== 'undefined') { - msgDescription = "success " + angular.toJson(response.data); - } - if (typeof(response.data[0].error) !== 'undefined') { - if(response.data[0].error.description.indexOf("unauthorized") > -1) { - self.displayWarn("Authorization error, please retry...", null); - } - else { - msgDescription = "error " + angular.toJson(response.data[0].error); - self.displayErrorMessage("Request Error, Please look in your habridge log: ", msgDescription); - } - return; - } - - self.displaySuccess("Request Executed: " + msgDescription); - }, - function (error) { - if (error.status === 401) - $rootScope.$broadcast('securityReinit', 'done'); - else - self.displayWarn("Request Error, Pleae look in your habridge log: ", error); + function (response) { + if (typeof (response.data[0].success) !== 'undefined') { + msgDescription = "success " + angular.toJson(response.data); } + if (typeof (response.data[0].error) !== 'undefined') { + if (response.data[0].error.description.indexOf("unauthorized") > -1) { + self.displayWarn("Authorization error, please retry...", null); + } else { + msgDescription = "error " + angular.toJson(response.data[0].error); + self.displayErrorMessage("Request Error, Please look in your habridge log: ", msgDescription); + } + return; + } + + self.displaySuccess("Request Executed: " + msgDescription); + }, + function (error) { + if (error.status === 401) + $rootScope.$broadcast('securityReinit', 'done'); + else + self.displayWarn("Request Error, Pleae look in your habridge log: ", error); + } ); - return; + return; }; - + this.formatUrlItem = function (currentItem) { var formattedItem = ""; if (currentItem !== "") { @@ -1478,7 +1517,7 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n if (self.state.device !== undefined && self.state.device !== null && self.state.device.mapType !== undefined && self.state.device.mapType !== null && self.state.device.mapType !== "") { self.state.device.mapId = self.state.device.mapId + "-" + anId; if (dimpayload !== undefined && dimpayload !== null && dimpayload !== "") { - self.state.device.dimUrl = self.formatUrlItem(currentDim); + self.state.device.dimUrl = self.formatUrlItem(currentDim); } if (onpayload !== undefined && onpayload !== null && onpayload !== "") { @@ -1507,7 +1546,7 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n if (colorpayload !== undefined && colorpayload !== null && colorpayload !== "") self.state.device.colorUrl = "[{\"item\":"; } - + if (isObject) { if (dimpayload !== undefined && dimpayload !== null && dimpayload !== "") self.state.device.dimUrl = self.state.device.dimUrl + dimpayload; @@ -1517,7 +1556,7 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n self.state.device.offUrl = self.state.device.offUrl + offpayload; if (colorpayload !== undefined && colorpayload !== null && colorpayload !== "") self.state.device.colorUrl = self.state.device.colorUrl + colorpayload; - + } else { if (dimpayload !== undefined && dimpayload !== null && dimpayload !== "") self.state.device.dimUrl = self.state.device.dimUrl + "\"" + dimpayload + "\""; @@ -1528,7 +1567,7 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n if (colorpayload !== undefined && colorpayload !== null && colorpayload !== "") self.state.device.colorUrl = self.state.device.colorUrl + "\"" + colorpayload + "\""; } - + if (count !== undefined && count !== null && count !== "") { if (dimpayload !== undefined && dimpayload !== null && dimpayload !== "") self.state.device.dimUrl = self.state.device.dimUrl + ",\"count\":\"" + count; @@ -1560,350 +1599,447 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n }; }); -app.controller ('SystemController', function ($scope, $location, bridgeService, ngDialog) { - bridgeService.viewConfigs(); - bridgeService.loadBridgeSettings(); - $scope.bridge = bridgeService.state; - $scope.optionalbackupname = ""; - $scope.bridge.isInControl = false; - $scope.visible = false; - $scope.imgUrl = "glyphicon glyphicon-plus"; +app.controller('SystemController', function ($scope, $location, bridgeService, ngDialog) { + bridgeService.viewConfigs(); + bridgeService.loadBridgeSettings(); + $scope.bridge = bridgeService.state; + $scope.optionalbackupname = ""; + $scope.bridge.isInControl = false; + $scope.visible = false; + $scope.imgUrl = "glyphicon glyphicon-plus"; $scope.newhassport = "8123"; $scope.newdomoticzport = "8080"; $scope.newopenhabport = "8080"; $scope.newfhemport = "8080"; - $scope.addVeratoSettings = function (newveraname, newveraip) { - if($scope.bridge.settings.veraaddress === undefined || $scope.bridge.settings.veraaddress === null) { - $scope.bridge.settings.veraaddress = { devices: [] }; + $scope.addVeratoSettings = function (newveraname, newveraip) { + if ($scope.bridge.settings.veraaddress === undefined || $scope.bridge.settings.veraaddress === null) { + $scope.bridge.settings.veraaddress = { + devices: [] + }; } - var newVera = {name: newveraname, ip: newveraip }; - $scope.bridge.settings.veraaddress.devices.push(newVera); - $scope.newveraname = null; - $scope.newveraip = null; - }; - $scope.removeVeratoSettings = function (veraname, veraip) { - for(var i = $scope.bridge.settings.veraaddress.devices.length - 1; i >= 0; i--) { - if($scope.bridge.settings.veraaddress.devices[i].name === veraname && $scope.bridge.settings.veraaddress.devices[i].ip === veraip) { - $scope.bridge.settings.veraaddress.devices.splice(i, 1); - } - } - }; - $scope.addFibarotoSettings = function (newfibaroname, newfibaroip, newfibaroport, newfibarousername, newfibaropassword, filters) { - if($scope.bridge.settings.fibaroaddress === undefined || $scope.bridge.settings.fibaroaddress === null) { - $scope.bridge.settings.fibaroaddress = { devices: [] }; + var newVera = { + name: newveraname, + ip: newveraip + }; + $scope.bridge.settings.veraaddress.devices.push(newVera); + $scope.newveraname = null; + $scope.newveraip = null; + }; + $scope.removeVeratoSettings = function (veraname, veraip) { + for (var i = $scope.bridge.settings.veraaddress.devices.length - 1; i >= 0; i--) { + if ($scope.bridge.settings.veraaddress.devices[i].name === veraname && $scope.bridge.settings.veraaddress.devices[i].ip === veraip) { + $scope.bridge.settings.veraaddress.devices.splice(i, 1); + } } - var stringFilter = angular.toJson(filters); - var newFibaro = {name: newfibaroname, ip: newfibaroip, port: newfibaroport, username: newfibarousername, password: newfibaropassword, extensions: filters}; - $scope.bridge.settings.fibaroaddress.devices.push(newFibaro); - $scope.newfibaroname = null; - $scope.newfibaroip = null; - $scope.newfibaroport = null; - $scope.newfibarousername = null; - $scope.newfibaropassword = null; - }; - $scope.removeFibarotoSettings = function (fibaroname, fibaroip, fibaroport) { - for(var i = $scope.bridge.settings.fibaroaddress.devices.length - 1; i >= 0; i--) { - if($scope.bridge.settings.fibaroaddress.devices[i].name === fibaroname && $scope.bridge.settings.fibaroaddress.devices[i].ip === fibaroip && $scope.bridge.settings.fibaroaddress.devices[i].port === fibaroport) { - $scope.bridge.settings.fibaroaddress.devices.splice(i, 1); - } - } - }; - $scope.addHarmonytoSettings = function (newharmonyname, newharmonyip, newharmonywebhook) { - if($scope.bridge.settings.harmonyaddress === undefined || $scope.bridge.settings.harmonyaddress === null) { - $scope.bridge.settings.harmonyaddress = { devices: [] }; + }; + $scope.addFibarotoSettings = function (newfibaroname, newfibaroip, newfibaroport, newfibarousername, newfibaropassword, filters) { + if ($scope.bridge.settings.fibaroaddress === undefined || $scope.bridge.settings.fibaroaddress === null) { + $scope.bridge.settings.fibaroaddress = { + devices: [] + }; } - var newharmony = {name: newharmonyname, ip: newharmonyip, webhook: newharmonywebhook}; - $scope.bridge.settings.harmonyaddress.devices.push(newharmony); - $scope.newharmonyname = null; - $scope.newharmonyip = null; - }; - $scope.removeHarmonytoSettings = function (harmonyname, harmonyip) { - for(var i = $scope.bridge.settings.harmonyaddress.devices.length - 1; i >= 0; i--) { - if($scope.bridge.settings.harmonyaddress.devices[i].name === harmonyname && $scope.bridge.settings.harmonyaddress.devices[i].ip === harmonyip) { - $scope.bridge.settings.harmonyaddress.devices.splice(i, 1); - } - } - }; - $scope.addHuetoSettings = function (newhuename, newhueip) { - if($scope.bridge.settings.hueaddress === undefined || $scope.bridge.settings.hueaddress === null) { - $scope.bridge.settings.hueaddress = { devices: [] }; + var stringFilter = angular.toJson(filters); + var newFibaro = { + name: newfibaroname, + ip: newfibaroip, + port: newfibaroport, + username: newfibarousername, + password: newfibaropassword, + extensions: filters + }; + $scope.bridge.settings.fibaroaddress.devices.push(newFibaro); + $scope.newfibaroname = null; + $scope.newfibaroip = null; + $scope.newfibaroport = null; + $scope.newfibarousername = null; + $scope.newfibaropassword = null; + }; + $scope.removeFibarotoSettings = function (fibaroname, fibaroip, fibaroport) { + for (var i = $scope.bridge.settings.fibaroaddress.devices.length - 1; i >= 0; i--) { + if ($scope.bridge.settings.fibaroaddress.devices[i].name === fibaroname && $scope.bridge.settings.fibaroaddress.devices[i].ip === fibaroip && $scope.bridge.settings.fibaroaddress.devices[i].port === fibaroport) { + $scope.bridge.settings.fibaroaddress.devices.splice(i, 1); + } } - var newhue = {name: newhuename, ip: newhueip }; - $scope.bridge.settings.hueaddress.devices.push(newhue); - $scope.newhuename = null; - $scope.newhueip = null; - }; - $scope.removeHuetoSettings = function (huename, hueip) { - for(var i = $scope.bridge.settings.hueaddress.devices.length - 1; i >= 0; i--) { - if($scope.bridge.settings.hueaddress.devices[i].name === huename && $scope.bridge.settings.hueaddress.devices[i].ip === hueip) { - $scope.bridge.settings.hueaddress.devices.splice(i, 1); - } - } - }; - $scope.addHaltoSettings = function (newhalname, newhalip, newhalsecure, newhaltoken) { - if($scope.bridge.settings.haladdress === undefined || $scope.bridge.settings.haladdress === null) { - $scope.bridge.settings.haladdress = { devices: [] }; + }; + $scope.addHarmonytoSettings = function (newharmonyname, newharmonyip, newharmonywebhook) { + if ($scope.bridge.settings.harmonyaddress === undefined || $scope.bridge.settings.harmonyaddress === null) { + $scope.bridge.settings.harmonyaddress = { + devices: [] + }; } - var newhal = {name: newhalname, ip: newhalip, secure: newhalsecure, password: newhaltoken }; - $scope.bridge.settings.haladdress.devices.push(newhal); - $scope.newhalname = null; - $scope.newhalip = null; - }; - $scope.removeHaltoSettings = function (halname, halip) { - for(var i = $scope.bridge.settings.haladdress.devices.length - 1; i >= 0; i--) { - if($scope.bridge.settings.haladdress.devices[i].name === halname && $scope.bridge.settings.haladdress.devices[i].ip === halip) { - $scope.bridge.settings.haladdress.devices.splice(i, 1); - } - } - }; - $scope.addMQTTtoSettings = function (newmqttname, newmqttip, newmqttusername, newmqttpassword) { - if($scope.bridge.settings.mqttaddress === undefined || $scope.bridge.settings.mqttaddress === null) { - $scope.bridge.settings.mqttaddress = { devices: [] }; + var newharmony = { + name: newharmonyname, + ip: newharmonyip, + webhook: newharmonywebhook + }; + $scope.bridge.settings.harmonyaddress.devices.push(newharmony); + $scope.newharmonyname = null; + $scope.newharmonyip = null; + }; + $scope.removeHarmonytoSettings = function (harmonyname, harmonyip) { + for (var i = $scope.bridge.settings.harmonyaddress.devices.length - 1; i >= 0; i--) { + if ($scope.bridge.settings.harmonyaddress.devices[i].name === harmonyname && $scope.bridge.settings.harmonyaddress.devices[i].ip === harmonyip) { + $scope.bridge.settings.harmonyaddress.devices.splice(i, 1); + } } - var newmqtt = {name: newmqttname, ip: newmqttip, username: newmqttusername, password: newmqttpassword }; - $scope.bridge.settings.mqttaddress.devices.push(newmqtt); - $scope.newmqttname = null; - $scope.newmqttip = null; - $scope.newmqttusername = null; - $scope.newmqttpassword = null; - }; - $scope.removeMQTTtoSettings = function (mqttname, mqttip) { - for(var i = $scope.bridge.settings.mqttaddress.devices.length - 1; i >= 0; i--) { - if($scope.bridge.settings.mqttaddress.devices[i].name === mqttname && $scope.bridge.settings.mqttaddress.devices[i].ip === mqttip) { - $scope.bridge.settings.mqttaddress.devices.splice(i, 1); - } - } - }; - $scope.addHasstoSettings = function (newhassname, newhassip, newhassport, newhasspassword, newhasssecure) { - if($scope.bridge.settings.hassaddress === undefined || $scope.bridge.settings.hassaddress === null) { - $scope.bridge.settings.hassaddress = { devices: [] }; + }; + $scope.addHuetoSettings = function (newhuename, newhueip) { + if ($scope.bridge.settings.hueaddress === undefined || $scope.bridge.settings.hueaddress === null) { + $scope.bridge.settings.hueaddress = { + devices: [] + }; } - var newhass = {name: newhassname, ip: newhassip, port: newhassport, password: newhasspassword, secure: newhasssecure }; - $scope.bridge.settings.hassaddress.devices.push(newhass); - $scope.newhassname = null; - $scope.newhassip = null; - $scope.newhassport = null; - $scope.newhasspassword = null; - $scope.newhassport = "8123"; - }; - $scope.removeHasstoSettings = function (hassname, hassip) { - for(var i = $scope.bridge.settings.hassaddress.devices.length - 1; i >= 0; i--) { - if($scope.bridge.settings.hassaddress.devices[i].name === hassname && $scope.bridge.settings.hassaddress.devices[i].ip === hassip) { - $scope.bridge.settings.hassaddress.devices.splice(i, 1); - } - } - }; - $scope.addHomeWizardtoSettings = function (newhomewizardname, newhomewizardip, newhomewizardusername, newhomewizardpassword) { - if($scope.bridge.settings.homewizardaddress === undefined || $scope.bridge.settings.homewizardaddress === null) { - $scope.bridge.settings.homewizardaddress = { devices: [] }; - } - var newhomewizard = { name: newhomewizardname, ip: newhomewizardip, username: newhomewizardusername, password: newhomewizardpassword }; - $scope.bridge.settings.homewizardaddress.devices.push(newhomewizard); - $scope.newhomewizardname = null; - $scope.newhomewizardip = null; - $scope.newhomewizardusername = null; - $scope.newhomewizardpassword = null; - }; - $scope.removeHomeWizardtoSettings = function (homewizardname, homewizardip) { - for(var i = $scope.bridge.settings.homewizardaddress.devices.length - 1; i >= 0; i--) { - if($scope.bridge.settings.homewizardaddress.devices[i].name === homewizardname && $scope.bridge.settings.homewizardaddress.devices[i].ip === homewizardip) { - $scope.bridge.settings.homewizardaddress.devices.splice(i, 1); - } - } - }; - $scope.addDomoticztoSettings = function (newdomoticzname, newdomoticzip, newdomoticzport, newdomoticzusername, newdomoticzpassword, newdomoticzsecure) { - if($scope.bridge.settings.domoticzaddress === undefined || $scope.bridge.settings.domoticzaddress === null) { - $scope.bridge.settings.domoticzaddress = { devices: [] }; + var newhue = { + name: newhuename, + ip: newhueip + }; + $scope.bridge.settings.hueaddress.devices.push(newhue); + $scope.newhuename = null; + $scope.newhueip = null; + }; + $scope.removeHuetoSettings = function (huename, hueip) { + for (var i = $scope.bridge.settings.hueaddress.devices.length - 1; i >= 0; i--) { + if ($scope.bridge.settings.hueaddress.devices[i].name === huename && $scope.bridge.settings.hueaddress.devices[i].ip === hueip) { + $scope.bridge.settings.hueaddress.devices.splice(i, 1); + } } - var newdomoticz = {name: newdomoticzname, ip: newdomoticzip, port: newdomoticzport, username: newdomoticzusername, password: newdomoticzpassword, secure: newdomoticzsecure }; - $scope.bridge.settings.domoticzaddress.devices.push(newdomoticz); - $scope.newdomoticzname = null; - $scope.newdomoticzip = null; - $scope.newdomoticzport = "8080"; - $scope.newdomoticzpassword = null; - }; - $scope.removeDomoticztoSettings = function (domoticzname, domoticzip) { - for(var i = $scope.bridge.settings.domoticzaddress.devices.length - 1; i >= 0; i--) { - if($scope.bridge.settings.domoticzaddress.devices[i].name === domoticzname && $scope.bridge.settings.domoticzaddress.devices[i].ip === domoticzip) { - $scope.bridge.settings.domoticzaddress.devices.splice(i, 1); - } - } - }; - $scope.addSomfytoSettings = function (newsomfyname, newsomfyip, newsomfyusername, newsomfypassword) { - if($scope.bridge.settings.somfyaddress == null) { - $scope.bridge.settings.somfyaddress = { devices: [] }; - } - var newSomfy = {name: newsomfyname, ip: newsomfyip, username: newsomfyusername, password: newsomfypassword }; - $scope.bridge.settings.somfyaddress.devices.push(newSomfy); - $scope.newsomfyname = null; - $scope.newsomfyip = null; - $scope.newsomfyusername = null; - $scope.newsomfypassword = null; - }; - $scope.removeSomfytoSettings = function (somfyname, somfyip) { - for(var i = $scope.bridge.settings.somfyaddress.devices.length - 1; i >= 0; i--) { - if($scope.bridge.settings.somfyaddress.devices[i].name === somfyname && $scope.bridge.settings.somfyaddress.devices[i].ip === somfyip) { - $scope.bridge.settings.somfyaddress.devices.splice(i, 1); - } - } - }; - $scope.addOpenHABtoSettings = function (newopenhabname, newopenhabip, newopenhabport, newopenhabusername, newopenhabpassword, newopenhabsecure) { - if($scope.bridge.settings.openhabaddress === undefined || $scope.bridge.settings.openhabaddress === null) { - $scope.bridge.settings.openhabaddress = { devices: [] }; + }; + $scope.addHaltoSettings = function (newhalname, newhalip, newhalsecure, newhaltoken) { + if ($scope.bridge.settings.haladdress === undefined || $scope.bridge.settings.haladdress === null) { + $scope.bridge.settings.haladdress = { + devices: [] + }; } - var newopenhab = {name: newopenhabname, ip: newopenhabip, port: newopenhabport, username: newopenhabusername, password: newopenhabpassword, secure: newopenhabsecure }; - $scope.bridge.settings.openhabaddress.devices.push(newopenhab); - $scope.newopenhabname = null; - $scope.newopenhabip = null; - $scope.newopenhabport = "8080"; - $scope.newopenhabusername = null; - $scope.newopenhabpassword = null; - }; - $scope.removeOpenHABtoSettings = function (openhabname, openhabip) { - for(var i = $scope.bridge.settings.openhabaddress.devices.length - 1; i >= 0; i--) { - if($scope.bridge.settings.openhabaddress.devices[i].name === openhabname && $scope.bridge.settings.openhabaddress.devices[i].ip === openhabip) { - $scope.bridge.settings.openhabaddress.devices.splice(i, 1); - } - } - }; + var newhal = { + name: newhalname, + ip: newhalip, + secure: newhalsecure, + password: newhaltoken + }; + $scope.bridge.settings.haladdress.devices.push(newhal); + $scope.newhalname = null; + $scope.newhalip = null; + }; + $scope.removeHaltoSettings = function (halname, halip) { + for (var i = $scope.bridge.settings.haladdress.devices.length - 1; i >= 0; i--) { + if ($scope.bridge.settings.haladdress.devices[i].name === halname && $scope.bridge.settings.haladdress.devices[i].ip === halip) { + $scope.bridge.settings.haladdress.devices.splice(i, 1); + } + } + }; + $scope.addMQTTtoSettings = function (newmqttname, newmqttip, newmqttusername, newmqttpassword) { + if ($scope.bridge.settings.mqttaddress === undefined || $scope.bridge.settings.mqttaddress === null) { + $scope.bridge.settings.mqttaddress = { + devices: [] + }; + } + var newmqtt = { + name: newmqttname, + ip: newmqttip, + username: newmqttusername, + password: newmqttpassword + }; + $scope.bridge.settings.mqttaddress.devices.push(newmqtt); + $scope.newmqttname = null; + $scope.newmqttip = null; + $scope.newmqttusername = null; + $scope.newmqttpassword = null; + }; + $scope.removeMQTTtoSettings = function (mqttname, mqttip) { + for (var i = $scope.bridge.settings.mqttaddress.devices.length - 1; i >= 0; i--) { + if ($scope.bridge.settings.mqttaddress.devices[i].name === mqttname && $scope.bridge.settings.mqttaddress.devices[i].ip === mqttip) { + $scope.bridge.settings.mqttaddress.devices.splice(i, 1); + } + } + }; + $scope.addHasstoSettings = function (newhassname, newhassip, newhassport, newhasspassword, newhasssecure) { + if ($scope.bridge.settings.hassaddress === undefined || $scope.bridge.settings.hassaddress === null) { + $scope.bridge.settings.hassaddress = { + devices: [] + }; + } + var newhass = { + name: newhassname, + ip: newhassip, + port: newhassport, + password: newhasspassword, + secure: newhasssecure + }; + $scope.bridge.settings.hassaddress.devices.push(newhass); + $scope.newhassname = null; + $scope.newhassip = null; + $scope.newhassport = null; + $scope.newhasspassword = null; + $scope.newhassport = "8123"; + }; + $scope.removeHasstoSettings = function (hassname, hassip) { + for (var i = $scope.bridge.settings.hassaddress.devices.length - 1; i >= 0; i--) { + if ($scope.bridge.settings.hassaddress.devices[i].name === hassname && $scope.bridge.settings.hassaddress.devices[i].ip === hassip) { + $scope.bridge.settings.hassaddress.devices.splice(i, 1); + } + } + }; + $scope.addHomeWizardtoSettings = function (newhomewizardname, newhomewizardip, newhomewizardusername, newhomewizardpassword) { + if ($scope.bridge.settings.homewizardaddress === undefined || $scope.bridge.settings.homewizardaddress === null) { + $scope.bridge.settings.homewizardaddress = { + devices: [] + }; + } + var newhomewizard = { + name: newhomewizardname, + ip: newhomewizardip, + username: newhomewizardusername, + password: newhomewizardpassword + }; + $scope.bridge.settings.homewizardaddress.devices.push(newhomewizard); + $scope.newhomewizardname = null; + $scope.newhomewizardip = null; + $scope.newhomewizardusername = null; + $scope.newhomewizardpassword = null; + }; + $scope.removeHomeWizardtoSettings = function (homewizardname, homewizardip) { + for (var i = $scope.bridge.settings.homewizardaddress.devices.length - 1; i >= 0; i--) { + if ($scope.bridge.settings.homewizardaddress.devices[i].name === homewizardname && $scope.bridge.settings.homewizardaddress.devices[i].ip === homewizardip) { + $scope.bridge.settings.homewizardaddress.devices.splice(i, 1); + } + } + }; + $scope.addDomoticztoSettings = function (newdomoticzname, newdomoticzip, newdomoticzport, newdomoticzusername, newdomoticzpassword, newdomoticzsecure) { + if ($scope.bridge.settings.domoticzaddress === undefined || $scope.bridge.settings.domoticzaddress === null) { + $scope.bridge.settings.domoticzaddress = { + devices: [] + }; + } + var newdomoticz = { + name: newdomoticzname, + ip: newdomoticzip, + port: newdomoticzport, + username: newdomoticzusername, + password: newdomoticzpassword, + secure: newdomoticzsecure + }; + $scope.bridge.settings.domoticzaddress.devices.push(newdomoticz); + $scope.newdomoticzname = null; + $scope.newdomoticzip = null; + $scope.newdomoticzport = "8080"; + $scope.newdomoticzpassword = null; + }; + $scope.removeDomoticztoSettings = function (domoticzname, domoticzip) { + for (var i = $scope.bridge.settings.domoticzaddress.devices.length - 1; i >= 0; i--) { + if ($scope.bridge.settings.domoticzaddress.devices[i].name === domoticzname && $scope.bridge.settings.domoticzaddress.devices[i].ip === domoticzip) { + $scope.bridge.settings.domoticzaddress.devices.splice(i, 1); + } + } + }; + $scope.addSomfytoSettings = function (newsomfyname, newsomfyip, newsomfyusername, newsomfypassword) { + if ($scope.bridge.settings.somfyaddress == null) { + $scope.bridge.settings.somfyaddress = { + devices: [] + }; + } + var newSomfy = { + name: newsomfyname, + ip: newsomfyip, + username: newsomfyusername, + password: newsomfypassword + }; + $scope.bridge.settings.somfyaddress.devices.push(newSomfy); + $scope.newsomfyname = null; + $scope.newsomfyip = null; + $scope.newsomfyusername = null; + $scope.newsomfypassword = null; + }; + $scope.removeSomfytoSettings = function (somfyname, somfyip) { + for (var i = $scope.bridge.settings.somfyaddress.devices.length - 1; i >= 0; i--) { + if ($scope.bridge.settings.somfyaddress.devices[i].name === somfyname && $scope.bridge.settings.somfyaddress.devices[i].ip === somfyip) { + $scope.bridge.settings.somfyaddress.devices.splice(i, 1); + } + } + }; + $scope.addOpenHABtoSettings = function (newopenhabname, newopenhabip, newopenhabport, newopenhabusername, newopenhabpassword, newopenhabsecure) { + if ($scope.bridge.settings.openhabaddress === undefined || $scope.bridge.settings.openhabaddress === null) { + $scope.bridge.settings.openhabaddress = { + devices: [] + }; + } + var newopenhab = { + name: newopenhabname, + ip: newopenhabip, + port: newopenhabport, + username: newopenhabusername, + password: newopenhabpassword, + secure: newopenhabsecure + }; + $scope.bridge.settings.openhabaddress.devices.push(newopenhab); + $scope.newopenhabname = null; + $scope.newopenhabip = null; + $scope.newopenhabport = "8080"; + $scope.newopenhabusername = null; + $scope.newopenhabpassword = null; + }; + $scope.removeOpenHABtoSettings = function (openhabname, openhabip) { + for (var i = $scope.bridge.settings.openhabaddress.devices.length - 1; i >= 0; i--) { + if ($scope.bridge.settings.openhabaddress.devices[i].name === openhabname && $scope.bridge.settings.openhabaddress.devices[i].ip === openhabip) { + $scope.bridge.settings.openhabaddress.devices.splice(i, 1); + } + } + }; - $scope.addMozIottoSettings = function (newmoziotname, newmoziotip, newmoziotport, newmoziotusername, newmoziotpassword, newmoziotsecure) { - if($scope.bridge.settings.moziotaddress === undefined || $scope.bridge.settings.moziotaddress === null) { - $scope.bridge.settings.moziotaddress = { devices: [] }; + $scope.addMozIottoSettings = function (newmoziotname, newmoziotip, newmoziotport, newmoziotusername, newmoziotpassword, newmoziotsecure) { + if ($scope.bridge.settings.moziotaddress === undefined || $scope.bridge.settings.moziotaddress === null) { + $scope.bridge.settings.moziotaddress = { + devices: [] + }; } - var newmoziot = {name: newmoziotname, ip: newmoziotip, port: newmoziotport, username: newmoziotusername, password: newmoziotpassword, secure: newmoziotsecure }; - $scope.bridge.settings.moziotaddress.devices.push(newmoziot); - $scope.newmoziotname = null; - $scope.newmoziotip = null; - $scope.newmoziotport = "4443"; - $scope.newmoziotusername = null; - $scope.newmoziotpassword = null; - }; - $scope.removeMozIottoSettings = function (moziotname, moziotip) { - for(var i = $scope.bridge.settings.moziotaddress.devices.length - 1; i >= 0; i--) { - if($scope.bridge.settings.moziotaddress.devices[i].name === moziotname && $scope.bridge.settings.moziotaddress.devices[i].ip === moziotip) { - $scope.bridge.settings.moziotaddress.devices.splice(i, 1); - } - } - }; - - $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 newmoziot = { + name: newmoziotname, + ip: newmoziotip, + port: newmoziotport, + username: newmoziotusername, + password: newmoziotpassword, + secure: newmoziotsecure + }; + $scope.bridge.settings.moziotaddress.devices.push(newmoziot); + $scope.newmoziotname = null; + $scope.newmoziotip = null; + $scope.newmoziotport = "4443"; + $scope.newmoziotusername = null; + $scope.newmoziotpassword = null; + }; + $scope.removeMozIottoSettings = function (moziotname, moziotip) { + for (var i = $scope.bridge.settings.moziotaddress.devices.length - 1; i >= 0; i--) { + if ($scope.bridge.settings.moziotaddress.devices[i].name === moziotname && $scope.bridge.settings.moziotaddress.devices[i].ip === moziotip) { + $scope.bridge.settings.moziotaddress.devices.splice(i, 1); + } } - 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 = "8080"; - $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(); - }; - $scope.bridgeStop = function () { - bridgeService.stop(); - }; - $scope.saveSettings = function() { - bridgeService.saveSettings(); - }; - $scope.goBridgeUrl = function (url) { - window.open(url, "_blank"); - }; - $scope.backupSettings = function (optionalbackupname) { - bridgeService.backupSettings(optionalbackupname); - }; - $scope.restoreSettings = function (backupname) { - bridgeService.restoreSettings(backupname); - }; - $scope.deleteSettingsBackup = function (backupname) { - bridgeService.deleteSettingsBackup(backupname); - }; - $scope.toggle = function () { - $scope.visible = !$scope.visible; - if($scope.visible) - $scope.imgUrl = "glyphicon glyphicon-minus"; - else - $scope.imgUrl = "glyphicon glyphicon-plus"; - }; - - $scope.changeSeuritySettings = function () { - bridgeService.getSecurityInfo(); + $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 = "8080"; + $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(); + }; + $scope.bridgeStop = function () { + bridgeService.stop(); + }; + $scope.saveSettings = function () { + bridgeService.saveSettings(); + }; + $scope.goBridgeUrl = function (url) { + window.open(url, "_blank"); + }; + $scope.backupSettings = function (optionalbackupname) { + bridgeService.backupSettings(optionalbackupname); + }; + $scope.restoreSettings = function (backupname) { + bridgeService.restoreSettings(backupname); + }; + $scope.deleteSettingsBackup = function (backupname) { + bridgeService.deleteSettingsBackup(backupname); + }; + $scope.toggle = function () { + $scope.visible = !$scope.visible; + if ($scope.visible) + $scope.imgUrl = "glyphicon glyphicon-minus"; + else + $scope.imgUrl = "glyphicon glyphicon-plus"; + }; + + $scope.changeSeuritySettings = function () { + bridgeService.getSecurityInfo(); ngDialog.open({ template: 'views/securitydialog.html', controller: 'SecurityDialogCtrl', className: 'ngdialog-theme-default' }); - }; + }; }); -app.directive('autofocus', ['$timeout', function($timeout) { - return { - restrict: 'A', - link : function($scope, $element) { - $timeout(function() { - $element[0].focus(); - }); - } - }; - }]); +app.directive('autofocus', ['$timeout', function ($timeout) { + return { + restrict: 'A', + link: function ($scope, $element) { + $timeout(function () { + $element[0].focus(); + }); + } + }; +}]); app.directive('nuCheck', [function () { - return { - require: 'ngModel', - link: function (scope, elem, attrs, ctrl) { - var newUser = '#' + attrs.nuCheck; - elem.add(newUser).on('keyup', function () { - scope.$apply(function () { - if($(newUser).val().length > 0 ) { - scope.addingUser = true; - scope.username = $(newUser).val(); - if(scope.showPassword === false) - scope.showPassword = true; - } - else { - scope.addingUser = false; - if(scope.loggedInUser !== undefined) - scope.username = scope.loggedInUser; - scope.showPassword = scope.isSecure; - } - }); - }); - } - }; + return { + require: 'ngModel', + link: function (scope, elem, attrs, ctrl) { + var newUser = '#' + attrs.nuCheck; + elem.add(newUser).on('keyup', function () { + scope.$apply(function () { + if ($(newUser).val().length > 0) { + scope.addingUser = true; + scope.username = $(newUser).val(); + if (scope.showPassword === false) + scope.showPassword = true; + } else { + scope.addingUser = false; + if (scope.loggedInUser !== undefined) + scope.username = scope.loggedInUser; + scope.showPassword = scope.isSecure; + } + }); + }); + } + }; }]); app.directive('pwCheck', [function () { - return { - require: 'ngModel', - link: function (scope, elem, attrs, ctrl) { - var firstPassword = '#' + attrs.pwCheck; - elem.add(firstPassword).on('keyup', function () { - scope.$apply(function () { - var isMatched = false; - if(elem.val().length > 0 && $(firstPassword).val().length > 0) - isMatched = (elem.val() === $(firstPassword).val()); - ctrl.$setValidity('pwmatch', isMatched); - scope.matched = isMatched; - }); - }); - } - }; + return { + require: 'ngModel', + link: function (scope, elem, attrs, ctrl) { + var firstPassword = '#' + attrs.pwCheck; + elem.add(firstPassword).on('keyup', function () { + scope.$apply(function () { + var isMatched = false; + if (elem.val().length > 0 && $(firstPassword).val().length > 0) + isMatched = (elem.val() === $(firstPassword).val()); + ctrl.$setValidity('pwmatch', isMatched); + scope.matched = isMatched; + }); + }); + } + }; }]); app.controller('SecurityDialogCtrl', function ($scope, bridgeService, ngDialog) { $scope.loggedInUser = bridgeService.state.loggedInUser; - if(bridgeService.state.loggedInUser !== undefined) + if (bridgeService.state.loggedInUser !== undefined) $scope.username = bridgeService.state.loggedInUser; else $scope.username = ""; @@ -1919,38 +2055,38 @@ app.controller('SecurityDialogCtrl', function ($scope, bridgeService, ngDialog) $scope.setSecurityInfo = function () { bridgeService.changeSecuritySettings($scope.useLinkButton, $scope.secureHueApi, $scope.execGarden); }; - + $scope.changePassword = function (password, password2) { bridgeService.changePassword(password, password2); }; - + $scope.addUser = function (newUser, password, password2) { bridgeService.addUser(newUser, password, password2); $scope.addingUser = false; - if(bridgeService.staet.loggedInUser !== undefined) + if (bridgeService.staet.loggedInUser !== undefined) $scope.username = bridgeService.state.loggedInUser; else $scope.username = ""; $scope.showPassword = $scope.isSecure; }; - + $scope.delUser = function (newUser) { bridgeService.delUser(newUser); $scope.addingUser = false; - if(bridgeService.state.loggedInUser !== undefined) + if (bridgeService.state.loggedInUser !== undefined) $scope.username = bridgeService.state.loggedInUser; else $scope.username = ""; bridgeService.getHABridgeVersion(); $scope.showPassword = $scope.isSecure; }; - + $scope.dismissDialog = function () { ngDialog.close('ngdialog1'); }; - + $scope.setBlankPassword = function (theElementName) { - if($scope.firstTime) { + if ($scope.firstTime) { var theElement = "#" + theElementName; $(theElement).strength(); $scope.firstTime = false; @@ -1966,49 +2102,48 @@ app.controller('ManageLinksDialogCtrl', function ($scope, bridgeService, ngDialo bridgeService.setWhitelist($scope.whitelist); ngDialog.close('ngdialog1'); }; - + $scope.delEntry = function (anEntry) { - for(var key in $scope.whitelist) { - if ($scope.whitelist.hasOwnProperty(key)) { - var theEntry = $scope.whitelist[key]; - if(theEntry.name === anEntry) { - delete $scope.whitelist[key]; - } - } - } + for (var key in $scope.whitelist) { + if ($scope.whitelist.hasOwnProperty(key)) { + var theEntry = $scope.whitelist[key]; + if (theEntry.name === anEntry) { + delete $scope.whitelist[key]; + } + } + } }; - - $scope.refresh = function () { + + $scope.refresh = function () { bridgeService.getWhitelist(); $scope.whitelist = bridgeService.state.whitelist; }; - + $scope.delAll = function () { $scope.whitelist = null; }; - + $scope.dismissDialog = function () { ngDialog.close('ngdialog1'); }; }); app.controller('LogsController', function ($scope, $location, bridgeService) { - bridgeService.viewLogs(); - $scope.bridge = bridgeService.state; - $scope.levels = ["INFO_INT", "WARN_INT", "DEBUG_INT", "TRACE_INT"]; + bridgeService.viewLogs(); + $scope.bridge = bridgeService.state; + $scope.levels = ["INFO_INT", "WARN_INT", "DEBUG_INT", "TRACE_INT"]; $scope.updateComponents = []; $scope.visible = false; $scope.imgUrl = "glyphicon glyphicon-plus"; - $scope.updateLogs = function() { + $scope.updateLogs = function () { bridgeService.viewLogs(); }; $scope.toggle = function () { $scope.visible = !$scope.visible; - if($scope.visible) { + if ($scope.visible) { $scope.imgUrl = "glyphicon glyphicon-minus"; - bridgeService.viewLoggerInfo(); - } - else + bridgeService.viewLoggerInfo(); + } else $scope.imgUrl = "glyphicon glyphicon-plus"; }; $scope.addToUpdate = function (logInfo) { @@ -2024,11 +2159,11 @@ app.controller('LogsController', function ($scope, $location, bridgeService) { $scope.updateComponents.push(logInfo); } }; - + $scope.updateLoggers = function () { bridgeService.updateLogLevels($scope.updateComponents); }; - + $scope.reloadLoggers = function () { bridgeService.viewLoggerInfo(); }; @@ -2037,22 +2172,22 @@ app.controller('LogsController', function ($scope, $location, bridgeService) { app.directive('postrenderAction', postrenderAction); /* @ngInject */ function postrenderAction($timeout) { - // ### Directive Interface - // Defines base properties for the directive. - var directive = { - restrict: 'A', - priority: 101, - link: link - }; - return directive; + // ### Directive Interface + // Defines base properties for the directive. + var directive = { + restrict: 'A', + priority: 101, + link: link + }; + return directive; - // ### Link Function - // Provides functionality for the directive during the DOM building/data binding stage. - function link(scope, element, attrs) { - $timeout(function() { - scope.$evalAsync(attrs.postrenderAction); - }, 0); - } + // ### Link Function + // Provides functionality for the directive during the DOM building/data binding stage. + function link(scope, element, attrs) { + $timeout(function () { + scope.$evalAsync(attrs.postrenderAction); + }, 0); + } } app.controller('ViewingController', function ($scope, $location, bridgeService, ngDialog) { @@ -2069,8 +2204,8 @@ app.controller('ViewingController', function ($scope, $location, bridgeService, $scope.testUrl = function (device, type) { var dialogNeeded = false; if ((type === "on" && device.onUrl !== undefined && bridgeService.aContainsB(device.onUrl, "${intensity")) || - (type === "off" && device.offUrl !== undefined && bridgeService.aContainsB(device.offUrl, "${intensity")) || - (type === "dim" && device.dimUrl !== undefined)) { + (type === "off" && device.offUrl !== undefined && bridgeService.aContainsB(device.offUrl, "${intensity")) || + (type === "dim" && device.dimUrl !== undefined)) { $scope.bridge.device = device; $scope.bridge.type = type; ngDialog.open({ @@ -2078,10 +2213,9 @@ app.controller('ViewingController', function ($scope, $location, bridgeService, controller: 'ValueDialogCtrl', className: 'ngdialog-theme-default' }); - } - else if ((type === "on" && device.onUrl !== undefined && bridgeService.aContainsB(device.onUrl, "${color")) || - (type === "off" && device.offUrl !== undefined && bridgeService.aContainsB(device.offUrl, "${color")) || - (type === "color" && device.colorUrl !== undefined)) { + } else if ((type === "on" && device.onUrl !== undefined && bridgeService.aContainsB(device.onUrl, "${color")) || + (type === "off" && device.offUrl !== undefined && bridgeService.aContainsB(device.offUrl, "${color")) || + (type === "color" && device.colorUrl !== undefined)) { $scope.bridge.device = device; $scope.bridge.type = type; ngDialog.open({ @@ -2089,8 +2223,7 @@ app.controller('ViewingController', function ($scope, $location, bridgeService, controller: 'ColorDialogCtrl', className: 'ngdialog-theme-default' }); - } - else + } else bridgeService.testUrl(device, type, null, type); }; $scope.deleteDevice = function (device) { @@ -2105,13 +2238,13 @@ app.controller('ViewingController', function ($scope, $location, bridgeService, bridgeService.editDevice(device); $location.path('/editdevice'); }; - $scope.renumberDevices = function() { + $scope.renumberDevices = function () { bridgeService.renumberDevices(); }; - $scope.pushLinkButton = function() { + $scope.pushLinkButton = function () { bridgeService.pushLinkButton(); }; - $scope.manageLinksButton = function() { + $scope.manageLinksButton = function () { ngDialog.open({ template: 'views/managelinksdialog.html', controller: 'ManageLinksDialogCtrl', @@ -2129,54 +2262,53 @@ app.controller('ViewingController', function ($scope, $location, bridgeService, }; $scope.toggle = function () { $scope.visible = !$scope.visible; - if($scope.visible) + if ($scope.visible) $scope.imgUrl = "glyphicon glyphicon-minus"; else $scope.imgUrl = "glyphicon glyphicon-plus"; }; $scope.toggleBk = function () { $scope.visibleBk = !$scope.visibleBk; - if($scope.visibleBk) + if ($scope.visibleBk) $scope.imgBkUrl = "glyphicon glyphicon-minus"; else $scope.imgBkUrl = "glyphicon glyphicon-plus"; }; - $scope.goToRow = function() { + $scope.goToRow = function () { if (bridgeService.state.queueDevId !== null && bridgeService.state.queueDevId !== "") { - bridgeService.state.viewDevId = bridgeService.state.queueDevId; - $scope.$broadcast("rowSelected", bridgeService.state.viewDevId); - console.log("Go to Row selected Id <<" + bridgeService.state.viewDevId + ">>"); - bridgeService.state.queueDevId = null; - } - }; - }); + bridgeService.state.viewDevId = bridgeService.state.queueDevId; + $scope.$broadcast("rowSelected", bridgeService.state.viewDevId); + console.log("Go to Row selected Id <<" + bridgeService.state.viewDevId + ">>"); + bridgeService.state.queueDevId = null; + } + }; +}); app.controller('ValueDialogCtrl', function ($scope, bridgeService, ngDialog) { $scope.slider = { - value: 100, - options: { - floor: 1, - ceil: 100, - showSelectionBar: true - } - }; + value: 100, + options: { + floor: 1, + ceil: 100, + showSelectionBar: true + } + }; $scope.bridge = bridgeService.state; $scope.valueType = "percentage"; $scope.changeScale = function () { - if($scope.valueType === "raw") { - $scope.slider.options.ceil = 254; + if ($scope.valueType === "raw") { + $scope.slider.options.ceil = 254; $scope.slider.value = 254; - } - else { - $scope.slider.options.ceil = 100; - $scope.slider.value = 100; + } else { + $scope.slider.options.ceil = 100; + $scope.slider.value = 100; } }; $scope.setValue = function () { ngDialog.close('ngdialog1'); var theValue = 1; - if($scope.valueType === "percentage") + if ($scope.valueType === "percentage") theValue = Math.round(($scope.slider.value * 0.01) * 255); else theValue = $scope.slider.value; @@ -2188,13 +2320,13 @@ app.controller('ValueDialogCtrl', function ($scope, bridgeService, ngDialog) { app.controller('ColorDialogCtrl', function ($scope, bridgeService, ngDialog) { $scope.rgbPicker = { - color: 'rgb(255,255,255)' - }; + color: 'rgb(255,255,255)' + }; $scope.bridge = bridgeService.state; $scope.setValue = function () { ngDialog.close('ngdialog1'); - var next = $scope.rgbPicker.color.substr($scope.rgbPicker.color.indexOf('(') + 1); + var next = $scope.rgbPicker.color.substr($scope.rgbPicker.color.indexOf('(') + 1); var red = next.substr(0, next.indexOf(',')); next = next.substr(next.indexOf(',') + 1); var green = next.substr(0, next.indexOf(',')); @@ -2223,9 +2355,15 @@ app.controller('VeraController', function ($scope, $location, bridgeService, ngD $scope.bridge = bridgeService.state; $scope.device = bridgeService.state.device; $scope.device_dim_control = ""; - $scope.bulk = { devices: [] }; + $scope.bulk = { + devices: [] + }; $scope.selectAll = false; - $scope.vera = {base: "http://", port: "3480", id: ""}; + $scope.vera = { + base: "http://", + port: "3480", + id: "" + }; bridgeService.viewVeraDevices(); bridgeService.viewVeraScenes(); $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; @@ -2238,30 +2376,29 @@ app.controller('VeraController', function ($scope, $location, bridgeService, ngD }; $scope.buildDeviceUrls = function (veradevice, dim_control, buildonly) { - if(dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0) { - dimpayload = "http://" + veradevice.veraaddress + ":" + $scope.vera.port + + if (dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0) { + dimpayload = "http://" + veradevice.veraaddress + ":" + $scope.vera.port + "/data_request?id=action&output_format=json&DeviceNum=" + veradevice.id + "&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=" + dim_control; - } - else - dimpayload = "http://" + veradevice.veraaddress + ":" + $scope.vera.port + - "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum=" + - veradevice.id; - onpayload = "http://" + veradevice.veraaddress + ":" + $scope.vera.port + - "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum=" + - veradevice.id; - offpayload = "http://" + veradevice.veraaddress + ":" + $scope.vera.port + - "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum=" + - veradevice.id; - - bridgeService.buildUrls(onpayload, dimpayload, offpayload, null, false, veradevice.id, veradevice.name, veradevice.veraname, "switch", "veraDevice", null, null); - $scope.device = bridgeService.state.device; - if (!buildonly) { - bridgeService.editNewDevice($scope.device); - $location.path('/editdevice'); - } + } else + dimpayload = "http://" + veradevice.veraaddress + ":" + $scope.vera.port + + "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum=" + + veradevice.id; + onpayload = "http://" + veradevice.veraaddress + ":" + $scope.vera.port + + "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum=" + + veradevice.id; + offpayload = "http://" + veradevice.veraaddress + ":" + $scope.vera.port + + "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum=" + + veradevice.id; + + bridgeService.buildUrls(onpayload, dimpayload, offpayload, null, false, veradevice.id, veradevice.name, veradevice.veraname, "switch", "veraDevice", null, null); + $scope.device = bridgeService.state.device; + if (!buildonly) { + bridgeService.editNewDevice($scope.device); + $location.path('/editdevice'); + } }; $scope.buildSceneUrls = function (verascene) { @@ -2278,46 +2415,48 @@ app.controller('VeraController', function ($scope, $location, bridgeService, ngD $location.path('/editdevice'); }; - $scope.bulkAddDevices = function(dim_control) { + $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.veradevices.length; x++) { - if(bridgeService.state.veradevices[x].id === $scope.bulk.devices[i]) { - $scope.buildDeviceUrls(bridgeService.state.veradevices[x],dim_control,true); + 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, 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 + 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.viewVeraDevices(); - bridgeService.viewVeraScenes(); - }, - function (error) { - bridgeService.displayWarn("Error adding Vera devices in bulk.", error); - } - ); - $scope.bulk = { devices: [] }; + function () { + $scope.clearDevice(); + bridgeService.viewDevices(); + bridgeService.viewVeraDevices(); + bridgeService.viewVeraScenes(); + }, + function (error) { + bridgeService.displayWarn("Error adding Vera devices in bulk.", error); + } + ); + $scope.bulk = { + devices: [] + }; $scope.selectAll = false; }; @@ -2327,7 +2466,7 @@ app.controller('VeraController', function ($scope, $location, bridgeService, ngD // is currently selected if (idx > -1) { $scope.bulk.devices.splice(idx, 1); - if($scope.bulk.devices.length === 0 && $scope.selectAll) + if ($scope.bulk.devices.length === 0 && $scope.selectAll) $scope.selectAll = false; } @@ -2339,14 +2478,15 @@ app.controller('VeraController', function ($scope, $location, bridgeService, ngD }; $scope.toggleSelectAll = function toggleSelectAll() { - if($scope.selectAll) { + if ($scope.selectAll) { $scope.selectAll = false; - $scope.bulk = { devices: [] }; - } - else { + $scope.bulk = { + devices: [] + }; + } else { $scope.selectAll = true; - for(var x = 0; x < bridgeService.state.veradevices.length; x++) { - if($scope.bulk.devices.indexOf(bridgeService.state.veradevices[x]) < 0) + for (var x = 0; x < bridgeService.state.veradevices.length; x++) { + if ($scope.bulk.devices.indexOf(bridgeService.state.veradevices[x]) < 0) $scope.bulk.devices.push(bridgeService.state.veradevices[x].id); } } @@ -2354,7 +2494,7 @@ app.controller('VeraController', function ($scope, $location, bridgeService, ngD $scope.toggleButtons = function () { $scope.buttonsVisible = !$scope.buttonsVisible; - if($scope.buttonsVisible) + if ($scope.buttonsVisible) $scope.imgButtonsUrl = "glyphicon glyphicon-minus"; else $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; @@ -2368,7 +2508,7 @@ app.controller('VeraController', function ($scope, $location, bridgeService, ngD className: 'ngdialog-theme-default' }); }; - + $scope.editDevice = function (device) { bridgeService.editDevice(device); $location.path('/editdevice'); @@ -2379,9 +2519,15 @@ app.controller('FibaroController', function ($scope, $location, bridgeService, n $scope.bridge = bridgeService.state; $scope.device = bridgeService.state.device; $scope.device_dim_control = ""; - $scope.bulk = { devices: [] }; + $scope.bulk = { + devices: [] + }; $scope.selectAll = false; - $scope.fibaro = {base: "http://", port: "80", id: ""}; + $scope.fibaro = { + base: "http://", + port: "80", + id: "" + }; bridgeService.viewFibaroDevices(); bridgeService.viewFibaroScenes(); $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; @@ -2395,13 +2541,13 @@ app.controller('FibaroController', function ($scope, $location, bridgeService, n $scope.buildDeviceUrls = function (fibarodevice, dim_control, buildonly) { var dimpayload = null; - 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) dimpayload = "http://" + fibarodevice.fibaroaddress + ":" + fibarodevice.fibaroport + "/api/callAction?deviceID=" + fibarodevice.id + "&name=setValue&arg1=" + dim_control; - + onpayload = "http://" + fibarodevice.fibaroaddress + ":" + fibarodevice.fibaroport + "/api/callAction?deviceID=" + fibarodevice.id + "&name=turnOn"; offpayload = "http://" + fibarodevice.fibaroaddress + ":" + fibarodevice.fibaroport + "/api/callAction?deviceID=" + fibarodevice.id + "&name=turnOff"; - bridgeService.buildUrls(onpayload, dimpayload, offpayload, null, false, fibarodevice.id, fibarodevice.name, fibarodevice.fibaroname, "switch", "fibaroDevice", null, null); + bridgeService.buildUrls(onpayload, dimpayload, offpayload, null, false, fibarodevice.id, fibarodevice.name, fibarodevice.fibaroname, "switch", "fibaroDevice", null, null); bridgeService.state.device.headers = "[{\"name\":\"Authorization\",\"value\":\"" + fibarodevice.fibaroAuth + "\"}]"; $scope.device = bridgeService.state.device; if (!buildonly) { @@ -2423,45 +2569,47 @@ app.controller('FibaroController', function ($scope, $location, bridgeService, n $location.path('/editdevice'); }; - $scope.bulkAddDevices = function(dim_control) { + $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.fibarodevices.length; x++) { - if(bridgeService.state.fibarodevices[x].id === $scope.bulk.devices[i]) { - $scope.buildDeviceUrls(bridgeService.state.fibarodevices[x],dim_control,true); + for (var i = 0; i < $scope.bulk.devices.length; i++) { + for (var x = 0; x < bridgeService.state.fibarodevices.length; x++) { + if (bridgeService.state.fibarodevices[x].id === $scope.bulk.devices[i]) { + $scope.buildDeviceUrls(bridgeService.state.fibarodevices[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, - headers: $scope.device.headers, - httpVerb: $scope.device.httpVerb, - contentType: $scope.device.contentType, - contentBody: $scope.device.contentBody, - contentBodyDim: $scope.device.contentBodyDim, - contentBodyOff: $scope.device.contentBodyOff + 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, + 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.viewfibaroDevices(); - bridgeService.viewfibaroScenes(); - }, - function (error) { - bridgeService.displayWarn("Error adding fibaro devices in bulk.", error); - } - ); - $scope.bulk = { devices: [] }; + function () { + $scope.clearDevice(); + bridgeService.viewDevices(); + bridgeService.viewfibaroDevices(); + bridgeService.viewfibaroScenes(); + }, + function (error) { + bridgeService.displayWarn("Error adding fibaro devices in bulk.", error); + } + ); + $scope.bulk = { + devices: [] + }; $scope.selectAll = false; }; @@ -2471,7 +2619,7 @@ app.controller('FibaroController', function ($scope, $location, bridgeService, n // is currently selected if (idx > -1) { $scope.bulk.devices.splice(idx, 1); - if($scope.bulk.devices.length === 0 && $scope.selectAll) + if ($scope.bulk.devices.length === 0 && $scope.selectAll) $scope.selectAll = false; } @@ -2483,14 +2631,15 @@ app.controller('FibaroController', function ($scope, $location, bridgeService, n }; $scope.toggleSelectAll = function toggleSelectAll() { - if($scope.selectAll) { + if ($scope.selectAll) { $scope.selectAll = false; - $scope.bulk = { devices: [] }; - } - else { + $scope.bulk = { + devices: [] + }; + } else { $scope.selectAll = true; - for(var x = 0; x < bridgeService.state.fibarodevices.length; x++) { - if($scope.bulk.devices.indexOf(bridgeService.state.fibarodevices[x]) < 0) + for (var x = 0; x < bridgeService.state.fibarodevices.length; x++) { + if ($scope.bulk.devices.indexOf(bridgeService.state.fibarodevices[x]) < 0) $scope.bulk.devices.push(bridgeService.state.fibarodevices[x].id); } } @@ -2498,7 +2647,7 @@ app.controller('FibaroController', function ($scope, $location, bridgeService, n $scope.toggleButtons = function () { $scope.buttonsVisible = !$scope.buttonsVisible; - if($scope.buttonsVisible) + if ($scope.buttonsVisible) $scope.imgButtonsUrl = "glyphicon glyphicon-minus"; else $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; @@ -2512,7 +2661,7 @@ app.controller('FibaroController', function ($scope, $location, bridgeService, n className: 'ngdialog-theme-default' }); }; - + $scope.editDevice = function (device) { bridgeService.editDevice(device); $location.path('/editdevice'); @@ -2538,9 +2687,9 @@ app.controller('HarmonyController', function ($scope, $location, bridgeService, $scope.buildActivityUrls = function (harmonyactivity) { onpayload = "{\"name\":\"" + harmonyactivity.activity.id + "\",\"hub\":\"" + harmonyactivity.hub + "\"}"; - offpayload = "{\"name\":\"-1\",\"hub\":\"" + harmonyactivity.hub + "\"}"; + offpayload = "{\"name\":\"-1\",\"hub\":\"" + harmonyactivity.hub + "\"}"; - bridgeService.buildUrls(onpayload, null, offpayload, null, true, harmonyactivity.activity.id, harmonyactivity.activity.label, harmonyactivity.hub, "activity", "harmonyActivity", null, null); + bridgeService.buildUrls(onpayload, null, offpayload, null, true, harmonyactivity.activity.id, harmonyactivity.activity.label, harmonyactivity.hub, "activity", "harmonyActivity", null, null); $scope.device = bridgeService.state.device; bridgeService.editNewDevice($scope.device); $location.path('/editdevice'); @@ -2550,16 +2699,16 @@ app.controller('HarmonyController', function ($scope, $location, bridgeService, var actionOn = angular.fromJson(onbutton); var actionOff = angular.fromJson(offbutton); var postCmd = "\"}"; - if(onpresstime !== undefined && onpresstime !== "0") - postCmd = "\",\"pressTime\":" + onpresstime + "}"; + if (onpresstime !== undefined && onpresstime !== "0") + postCmd = "\",\"pressTime\":" + onpresstime + "}"; onpayload = "{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + actionOn.command + "\",\"hub\":\"" + harmonydevice.hub + postCmd; - if(offpresstime !== undefined && offpresstime !== "0") - postCmd = "\",\"pressTime\":" + offpresstime + "}"; + if (offpresstime !== undefined && offpresstime !== "0") + postCmd = "\",\"pressTime\":" + offpresstime + "}"; else postCmd = "\"}"; offpayload = "{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + actionOff.command + "\",\"hub\":\"" + harmonydevice.hub + postCmd; - bridgeService.buildUrls(onpayload, null, offpayload, null, true, actionOn.command, harmonydevice.device.label, harmonydevice.hub, "button", "harmonyButton", null, null); + bridgeService.buildUrls(onpayload, null, offpayload, null, true, actionOn.command, harmonydevice.device.label, harmonydevice.hub, "button", "harmonyButton", null, null); $scope.device = bridgeService.state.device; bridgeService.editNewDevice($scope.device); $location.path('/editdevice'); @@ -2567,7 +2716,7 @@ app.controller('HarmonyController', function ($scope, $location, bridgeService, $scope.toggleButtons = function () { $scope.buttonsVisible = !$scope.buttonsVisible; - if($scope.buttonsVisible) + if ($scope.buttonsVisible) $scope.imgButtonsUrl = "glyphicon glyphicon-minus"; else $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; @@ -2581,7 +2730,7 @@ app.controller('HarmonyController', function ($scope, $location, bridgeService, className: 'ngdialog-theme-default' }); }; - + $scope.editDevice = function (device) { bridgeService.editDevice(device); $location.path('/editdevice'); @@ -2603,7 +2752,7 @@ app.controller('NestController', function ($scope, $location, bridgeService, ngD $scope.buildNestHomeUrls = function (nestitem) { onpayload = "{\"name\":\"" + nestitem.id + "\",\"away\":false,\"control\":\"status\"}"; offpayload = "{\"name\":\"" + nestitem.id + "\",\"away\":true,\"control\":\"status\"}"; - bridgeService.buildUrls(onpayload, null, offpayload, null, true, nestitem.id, nestitem.name, nestitem.name, "home", "nestHomeAway", null, null); + bridgeService.buildUrls(onpayload, null, offpayload, null, true, nestitem.id, nestitem.name, nestitem.name, "home", "nestHomeAway", null, null); $scope.device = bridgeService.state.device; bridgeService.editNewDevice($scope.device); $location.path('/editdevice'); @@ -2613,7 +2762,7 @@ app.controller('NestController', function ($scope, $location, bridgeService, ngD onpayload = "{\"name\":\"" + nestitem.id + "\",\"control\":\"temp\",\"temp\":\"${intensity.percent}\"}"; dimpayload = "{\"name\":\"" + nestitem.id + "\",\"control\":\"temp\",\"temp\":\"${intensity.percent}\"}"; offpayload = "{\"name\":\"" + nestitem.id + "\",\"control\":\"off\"}"; - bridgeService.buildUrls(onpayload, dimpayload, offpayload, null, true, nestitem.id + "-SetTemp", nestitem.name.substr(0, nestitem.name.indexOf("(")) + " Temperature", nestitem.location, "thermo", "nestThermoSet", null, null); + bridgeService.buildUrls(onpayload, dimpayload, offpayload, null, true, nestitem.id + "-SetTemp", nestitem.name.substr(0, nestitem.name.indexOf("(")) + " Temperature", nestitem.location, "thermo", "nestThermoSet", null, null); $scope.device = bridgeService.state.device; bridgeService.editNewDevice($scope.device); $location.path('/editdevice'); @@ -2623,7 +2772,7 @@ app.controller('NestController', function ($scope, $location, bridgeService, ngD onpayload = "{\"name\":\"" + nestitem.id + "\",\"control\":\"heat\"}"; dimpayload = "{\"name\":\"" + nestitem.id + "\",\"control\":\"temp\",\"temp\":\"${intensity.percent}\"}"; offpayload = "{\"name\":\"" + nestitem.id + "\",\"control\":\"off\"}"; - bridgeService.buildUrls(onpayload, dimpayload, offpayload, null, true, nestitem.id + "-SetHeat", nestitem.name.substr(0, nestitem.name.indexOf("(")) + " Heat", nestitem.location, "thermo", "nestThermoSet", null, null); + bridgeService.buildUrls(onpayload, dimpayload, offpayload, null, true, nestitem.id + "-SetHeat", nestitem.name.substr(0, nestitem.name.indexOf("(")) + " Heat", nestitem.location, "thermo", "nestThermoSet", null, null); $scope.device = bridgeService.state.device; bridgeService.editNewDevice($scope.device); $location.path('/editdevice'); @@ -2633,7 +2782,7 @@ app.controller('NestController', function ($scope, $location, bridgeService, ngD onpayload = "{\"name\":\"" + nestitem.id + "\",\"control\":\"cool\"}"; dimpayload = "{\"name\":\"" + nestitem.id + "\",\"control\":\"temp\",\"temp\":\"${intensity.percent}\"}"; offpayload = "{\"name\":\"" + nestitem.id + "\",\"control\":\"off\"}"; - bridgeService.buildUrls(onpayload,dimpayload, offpayload, null, true, nestitem.id + "-SetCool", nestitem.name.substr(0, nestitem.name.indexOf("(")) + " Cool", nestitem.location, "thermo", "nestThermoSet", null, null); + bridgeService.buildUrls(onpayload, dimpayload, offpayload, null, true, nestitem.id + "-SetCool", nestitem.name.substr(0, nestitem.name.indexOf("(")) + " Cool", nestitem.location, "thermo", "nestThermoSet", null, null); $scope.device = bridgeService.state.device; bridgeService.editNewDevice($scope.device); $location.path('/editdevice'); @@ -2642,7 +2791,7 @@ app.controller('NestController', function ($scope, $location, bridgeService, ngD $scope.buildNestRangeUrls = function (nestitem) { onpayload = "{\"name\":\"" + nestitem.id + "\",\"control\":\"range\"}"; offpayload = "{\"name\":\"" + nestitem.id + "\",\"control\":\"off\"}"; - bridgeService.buildUrls(onpayload, null, offpayload, null, true, nestitem.id + "-SetRange", nestitem.name.substr(0, nestitem.name.indexOf("(")) + " Range", nestitem.location, "thermo", "nestThermoSet", null, null); + bridgeService.buildUrls(onpayload, null, offpayload, null, true, nestitem.id + "-SetRange", nestitem.name.substr(0, nestitem.name.indexOf("(")) + " Range", nestitem.location, "thermo", "nestThermoSet", null, null); $scope.device = bridgeService.state.device; bridgeService.editNewDevice($scope.device); $location.path('/editdevice'); @@ -2651,7 +2800,7 @@ app.controller('NestController', function ($scope, $location, bridgeService, ngD $scope.buildNestOffUrls = function (nestitem) { onpayload = "{\"name\":\"" + nestitem.id + "\",\"control\":\"range\"}"; offpayload = "{\"name\":\"" + nestitem.id + "\",\"control\":\"off\"}"; - bridgeService.buildUrls(onpayload, null, offpayload, null, true, nestitem.id + "-TurnOff", nestitem.name.substr(0, nestitem.name.indexOf("(")) + " Thermostat", nestitem.location, "thermo", "nestThermoSet", null, null); + bridgeService.buildUrls(onpayload, null, offpayload, null, true, nestitem.id + "-TurnOff", nestitem.name.substr(0, nestitem.name.indexOf("(")) + " Thermostat", nestitem.location, "thermo", "nestThermoSet", null, null); $scope.device = bridgeService.state.device; bridgeService.editNewDevice($scope.device); $location.path('/editdevice'); @@ -2660,7 +2809,7 @@ app.controller('NestController', function ($scope, $location, bridgeService, ngD $scope.buildNestFanUrls = function (nestitem) { onpayload = "{\"name\":\"" + nestitem.id + "\",\"control\":\"fan-on\"}"; offpayload = "{\"name\":\"" + nestitem.id + "\",\"control\":\"fan-auto\"}"; - bridgeService.buildUrls(onpayload, null, offpayload, null, true, nestitem.id + "-SetFan", nestitem.name.substr(0, nestitem.name.indexOf("(")) + " Fan", nestitem.location, "thermo", "nestThermoSet", null, null); + bridgeService.buildUrls(onpayload, null, offpayload, null, true, nestitem.id + "-SetFan", nestitem.name.substr(0, nestitem.name.indexOf("(")) + " Fan", nestitem.location, "thermo", "nestThermoSet", null, null); $scope.device = bridgeService.state.device; bridgeService.editNewDevice($scope.device); $location.path('/editdevice'); @@ -2668,7 +2817,7 @@ app.controller('NestController', function ($scope, $location, bridgeService, ngD $scope.toggleButtons = function () { $scope.buttonsVisible = !$scope.buttonsVisible; - if($scope.buttonsVisible) + if ($scope.buttonsVisible) $scope.imgButtonsUrl = "glyphicon glyphicon-minus"; else $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; @@ -2682,7 +2831,7 @@ app.controller('NestController', function ($scope, $location, bridgeService, ngD className: 'ngdialog-theme-default' }); }; - + $scope.editDevice = function (device) { bridgeService.editDevice(device); $location.path('/editdevice'); @@ -2692,7 +2841,9 @@ app.controller('NestController', function ($scope, $location, bridgeService, ngD app.controller('HueController', function ($scope, $location, bridgeService, ngDialog) { $scope.bridge = bridgeService.state; $scope.device = bridgeService.state.device; - $scope.bulk = { devices: [] }; + $scope.bulk = { + devices: [] + }; $scope.selectAll = false; bridgeService.viewHueDevices(); $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; @@ -2704,9 +2855,9 @@ app.controller('HueController', function ($scope, $location, bridgeService, ngDi }; $scope.buildDeviceUrls = function (huedevice, buildonly) { - onpayload = "{\"ipAddress\":\"" + huedevice.hueaddress + "\",\"deviceId\":\"" + huedevice.huedeviceid +"\",\"hueName\":\"" + huedevice.huename + "\"}"; - offpayload = "{\"ipAddress\":\"" + huedevice.hueaddress + "\",\"deviceId\":\"" + huedevice.huedeviceid +"\",\"hueName\":\"" + huedevice.huename + "\"}"; - bridgeService.buildUrls(onpayload, null, offpayload, null, true, huedevice.device.uniqueid, huedevice.device.name, huedevice.huename, "passthru", "hueDevice", null, null); + onpayload = "{\"ipAddress\":\"" + huedevice.hueaddress + "\",\"deviceId\":\"" + huedevice.huedeviceid + "\",\"hueName\":\"" + huedevice.huename + "\"}"; + offpayload = "{\"ipAddress\":\"" + huedevice.hueaddress + "\",\"deviceId\":\"" + huedevice.huedeviceid + "\",\"hueName\":\"" + huedevice.huename + "\"}"; + bridgeService.buildUrls(onpayload, null, offpayload, null, true, huedevice.device.uniqueid, huedevice.device.name, huedevice.huename, "passthru", "hueDevice", null, null); $scope.device = bridgeService.state.device; if (!buildonly) { bridgeService.editNewDevice($scope.device); @@ -2714,46 +2865,48 @@ app.controller('HueController', function ($scope, $location, bridgeService, ngDi } }; - $scope.bulkAddDevices = function() { + $scope.bulkAddDevices = function () { var devicesList = []; $scope.clearDevice(); - for(var i = 0; i < $scope.bulk.devices.length; i++) { - for(var x = 0; x < bridgeService.state.huedevices.length; x++) { - if(bridgeService.state.huedevices[x].device.uniqueid === $scope.bulk.devices[i]) { - $scope.buildDeviceUrls(bridgeService.state.huedevices[x],true); + for (var i = 0; i < $scope.bulk.devices.length; i++) { + for (var x = 0; x < bridgeService.state.huedevices.length; x++) { + if (bridgeService.state.huedevices[x].device.uniqueid === $scope.bulk.devices[i]) { + $scope.buildDeviceUrls(bridgeService.state.huedevices[x], 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 + 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.viewHueDevices(); - }, - function (error) { - bridgeService.displayWarn("Error adding Hue devices in bulk.", error); - } - ); + function () { + $scope.clearDevice(); + bridgeService.viewDevices(); + bridgeService.viewHueDevices(); + }, + function (error) { + bridgeService.displayWarn("Error adding Hue devices in bulk.", error); + } + ); - $scope.bulk = { devices: [] }; + $scope.bulk = { + devices: [] + }; $scope.selectAll = false; }; @@ -2763,7 +2916,7 @@ app.controller('HueController', function ($scope, $location, bridgeService, ngDi // is currently selected if (idx > -1) { $scope.bulk.devices.splice(idx, 1); - if($scope.bulk.devices.length === 0 && $scope.selectAll) + if ($scope.bulk.devices.length === 0 && $scope.selectAll) $scope.selectAll = false; } @@ -2775,14 +2928,15 @@ app.controller('HueController', function ($scope, $location, bridgeService, ngDi }; $scope.toggleSelectAll = function toggleSelectAll() { - if($scope.selectAll) { + if ($scope.selectAll) { $scope.selectAll = false; - $scope.bulk = { devices: [] }; - } - else { + $scope.bulk = { + devices: [] + }; + } else { $scope.selectAll = true; - for(var x = 0; x < bridgeService.state.huedevices.length; x++) { - if($scope.bulk.devices.indexOf(bridgeService.state.huedevices[x]) < 0 && !bridgeService.findDeviceByMapId(bridgeService.state.huedevices[x].device.uniqueid, bridgeService.state.huedevices[x].huename, "hueDevice")) + for (var x = 0; x < bridgeService.state.huedevices.length; x++) { + if ($scope.bulk.devices.indexOf(bridgeService.state.huedevices[x]) < 0 && !bridgeService.findDeviceByMapId(bridgeService.state.huedevices[x].device.uniqueid, bridgeService.state.huedevices[x].huename, "hueDevice")) $scope.bulk.devices.push(bridgeService.state.huedevices[x].device.uniqueid); } } @@ -2790,7 +2944,7 @@ app.controller('HueController', function ($scope, $location, bridgeService, ngDi $scope.toggleButtons = function () { $scope.buttonsVisible = !$scope.buttonsVisible; - if($scope.buttonsVisible) + if ($scope.buttonsVisible) $scope.imgButtonsUrl = "glyphicon glyphicon-minus"; else $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; @@ -2804,7 +2958,7 @@ app.controller('HueController', function ($scope, $location, bridgeService, ngDi className: 'ngdialog-theme-default' }); }; - + $scope.editDevice = function (device) { bridgeService.editDevice(device); $location.path('/editdevice'); @@ -2815,7 +2969,9 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi $scope.bridge = bridgeService.state; $scope.device = bridgeService.state.device; $scope.device_dim_control = ""; - $scope.bulk = { devices: [] }; + $scope.bulk = { + devices: [] + }; $scope.selectAll = false; bridgeService.viewHalDevices(); $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; @@ -2832,30 +2988,27 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi var preOffCmd = ""; var nameCmd = ""; var aDeviceType; - if(haldevice.haldevicetype === "Group") { + if (haldevice.haldevicetype === "Group") { aDeviceType = "group"; preOnCmd = "/GroupService!GroupCmd=On"; preOffCmd = "/GroupService!GroupCmd=Off"; nameCmd = "!GroupName="; - } - else if(haldevice.haldevicetype === "Macro") { + } else if (haldevice.haldevicetype === "Macro") { aDeviceType = "macro"; preOnCmd = "/MacroService!MacroCmd=Set!MacroName="; preOffCmd = preOnCmd; - } - else if(haldevice.haldevicetype === "Scene") { + } else if (haldevice.haldevicetype === "Scene") { aDeviceType = "scene"; preOnCmd = "/SceneService!SceneCmd=Set!SceneName="; preOffCmd = preOnCmd; - } - else { + } else { aDeviceType = "switch"; preOnCmd = "/DeviceService!DeviceCmd=SetDevice!DeviceValue=On"; preDimCmd = "/DeviceService!DeviceCmd=SetDevice!DeviceValue=Dim!DevicePercent="; preOffCmd = "/DeviceService!DeviceCmd=SetDevice!DeviceValue=Off"; nameCmd = "!DeviceName="; } - if((dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0) && aDeviceType === "switch") + if ((dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0) && aDeviceType === "switch") dimpayload = "http://" + haldevice.haladdress.ip + preDimCmd + dim_control + @@ -2867,14 +3020,14 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi nameCmd + haldevice.haldevicename.replaceAll(" ", "%20"); onpayload = "http://" + haldevice.haladdress.ip + - preOnCmd + - nameCmd + - haldevice.haldevicename.replaceAll(" ", "%20"); - offpayload = "http://" + haldevice.haladdress.ip + - preOffCmd + - nameCmd + - haldevice.haldevicename.replaceAll(" ", "%20"); - bridgeService.buildUrls(onpayload, dimpayload, offpayload, null, false, haldevice.haldevicename + "-" + haldevice.haladdress.name, haldevice.haldevicename, haldevice.haladdress.name, aDeviceType, "halDevice", null, null); + preOnCmd + + nameCmd + + haldevice.haldevicename.replaceAll(" ", "%20"); + offpayload = "http://" + haldevice.haladdress.ip + + preOffCmd + + nameCmd + + haldevice.haldevicename.replaceAll(" ", "%20"); + bridgeService.buildUrls(onpayload, dimpayload, offpayload, null, false, haldevice.haldevicename + "-" + haldevice.haladdress.name, haldevice.haldevicename, haldevice.haladdress.name, aDeviceType, "halDevice", null, null); $scope.device = bridgeService.state.device; if (!buildonly) { bridgeService.editNewDevice($scope.device); @@ -2888,7 +3041,7 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi onpayload = "http://" + haldevice.haladdress.ip + "/IrService!IrCmd=Set!IrDevice=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!IrButton=" + actionOn.DeviceName.replaceAll(" ", "%20"); offpayload = "http://" + haldevice.haladdress.ip + "/IrService!IrCmd=Set!IrDevice=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!IrButton=" + actionOff.DeviceName.replaceAll(" ", "%20"); - bridgeService.buildUrls(onpayload, null, offpayload, null, false, haldevice.haldevicename + "-" + haldevice.haladdress.name + "-" + actionOn.DeviceName, haldevice.haldevicename, haldevice.haladdress.name, "button", "halButton", null, null); + bridgeService.buildUrls(onpayload, null, offpayload, null, false, haldevice.haldevicename + "-" + haldevice.haladdress.name + "-" + actionOn.DeviceName, haldevice.haldevicename, haldevice.haladdress.name, "button", "halButton", null, null); $scope.device = bridgeService.state.device; if (!buildonly) { bridgeService.editNewDevice($scope.device); @@ -2899,7 +3052,7 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi $scope.buildHALHomeUrls = function (haldevice, buildonly) { onpayload = "http://" + haldevice.haladdress.ip + "/ModeService!ModeCmd=Set!ModeName=Home"; offpayload = "http://" + haldevice.haladdress.ip + "/ModeService!ModeCmd=Set!ModeName=Away"; - bridgeService.buildUrls(onpayload, null, offpayload, null, false, haldevice.haldevicename + "-" + haldevice.haladdress.name + "-HomeAway", haldevice.haldevicename, haldevice.haladdress.name, "home", "halHome", null, null); + bridgeService.buildUrls(onpayload, null, offpayload, null, false, haldevice.haldevicename + "-" + haldevice.haladdress.name + "-HomeAway", haldevice.haldevicename, haldevice.haladdress.name, "home", "halHome", null, null); $scope.device = bridgeService.state.device; if (!buildonly) { bridgeService.editNewDevice($scope.device); @@ -2909,18 +3062,18 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi $scope.buildHALHeatUrls = function (haldevice, buildonly) { onpayload = "http://" + haldevice.haladdress.ip + - "/HVACService!HVACCmd=Set!HVACName=" + - haldevice.haldevicename.replaceAll(" ", "%20") + - "!HVACMode=Heat"; + "/HVACService!HVACCmd=Set!HVACName=" + + haldevice.haldevicename.replaceAll(" ", "%20") + + "!HVACMode=Heat"; dimpayload = "http://" + haldevice.haladdress.ip + - "/HVACService!HVACCmd=Set!HVACName=" + - haldevice.haldevicename.replaceAll(" ", "%20") + - "!HVACMode=Heat!HeatSpValue=${intensity.percent}"; + "/HVACService!HVACCmd=Set!HVACName=" + + haldevice.haldevicename.replaceAll(" ", "%20") + + "!HVACMode=Heat!HeatSpValue=${intensity.percent}"; offpayload = "http://" + haldevice.haladdress.ip + - "/HVACService!HVACCmd=Set!HVACName=" + - haldevice.haldevicename.replaceAll(" ", "%20") + - "!HVACMode=Off"; - bridgeService.buildUrls(onpayload, dimpayload, offpayload, null, false, haldevice.haldevicename + "-" + haldevice.haladdress.name + "-SetHeat", haldevice.haldevicename + " Heat", haldevice.haladdress.name, "thermo", "halThermoSet", null, null); + "/HVACService!HVACCmd=Set!HVACName=" + + haldevice.haldevicename.replaceAll(" ", "%20") + + "!HVACMode=Off"; + bridgeService.buildUrls(onpayload, dimpayload, offpayload, null, false, haldevice.haldevicename + "-" + haldevice.haladdress.name + "-SetHeat", haldevice.haldevicename + " Heat", haldevice.haladdress.name, "thermo", "halThermoSet", null, null); $scope.device = bridgeService.state.device; if (!buildonly) { bridgeService.editNewDevice($scope.device); @@ -2930,18 +3083,18 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi $scope.buildHALCoolUrls = function (haldevice, buildonly) { onpayload = "http://" + haldevice.haladdress.ip + - "/HVACService!HVACCmd=Set!HVACName=" + - haldevice.haldevicename.replaceAll(" ", "%20") + - "!HVACMode=Cool"; + "/HVACService!HVACCmd=Set!HVACName=" + + haldevice.haldevicename.replaceAll(" ", "%20") + + "!HVACMode=Cool"; dimpayload = "http://" + haldevice.haladdress.ip + - "/HVACService!HVACCmd=Set!HVACName=" + - haldevice.haldevicename.replaceAll(" ", "%20") + - "!HVACMode=Cool!CoolSpValue=${intensity.percent}"; + "/HVACService!HVACCmd=Set!HVACName=" + + haldevice.haldevicename.replaceAll(" ", "%20") + + "!HVACMode=Cool!CoolSpValue=${intensity.percent}"; offpayload = "http://" + haldevice.haladdress.ip + - "/HVACService!HVACCmd=Set!HVACName=" + - haldevice.haldevicename.replaceAll(" ", "%20") + - "!HVACMode=Off"; - bridgeService.buildUrls(onpayload, dimpayload, offpayload, null, false, haldevice.haldevicename + "-" + haldevice.haladdress.name + "-SetCool", haldevice.haldevicename + " Cool", haldevice.haladdress.name, "thermo", "halThermoSet", null, null); + "/HVACService!HVACCmd=Set!HVACName=" + + haldevice.haldevicename.replaceAll(" ", "%20") + + "!HVACMode=Off"; + bridgeService.buildUrls(onpayload, dimpayload, offpayload, null, false, haldevice.haldevicename + "-" + haldevice.haladdress.name + "-SetCool", haldevice.haldevicename + " Cool", haldevice.haladdress.name, "thermo", "halThermoSet", null, null); $scope.device = bridgeService.state.device; if (!buildonly) { bridgeService.editNewDevice($scope.device); @@ -2951,14 +3104,14 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi $scope.buildHALAutoUrls = function (haldevice, buildonly) { onpayload = "http://" + haldevice.haladdress.ip + - "/HVACService!HVACCmd=Set!HVACName=" + - haldevice.haldevicename.replaceAll(" ", "%20") + - "!HVACMode=Auto"; + "/HVACService!HVACCmd=Set!HVACName=" + + haldevice.haldevicename.replaceAll(" ", "%20") + + "!HVACMode=Auto"; offpayload = "http://" + haldevice.haladdress.ip + - "/HVACService!HVACCmd=Set!HVACName=" + - haldevice.haldevicename.replaceAll(" ", "%20") + - "!HVACMode=Off"; - bridgeService.buildUrls(onpayload, null, offpayload, null, false, haldevice.haldevicename + "-" + haldevice.haladdress.name + "-SetAuto", haldevice.haldevicename + " Auto", haldevice.haladdress.name, "thermo", "halThermoSet", null, null); + "/HVACService!HVACCmd=Set!HVACName=" + + haldevice.haldevicename.replaceAll(" ", "%20") + + "!HVACMode=Off"; + bridgeService.buildUrls(onpayload, null, offpayload, null, false, haldevice.haldevicename + "-" + haldevice.haladdress.name + "-SetAuto", haldevice.haldevicename + " Auto", haldevice.haladdress.name, "thermo", "halThermoSet", null, null); $scope.device = bridgeService.state.device; if (!buildonly) { bridgeService.editNewDevice($scope.device); @@ -2968,14 +3121,14 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi $scope.buildHALOffUrls = function (haldevice, buildonly) { onpayload = "http://" + haldevice.haladdress.ip + - "/HVACService!HVACCmd=Set!HVACName=" + - haldevice.haldevicename.replaceAll(" ", "%20") + - "!HVACMode=Auto"; + "/HVACService!HVACCmd=Set!HVACName=" + + haldevice.haldevicename.replaceAll(" ", "%20") + + "!HVACMode=Auto"; offpayload = "http://" + haldevice.haladdress.ip + - "/HVACService!HVACCmd=Set!HVACName=" + - haldevice.haldevicename.replaceAll(" ", "%20") + - "!HVACMode=Off"; - bridgeService.buildUrls(onpayload, null, offpayload, null, false, haldevice.haldevicename + "-" + haldevice.haladdress.name + "-TurnOff", haldevice.haldevicename + " Thermostat", haldevice.haladdress.name, "thermo", "halThermoSet", null, null); + "/HVACService!HVACCmd=Set!HVACName=" + + haldevice.haldevicename.replaceAll(" ", "%20") + + "!HVACMode=Off"; + bridgeService.buildUrls(onpayload, null, offpayload, null, false, haldevice.haldevicename + "-" + haldevice.haladdress.name + "-TurnOff", haldevice.haldevicename + " Thermostat", haldevice.haladdress.name, "thermo", "halThermoSet", null, null); $scope.device = bridgeService.state.device; if (!buildonly) { bridgeService.editNewDevice($scope.device); @@ -2992,7 +3145,7 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!FanMode=Auto"; - bridgeService.buildUrls(onpayload, null, offpayload, null, false, haldevice.haldevicename + "-" + haldevice.haladdress.name + "-SetFan", haldevice.haldevicename + " Fan", haldevice.haladdress.name, "thermo", "halThermoSet", null, null); + bridgeService.buildUrls(onpayload, null, offpayload, null, false, haldevice.haldevicename + "-" + haldevice.haladdress.name + "-SetFan", haldevice.haldevicename + " Fan", haldevice.haladdress.name, "thermo", "halThermoSet", null, null); $scope.device = bridgeService.state.device; if (!buildonly) { bridgeService.editNewDevice($scope.device); @@ -3000,50 +3153,52 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi } }; - $scope.bulkAddDevices = function(dim_control) { + $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.haldevices.length; x++) { - if(bridgeService.state.haldevices[x].haldevicename === $scope.bulk.devices[i]) { - if(bridgeService.state.haldevices[x].haldevicetype === "HVAC") + for (var i = 0; i < $scope.bulk.devices.length; i++) { + for (var x = 0; x < bridgeService.state.haldevices.length; x++) { + if (bridgeService.state.haldevices[x].haldevicename === $scope.bulk.devices[i]) { + if (bridgeService.state.haldevices[x].haldevicetype === "HVAC") $scope.buildHALAutoUrls(bridgeService.state.haldevices[x], true); - else if(bridgeService.state.haldevices[x].haldevicetype === "HOME") + else if (bridgeService.state.haldevices[x].haldevicetype === "HOME") $scope.buildHALHomeUrls(bridgeService.state.haldevices[x], true); else - $scope.buildDeviceUrls(bridgeService.state.haldevices[x],dim_control, true); + $scope.buildDeviceUrls(bridgeService.state.haldevices[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 + 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 HAL devices in bulk.", error); - } - ); - $scope.bulk = { devices: [] }; + function () { + $scope.clearDevice(); + bridgeService.viewDevices(); + bridgeService.viewHalDevices(); + }, + function (error) { + bridgeService.displayWarn("Error adding HAL devices in bulk.", error); + } + ); + $scope.bulk = { + devices: [] + }; $scope.selectAll = false; }; @@ -3053,7 +3208,7 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi // is currently selected if (idx > -1) { $scope.bulk.devices.splice(idx, 1); - if($scope.bulk.devices.length === 0 && $scope.selectAll) + if ($scope.bulk.devices.length === 0 && $scope.selectAll) $scope.selectAll = false; } @@ -3065,14 +3220,15 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi }; $scope.toggleSelectAll = function toggleSelectAll() { - if($scope.selectAll) { + if ($scope.selectAll) { $scope.selectAll = false; - $scope.bulk = { devices: [] }; - } - else { + $scope.bulk = { + devices: [] + }; + } else { $scope.selectAll = true; - for(var x = 0; x < bridgeService.state.haldevices.length; x++) { - if($scope.bulk.devices.indexOf(bridgeService.state.haldevices[x]) < 0) + for (var x = 0; x < bridgeService.state.haldevices.length; x++) { + if ($scope.bulk.devices.indexOf(bridgeService.state.haldevices[x]) < 0) $scope.bulk.devices.push(bridgeService.state.haldevices[x].haldevicename); } } @@ -3080,7 +3236,7 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi $scope.toggleButtons = function () { $scope.buttonsVisible = !$scope.buttonsVisible; - if($scope.buttonsVisible) + if ($scope.buttonsVisible) $scope.imgButtonsUrl = "glyphicon glyphicon-minus"; else $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; @@ -3094,7 +3250,7 @@ app.controller('HalController', function ($scope, $location, bridgeService, ngDi className: 'ngdialog-theme-default' }); }; - + $scope.editDevice = function (device) { bridgeService.editDevice(device); $location.path('/editdevice'); @@ -3116,14 +3272,14 @@ app.controller('MQTTController', function ($scope, $location, bridgeService, ngD }; $scope.buildMQTTPublish = function (mqttbroker, mqtttopic, mqttmessage, mqttqos, mqttretain) { - if(mqttretain === 'undefined') + if (mqttretain === 'undefined') mqttretain = false; - if(mqttqos === 'undefined') + 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 + "\"}"; - bridgeService.buildUrls(onpayload, null, offpayload, null, true, mqttbroker.clientId + "-" + mqtttopic, mqttbroker.clientId + mqtttopic, mqttbroker.clientId, "mqtt", "mqttMessage", null, null); + bridgeService.buildUrls(onpayload, null, offpayload, null, true, mqttbroker.clientId + "-" + mqtttopic, mqttbroker.clientId + mqtttopic, mqttbroker.clientId, "mqtt", "mqttMessage", null, null); $scope.device = bridgeService.state.device; bridgeService.editNewDevice($scope.device); $location.path('/editdevice'); @@ -3131,7 +3287,7 @@ app.controller('MQTTController', function ($scope, $location, bridgeService, ngD $scope.toggleButtons = function () { $scope.buttonsVisible = !$scope.buttonsVisible; - if($scope.buttonsVisible) + if ($scope.buttonsVisible) $scope.imgButtonsUrl = "glyphicon glyphicon-minus"; else $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; @@ -3145,7 +3301,7 @@ app.controller('MQTTController', function ($scope, $location, bridgeService, ngD className: 'ngdialog-theme-default' }); }; - + $scope.editDevice = function (device) { bridgeService.editDevice(device); $location.path('/editdevice'); @@ -3156,7 +3312,9 @@ app.controller('HassController', function ($scope, $location, bridgeService, ngD $scope.bridge = bridgeService.state; $scope.device = bridgeService.state.device; $scope.device_dim_control = ""; - $scope.bulk = { devices: [] }; + $scope.bulk = { + devices: [] + }; $scope.selectAll = false; bridgeService.viewHassDevices(); $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; @@ -3169,13 +3327,13 @@ app.controller('HassController', function ($scope, $location, bridgeService, ngD $scope.buildDeviceUrls = function (hassdevice, dim_control, buildonly) { onpayload = "{\"entityId\":\"" + hassdevice.deviceState.entity_id + "\",\"hassName\":\"" + hassdevice.hassname + "\",\"state\":\"on\"}"; - 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)) dimpayload = "{\"entityId\":\"" + hassdevice.deviceState.entity_id + "\",\"hassName\":\"" + hassdevice.hassname + "\",\"state\":\"on\",\"bri\":\"" + dim_control + "\"}"; else dimpayload = "{\"entityId\":\"" + hassdevice.deviceState.entity_id + "\",\"hassName\":\"" + hassdevice.hassname + "\",\"state\":\"on\"}"; offpayload = "{\"entityId\":\"" + hassdevice.deviceState.entity_id + "\",\"hassName\":\"" + hassdevice.hassname + "\",\"state\":\"off\"}"; - bridgeService.buildUrls(onpayload, dimpayload, offpayload, null, true, hassdevice.hassname + "-" + hassdevice.deviceState.entity_id, hassdevice.deviceState.entity_id, hassdevice.hassname, hassdevice.domain, "hassDevice", null, null); + bridgeService.buildUrls(onpayload, dimpayload, offpayload, null, true, hassdevice.hassname + "-" + hassdevice.deviceState.entity_id, hassdevice.deviceState.entity_id, hassdevice.hassname, hassdevice.domain, "hassDevice", null, null); $scope.device = bridgeService.state.device; if (!buildonly) { bridgeService.editNewDevice($scope.device); @@ -3183,45 +3341,47 @@ app.controller('HassController', function ($scope, $location, bridgeService, ngD } }; - $scope.bulkAddDevices = function(dim_control) { + $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.hassdevices.length; x++) { - if(bridgeService.state.hassdevices[x].deviceState.entity_id === $scope.bulk.devices[i] && bridgeService.state.hassdevices[x].domain !== "sensor" && bridgeService.state.hassdevices[x].domain !== "sun") { - $scope.buildDeviceUrls(bridgeService.state.hassdevices[x],dim_control,true); + for (var i = 0; i < $scope.bulk.devices.length; i++) { + for (var x = 0; x < bridgeService.state.hassdevices.length; x++) { + if (bridgeService.state.hassdevices[x].deviceState.entity_id === $scope.bulk.devices[i] && bridgeService.state.hassdevices[x].domain !== "sensor" && bridgeService.state.hassdevices[x].domain !== "sun") { + $scope.buildDeviceUrls(bridgeService.state.hassdevices[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 + 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.viewHassDevices(); - }, - function (error) { - bridgeService.displayWarn("Error adding Hass devices in bulk.", error); - } - ); - $scope.bulk = { devices: [] }; + function () { + $scope.clearDevice(); + bridgeService.viewDevices(); + bridgeService.viewHassDevices(); + }, + function (error) { + bridgeService.displayWarn("Error adding Hass devices in bulk.", error); + } + ); + $scope.bulk = { + devices: [] + }; $scope.selectAll = false; }; @@ -3231,7 +3391,7 @@ app.controller('HassController', function ($scope, $location, bridgeService, ngD // is currently selected if (idx > -1) { $scope.bulk.devices.splice(idx, 1); - if($scope.bulk.devices.length === 0 && $scope.selectAll) + if ($scope.bulk.devices.length === 0 && $scope.selectAll) $scope.selectAll = false; } @@ -3243,14 +3403,15 @@ app.controller('HassController', function ($scope, $location, bridgeService, ngD }; $scope.toggleSelectAll = function toggleSelectAll() { - if($scope.selectAll) { + if ($scope.selectAll) { $scope.selectAll = false; - $scope.bulk = { devices: [] }; - } - else { + $scope.bulk = { + devices: [] + }; + } else { $scope.selectAll = true; - for(var x = 0; x < bridgeService.state.hassdevices.length; x++) { - if($scope.bulk.devices.indexOf(bridgeService.state.hassdevices[x].deviceState.entity_id) < 0 && bridgeService.state.hassdevices[x].domain !== "sensor" && bridgeService.state.hassdevices[x].domain !== "sun") + for (var x = 0; x < bridgeService.state.hassdevices.length; x++) { + if ($scope.bulk.devices.indexOf(bridgeService.state.hassdevices[x].deviceState.entity_id) < 0 && bridgeService.state.hassdevices[x].domain !== "sensor" && bridgeService.state.hassdevices[x].domain !== "sun") $scope.bulk.devices.push(bridgeService.state.hassdevices[x].deviceState.entity_id); } } @@ -3258,7 +3419,7 @@ app.controller('HassController', function ($scope, $location, bridgeService, ngD $scope.toggleButtons = function () { $scope.buttonsVisible = !$scope.buttonsVisible; - if($scope.buttonsVisible) + if ($scope.buttonsVisible) $scope.imgButtonsUrl = "glyphicon glyphicon-minus"; else $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; @@ -3272,7 +3433,7 @@ app.controller('HassController', function ($scope, $location, bridgeService, ngD className: 'ngdialog-theme-default' }); }; - + $scope.editDevice = function (device) { bridgeService.editDevice(device); $location.path('/editdevice'); @@ -3280,136 +3441,143 @@ app.controller('HassController', function ($scope, $location, bridgeService, ngD }); app.controller('HomeWizardController', 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.viewHomeWizardDevices(); - $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; - $scope.buttonsVisible = false; + $scope.bridge = bridgeService.state; + $scope.device = bridgeService.state.device; + $scope.device_dim_control = ""; + $scope.bulk = { + devices: [] + }; + $scope.selectAll = false; + bridgeService.viewHomeWizardDevices(); + $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; + $scope.buttonsVisible = false; - $scope.clearDevice = function () { - bridgeService.clearDevice(); - $scope.device = bridgeService.state.device; - }; + $scope.clearDevice = function () { + bridgeService.clearDevice(); + $scope.device = bridgeService.state.device; + }; - $scope.buildDeviceUrls = function (homewizarddevice, buildonly) { - - dimpayload = "{\"deviceid\":\"" + homewizarddevice.id + "\",\"action\":\"on\"}"; - onpayload = "{\"deviceid\":\"" + homewizarddevice.id + "\",\"action\":\"on\"}"; - offpayload = "{\"deviceid\":\"" + homewizarddevice.id + "\",\"action\":\"off\"}"; - - bridgeService.buildUrls(onpayload, dimpayload, offpayload, null, true, homewizarddevice.id ,homewizarddevice.name, homewizarddevice.gateway, null, "homewizardDevice", null, null); - $scope.device = bridgeService.state.device; - - if (!buildonly) { - bridgeService.editNewDevice($scope.device); - $location.path('/editdevice'); - } - }; + $scope.buildDeviceUrls = function (homewizarddevice, buildonly) { - $scope.bulkAddDevices = function() { - var devicesList = []; - $scope.clearDevice(); - for(var i = 0; i < $scope.bulk.devices.length; i++) { - for(var x = 0; x < bridgeService.state.homewizarddevices.length; x++) { - if(bridgeService.state.homewizarddevices[x].id === $scope.bulk.devices[i]) { - $scope.buildDeviceUrls(bridgeService.state.homewizarddevices[x],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 HomeWizard devices in bulk.", error); - } - ); - $scope.bulk = { devices: [] }; - $scope.selectAll = false; - }; + dimpayload = "{\"deviceid\":\"" + homewizarddevice.id + "\",\"action\":\"on\"}"; + onpayload = "{\"deviceid\":\"" + homewizarddevice.id + "\",\"action\":\"on\"}"; + offpayload = "{\"deviceid\":\"" + homewizarddevice.id + "\",\"action\":\"off\"}"; - $scope.toggleSelection = function toggleSelection(deviceId) { - var idx = $scope.bulk.devices.indexOf(deviceId); + bridgeService.buildUrls(onpayload, dimpayload, offpayload, null, true, homewizarddevice.id, homewizarddevice.name, homewizarddevice.gateway, null, "homewizardDevice", null, null); + $scope.device = bridgeService.state.device; - // is currently selected - if (idx > -1) { - $scope.bulk.devices.splice(idx, 1); - if($scope.bulk.devices.length === 0 && $scope.selectAll) - $scope.selectAll = false; - } + if (!buildonly) { + bridgeService.editNewDevice($scope.device); + $location.path('/editdevice'); + } + }; - // is newly selected - else { - $scope.bulk.devices.push(deviceId); - $scope.selectAll = true; - } - }; + $scope.bulkAddDevices = function () { + var devicesList = []; + $scope.clearDevice(); + for (var i = 0; i < $scope.bulk.devices.length; i++) { + for (var x = 0; x < bridgeService.state.homewizarddevices.length; x++) { + if (bridgeService.state.homewizarddevices[x].id === $scope.bulk.devices[i]) { + $scope.buildDeviceUrls(bridgeService.state.homewizarddevices[x], 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 HomeWizard devices in bulk.", error); + } + ); + $scope.bulk = { + devices: [] + }; + $scope.selectAll = false; + }; - $scope.toggleSelectAll = function toggleSelectAll() { - if($scope.selectAll) { - $scope.selectAll = false; - $scope.bulk = { devices: [] }; - } - else { - $scope.selectAll = true; - for(var x = 0; x < bridgeService.state.homewizarddevices.length; x++) { - if($scope.bulk.devices.indexOf(bridgeService.state.homewizarddevices[x]) < 0) - $scope.bulk.devices.push(bridgeService.state.homewizarddevices[x].devicename); - } - } - }; + $scope.toggleSelection = function toggleSelection(deviceId) { + var idx = $scope.bulk.devices.indexOf(deviceId); - $scope.toggleButtons = function () { - $scope.buttonsVisible = !$scope.buttonsVisible; - if($scope.buttonsVisible) - $scope.imgButtonsUrl = "glyphicon glyphicon-minus"; - else - $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; - }; + // is currently selected + if (idx > -1) { + $scope.bulk.devices.splice(idx, 1); + if ($scope.bulk.devices.length === 0 && $scope.selectAll) + $scope.selectAll = false; + } - $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'); - }; + // 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.homewizarddevices.length; x++) { + if ($scope.bulk.devices.indexOf(bridgeService.state.homewizarddevices[x]) < 0) + $scope.bulk.devices.push(bridgeService.state.homewizarddevices[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('DomoticzController', function ($scope, $location, bridgeService, ngDialog) { $scope.bridge = bridgeService.state; $scope.device = bridgeService.state.device; $scope.device_dim_control = ""; - $scope.bulk = { devices: [] }; + $scope.bulk = { + devices: [] + }; $scope.selectAll = false; bridgeService.viewDomoticzDevices(); $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; @@ -3428,20 +3596,19 @@ app.controller('DomoticzController', function ($scope, $location, bridgeService, var nameCmd = ""; var aDeviceType; var postCmd = ""; - if(domoticzdevice.devicetype === "Scene" || domoticzdevice.devicetype === "Group") { + if (domoticzdevice.devicetype === "Scene" || domoticzdevice.devicetype === "Group") { aDeviceType = "scene"; preCmd = "/json.htm?type=command¶m=switchscene&idx="; postOnCmd = "&switchcmd=On"; postOffCmd = "&switchcmd=Off"; - } - else { + } else { aDeviceType = "switch"; preCmd = "/json.htm?type=command¶m=switchlight&idx="; postOnCmd = "&switchcmd=On"; postDimCmd = "&switchcmd=Set%20Level&level="; postOffCmd = "&switchcmd=Off"; } - if((dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0) && aDeviceType === "switch") + if ((dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0) && aDeviceType === "switch") dimpayload = "http://" + domoticzdevice.domoticzaddress + preCmd + domoticzdevice.idx + @@ -3450,14 +3617,14 @@ app.controller('DomoticzController', function ($scope, $location, bridgeService, else dimpayload = null; onpayload = "http://" + domoticzdevice.domoticzaddress + - preCmd + - domoticzdevice.idx + - postOnCmd; + preCmd + + domoticzdevice.idx + + postOnCmd; offpayload = "http://" + domoticzdevice.domoticzaddress + - preCmd + - domoticzdevice.idx + - postOffCmd; - bridgeService.buildUrls(onpayload, dimpayload, offpayload, null, false, domoticzdevice.devicename + "-" + domoticzdevice.domoticzname, domoticzdevice.devicename, domoticzdevice.domoticzname, aDeviceType, "domoticzDevice", null, null); + preCmd + + domoticzdevice.idx + + postOffCmd; + bridgeService.buildUrls(onpayload, dimpayload, offpayload, null, false, domoticzdevice.devicename + "-" + domoticzdevice.domoticzname, domoticzdevice.devicename, domoticzdevice.domoticzname, aDeviceType, "domoticzDevice", null, null); $scope.device = bridgeService.state.device; if (!buildonly) { bridgeService.editNewDevice($scope.device); @@ -3465,45 +3632,47 @@ app.controller('DomoticzController', function ($scope, $location, bridgeService, } }; - $scope.bulkAddDevices = function(dim_control) { + $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.domoticzdevices.length; x++) { - if(bridgeService.state.domoticzdevices[x].devicename === $scope.bulk.devices[i]) { - $scope.buildDeviceUrls(bridgeService.state.domoticzdevices[x],dim_control,true); + for (var i = 0; i < $scope.bulk.devices.length; i++) { + for (var x = 0; x < bridgeService.state.domoticzdevices.length; x++) { + if (bridgeService.state.domoticzdevices[x].devicename === $scope.bulk.devices[i]) { + $scope.buildDeviceUrls(bridgeService.state.domoticzdevices[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 + 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 Domoticz devices in bulk.", error); - } - ); - $scope.bulk = { devices: [] }; + function () { + $scope.clearDevice(); + bridgeService.viewDevices(); + bridgeService.viewHalDevices(); + }, + function (error) { + bridgeService.displayWarn("Error adding Domoticz devices in bulk.", error); + } + ); + $scope.bulk = { + devices: [] + }; $scope.selectAll = false; }; @@ -3513,7 +3682,7 @@ app.controller('DomoticzController', function ($scope, $location, bridgeService, // is currently selected if (idx > -1) { $scope.bulk.devices.splice(idx, 1); - if($scope.bulk.devices.length === 0 && $scope.selectAll) + if ($scope.bulk.devices.length === 0 && $scope.selectAll) $scope.selectAll = false; } @@ -3525,14 +3694,15 @@ app.controller('DomoticzController', function ($scope, $location, bridgeService, }; $scope.toggleSelectAll = function toggleSelectAll() { - if($scope.selectAll) { + if ($scope.selectAll) { $scope.selectAll = false; - $scope.bulk = { devices: [] }; - } - else { + $scope.bulk = { + devices: [] + }; + } else { $scope.selectAll = true; - for(var x = 0; x < bridgeService.state.domoticzdevices.length; x++) { - if($scope.bulk.devices.indexOf(bridgeService.state.domoticzdevices[x]) < 0) + for (var x = 0; x < bridgeService.state.domoticzdevices.length; x++) { + if ($scope.bulk.devices.indexOf(bridgeService.state.domoticzdevices[x]) < 0) $scope.bulk.devices.push(bridgeService.state.domoticzdevices[x].devicename); } } @@ -3540,7 +3710,7 @@ app.controller('DomoticzController', function ($scope, $location, bridgeService, $scope.toggleButtons = function () { $scope.buttonsVisible = !$scope.buttonsVisible; - if($scope.buttonsVisible) + if ($scope.buttonsVisible) $scope.imgButtonsUrl = "glyphicon glyphicon-minus"; else $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; @@ -3554,7 +3724,7 @@ app.controller('DomoticzController', function ($scope, $location, bridgeService, className: 'ngdialog-theme-default' }); }; - + $scope.editDevice = function (device) { bridgeService.editDevice(device); $location.path('/editdevice'); @@ -3565,7 +3735,9 @@ app.controller('LifxController', function ($scope, $location, bridgeService, ngD $scope.bridge = bridgeService.state; $scope.device = bridgeService.state.device; $scope.device_dim_control = ""; - $scope.bulk = { devices: [] }; + $scope.bulk = { + devices: [] + }; $scope.selectAll = false; bridgeService.viewLifxDevices(); $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; @@ -3585,7 +3757,7 @@ app.controller('LifxController', function ($scope, $location, bridgeService, ngD dimpayload = angular.toJson(lifxdevice); onpayload = angular.toJson(lifxdevice); offpayload = angular.toJson(lifxdevice); - bridgeService.buildUrls(onpayload, dimpayload, offpayload, null, true, lifxdevice.name, lifxdevice.name, lifxdevice.name, null, "lifxDevice", null, null); + bridgeService.buildUrls(onpayload, dimpayload, offpayload, null, true, lifxdevice.name, lifxdevice.name, lifxdevice.name, null, "lifxDevice", null, null); $scope.device = bridgeService.state.device; if (!buildonly) { bridgeService.editNewDevice($scope.device); @@ -3593,45 +3765,47 @@ app.controller('LifxController', function ($scope, $location, bridgeService, ngD } }; - $scope.bulkAddDevices = function(dim_control) { + $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.lifxdevices.length; x++) { - if(bridgeService.state.lifxdevices[x].devicename === $scope.bulk.devices[i]) { - $scope.buildDeviceUrls(bridgeService.state.lifxdevices[x],dim_control,true); + for (var i = 0; i < $scope.bulk.devices.length; i++) { + for (var x = 0; x < bridgeService.state.lifxdevices.length; x++) { + if (bridgeService.state.lifxdevices[x].devicename === $scope.bulk.devices[i]) { + $scope.buildDeviceUrls(bridgeService.state.lifxdevices[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 + 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 LIFX devices in bulk.", error); - } - ); - $scope.bulk = { devices: [] }; + function () { + $scope.clearDevice(); + bridgeService.viewDevices(); + bridgeService.viewHalDevices(); + }, + function (error) { + bridgeService.displayWarn("Error adding LIFX devices in bulk.", error); + } + ); + $scope.bulk = { + devices: [] + }; $scope.selectAll = false; }; @@ -3641,7 +3815,7 @@ app.controller('LifxController', function ($scope, $location, bridgeService, ngD // is currently selected if (idx > -1) { $scope.bulk.devices.splice(idx, 1); - if($scope.bulk.devices.length === 0 && $scope.selectAll) + if ($scope.bulk.devices.length === 0 && $scope.selectAll) $scope.selectAll = false; } @@ -3653,14 +3827,15 @@ app.controller('LifxController', function ($scope, $location, bridgeService, ngD }; $scope.toggleSelectAll = function toggleSelectAll() { - if($scope.selectAll) { + if ($scope.selectAll) { $scope.selectAll = false; - $scope.bulk = { devices: [] }; - } - else { + $scope.bulk = { + devices: [] + }; + } else { $scope.selectAll = true; - for(var x = 0; x < bridgeService.state.lifxdevices.length; x++) { - if($scope.bulk.devices.indexOf(bridgeService.state.lifxdevices[x]) < 0) + for (var x = 0; x < bridgeService.state.lifxdevices.length; x++) { + if ($scope.bulk.devices.indexOf(bridgeService.state.lifxdevices[x]) < 0) $scope.bulk.devices.push(bridgeService.state.lifxdevices[x].devicename); } } @@ -3668,7 +3843,7 @@ app.controller('LifxController', function ($scope, $location, bridgeService, ngD $scope.toggleButtons = function () { $scope.buttonsVisible = !$scope.buttonsVisible; - if($scope.buttonsVisible) + if ($scope.buttonsVisible) $scope.imgButtonsUrl = "glyphicon glyphicon-minus"; else $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; @@ -3682,7 +3857,7 @@ app.controller('LifxController', function ($scope, $location, bridgeService, ngD className: 'ngdialog-theme-default' }); }; - + $scope.editDevice = function (device) { bridgeService.editDevice(device); $location.path('/editdevice'); @@ -3693,9 +3868,15 @@ app.controller('SomfyController', function ($scope, $location, bridgeService, ng $scope.bridge = bridgeService.state; $scope.device = bridgeService.state.device; $scope.device_dim_control = ""; - $scope.bulk = { devices: [] }; + $scope.bulk = { + devices: [] + }; $scope.selectAll = false; - $scope.somfy = {base: "http://", port: "3480", id: ""}; + $scope.somfy = { + base: "http://", + port: "3480", + id: "" + }; bridgeService.viewDevices(); //Needs this if you're navigating to the 'somfy' page directly without going to the home page first.. bridgeService.viewSomfyDevices(); $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; @@ -3708,59 +3889,61 @@ app.controller('SomfyController', function ($scope, $location, bridgeService, ng }; $scope.buildDeviceUrls = function (somfydevice, dim_control, buildonly) { - //TODO - support partial window opening - add back 'dim_control' second param in here, and in somfydevice.html - dimpayload = null; - onpayload = "{\"label\":\"Label that is ignored probably\",\"actions\":[{\"deviceURL\":\""+ somfydevice.deviceUrl+"\",\"commands\":[{\"name\":\"open\",\"parameters\":[]}]}]}"; - offpayload = "{\"label\":\"Label that is ignored probably\",\"actions\":[{\"deviceURL\":\""+ somfydevice.deviceUrl+"\",\"commands\":[{\"name\":\"close\",\"parameters\":[]}]}]}"; + //TODO - support partial window opening - add back 'dim_control' second param in here, and in somfydevice.html + dimpayload = null; + onpayload = "{\"label\":\"Label that is ignored probably\",\"actions\":[{\"deviceURL\":\"" + somfydevice.deviceUrl + "\",\"commands\":[{\"name\":\"open\",\"parameters\":[]}]}]}"; + offpayload = "{\"label\":\"Label that is ignored probably\",\"actions\":[{\"deviceURL\":\"" + somfydevice.deviceUrl + "\",\"commands\":[{\"name\":\"close\",\"parameters\":[]}]}]}"; - bridgeService.buildUrls(onpayload, dimpayload, offpayload, null, true, somfydevice.id, somfydevice.name, somfydevice.somfyname, "switch", "somfyDevice", null, null); - $scope.device = bridgeService.state.device; - if (!buildonly) { - bridgeService.editNewDevice($scope.device); - $location.path('/editdevice'); - } + bridgeService.buildUrls(onpayload, dimpayload, offpayload, null, true, somfydevice.id, somfydevice.name, somfydevice.somfyname, "switch", "somfyDevice", null, null); + $scope.device = bridgeService.state.device; + if (!buildonly) { + bridgeService.editNewDevice($scope.device); + $location.path('/editdevice'); + } }; - $scope.bulkAddDevices = function(dim_control) { + $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.somfydevices.length; x++) { - if(bridgeService.state.somfydevices[x].id === $scope.bulk.devices[i]) { - $scope.buildDeviceUrls(bridgeService.state.somfydevices[x],dim_control, true); + for (var i = 0; i < $scope.bulk.devices.length; i++) { + for (var x = 0; x < bridgeService.state.somfydevices.length; x++) { + if (bridgeService.state.somfydevices[x].id === $scope.bulk.devices[i]) { + $scope.buildDeviceUrls(bridgeService.state.somfydevices[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 + 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.viewSomfyDevices(); - }, - function (error) { - bridgeService.displayWarn("Error adding Somfy devices in bulk.", error); - } - ); - $scope.bulk = { devices: [] }; + function () { + $scope.clearDevice(); + bridgeService.viewDevices(); + bridgeService.viewSomfyDevices(); + }, + function (error) { + bridgeService.displayWarn("Error adding Somfy devices in bulk.", error); + } + ); + $scope.bulk = { + devices: [] + }; $scope.selectAll = false; }; @@ -3770,7 +3953,7 @@ app.controller('SomfyController', function ($scope, $location, bridgeService, ng // is currently selected if (idx > -1) { $scope.bulk.devices.splice(idx, 1); - if($scope.bulk.devices.length === 0 && $scope.selectAll) + if ($scope.bulk.devices.length === 0 && $scope.selectAll) $scope.selectAll = false; } @@ -3782,14 +3965,15 @@ app.controller('SomfyController', function ($scope, $location, bridgeService, ng }; $scope.toggleSelectAll = function toggleSelectAll() { - if($scope.selectAll) { + if ($scope.selectAll) { $scope.selectAll = false; - $scope.bulk = { devices: [] }; - } - else { + $scope.bulk = { + devices: [] + }; + } else { $scope.selectAll = true; - for(var x = 0; x < bridgeService.state.somfydevices.length; x++) { - if($scope.bulk.devices.indexOf(bridgeService.state.somfydevices[x]) < 0 && !bridgeService.findDeviceByMapId(bridgeService.state.somfydevices[x].id, bridgeService.state.somfydevices[x].somfyname, "somfyDevice")) + for (var x = 0; x < bridgeService.state.somfydevices.length; x++) { + if ($scope.bulk.devices.indexOf(bridgeService.state.somfydevices[x]) < 0 && !bridgeService.findDeviceByMapId(bridgeService.state.somfydevices[x].id, bridgeService.state.somfydevices[x].somfyname, "somfyDevice")) $scope.bulk.devices.push(bridgeService.state.somfydevices[x].id); } } @@ -3797,7 +3981,7 @@ app.controller('SomfyController', function ($scope, $location, bridgeService, ng $scope.toggleButtons = function () { $scope.buttonsVisible = !$scope.buttonsVisible; - if($scope.buttonsVisible) + if ($scope.buttonsVisible) $scope.imgButtonsUrl = "glyphicon glyphicon-minus"; else $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; @@ -3822,12 +4006,14 @@ app.controller('OpenHABController', function ($scope, $location, bridgeService, $scope.bridge = bridgeService.state; $scope.device = bridgeService.state.device; $scope.device_dim_control = ""; - $scope.bulk = { devices: [] }; + $scope.bulk = { + devices: [] + }; $scope.selectAll = false; bridgeService.viewOpenHABDevices(); $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; $scope.buttonsVisible = false; - + $scope.clearDevice = function () { bridgeService.clearDevice(); $scope.device = bridgeService.state.device; @@ -3835,46 +4021,44 @@ app.controller('OpenHABController', function ($scope, $location, bridgeService, $scope.buildDeviceUrls = function (openhabdevice, dim_control, onaction, ondata, dimaction, dimdata, offaction, offdata, coloraction, colordata, buildonly) { var preCmd = "/rest/items/" + openhabdevice.item.name; - if(openhabdevice.item.type !== 'String') { - if((dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0)) { + if (openhabdevice.item.type !== 'String') { + if ((dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0)) { dimpayload = "{\"url\":\"http://" + openhabdevice.address + preCmd + "\",\"command\":\"" + dim_control + "\"}"; - } - else + } else dimpayload = null; onpayload = "{\"url\":\"http://" + openhabdevice.address + preCmd + "\",\"command\":\"ON\"}"; offpayload = "{\"url\":\"http://" + openhabdevice.address + preCmd + "\",\"command\":\"OFF\"}"; colorpayload = null; - } - else { - if(onaction === 'other') + } else { + if (onaction === 'other') onpayload = "{\"url\":\"http://" + openhabdevice.address + preCmd + "\",\"command\":\"" + ondata + "\"}"; - else if(onaction !== undefined && onaction !== null && onaction !== '') + else if (onaction !== undefined && onaction !== null && onaction !== '') onpayload = "{\"url\":\"http://" + openhabdevice.address + preCmd + "\",\"command\":\"" + onaction + "\"}"; else onpayload = null; - - if(dimaction === 'other') + + if (dimaction === 'other') dimpayload = "{\"url\":\"http://" + openhabdevice.address + preCmd + "\",\"command\":\"" + dimdata + "\"}"; - else if(dimaction !== undefined && dimaction !== null && dimaction !== '') + else if (dimaction !== undefined && dimaction !== null && dimaction !== '') dimpayload = "{\"url\":\"http://" + openhabdevice.address + preCmd + "\",\"command\":\"" + dimaction + "\"}"; else dimpayload = null; - if(offaction === 'other') + if (offaction === 'other') offpayload = "{\"url\":\"http://" + openhabdevice.address + preCmd + "\",\"command\":\"" + offdata + "\"}"; - else if(offaction !== undefined && offaction !== null && offaction !== '') + else if (offaction !== undefined && offaction !== null && offaction !== '') offpayload = "{\"url\":\"http://" + openhabdevice.address + preCmd + "\",\"command\":\"" + offaction + "\"}"; else offpayload = null; - if(coloraction === 'other') + if (coloraction === 'other') colorpayload = "{\"url\":\"http://" + openhabdevice.address + preCmd + "\",\"command\":\"" + colordata + "\"}"; - else if(coloraction !== undefined && coloraction !== null && coloraction !== '') + else if (coloraction !== undefined && coloraction !== null && coloraction !== '') colorpayload = "{\"url\":\"http://" + openhabdevice.address + preCmd + "\",\"command\":\"" + coloraction + "\"}"; else colorpayload = null; } - bridgeService.buildUrls(onpayload, dimpayload, offpayload, colorpayload, true, openhabdevice.item.name + "-" + openhabdevice.name, openhabdevice.item.name, openhabdevice.name, openhabdevice.item.type, "openhabDevice", null, null); + bridgeService.buildUrls(onpayload, dimpayload, offpayload, colorpayload, true, openhabdevice.item.name + "-" + openhabdevice.name, openhabdevice.item.name, openhabdevice.name, openhabdevice.item.type, "openhabDevice", null, null); $scope.device = bridgeService.state.device; if (!buildonly) { bridgeService.editNewDevice($scope.device); @@ -3882,45 +4066,47 @@ app.controller('OpenHABController', function ($scope, $location, bridgeService, } }; - $scope.bulkAddDevices = function(dim_control) { + $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.openhabdevices.length; x++) { - if(bridgeService.state.openhabdevices[x].devicename === $scope.bulk.devices[i]) { - $scope.buildDeviceUrls(bridgeService.state.openhabdevices[x],dim_control, null, null, null, null, null, null, null, null, true); + for (var i = 0; i < $scope.bulk.devices.length; i++) { + for (var x = 0; x < bridgeService.state.openhabdevices.length; x++) { + if (bridgeService.state.openhabdevices[x].devicename === $scope.bulk.devices[i]) { + $scope.buildDeviceUrls(bridgeService.state.openhabdevices[x], dim_control, null, null, null, null, null, null, null, null, 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 + 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 openhab devices in bulk.", error); - } - ); - $scope.bulk = { devices: [] }; + function () { + $scope.clearDevice(); + bridgeService.viewDevices(); + bridgeService.viewHalDevices(); + }, + function (error) { + bridgeService.displayWarn("Error adding openhab devices in bulk.", error); + } + ); + $scope.bulk = { + devices: [] + }; $scope.selectAll = false; }; @@ -3930,7 +4116,7 @@ app.controller('OpenHABController', function ($scope, $location, bridgeService, // is currently selected if (idx > -1) { $scope.bulk.devices.splice(idx, 1); - if($scope.bulk.devices.length === 0 && $scope.selectAll) + if ($scope.bulk.devices.length === 0 && $scope.selectAll) $scope.selectAll = false; } @@ -3942,14 +4128,15 @@ app.controller('OpenHABController', function ($scope, $location, bridgeService, }; $scope.toggleSelectAll = function toggleSelectAll() { - if($scope.selectAll) { + if ($scope.selectAll) { $scope.selectAll = false; - $scope.bulk = { devices: [] }; - } - else { + $scope.bulk = { + devices: [] + }; + } else { $scope.selectAll = true; - for(var x = 0; x < bridgeService.state.openhabdevices.length; x++) { - if($scope.bulk.devices.indexOf(bridgeService.state.openhabdevices[x]) < 0) + for (var x = 0; x < bridgeService.state.openhabdevices.length; x++) { + if ($scope.bulk.devices.indexOf(bridgeService.state.openhabdevices[x]) < 0) $scope.bulk.devices.push(bridgeService.state.openhabdevices[x].devicename); } } @@ -3957,7 +4144,7 @@ app.controller('OpenHABController', function ($scope, $location, bridgeService, $scope.toggleButtons = function () { $scope.buttonsVisible = !$scope.buttonsVisible; - if($scope.buttonsVisible) + if ($scope.buttonsVisible) $scope.imgButtonsUrl = "glyphicon glyphicon-minus"; else $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; @@ -3971,7 +4158,7 @@ app.controller('OpenHABController', function ($scope, $location, bridgeService, className: 'ngdialog-theme-default' }); }; - + $scope.editDevice = function (device) { bridgeService.editDevice(device); $location.path('/editdevice'); @@ -3982,35 +4169,38 @@ app.controller('MozIotController', function ($scope, $location, bridgeService, n $scope.bridge = bridgeService.state; $scope.device = bridgeService.state.device; $scope.device_dim_control = ""; - $scope.bulk = { devices: [] }; + $scope.bulk = { + devices: [] + }; $scope.selectAll = false; bridgeService.viewMozIotDevices(); $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; $scope.buttonsVisible = false; - + $scope.clearDevice = function () { bridgeService.clearDevice(); $scope.device = bridgeService.state.device; }; - $scope.buildDeviceUrls = function (moziotdevice, dim_control, colordata, buildonly) { - var preCmd = moziotdevice.href + "/"; + $scope.buildDeviceUrls = function (moziotdevice, dim_control, coloraction, colordata, buildonly) { + var preCmd = moziotdevice.deviceDetail.href + "/properties/"; onpayload = null; offpayload = null; dimpayload = null; colorpayload = null; - if(moziotdevice.properties.on !== undefined) { + if (moziotdevice.deviceDetail.properties.on !== undefined) { onpayload = "{\"url\":\"" + preCmd + "on\",\"command\":{\"on\":true}}"; offpayload = "{\"url\":\"" + preCmd + "on\",\"command\":{\"on\":false}}"; } - if(moziotdevice.properties.level !== undefined) { - dimpayload = "{\"url\":\"" + preCmd + "level\",\"command\":{\"level\":" + dim_control + "}}"; - } - if(moziotdevice.properties.color !== undefined) { - colorpayload = "{\"url\":\"" + preCmd + "color\",\"command\":\"{\"color\":" + colordata + "}}"; + if (dim_control !== undefined && dim_control !== "") { + dimpayload = "{\"url\":\"" + preCmd + "level\",\"command\":{\"level\":\"" + dim_control + "\"}}"; } + if (coloraction === 'other') + colorpayload = "{\"url\":\"" + preCmd + "color\",\"command\":{\"color\":\"" + colordata + "\"}}"; + else if (coloraction !== undefined && coloraction !== null && coloraction !== '') + colorpayload = "{\"url\":\"" + preCmd + "color\",\"command\":{\"color\":\"" + coloraction + "\"}}"; - bridgeService.buildUrls(onpayload, dimpayload, offpayload, colorpayload, true, moziotdevice.name + "-" + moziotdevice.type, moziotdevice.name, moziotdevice.name, moziotdevice.type, "moziotDevice", null, null); + bridgeService.buildUrls(onpayload, dimpayload, offpayload, colorpayload, true, moziotdevice.deviceDetail.name + "-" + moziotdevice.deviceDetail.type, moziotdevice.deviceDetail.name, moziotdevice.gatewayName, "Switch", "moziotDevice", null, null); $scope.device = bridgeService.state.device; if (!buildonly) { bridgeService.editNewDevice($scope.device); @@ -4018,45 +4208,47 @@ app.controller('MozIotController', function ($scope, $location, bridgeService, n } }; - $scope.bulkAddDevices = function(dim_control) { + $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.moziotdevices.length; x++) { - if(bridgeService.state.moziotdevices[x].devicename === $scope.bulk.devices[i]) { - $scope.buildDeviceUrls(bridgeService.state.moziotdevices[x],dim_control, null, true); + for (var i = 0; i < $scope.bulk.devices.length; i++) { + for (var x = 0; x < bridgeService.state.moziotdevices.length; x++) { + if (bridgeService.state.moziotdevices[x].devicename === $scope.bulk.devices[i]) { + $scope.buildDeviceUrls(bridgeService.state.moziotdevices[x], dim_control, null, null, 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 + 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 Mozilla IOT devices in bulk.", error); - } - ); - $scope.bulk = { devices: [] }; + function () { + $scope.clearDevice(); + bridgeService.viewDevices(); + bridgeService.viewHalDevices(); + }, + function (error) { + bridgeService.displayWarn("Error adding Mozilla IOT devices in bulk.", error); + } + ); + $scope.bulk = { + devices: [] + }; $scope.selectAll = false; }; @@ -4066,7 +4258,7 @@ app.controller('MozIotController', function ($scope, $location, bridgeService, n // is currently selected if (idx > -1) { $scope.bulk.devices.splice(idx, 1); - if($scope.bulk.devices.length === 0 && $scope.selectAll) + if ($scope.bulk.devices.length === 0 && $scope.selectAll) $scope.selectAll = false; } @@ -4078,14 +4270,15 @@ app.controller('MozIotController', function ($scope, $location, bridgeService, n }; $scope.toggleSelectAll = function toggleSelectAll() { - if($scope.selectAll) { + if ($scope.selectAll) { $scope.selectAll = false; - $scope.bulk = { devices: [] }; - } - else { + $scope.bulk = { + devices: [] + }; + } else { $scope.selectAll = true; - for(var x = 0; x < bridgeService.state.moziotdevices.length; x++) { - if($scope.bulk.devices.indexOf(bridgeService.state.moziotdevices[x]) < 0) + for (var x = 0; x < bridgeService.state.moziotdevices.length; x++) { + if ($scope.bulk.devices.indexOf(bridgeService.state.moziotdevices[x]) < 0) $scope.bulk.devices.push(bridgeService.state.moziotdevices[x].devicename); } } @@ -4093,7 +4286,7 @@ app.controller('MozIotController', function ($scope, $location, bridgeService, n $scope.toggleButtons = function () { $scope.buttonsVisible = !$scope.buttonsVisible; - if($scope.buttonsVisible) + if ($scope.buttonsVisible) $scope.imgButtonsUrl = "glyphicon glyphicon-minus"; else $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; @@ -4107,7 +4300,7 @@ app.controller('MozIotController', function ($scope, $location, bridgeService, n className: 'ngdialog-theme-default' }); }; - + $scope.editDevice = function (device) { bridgeService.editDevice(device); $location.path('/editdevice'); @@ -4118,12 +4311,14 @@ app.controller('FhemController', function ($scope, $location, bridgeService, ngD $scope.bridge = bridgeService.state; $scope.device = bridgeService.state.device; $scope.device_dim_control = ""; - $scope.bulk = { devices: [] }; + $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; @@ -4131,30 +4326,25 @@ 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.toLowerCase().indexOf("dim") >= 0) { - if((dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 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 + } 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)) { + } 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 + } else dimpayload = "{\"url\":\"http://" + fhemdevice.address + preCmd + "\",\"command\":\"pct%20${intensity.percent}\"}"; - } - else + } else dimpayload = null; - if(fhemdevice.item.PossibleSets.toLowerCase().indexOf("rgb") >= 0) { + if (fhemdevice.item.PossibleSets.toLowerCase().indexOf("rgb") >= 0) { colorpayload = "{\"url\":\"http://" + fhemdevice.address + preCmd + "\",\"command\":\"RGB%20${color.rgbx}\"}"; - } - else + } 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); + 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); @@ -4162,45 +4352,47 @@ app.controller('FhemController', function ($scope, $location, bridgeService, ngD } }; - $scope.bulkAddDevices = function(dim_control) { + $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].item.Name === $scope.bulk.devices[i]) { - $scope.buildDeviceUrls(bridgeService.state.fhemdevices[x],dim_control,true); + 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].item.Name === $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 + 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: [] }; + function () { + $scope.clearDevice(); + bridgeService.viewDevices(); + bridgeService.viewHalDevices(); + }, + function (error) { + bridgeService.displayWarn("Error adding fhem devices in bulk.", error); + } + ); + $scope.bulk = { + devices: [] + }; $scope.selectAll = false; }; @@ -4210,7 +4402,7 @@ app.controller('FhemController', function ($scope, $location, bridgeService, ngD // is currently selected if (idx > -1) { $scope.bulk.devices.splice(idx, 1); - if($scope.bulk.devices.length === 0 && $scope.selectAll) + if ($scope.bulk.devices.length === 0 && $scope.selectAll) $scope.selectAll = false; } @@ -4222,14 +4414,15 @@ app.controller('FhemController', function ($scope, $location, bridgeService, ngD }; $scope.toggleSelectAll = function toggleSelectAll() { - if($scope.selectAll) { + if ($scope.selectAll) { $scope.selectAll = false; - $scope.bulk = { devices: [] }; - } - else { + $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) + 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].item.Name); } } @@ -4237,7 +4430,7 @@ app.controller('FhemController', function ($scope, $location, bridgeService, ngD $scope.toggleButtons = function () { $scope.buttonsVisible = !$scope.buttonsVisible; - if($scope.buttonsVisible) + if ($scope.buttonsVisible) $scope.imgButtonsUrl = "glyphicon glyphicon-minus"; else $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; @@ -4251,7 +4444,7 @@ app.controller('FhemController', function ($scope, $location, bridgeService, ngD className: 'ngdialog-theme-default' }); }; - + $scope.editDevice = function (device) { bridgeService.editDevice(device); $location.path('/editdevice'); @@ -4262,12 +4455,14 @@ app.controller('BroadlinkController', function ($scope, $location, bridgeService $scope.bridge = bridgeService.state; $scope.device = bridgeService.state.device; $scope.device_dim_control = ""; - $scope.bulk = { devices: [] }; + $scope.bulk = { + devices: [] + }; $scope.selectAll = false; bridgeService.viewBroadlinkDevices(); $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; $scope.buttonsVisible = false; - + $scope.clearDevice = function () { bridgeService.clearDevice(); $scope.device = bridgeService.state.device; @@ -4280,36 +4475,35 @@ app.controller('BroadlinkController', function ($scope, $location, bridgeService $scope.buildDeviceUrls = function (broadlinkdevice, dim_control, ondata, dimdata, offdata, colordata, buildonly) { var preCmd = "{\"id\":\"" + broadlinkdevice.id + "\",\"name\":\"" + broadlinkdevice.name + "\",\"type\":\"" + broadlinkdevice.type + "\",\"ipAddr\":\"" + broadlinkdevice.ipAddr + "\",\"macAddr\":\"" + broadlinkdevice.macAddr + "\",\"command\":\""; - if(broadlinkdevice.baseType === '0000' || broadlinkdevice.baseType === '2711') { + if (broadlinkdevice.baseType === '0000' || broadlinkdevice.baseType === '2711') { dimpayload = null; colorpayload = null; onpayload = preCmd + "on\"}"; offpayload = preCmd + "off\"}"; - } - else if(broadlinkdevice.baseType === '4EB5') { + } else if (broadlinkdevice.baseType === '4EB5') { dimpayload = null; colorpayload = null; onpayload = preCmd + "on\",\"data\":\"" + ondata + "\"}"; offpayload = preCmd + "off\",\"data\":\"" + offdata + "\"}"; } else { - if( ondata !== undefined && ondata !== null && ondata !== "") - onpayload = preCmd + "ircommand\",\"data\":\"" + ondata + "\"}"; + if (ondata !== undefined && ondata !== null && ondata !== "") + onpayload = preCmd + "ircommand\",\"data\":\"" + ondata + "\"}"; else onpayload = null; - if( dimdata !== undefined && dimdata !== null && dimdata !== "") - dimpayload = preCmd + "ircommand\",\"data\":\"" + dimdata + "\"}"; + if (dimdata !== undefined && dimdata !== null && dimdata !== "") + dimpayload = preCmd + "ircommand\",\"data\":\"" + dimdata + "\"}"; else dimpayload = null; - if( offdata !== undefined && offdata !== null && offdata !== "") - offpayload = preCmd + "ircommand\",\"data\":\"" + offdata + "\"}"; + if (offdata !== undefined && offdata !== null && offdata !== "") + offpayload = preCmd + "ircommand\",\"data\":\"" + offdata + "\"}"; else offpayload = null; - if( colordata !== undefined && colordata !== null && colordata !== "") - colorpayload = preCmd + "ircommand\",\"data\":\"" + colordata + "\"}"; + if (colordata !== undefined && colordata !== null && colordata !== "") + colorpayload = preCmd + "ircommand\",\"data\":\"" + colordata + "\"}"; else colorpayload = null; } - bridgeService.buildUrls(onpayload, dimpayload, offpayload, colorpayload, true, broadlinkdevice.id, broadlinkdevice.name, broadlinkdevice.id, broadlinkdevice.desc, "broadlinkDevice", null, null); + bridgeService.buildUrls(onpayload, dimpayload, offpayload, colorpayload, true, broadlinkdevice.id, broadlinkdevice.name, broadlinkdevice.id, broadlinkdevice.desc, "broadlinkDevice", null, null); $scope.device = bridgeService.state.device; if (!buildonly) { bridgeService.editNewDevice($scope.device); @@ -4317,45 +4511,47 @@ app.controller('BroadlinkController', function ($scope, $location, bridgeService } }; - $scope.bulkAddDevices = function(dim_control) { + $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.broadlinkdevices.length; x++) { - if(bridgeService.state.broadlinkdevices[x].devicename === $scope.bulk.devices[i]) { - $scope.buildDeviceUrls(bridgeService.state.broadlinkdevices[x],dim_control,null,null,null,null,true); + for (var i = 0; i < $scope.bulk.devices.length; i++) { + for (var x = 0; x < bridgeService.state.broadlinkdevices.length; x++) { + if (bridgeService.state.broadlinkdevices[x].devicename === $scope.bulk.devices[i]) { + $scope.buildDeviceUrls(bridgeService.state.broadlinkdevices[x], dim_control, null, null, null, null, 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 + 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 openhab devices in bulk.", error); - } - ); - $scope.bulk = { devices: [] }; + function () { + $scope.clearDevice(); + bridgeService.viewDevices(); + bridgeService.viewHalDevices(); + }, + function (error) { + bridgeService.displayWarn("Error adding openhab devices in bulk.", error); + } + ); + $scope.bulk = { + devices: [] + }; $scope.selectAll = false; }; @@ -4365,7 +4561,7 @@ app.controller('BroadlinkController', function ($scope, $location, bridgeService // is currently selected if (idx > -1) { $scope.bulk.devices.splice(idx, 1); - if($scope.bulk.devices.length === 0 && $scope.selectAll) + if ($scope.bulk.devices.length === 0 && $scope.selectAll) $scope.selectAll = false; } @@ -4377,14 +4573,15 @@ app.controller('BroadlinkController', function ($scope, $location, bridgeService }; $scope.toggleSelectAll = function toggleSelectAll() { - if($scope.selectAll) { + if ($scope.selectAll) { $scope.selectAll = false; - $scope.bulk = { devices: [] }; - } - else { + $scope.bulk = { + devices: [] + }; + } else { $scope.selectAll = true; - for(var x = 0; x < bridgeService.state.broadlinkdevices.length; x++) { - if($scope.bulk.devices.indexOf(bridgeService.state.broadlinkdevices[x]) < 0) + for (var x = 0; x < bridgeService.state.broadlinkdevices.length; x++) { + if ($scope.bulk.devices.indexOf(bridgeService.state.broadlinkdevices[x]) < 0) $scope.bulk.devices.push(bridgeService.state.broadlinkdevices[x].devicename); } } @@ -4392,7 +4589,7 @@ app.controller('BroadlinkController', function ($scope, $location, bridgeService $scope.toggleButtons = function () { $scope.buttonsVisible = !$scope.buttonsVisible; - if($scope.buttonsVisible) + if ($scope.buttonsVisible) $scope.imgButtonsUrl = "glyphicon glyphicon-minus"; else $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; @@ -4406,7 +4603,7 @@ app.controller('BroadlinkController', function ($scope, $location, bridgeService className: 'ngdialog-theme-default' }); }; - + $scope.editDevice = function (device) { bridgeService.editDevice(device); $location.path('/editdevice'); @@ -4426,29 +4623,29 @@ app.controller('EditController', function ($scope, $location, bridgeService) { $scope.offUrl = null; $scope.colorUrl = null; if ($scope.device !== undefined && $scope.device.name !== undefined) { - if($scope.bridge.device.onUrl !== undefined) { + if ($scope.bridge.device.onUrl !== undefined) { $scope.onDevices = bridgeService.getCallObjects($scope.bridge.device.onUrl); $scope.onUrl = $scope.bridge.device.onUrl.split("},").join("},\n"); } - if($scope.bridge.device.dimUrl !== undefined) { + if ($scope.bridge.device.dimUrl !== undefined) { $scope.dimDevices = bridgeService.getCallObjects($scope.bridge.device.dimUrl); $scope.dimUrl = $scope.bridge.device.dimUrl.split("},").join("},\n"); } - if($scope.bridge.device.offUrl !== undefined) { + if ($scope.bridge.device.offUrl !== undefined) { $scope.offDevices = bridgeService.getCallObjects($scope.bridge.device.offUrl); $scope.offUrl = $scope.bridge.device.offUrl.split("},").join("},\n"); } - if($scope.bridge.device.colorUrl !== undefined) { + if ($scope.bridge.device.colorUrl !== undefined) { $scope.colorDevices = bridgeService.getCallObjects($scope.bridge.device.colorUrl); $scope.colorUrl = $scope.bridge.device.colorUrl.split("},").join("},\n"); } } - + $scope.newOnItem = {}; $scope.newDimItem = {}; $scope.newOffItem = {}; $scope.newColorItem = {}; - $scope.mapTypeSelected = bridgeService.getMapType($scope.device.mapType); + $scope.mapTypeSelected = bridgeService.getMapType($scope.device.mapType); $scope.device_dim_control = ""; $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; $scope.buttonsVisible = false; @@ -4473,12 +4670,12 @@ app.controller('EditController', function ($scope, $location, bridgeService) { }; $scope.editDevice = function (copy) { - if($scope.device.name === "" && $scope.device.onUrl === "") { + if ($scope.device.name === "" && $scope.device.onUrl === "") { $scope.clearDevice(); bridgeService.displayWarn("Error adding/editing device. Name has not been given.", null); return; } - if(($scope.device.name === $scope.bridge.olddevicename) && copy) { + if (($scope.device.name === $scope.bridge.olddevicename) && copy) { $scope.clearDevice(); bridgeService.displayWarn("Error adding device. Name has not been changed from original.", null); return; @@ -4486,19 +4683,19 @@ app.controller('EditController', function ($scope, $location, bridgeService) { if (copy) { $scope.device.id = null; $scope.device.uniqueid = null; - if($scope.bridge.olddevicename !== null && $scope.bridge.olddevicename !== "") + if ($scope.bridge.olddevicename !== null && $scope.bridge.olddevicename !== "") $scope.device.mapId = $scope.device.mapId + "-copy"; } - if($scope.mapTypeSelected !== undefined && $scope.mapTypeSelected !== null) + if ($scope.mapTypeSelected !== undefined && $scope.mapTypeSelected !== null) $scope.device.mapType = $scope.mapTypeSelected[0]; else $scope.device.mapType = null; - + if ($scope.showUrls) { - $scope.device.onUrl = ($scope.onUrl == undefined || $scope.onUrl == null || $scope.onUrl == "") ? null : $scope.onUrl.replace(/\r?\n|\r/g,""); - $scope.device.dimUrl = ($scope.dimUrl == undefined || $scope.dimUrl == null || $scope.dimUrl == "") ? null : $scope.dimUrl.replace(/\r?\n|\r/g,""); - $scope.device.offUrl = ($scope.offUrl == undefined || $scope.offUrl == null || $scope.offUrl == "") ? null : $scope.offUrl.replace(/\r?\n|\r/g,""); - $scope.device.colorUrl = ($scope.colorUrl == undefined || $scope.colorUrl == null || $scope.colorUrl == "") ? null : $scope.colorUrl.replace(/\r?\n|\r/g,""); + $scope.device.onUrl = ($scope.onUrl == undefined || $scope.onUrl == null || $scope.onUrl == "") ? null : $scope.onUrl.replace(/\r?\n|\r/g, ""); + $scope.device.dimUrl = ($scope.dimUrl == undefined || $scope.dimUrl == null || $scope.dimUrl == "") ? null : $scope.dimUrl.replace(/\r?\n|\r/g, ""); + $scope.device.offUrl = ($scope.offUrl == undefined || $scope.offUrl == null || $scope.offUrl == "") ? null : $scope.offUrl.replace(/\r?\n|\r/g, ""); + $scope.device.colorUrl = ($scope.colorUrl == undefined || $scope.colorUrl == null || $scope.colorUrl == "") ? null : $scope.colorUrl.replace(/\r?\n|\r/g, ""); } else { if ($scope.onDevices !== null) $scope.device.onUrl = angular.toJson(bridgeService.updateCallObjectsType($scope.onDevices)); @@ -4507,100 +4704,140 @@ app.controller('EditController', function ($scope, $location, bridgeService) { if ($scope.offDevices !== null) $scope.device.offUrl = angular.toJson(bridgeService.updateCallObjectsType($scope.offDevices)); if ($scope.colorDevices !== null) - $scope.device.colorUrl = angular.toJson(bridgeService.updateCallObjectsType($scope.colorDevices)); + $scope.device.colorUrl = angular.toJson(bridgeService.updateCallObjectsType($scope.colorDevices)); } - + bridgeService.addDevice($scope.device).then( - function () { - bridgeService.state.queueDevId = $scope.device.id; - console.log("Device updated for Q Id <<" + bridgeService.state.queueDevId + ">>"); - $scope.clearDevice(); - $location.path('/'); - }, - function (error) { - bridgeService.displayWarn("Error adding/updating device....", error); - } + function () { + bridgeService.state.queueDevId = $scope.device.id; + console.log("Device updated for Q Id <<" + bridgeService.state.queueDevId + ">>"); + $scope.clearDevice(); + $location.path('/'); + }, + function (error) { + bridgeService.displayWarn("Error adding/updating device....", error); + } ); }; - $scope.addItemOn = function (anItem) { - if (anItem.item === undefined || anItem.item === null || anItem.item === "") - return; - var newitem = { item: anItem.item, type: anItem.type, delay: anItem.delay, count: anItem.count, filterIPs: anItem.filterIPs, httpVerb: anItem.httpVerb, httpBody: anItem.httpBody, httpHeaders: anItem.httpHeaders, contentType: anItem.contentType }; - if ($scope.onDevices === null) - $scope.onDevices = []; - $scope.onDevices.push(newitem); - $scope.newOnItem = {}; - }; - $scope.removeItemOn = function (anItem) { - for(var i = $scope.onDevices.length - 1; i >= 0; i--) { - if($scope.onDevices[i] === anItem) { - $scope.onDevices.splice(i, 1); - } - } - $scope.newOnItem = {}; - }; + $scope.addItemOn = function (anItem) { + if (anItem.item === undefined || anItem.item === null || anItem.item === "") + return; + var newitem = { + item: anItem.item, + type: anItem.type, + delay: anItem.delay, + count: anItem.count, + filterIPs: anItem.filterIPs, + httpVerb: anItem.httpVerb, + httpBody: anItem.httpBody, + httpHeaders: anItem.httpHeaders, + contentType: anItem.contentType + }; + if ($scope.onDevices === null) + $scope.onDevices = []; + $scope.onDevices.push(newitem); + $scope.newOnItem = {}; + }; + $scope.removeItemOn = function (anItem) { + for (var i = $scope.onDevices.length - 1; i >= 0; i--) { + if ($scope.onDevices[i] === anItem) { + $scope.onDevices.splice(i, 1); + } + } + $scope.newOnItem = {}; + }; - $scope.addItemDim = function (anItem) { - if (anItem.item === undefined || anItem.item === null || anItem.item === "") - return; - var newitem = { item: anItem.item, type: anItem.type, delay: anItem.delay, count: anItem.count, filterIPs: anItem.filterIPs, httpVerb: anItem.httpVerb, httpBody: anItem.httpBody, httpHeaders: anItem.httpHeaders, contentType: anItem.contentType }; - if ($scope.dimDevices === null) - $scope.dimDevices = []; - $scope.dimDevices.push(newitem); - $scope.newDimItem = {}; - }; - $scope.removeItemDim = function (anItem) { - for(var i = $scope.dimDevices.length - 1; i >= 0; i--) { - if($scope.dimDevices[i] === anItem) { - $scope.dimDevices.splice(i, 1); - } - } - $scope.newDimItem = {}; - }; + $scope.addItemDim = function (anItem) { + if (anItem.item === undefined || anItem.item === null || anItem.item === "") + return; + var newitem = { + item: anItem.item, + type: anItem.type, + delay: anItem.delay, + count: anItem.count, + filterIPs: anItem.filterIPs, + httpVerb: anItem.httpVerb, + httpBody: anItem.httpBody, + httpHeaders: anItem.httpHeaders, + contentType: anItem.contentType + }; + if ($scope.dimDevices === null) + $scope.dimDevices = []; + $scope.dimDevices.push(newitem); + $scope.newDimItem = {}; + }; + $scope.removeItemDim = function (anItem) { + for (var i = $scope.dimDevices.length - 1; i >= 0; i--) { + if ($scope.dimDevices[i] === anItem) { + $scope.dimDevices.splice(i, 1); + } + } + $scope.newDimItem = {}; + }; - $scope.addItemOff = function (anItem) { - if (anItem.item === undefined || anItem.item === null || anItem.item === "") - return; - var newitem = { item: anItem.item, type: anItem.type, delay: anItem.delay, count: anItem.count, filterIPs: anItem.filterIPs, httpVerb: anItem.httpVerb, httpBody: anItem.httpBody, httpHeaders: anItem.httpHeaders, contentType: anItem.contentType }; - if ($scope.offDevices === null) - $scope.offDevices = []; - $scope.offDevices.push(newitem); - $scope.newOffItem = {}; - }; - $scope.removeItemOff = function (anItem) { - for(var i = $scope.offDevices.length - 1; i >= 0; i--) { - if($scope.offDevices[i] === anItem) { - $scope.offDevices.splice(i, 1); - } - } - $scope.newOffItem = {}; - }; + $scope.addItemOff = function (anItem) { + if (anItem.item === undefined || anItem.item === null || anItem.item === "") + return; + var newitem = { + item: anItem.item, + type: anItem.type, + delay: anItem.delay, + count: anItem.count, + filterIPs: anItem.filterIPs, + httpVerb: anItem.httpVerb, + httpBody: anItem.httpBody, + httpHeaders: anItem.httpHeaders, + contentType: anItem.contentType + }; + if ($scope.offDevices === null) + $scope.offDevices = []; + $scope.offDevices.push(newitem); + $scope.newOffItem = {}; + }; + $scope.removeItemOff = function (anItem) { + for (var i = $scope.offDevices.length - 1; i >= 0; i--) { + if ($scope.offDevices[i] === anItem) { + $scope.offDevices.splice(i, 1); + } + } + $scope.newOffItem = {}; + }; - $scope.addItemColor = function (anItem) { - if (anItem.item === undefined || anItem.item === null || anItem.item === "") - return; - var newitem = { item: anItem.item, type: anItem.type, delay: anItem.delay, count: anItem.count, filterIPs: anItem.filterIPs, httpVerb: anItem.httpVerb, httpBody: anItem.httpBody, httpHeaders: anItem.httpHeaders, contentType: anItem.contentType }; - if ($scope.colorDevices === null) - $scope.colorDevices = []; - $scope.colorDevices.push(newitem); - $scope.newColorItem = {}; - }; - $scope.removeItemColor = function (anItem) { - for(var i = $scope.colorDevices.length - 1; i >= 0; i--) { - if($scope.colorDevices[i] === anItem) { - $scope.colorDevices.splice(i, 1); - } - } - $scope.newColorItem = {}; - }; + $scope.addItemColor = function (anItem) { + if (anItem.item === undefined || anItem.item === null || anItem.item === "") + return; + var newitem = { + item: anItem.item, + type: anItem.type, + delay: anItem.delay, + count: anItem.count, + filterIPs: anItem.filterIPs, + httpVerb: anItem.httpVerb, + httpBody: anItem.httpBody, + httpHeaders: anItem.httpHeaders, + contentType: anItem.contentType + }; + if ($scope.colorDevices === null) + $scope.colorDevices = []; + $scope.colorDevices.push(newitem); + $scope.newColorItem = {}; + }; + $scope.removeItemColor = function (anItem) { + for (var i = $scope.colorDevices.length - 1; i >= 0; i--) { + if ($scope.colorDevices[i] === anItem) { + $scope.colorDevices.splice(i, 1); + } + } + $scope.newColorItem = {}; + }; $scope.toggleButtons = function () { $scope.buttonsVisible = !$scope.buttonsVisible; - if($scope.buttonsVisible) + if ($scope.buttonsVisible) $scope.imgButtonsUrl = "glyphicon glyphicon-minus"; else $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; @@ -4609,15 +4846,15 @@ app.controller('EditController', function ($scope, $location, bridgeService) { $scope.changeEditmode = function () { // copy local changes over to other edit mode if ($scope.showUrls) { - $scope.onDevices = ($scope.onUrl == undefined || $scope.onUrl == null || $scope.onUrl == "") ? null : bridgeService.getCallObjects($scope.onUrl.replace(/\r?\n|\r/g,"")); - $scope.dimDevices = ($scope.dimUrl == undefined || $scope.dimUrl == null || $scope.dimUrl == "") ? null : bridgeService.getCallObjects($scope.dimUrl.replace(/\r?\n|\r/g,"")); - $scope.offDevices = ($scope.offUrl == undefined || $scope.offUrl == null || $scope.offUrl == "") ? null : bridgeService.getCallObjects($scope.offUrl.replace(/\r?\n|\r/g,"")); - $scope.colorDevices = ($scope.colorUrl == undefined || $scope.colorUrl == null || $scope.colorUrl == "") ? null : bridgeService.getCallObjects($scope.colorUrl.replace(/\r?\n|\r/g,"")); + $scope.onDevices = ($scope.onUrl == undefined || $scope.onUrl == null || $scope.onUrl == "") ? null : bridgeService.getCallObjects($scope.onUrl.replace(/\r?\n|\r/g, "")); + $scope.dimDevices = ($scope.dimUrl == undefined || $scope.dimUrl == null || $scope.dimUrl == "") ? null : bridgeService.getCallObjects($scope.dimUrl.replace(/\r?\n|\r/g, "")); + $scope.offDevices = ($scope.offUrl == undefined || $scope.offUrl == null || $scope.offUrl == "") ? null : bridgeService.getCallObjects($scope.offUrl.replace(/\r?\n|\r/g, "")); + $scope.colorDevices = ($scope.colorUrl == undefined || $scope.colorUrl == null || $scope.colorUrl == "") ? null : bridgeService.getCallObjects($scope.colorUrl.replace(/\r?\n|\r/g, "")); } else { $scope.onUrl = ($scope.onDevices !== null) ? angular.toJson(bridgeService.updateCallObjectsType($scope.onDevices)).split("},").join("},\n") : null; $scope.dimUrl = ($scope.dimDevices !== null) ? angular.toJson(bridgeService.updateCallObjectsType($scope.dimDevices)).split("},").join("},\n") : null; $scope.offUrl = ($scope.offDevices !== null) ? angular.toJson(bridgeService.updateCallObjectsType($scope.offDevices)).split("},").join("},\n") : null; - $scope.colorUrl = ($scope.colorDevices !== null) ? angular.toJson(bridgeService.updateCallObjectsType($scope.colorDevices)).split("},").join("},\n") : null; + $scope.colorUrl = ($scope.colorDevices !== null) ? angular.toJson(bridgeService.updateCallObjectsType($scope.colorDevices)).split("},").join("},\n") : null; } $scope.showUrls = !$scope.showUrls; }; @@ -4625,12 +4862,12 @@ app.controller('EditController', function ($scope, $location, bridgeService) { }); app.filter('configuredVeraDevices', function (bridgeService) { - return function(input) { + return function (input) { var out = []; - if(input === undefined || input === null || input.length === undefined) + if (input === undefined || input === null || input.length === undefined) return out; for (var i = 0; i < input.length; i++) { - if(bridgeService.deviceContainsType(input[i], "veraDevice")){ + if (bridgeService.deviceContainsType(input[i], "veraDevice")) { out.push(input[i]); } } @@ -4639,12 +4876,12 @@ app.filter('configuredVeraDevices', function (bridgeService) { }); app.filter('configuredVeraScenes', function (bridgeService) { - return function(input) { + return function (input) { var out = []; - if(input === undefined || input === null || input.length === undefined) + if (input === undefined || input === null || input.length === undefined) return out; for (var i = 0; i < input.length; i++) { - if(bridgeService.deviceContainsType(input[i], "veraScene")){ + if (bridgeService.deviceContainsType(input[i], "veraScene")) { out.push(input[i]); } } @@ -4653,12 +4890,12 @@ app.filter('configuredVeraScenes', function (bridgeService) { }); app.filter('configuredFibaroDevices', function (bridgeService) { - return function(input) { + return function (input) { var out = []; - if(input === undefined || input === null || input.length === undefined) + if (input === undefined || input === null || input.length === undefined) return out; for (var i = 0; i < input.length; i++) { - if(bridgeService.deviceContainsType(input[i], "fibaroDevice")){ + if (bridgeService.deviceContainsType(input[i], "fibaroDevice")) { out.push(input[i]); } } @@ -4667,12 +4904,12 @@ app.filter('configuredFibaroDevices', function (bridgeService) { }); app.filter('configuredFibaroScenes', function (bridgeService) { - return function(input) { + return function (input) { var out = []; - if(input === undefined || input === null || input.length === undefined) + if (input === undefined || input === null || input.length === undefined) return out; for (var i = 0; i < input.length; i++) { - if(bridgeService.deviceContainsType(input[i], "fibaroScene")){ + if (bridgeService.deviceContainsType(input[i], "fibaroScene")) { out.push(input[i]); } } @@ -4681,12 +4918,12 @@ app.filter('configuredFibaroScenes', function (bridgeService) { }); app.filter('configuredNestItems', function (bridgeService) { - return function(input) { + return function (input) { var out = []; - if(input === undefined || input === null || input.length === undefined) + if (input === undefined || input === null || input.length === undefined) return out; for (var i = 0; i < input.length; i++) { - if(bridgeService.deviceContainsType(input[i], "nest")){ + if (bridgeService.deviceContainsType(input[i], "nest")) { out.push(input[i]); } } @@ -4695,12 +4932,12 @@ app.filter('configuredNestItems', function (bridgeService) { }); app.filter('configuredHueItems', function (bridgeService) { - return function(input) { + return function (input) { var out = []; - if(input === undefined || input === null || input.length === undefined) + if (input === undefined || input === null || input.length === undefined) return out; for (var i = 0; i < input.length; i++) { - if(bridgeService.deviceContainsType(input[i], "hue")){ + if (bridgeService.deviceContainsType(input[i], "hue")) { out.push(input[i]); } } @@ -4709,12 +4946,12 @@ app.filter('configuredHueItems', function (bridgeService) { }); app.filter('configuredHalItems', function (bridgeService) { - return function(input) { + return function (input) { var out = []; - if(input === undefined || input === null || input.length === undefined) + if (input === undefined || input === null || input.length === undefined) return out; for (var i = 0; i < input.length; i++) { - if(bridgeService.deviceContainsType(input[i], "hal")){ + if (bridgeService.deviceContainsType(input[i], "hal")) { out.push(input[i]); } } @@ -4723,12 +4960,12 @@ app.filter('configuredHalItems', function (bridgeService) { }); app.filter('configuredHarmonyActivities', function (bridgeService) { - return function(input) { + return function (input) { var out = []; - if(input === undefined || input === null || input.length === undefined) + if (input === undefined || input === null || input.length === undefined) return out; for (var i = 0; i < input.length; i++) { - if(bridgeService.deviceContainsType(input[i], "harmonyActivity")){ + if (bridgeService.deviceContainsType(input[i], "harmonyActivity")) { out.push(input[i]); } } @@ -4739,7 +4976,7 @@ app.filter('configuredHarmonyActivities', function (bridgeService) { app.filter('configuredHarmonyButtons', function (bridgeService) { return function (input) { var out = []; - if(input === undefined || input === null || input.length === undefined) + if (input === undefined || input === null || input.length === undefined) return out; for (var i = 0; i < input.length; i++) { if (bridgeService.deviceContainsType(input[i], "harmonyButton")) { @@ -4751,9 +4988,9 @@ app.filter('configuredHarmonyButtons', function (bridgeService) { }); app.filter('configuredMqttMsgs', function (bridgeService) { - return function(input) { + return function (input) { var out = []; - if(input === undefined || input === null || input.length === undefined) + if (input === undefined || input === null || input.length === undefined) return out; for (var i = 0; i < input.length; i++) { if (bridgeService.deviceContainsType(input[i], "mqtt")) { @@ -4765,9 +5002,9 @@ app.filter('configuredMqttMsgs', function (bridgeService) { }); app.filter('configuredHassItems', function (bridgeService) { - return function(input) { + return function (input) { var out = []; - if(input === undefined || input === null || input.length === undefined) + if (input === undefined || input === null || input.length === undefined) return out; for (var i = 0; i < input.length; i++) { if (bridgeService.deviceContainsType(input[i], "hass")) { @@ -4779,9 +5016,9 @@ app.filter('configuredHassItems', function (bridgeService) { }); app.filter('configuredDomoticzItems', function (bridgeService) { - return function(input) { + return function (input) { var out = []; - if(input === undefined || input === null || input.length === undefined) + if (input === undefined || input === null || input.length === undefined) return out; for (var i = 0; i < input.length; i++) { if (bridgeService.deviceContainsType(input[i], "domoticz")) { @@ -4793,9 +5030,9 @@ app.filter('configuredDomoticzItems', function (bridgeService) { }); app.filter('configuredLifxItems', function (bridgeService) { - return function(input) { + return function (input) { var out = []; - if(input === undefined || input === null || input.length === undefined) + if (input === undefined || input === null || input.length === undefined) return out; for (var i = 0; i < input.length; i++) { if (bridgeService.deviceContainsType(input[i], "lifx")) { @@ -4807,12 +5044,12 @@ app.filter('configuredLifxItems', function (bridgeService) { }); app.filter('configuredSomfyDevices', function (bridgeService) { - return function(input) { + return function (input) { var out = []; - if(input === undefined || input === null || input.length === undefined) + if (input === undefined || input === null || input.length === undefined) return out; for (var i = 0; i < input.length; i++) { - if(bridgeService.deviceContainsType(input[i], "somfyDevice")){ + if (bridgeService.deviceContainsType(input[i], "somfyDevice")) { out.push(input[i]); } } @@ -4821,12 +5058,12 @@ app.filter('configuredSomfyDevices', function (bridgeService) { }); app.filter('configuredHomeWizardDevices', function (bridgeService) { - return function(input) { + return function (input) { var out = []; - if(input === undefined || input === null || input.length === undefined) + if (input === undefined || input === null || input.length === undefined) return out; for (var i = 0; i < input.length; i++) { - if(bridgeService.deviceContainsType(input[i], "homewizardDevice")){ + if (bridgeService.deviceContainsType(input[i], "homewizardDevice")) { out.push(input[i]); } } @@ -4835,9 +5072,9 @@ app.filter('configuredHomeWizardDevices', function (bridgeService) { }); app.filter('configuredOpenHABItems', function (bridgeService) { - return function(input) { + return function (input) { var out = []; - if(input === undefined || input === null || input.length === undefined) + if (input === undefined || input === null || input.length === undefined) return out; for (var i = 0; i < input.length; i++) { if (bridgeService.deviceContainsType(input[i], "openhab")) { @@ -4849,9 +5086,9 @@ app.filter('configuredOpenHABItems', function (bridgeService) { }); app.filter('configuredFhemItems', function (bridgeService) { - return function(input) { + return function (input) { var out = []; - if(input === undefined || input === null || input.length === undefined) + if (input === undefined || input === null || input.length === undefined) return out; for (var i = 0; i < input.length; i++) { if (bridgeService.deviceContainsType(input[i], "fhem")) { @@ -4863,9 +5100,9 @@ app.filter('configuredFhemItems', function (bridgeService) { }); app.filter('configuredBroadlinkItems', function (bridgeService) { - return function(input) { + return function (input) { var out = []; - if(input === undefined || input === null || input.length === undefined) + if (input === undefined || input === null || input.length === undefined) return out; for (var i = 0; i < input.length; i++) { if (bridgeService.deviceContainsType(input[i], "broadlink")) { @@ -4877,9 +5114,9 @@ app.filter('configuredBroadlinkItems', function (bridgeService) { }); app.filter('filterDevicesByRequester', function () { - return function(input,search,mustContain,deviceType) { + return function (input, search, mustContain, deviceType) { var out = []; - if(input === undefined || input === null || input.length === undefined) + if (input === undefined || input === null || input.length === undefined) return out; var pattern = new RegExp(search); var patternType = new RegExp(deviceType); @@ -4891,15 +5128,15 @@ app.filter('filterDevicesByRequester', function () { if (!search || search.trim().length === 0) { // if search is empty and mustContain == true push only unfiltered devices if (mustContain) { if (!input[i].requesterAddress || input[i].requesterAddress.length === 0) { - pushRequester = true; + pushRequester = true; } } else { pushRequester = true; } } else { - if(pattern.test(input[i].requesterAddress) || !mustContain && (!input[i].requesterAddress || input[i].requesterAddress.length === 0)){ - pushRequester = true; - } + if (pattern.test(input[i].requesterAddress) || !mustContain && (!input[i].requesterAddress || input[i].requesterAddress.length === 0)) { + pushRequester = true; + } } // Check filter by deviceType @@ -4918,26 +5155,26 @@ app.filter('filterDevicesByRequester', function () { }); app.controller('LoginController', function ($scope, $location, Auth, bridgeService) { - $scope.failed = false; - $scope.isSecure = bridgeService.isSecure(); - $scope.loggedIn = Auth.isLoggedIn(); - $scope.login = function(username, password) { - Auth.login(username, password) - .then(function() { - $location.path("/"); - }, function() { - $scope.failed = true; - }); + $scope.failed = false; + $scope.isSecure = bridgeService.isSecure(); + $scope.loggedIn = Auth.isLoggedIn(); + $scope.login = function (username, password) { + Auth.login(username, password) + .then(function () { + $location.path("/"); + }, function () { + $scope.failed = true; + }); }; - $scope.logout = function() { - Auth.logout(); - $scope.isSecure = bridgeService.isSecure(); - $scope.loggedIn = Auth.isLoggedIn(); - if($scope.isSecure) - $location.path("/login"); - else - $location.path("/"); + $scope.logout = function () { + Auth.logout(); + $scope.isSecure = bridgeService.isSecure(); + $scope.loggedIn = Auth.isLoggedIn(); + if ($scope.isSecure) + $location.path("/login"); + else + $location.path("/"); }; }); @@ -4945,60 +5182,61 @@ app.controller('VersionController', function ($scope, bridgeService) { $scope.bridge = bridgeService.state; }); -app.directive('permission', ['Auth', function(Auth) { - return { - restrict: 'A', - scope: { - permission: '=' - }, - - link: function (scope, elem, attrs) { - scope.$watch(Auth.isLoggedIn, function() { - if (Auth.userHasPermission(scope.permission)) { - elem.show(); - } else { - elem.hide(); - } - }); - } - }; - }]); +app.directive('permission', ['Auth', function (Auth) { + return { + restrict: 'A', + scope: { + permission: '=' + }, -app.factory('Auth', function($resource, $rootScope, $sessionStorage, $http, $base64, bridgeService){ - - var auth = {}; - - /** - * Saves the current user in the root scope - * Call this in the app run() method - */ - auth.init = function(){ - if (auth.isLoggedIn()){ - $rootScope.user = auth.currentUser(); - } - }; - - auth.login = function(username, password){ + link: function (scope, elem, attrs) { + scope.$watch(Auth.isLoggedIn, function () { + if (Auth.userHasPermission(scope.permission)) { + elem.show(); + } else { + elem.hide(); + } + }); + } + }; +}]); + +app.factory('Auth', function ($resource, $rootScope, $sessionStorage, $http, $base64, bridgeService) { + + var auth = {}; + + /** + * Saves the current user in the root scope + * Call this in the app run() method + */ + auth.init = function () { + if (auth.isLoggedIn()) { + $rootScope.user = auth.currentUser(); + } + }; + + auth.login = function (username, password) { var newUserInfo = {}; newUserInfo = { - username: username, - password: password - }; + username: username, + password: password + }; var theEncodedPayload = $base64.encode(angular.toJson(newUserInfo)); - return $http.post(bridgeService.state.systemsbase + "/login", theEncodedPayload ).then( + return $http.post(bridgeService.state.systemsbase + "/login", theEncodedPayload).then( function (response) { var theResult = response.data; - $sessionStorage.user = theResult.user; - $rootScope.user = $sessionStorage.user; - bridgeService.state.loggedInUser = $sessionStorage.user.username; - bridgeService.getHABridgeVersion(); - }, function(error) { - bridgeService.displayWarn("Login Error: ", error); - }); - }; + $sessionStorage.user = theResult.user; + $rootScope.user = $sessionStorage.user; + bridgeService.state.loggedInUser = $sessionStorage.user.username; + bridgeService.getHABridgeVersion(); + }, + function (error) { + bridgeService.displayWarn("Login Error: ", error); + }); + }; - auth.logout = function() { + auth.logout = function () { delete $sessionStorage.user; delete $rootScope.user; delete bridgeService.state.loggedInUser; @@ -5014,60 +5252,60 @@ app.factory('Auth', function($resource, $rootScope, $sessionStorage, $http, $bas }; - auth.checkPermissionForView = function(view) { - if (!view.requiresAuthentication) { - return true; - } - - return userHasPermissionForView(view); - }; - - - var userHasPermissionForView = function(view){ - if(!auth.isLoggedIn()){ - return false; - } - - if(!view.permissions || !view.permissions.length){ - return true; - } - - return auth.userHasPermission(view.permissions); - }; - - - auth.userHasPermission = function(permissions){ - if(!bridgeService.isSecure()) - return true; - if(!auth.isLoggedIn()){ - return false; - } - - var found = false; - angular.forEach(permissions, function(permission, index){ - if ($sessionStorage.user.user_permissions.indexOf(permission) >= 0){ - found = true; - return; - } - }); - - return found; - }; - - - auth.currentUser = function(){ - if(!bridgeService.isSecure()) - return "nouser"; - return $sessionStorage.user; - }; - - - auth.isLoggedIn = function(){ - if(!bridgeService.isSecure()) - return true; - return $sessionStorage.user != null; - }; - - - return auth; + auth.checkPermissionForView = function (view) { + if (!view.requiresAuthentication) { + return true; + } + + return userHasPermissionForView(view); + }; + + + var userHasPermissionForView = function (view) { + if (!auth.isLoggedIn()) { + return false; + } + + if (!view.permissions || !view.permissions.length) { + return true; + } + + return auth.userHasPermission(view.permissions); + }; + + + auth.userHasPermission = function (permissions) { + if (!bridgeService.isSecure()) + return true; + if (!auth.isLoggedIn()) { + return false; + } + + var found = false; + angular.forEach(permissions, function (permission, index) { + if ($sessionStorage.user.user_permissions.indexOf(permission) >= 0) { + found = true; + return; + } + }); + + return found; + }; + + + auth.currentUser = function () { + if (!bridgeService.isSecure()) + return "nouser"; + return $sessionStorage.user; + }; + + + auth.isLoggedIn = function () { + if (!bridgeService.isSecure()) + return true; + return $sessionStorage.user != null; + }; + + + return auth; }); \ No newline at end of file diff --git a/src/main/resources/public/views/moziotdevice.html b/src/main/resources/public/views/moziotdevice.html index 7d35cf4..99acf20 100644 --- a/src/main/resources/public/views/moziotdevice.html +++ b/src/main/resources/public/views/moziotdevice.html @@ -19,7 +19,8 @@
  • HomeWizard Devices
  • OpenHAB Devices
  • FHEM Devices
  • - +
  • Broadlink Devices
  • Add/Edit
  • @@ -31,17 +32,18 @@

    For any Mozilla IOT 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 + 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 + 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 + done in the edit tab, click the 'Add Bridge Device' to finish that selection setup. The 'Already Configured Mozilla IOT Devices' list below will show what is already setup for your Mozilla IOT.

    Also, use this select menu for which type of dim control you would - like to be generated: @@ -53,94 +55,91 @@ 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 Mozilla IOT.

    - - - - - - - - - - - - - - - - - - - - -
    Row - NameTypeMozilla IOTColor ActionsBuild Actions
    {{$index+1}} - {{moziotdevice.name}}{{moziotdevice.type}}{{moziotdevice.name}} - - - -
    -
    - + + + + + + + + + + + + + + + + + + + + +
    Row + NameTypeMozilla IOTColor ActionsBuild Actions
    {{$index+1}} + {{moziotdevice.deviceDetail.name}}{{moziotdevice.deviceDetail.type}}{{moziotdevice.gatewayName}} + + + + +
    +
    +

    - Already Configured OpenHAB Devices + Already Configured OpenHAB Devices

    - - - - - - - - - - - - - - - - - - - - - -
    RowNameCategoryMozilla IOTMap IdActions
    {{$index+1}}{{device.name}}{{device.deviceType}}{{device.targetDevice}}{{device.mapId}} -

    - - -

    -
    -
    + + + + + + + + + + + + + + + + + + + + + +
    RowNameCategoryMozilla IOTMap IdActions
    {{$index+1}}{{device.name}}{{device.deviceType}}{{device.targetDevice}}{{device.mapId}} +

    + + +

    +
    +
    + \ No newline at end of file diff --git a/src/main/resources/public/views/openhabdevice.html b/src/main/resources/public/views/openhabdevice.html index d7660d2..4f3081a 100644 --- a/src/main/resources/public/views/openhabdevice.html +++ b/src/main/resources/public/views/openhabdevice.html @@ -151,7 +151,7 @@ value="{{option.value}}">{{option.label}} -