diff --git a/src/main/java/com/bwssystems/HABridge/BridgeSettingsDescriptor.java b/src/main/java/com/bwssystems/HABridge/BridgeSettingsDescriptor.java index 442513b..2ceeb5b 100644 --- a/src/main/java/com/bwssystems/HABridge/BridgeSettingsDescriptor.java +++ b/src/main/java/com/bwssystems/HABridge/BridgeSettingsDescriptor.java @@ -40,13 +40,16 @@ public class BridgeSettingsDescriptor { private String hubversion; private IpList domoticzaddress; private boolean domoticzconfigured; - + private IpList somfyaddress; + private boolean somfyconfigured; + public BridgeSettingsDescriptor() { super(); this.upnpstrict = true; this.traceupnp = false; this.nestconfigured = false; this.veraconfigured = false; + this.somfyconfigured = false; this.harmonyconfigured = false; this.hueconfigured = false; this.halconfigured = false; @@ -92,9 +95,15 @@ public class BridgeSettingsDescriptor { public IpList getVeraAddress() { return veraaddress; } + public IpList getSomfyAddress() { + return somfyaddress; + } public void setVeraAddress(IpList veraAddress) { this.veraaddress = veraAddress; } + public void setSomfyAddress(IpList somfyAddress) { + this.somfyaddress = somfyAddress; + } public IpList getHarmonyAddress() { return harmonyaddress; } @@ -128,9 +137,15 @@ public class BridgeSettingsDescriptor { public boolean isVeraconfigured() { return veraconfigured; } + public boolean isSomfyconfigured() { + return somfyconfigured; + } public void setVeraconfigured(boolean veraconfigured) { this.veraconfigured = veraconfigured; } + public void setSomfyconfigured(boolean somfyconfigured) { + this.somfyconfigured = somfyconfigured; + } public boolean isHarmonyconfigured() { return harmonyconfigured; } @@ -314,7 +329,7 @@ public class BridgeSettingsDescriptor { } public Boolean isValidHass() { if(this.getHassaddress() == null || this.getHassaddress().getDevices().size() <= 0) - return false; + return false; List devicesList = this.getHassaddress().getDevices(); if(devicesList.get(0).getIp().contains(Configuration.DEFAULT_ADDRESS)) return false; @@ -322,10 +337,18 @@ public class BridgeSettingsDescriptor { } public Boolean isValidDomoticz() { if(this.getDomoticzaddress() == null || this.getDomoticzaddress().getDevices().size() <= 0) - return false; + return false; List devicesList = this.getDomoticzaddress().getDevices(); if(devicesList.get(0).getIp().contains(Configuration.DEFAULT_ADDRESS)) return false; return true; } + public Boolean isValidSomfy() { + if(this.getSomfyAddress() == null || this.getSomfyAddress().getDevices().size() <= 0) + return false; + List devicesList = this.getSomfyAddress().getDevices(); + if(devicesList.get(0).getIp().contains(Configuration.DEFAULT_ADDRESS)) + return false; + return true; + } } diff --git a/src/main/java/com/bwssystems/HABridge/DeviceMapTypes.java b/src/main/java/com/bwssystems/HABridge/DeviceMapTypes.java index 870fa2c..fda444e 100644 --- a/src/main/java/com/bwssystems/HABridge/DeviceMapTypes.java +++ b/src/main/java/com/bwssystems/HABridge/DeviceMapTypes.java @@ -1,82 +1,84 @@ -package com.bwssystems.HABridge; - -import java.util.ArrayList; - -public class DeviceMapTypes { - - public final static String[] CUSTOM_DEVICE = { "custom", "Custom"}; - public final static String[] VERA_DEVICE = { "veraDevice", "Vera Device"}; - public final static String[] VERA_SCENE = { "veraScene", "Vera Scene"}; - public final static String[] HARMONY_ACTIVITY = { "harmonyActivity", "Harmony Activity"}; - public final static String[] HARMONY_BUTTON = { "harmonyButton", "Harmony Button"}; - public final static String[] NEST_HOMEAWAY = { "nestHomeAway", "Nest Home Status"}; - public final static String[] NEST_THERMO_SET = { "nestThermoSet", "Nest Thermostat"}; - public final static String[] HUE_DEVICE = { "hueDevice", "Hue Device"}; - public final static String[] HAL_DEVICE = { "halDevice", "HAL Device"}; - public final static String[] HAL_BUTTON = { "halButton", "HAL Button"}; - public final static String[] HAL_HOME = { "halHome", "HAL Home Status"}; - public final static String[] HAL_THERMO_SET = { "halThermoSet", "HAL Thermostat"}; - public final static String[] MQTT_MESSAGE = { "mqttMessage", "MQTT Message"}; - public final static String[] EXEC_DEVICE_COMPAT = { "exec", "Execute Script/Program"}; - public final static String[] CMD_DEVICE = { "cmdDevice", "Execute Command/Script/Program"}; - public final static String[] HASS_DEVICE = { "hassDevice", "HomeAssistant Device"}; - public final static String[] TCP_DEVICE = { "tcpDevice", "TCP Device"}; - public final static String[] TCP_DEVICE_COMPAT = { "TCP", "TCP Device"}; - public final static String[] UDP_DEVICE = { "udpDevice", "UDP Device"}; - public final static String[] UDP_DEVICE_COMPAT = { "UDP", "UDP Device"}; - public final static String[] HTTP_DEVICE = { "httpDevice", "HTTP Device"}; - public final static String[] DOMOTICZ_DEVICE = { "domoticzDevice", "Domoticz Device"}; - - public final static int typeIndex = 0; - public final static int displayIndex = 1; - - ArrayList deviceMapTypes; - - public DeviceMapTypes() { - super(); - deviceMapTypes = new ArrayList(); - deviceMapTypes.add(CMD_DEVICE); - deviceMapTypes.add(DOMOTICZ_DEVICE); - deviceMapTypes.add(HAL_DEVICE); - deviceMapTypes.add(HAL_HOME); - deviceMapTypes.add(HAL_THERMO_SET); - deviceMapTypes.add(HAL_BUTTON); - deviceMapTypes.add(HARMONY_ACTIVITY); - deviceMapTypes.add(HARMONY_BUTTON); - deviceMapTypes.add(HASS_DEVICE); - deviceMapTypes.add(HTTP_DEVICE); - deviceMapTypes.add(HUE_DEVICE); - deviceMapTypes.add(MQTT_MESSAGE); - deviceMapTypes.add(NEST_HOMEAWAY); - deviceMapTypes.add(NEST_THERMO_SET); - deviceMapTypes.add(TCP_DEVICE); - deviceMapTypes.add(UDP_DEVICE); - deviceMapTypes.add(VERA_DEVICE); - deviceMapTypes.add(VERA_SCENE); - } - public static int getTypeIndex() { - return typeIndex; - } - public static int getDisplayIndex() { - return displayIndex; - } - public ArrayList getDeviceMapTypes() { - return deviceMapTypes; - } - - public Boolean validateType(String type) { - if(type == null || type.trim().isEmpty()) - return false; - for(String[] mapType : deviceMapTypes) { - if(type.trim().contentEquals(mapType[typeIndex])) - return true; - } - if(type.trim().contentEquals(EXEC_DEVICE_COMPAT[typeIndex])) - return true; - if(type.trim().contentEquals(TCP_DEVICE_COMPAT[typeIndex])) - return true; - if(type.trim().contentEquals(UDP_DEVICE_COMPAT[typeIndex])) - return true; - return false; - } +package com.bwssystems.HABridge; + +import java.util.ArrayList; + +public class DeviceMapTypes { + + public final static String[] CUSTOM_DEVICE = { "custom", "Custom"}; + public final static String[] VERA_DEVICE = { "veraDevice", "Vera Device"}; + public final static String[] VERA_SCENE = { "veraScene", "Vera Scene"}; + public final static String[] HARMONY_ACTIVITY = { "harmonyActivity", "Harmony Activity"}; + public final static String[] HARMONY_BUTTON = { "harmonyButton", "Harmony Button"}; + public final static String[] NEST_HOMEAWAY = { "nestHomeAway", "Nest Home Status"}; + public final static String[] NEST_THERMO_SET = { "nestThermoSet", "Nest Thermostat"}; + public final static String[] HUE_DEVICE = { "hueDevice", "Hue Device"}; + public final static String[] HAL_DEVICE = { "halDevice", "HAL Device"}; + public final static String[] HAL_BUTTON = { "halButton", "HAL Button"}; + public final static String[] HAL_HOME = { "halHome", "HAL Home Status"}; + public final static String[] HAL_THERMO_SET = { "halThermoSet", "HAL Thermostat"}; + public final static String[] MQTT_MESSAGE = { "mqttMessage", "MQTT Message"}; + public final static String[] EXEC_DEVICE_COMPAT = { "exec", "Execute Script/Program"}; + public final static String[] CMD_DEVICE = { "cmdDevice", "Execute Command/Script/Program"}; + public final static String[] HASS_DEVICE = { "hassDevice", "HomeAssistant Device"}; + public final static String[] TCP_DEVICE = { "tcpDevice", "TCP Device"}; + public final static String[] TCP_DEVICE_COMPAT = { "TCP", "TCP Device"}; + public final static String[] UDP_DEVICE = { "udpDevice", "UDP Device"}; + public final static String[] UDP_DEVICE_COMPAT = { "UDP", "UDP Device"}; + public final static String[] HTTP_DEVICE = { "httpDevice", "HTTP Device"}; + public final static String[] DOMOTICZ_DEVICE = { "domoticzDevice", "Domoticz Device"}; + public final static String[] SOMFY_DEVICE = { "somfyDevice", "Somfy Device"}; + + public final static int typeIndex = 0; + public final static int displayIndex = 1; + + ArrayList deviceMapTypes; + + public DeviceMapTypes() { + super(); + deviceMapTypes = new ArrayList(); + deviceMapTypes.add(CMD_DEVICE); + deviceMapTypes.add(DOMOTICZ_DEVICE); + deviceMapTypes.add(HAL_DEVICE); + deviceMapTypes.add(HAL_HOME); + deviceMapTypes.add(HAL_THERMO_SET); + deviceMapTypes.add(HAL_BUTTON); + deviceMapTypes.add(HARMONY_ACTIVITY); + deviceMapTypes.add(HARMONY_BUTTON); + deviceMapTypes.add(HASS_DEVICE); + deviceMapTypes.add(HTTP_DEVICE); + deviceMapTypes.add(HUE_DEVICE); + deviceMapTypes.add(MQTT_MESSAGE); + deviceMapTypes.add(NEST_HOMEAWAY); + deviceMapTypes.add(NEST_THERMO_SET); + deviceMapTypes.add(TCP_DEVICE); + deviceMapTypes.add(UDP_DEVICE); + deviceMapTypes.add(VERA_DEVICE); + deviceMapTypes.add(VERA_SCENE); + deviceMapTypes.add(SOMFY_DEVICE); + } + public static int getTypeIndex() { + return typeIndex; + } + public static int getDisplayIndex() { + return displayIndex; + } + public ArrayList getDeviceMapTypes() { + return deviceMapTypes; + } + + public Boolean validateType(String type) { + if(type == null || type.trim().isEmpty()) + return false; + for(String[] mapType : deviceMapTypes) { + if(type.trim().contentEquals(mapType[typeIndex])) + return true; + } + if(type.trim().contentEquals(EXEC_DEVICE_COMPAT[typeIndex])) + return true; + if(type.trim().contentEquals(TCP_DEVICE_COMPAT[typeIndex])) + return true; + if(type.trim().contentEquals(UDP_DEVICE_COMPAT[typeIndex])) + return true; + return false; + } } \ No newline at end of file diff --git a/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java b/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java index e4b861b..43f7835 100644 --- a/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java +++ b/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java @@ -219,7 +219,13 @@ public class DeviceResource { return homeManager.findResource(DeviceMapTypes.DOMOTICZ_DEVICE[DeviceMapTypes.typeIndex]).getItems(DeviceMapTypes.DOMOTICZ_DEVICE[DeviceMapTypes.typeIndex]); }, new JsonTransformer()); - get (API_CONTEXT + "/map/types", "application/json", (request, response) -> { + get (API_CONTEXT + "/somfy/devices", "application/json", (request, response) -> { + log.debug("Get somfy devices"); + response.status(HttpStatus.SC_OK); + return homeManager.findResource(DeviceMapTypes.SOMFY_DEVICE[DeviceMapTypes.typeIndex]).getItems(DeviceMapTypes.SOMFY_DEVICE[DeviceMapTypes.typeIndex]); + }, new JsonTransformer()); + + get (API_CONTEXT + "/map/types", "application/json", (request, response) -> { log.debug("Get map types"); return new DeviceMapTypes().getDeviceMapTypes(); }, new JsonTransformer()); diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index bc77ffd..757ad9a 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -20,7 +20,7 @@ app.config (function ($locationProvider, $routeProvider) { controller: 'VeraController' }).when ('/verascenes', { templateUrl: 'views/verascene.html', - controller: 'VeraController' + controller: 'VeraController' }).when ('/harmonydevices', { templateUrl: 'views/harmonydevice.html', controller: 'HarmonyController' @@ -41,11 +41,14 @@ app.config (function ($locationProvider, $routeProvider) { controller: 'MQTTController' }).when ('/hassdevices', { templateUrl: 'views/hassdevice.html', - controller: 'HassController' + controller: 'HassController' }).when ('/domoticzdevices', { templateUrl: 'views/domoticzdevice.html', - controller: 'DomoticzController' - }).otherwise ({ + controller: 'DomoticzController' + }).when('/somfydevices', { + templateUrl: 'views/somfydevice.html', + controller: 'SomfyController' + }).otherwise ({ templateUrl: 'views/configuration.html', controller: 'ViewingController' }) @@ -71,7 +74,7 @@ String.prototype.replaceAll = function (search, replace) app.service ('bridgeService', function ($http, $window, ngToast) { var self = this; - this.state = {base: window.location.origin + "/api/devices", bridgelocation: window.location.origin, systemsbase: window.location.origin + "/system", huebase: window.location.origin + "/api", configs: [], backups: [], devices: [], device: {}, mapandid: [], type: "", settings: [], myToastMsg: [], logMsgs: [], loggerInfo: [], mapTypes: [], olddevicename: "", logShowAll: false, isInControl: false, showVera: false, showHarmony: false, showNest: false, showHue: false, showHal: false, showMqtt: false, showHass: false, showDomoticz: false, habridgeversion: ""}; + this.state = {base: window.location.origin + "/api/devices", bridgelocation: window.location.origin, systemsbase: window.location.origin + "/system", huebase: window.location.origin + "/api", configs: [], backups: [], devices: [], device: {}, mapandid: [], type: "", settings: [], myToastMsg: [], logMsgs: [], loggerInfo: [], mapTypes: [], olddevicename: "", logShowAll: false, isInControl: false, showVera: false, showHarmony: false, showNest: false, showHue: false, showHal: false, showMqtt: false, showHass: false, showDomoticz: false, showSomfy: false, habridgeversion: ""}; this.displayWarn = function(errorTitle, error) { var toastContent = errorTitle; @@ -164,20 +167,20 @@ app.service ('bridgeService', function ($http, $window, ngToast) { 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) return true; - - + + return false; } this.compareHarmonyNumber = function(r1, r2) { @@ -257,6 +260,11 @@ app.service ('bridgeService', function ($http, $window, ngToast) { return; } + this.updateShowSomfy = function () { + this.state.showSomfy = self.state.settings.somfyconfigured; + return; + } + this.loadBridgeSettings = function () { return $http.get(this.state.systemsbase + "/settings").then( function (response) { @@ -269,6 +277,7 @@ app.service ('bridgeService', function ($http, $window, ngToast) { self.updateShowMqtt(); self.updateShowHass(); self.updateShowDomoticz(); + self.updateShowSomfy(); }, function (error) { self.displayWarn("Load Bridge Settings Error: ", error); @@ -450,6 +459,20 @@ app.service ('bridgeService', function ($http, $window, ngToast) { ); }; + 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) { + self.displayWarn("Get Somfy Devices Error: ", error); + } + ); + }; + + this.formatCallItem = function (currentItem) { if(!currentItem.startsWith("{\"item") && !currentItem.startsWith("[{\"item")) { if (currentItem.startsWith("[") || currentItem.startsWith("{")) @@ -461,7 +484,7 @@ app.service ('bridgeService', function ($http, $window, ngToast) { return currentItem; }; - + this.getCallObjects = function (deviceString) { if (deviceString === undefined || deviceString === "") return null; @@ -481,7 +504,7 @@ app.service ('bridgeService', function ($http, $window, ngToast) { } return newDevices } - + this.updateCallObjectsType = function (theDevices) { var i, s, type, len = theDevices.length for (i=0; 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.bridgeReinit = function () { bridgeService.reinit(); }; @@ -1331,7 +1373,7 @@ app.controller('VeraController', function ($scope, $location, $http, bridgeServi className: 'ngdialog-theme-default' }); }; - + $scope.editDevice = function (device) { bridgeService.editDevice(device); $location.path('/editdevice'); @@ -1356,7 +1398,7 @@ app.controller('HarmonyController', function ($scope, $location, $http, bridgeSe $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, true, harmonyactivity.activity.id, harmonyactivity.activity.label, harmonyactivity.hub, "activity", "harmonyActivity", null, null); $scope.device = bridgeService.state.device; @@ -1392,7 +1434,7 @@ app.controller('HarmonyController', function ($scope, $location, $http, bridgeSe className: 'ngdialog-theme-default' }); }; - + $scope.editDevice = function (device) { bridgeService.editDevice(device); $location.path('/editdevice'); @@ -1493,7 +1535,7 @@ app.controller('NestController', function ($scope, $location, $http, bridgeServi className: 'ngdialog-theme-default' }); }; - + $scope.editDevice = function (device) { bridgeService.editDevice(device); $location.path('/editdevice'); @@ -1610,7 +1652,7 @@ app.controller('HueController', function ($scope, $location, $http, bridgeServic className: 'ngdialog-theme-default' }); }; - + $scope.editDevice = function (device) { bridgeService.editDevice(device); $location.path('/editdevice'); @@ -1680,7 +1722,7 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic + nameCmd + haldevice.haldevicename.replaceAll(" ", "%20") + postCmd; - offpayload = "http://" + haldevice.haladdress + offpayload = "http://" + haldevice.haladdress + preOffCmd + nameCmd + haldevice.haldevicename.replaceAll(" ", "%20") @@ -1713,17 +1755,17 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic }; $scope.buildHALHeatUrls = function (haldevice) { - onpayload = "http://" + haldevice.haladdress + onpayload = "http://" + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!HVACMode=Heat?Token=" + $scope.bridge.settings.haltoken; - dimpayload = "http://" + haldevice.haladdress + dimpayload = "http://" + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!HVACMode=Heat!HeatSpValue=${intensity.percent}?Token=" + $scope.bridge.settings.haltoken; - offpayload = "http://" + haldevice.haladdress + offpayload = "http://" + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!HVACMode=Off?Token=" @@ -1735,17 +1777,17 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic }; $scope.buildHALCoolUrls = function (haldevice) { - onpayload = "http://" + haldevice.haladdress + onpayload = "http://" + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!HVACMode=Cool?Token=" + $scope.bridge.settings.haltoken; - dimpayload = "http://" + haldevice.haladdress + dimpayload = "http://" + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!HVACMode=Cool!CoolSpValue=${intensity.percent}?Token=" + $scope.bridge.settings.haltoken; - offpayload = "http://" + haldevice.haladdress + offpayload = "http://" + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!HVACMode=Off?Token=" @@ -1757,12 +1799,12 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic }; $scope.buildHALAutoUrls = function (haldevice) { - onpayload = "http://" + haldevice.haladdress + onpayload = "http://" + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!HVACMode=Auto?Token=" + $scope.bridge.settings.haltoken; - offpayload = "http://" + haldevice.haladdress + offpayload = "http://" + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!HVACMode=Off?Token=" @@ -1773,16 +1815,16 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic }; $scope.buildHALOffUrls = function (haldevice) { - onpayload = "http://" + haldevice.haladdress + onpayload = "http://" + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!HVACMode=Auto?Token=" + $scope.bridge.settings.haltoken; - offpayload = "http://" + haldevice.haladdress + offpayload = "http://" + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!HVACMode=Off?Token=" - $scope.device.offUrl = "http://" + haldevice.haladdress + $scope.device.offUrl = "http://" + haldevice.haladdress bridgeService.buildUrls(onpayload, null, offpayload, false, haldevice.haldevicename + "-" + haldevice.halname + "-TurnOff", haldevice.haldevicename + " Thermostat", haldevice.halname, "thermo", "halThermoSet", null, null); $scope.device = bridgeService.state.device; bridgeService.editNewDevice($scope.device); @@ -1790,12 +1832,12 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic }; $scope.buildHALFanUrls = function (haldevice) { - onpayload = "http://" + haldevice.haladdress - + "/HVACService!HVACCmd=Set!HVACName=" - + haldevice.haldevicename.replaceAll(" ", "%20") + onpayload = "http://" + haldevice.haladdress + + "/HVACService!HVACCmd=Set!HVACName=" + + haldevice.haldevicename.replaceAll(" ", "%20") + "!FanMode=On?Token=" + $scope.bridge.settings.haltoken; - offpayload = "http://" + haldevice.haladdress + offpayload = "http://" + haldevice.haladdress + "/HVACService!HVACCmd=Set!HVACName=" + haldevice.haldevicename.replaceAll(" ", "%20") + "!FanMode=Auto?Token=" @@ -1897,7 +1939,7 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic className: 'ngdialog-theme-default' }); }; - + $scope.editDevice = function (device) { bridgeService.editDevice(device); $location.path('/editdevice'); @@ -1942,7 +1984,7 @@ app.controller('MQTTController', function ($scope, $location, $http, bridgeServi className: 'ngdialog-theme-default' }); }; - + $scope.editDevice = function (device) { bridgeService.editDevice(device); $location.path('/editdevice'); @@ -2137,7 +2179,7 @@ app.controller('HassController', function ($scope, $location, $http, bridgeServi className: 'ngdialog-theme-default' }); }; - + $scope.editDevice = function (device) { bridgeService.editDevice(device); $location.path('/editdevice'); @@ -2192,7 +2234,7 @@ app.controller('DomoticzController', function ($scope, $location, $http, bridgeS + preCmd + domoticzdevice.idx + postOnCmd; - offpayload = "http://" + domoticzdevice.domoticzaddress + offpayload = "http://" + domoticzdevice.domoticzaddress + preCmd + domoticzdevice.idx + postOffCmd; @@ -2288,7 +2330,131 @@ app.controller('DomoticzController', function ($scope, $location, $http, bridgeS className: 'ngdialog-theme-default' }); }; - + + $scope.editDevice = function (device) { + bridgeService.editDevice(device); + $location.path('/editdevice'); + }; +}); + +app.controller('SomfyController', function ($scope, $location, $http, bridgeService, ngDialog) { + $scope.bridge = bridgeService.state; + $scope.device = bridgeService.state.device; + $scope.device_dim_control = ""; + $scope.bulk = { devices: [] }; + $scope.selectAll = false; + $scope.somfy = {base: "http://", port: "3480", id: ""}; + bridgeService.viewSomfyDevices(); + $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; + $scope.buttonsVisible = false; + $scope.comparatorUniqueId = bridgeService.compareUniqueId; + + $scope.clearDevice = function () { + bridgeService.clearDevice(); + $scope.device = bridgeService.state.device; + }; + + $scope.buildDeviceUrls = function (somfydevice, dim_control) { + //TODO - support partial window opening + dimpayload = ""; + 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, true, somfydevice.id, somfydevice.name, somfydevice.somfyname, "switch", "somfyDevice", null, null); + $scope.device = bridgeService.state.device; + bridgeService.editNewDevice($scope.device); + $location.path('/editdevice'); + + }; + + + $scope.bulkAddDevices = function(dim_control) { + var devicesList = []; + 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); + 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 + }; + } + } + } + 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: [] }; + $scope.selectAll = false; + }; + + $scope.toggleSelection = function toggleSelection(deviceId) { + var idx = $scope.bulk.devices.indexOf(deviceId); + + // is currently selected + if (idx > -1) { + $scope.bulk.devices.splice(idx, 1); + if($scope.bulk.devices.length === 0 && $scope.selectAll) + $scope.selectAll = false; + } + + // is newly selected + else { + $scope.bulk.devices.push(deviceId); + $scope.selectAll = true; + } + }; + + $scope.toggleSelectAll = function toggleSelectAll() { + if($scope.selectAll) { + $scope.selectAll = false; + $scope.bulk = { devices: [] }; + } + else { + $scope.selectAll = true; + for(var x = 0; x < bridgeService.state.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); + } + } + }; + + $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'); @@ -2310,11 +2476,11 @@ app.controller('EditController', function ($scope, $location, $http, bridgeServi if($scope.bridge.device.offUrl !== undefined) $scope.offDevices = bridgeService.getCallObjects($scope.bridge.device.offUrl); } - + $scope.newOnItem = {}; $scope.newDimItem = {}; $scope.newOffItem = {}; - $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; @@ -2380,7 +2546,7 @@ app.controller('EditController', function ($scope, $location, $http, bridgeServi if($scope.onDevices[i].item === anItem.item && $scope.onDevices[i].type === anItem.type) { $scope.onDevices.splice(i, 1); } - } + } }; $scope.addItemDim = function (anItem) { @@ -2397,7 +2563,7 @@ app.controller('EditController', function ($scope, $location, $http, bridgeServi if($scope.dimDevices[i].item === anItem.item && $scope.dimDevices[i].type === anItem.type) { $scope.dimDevices.splice(i, 1); } - } + } }; $scope.addItemOff = function (anItem) { @@ -2414,7 +2580,7 @@ app.controller('EditController', function ($scope, $location, $http, bridgeServi if($scope.offDevices[i].item === anItem.item && $scope.offDevices[i].type === anItem.type) { $scope.offDevices.splice(i, 1); } - } + } }; $scope.toggleButtons = function () { $scope.buttonsVisible = !$scope.buttonsVisible; @@ -2566,6 +2732,36 @@ app.filter('configuredDomoticzItems', function (bridgeService) { } }); + +app.filter('availableSomfyDeviceId', function(bridgeService) { + return function(input) { + var out = []; + if(input == null) + return out; + for (var i = 0; i < input.length; i++) { + if(!bridgeService.findDeviceByMapId(input[i].id, input[i].somfyname, "somfyDevice")){ + out.push(input[i]); + } + } + return out; + } +}); + +app.filter('unavailableSomfyDeviceId', function(bridgeService) { + return function(input) { + var out = []; + if(input == null) + return out; + for (var i = 0; i < input.length; i++) { + if(bridgeService.findDeviceByMapId(input[i].id, input[i].somfyname, "somfyDevice")){ + out.push(input[i]); + } + } + return out; + } +}); + + app.controller('VersionController', function ($scope, bridgeService) { $scope.bridge = bridgeService.state; }); \ No newline at end of file