From 14e940134c7a8a2e712d8997e470910c59a3aebc Mon Sep 17 00:00:00 2001 From: bsamuels Date: Fri, 19 Jan 2018 14:46:45 -0600 Subject: [PATCH] Fixed openhab build screen and openhab invalid responses. Completed Broadlink impl Testing --- .../plugins/broadlink/BroadlinkHome.java | 18 +- .../plugins/broadlink/TestBLDevice.java | 26 +- .../plugins/broadlink/TestMP1Device.java | 29 +++ .../plugins/broadlink/TestRM2Device.java | 27 ++ .../plugins/broadlink/TestSP1Device.java | 30 +++ .../plugins/broadlink/TestSP2Device.java | 30 +++ .../HABridge/plugins/http/HTTPHandler.java | 5 +- .../HABridge/plugins/openhab/OpenHABHome.java | 8 +- .../plugins/openhab/OpenHABInstance.java | 2 + src/main/resources/public/scripts/app.js | 235 ++++++++++++++++- .../public/views/broadlinkdevice.html | 237 ++++++++++++++++++ .../resources/public/views/configuration.html | 1 + .../public/views/domoticzdevice.html | 1 + .../resources/public/views/editdevice.html | 1 + .../resources/public/views/fhemdevice.html | 3 +- .../resources/public/views/fibarodevice.html | 1 + .../resources/public/views/fibaroscene.html | 1 + .../resources/public/views/haldevice.html | 1 + .../public/views/harmonyactivity.html | 1 + .../resources/public/views/harmonydevice.html | 1 + .../resources/public/views/hassdevice.html | 1 + .../public/views/homewizarddevice.html | 1 + .../resources/public/views/huedevice.html | 1 + .../resources/public/views/lifxdevice.html | 1 + src/main/resources/public/views/logs.html | 1 + .../resources/public/views/mqttpublish.html | 1 + .../resources/public/views/nestactions.html | 1 + .../resources/public/views/openhabdevice.html | 70 +++++- .../resources/public/views/somfydevice.html | 1 + src/main/resources/public/views/system.html | 1 + .../resources/public/views/veradevice.html | 1 + .../resources/public/views/verascene.html | 1 + 32 files changed, 692 insertions(+), 47 deletions(-) create mode 100644 src/main/java/com/bwssystems/HABridge/plugins/broadlink/TestMP1Device.java create mode 100644 src/main/java/com/bwssystems/HABridge/plugins/broadlink/TestRM2Device.java create mode 100644 src/main/java/com/bwssystems/HABridge/plugins/broadlink/TestSP1Device.java create mode 100644 src/main/java/com/bwssystems/HABridge/plugins/broadlink/TestSP2Device.java create mode 100644 src/main/resources/public/views/broadlinkdevice.html diff --git a/src/main/java/com/bwssystems/HABridge/plugins/broadlink/BroadlinkHome.java b/src/main/java/com/bwssystems/HABridge/plugins/broadlink/BroadlinkHome.java index fb464db..11f225d 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/broadlink/BroadlinkHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/broadlink/BroadlinkHome.java @@ -41,7 +41,6 @@ public class BroadlinkHome implements Home { private static final String _rm2 = "RM2"; private Map broadlinkMap; private Boolean validBroadlink; - private Gson aGsonHandler; private boolean closed; private Boolean isDevMode; @@ -55,7 +54,6 @@ public class BroadlinkHome implements Home { @Override public Home createHome(BridgeSettings bridgeSettings) { broadlinkMap = null; - aGsonHandler = null; BLDevice[] clients; isDevMode = Boolean.parseBoolean(System.getProperty("dev.mode", "false")); @@ -127,10 +125,7 @@ public class BroadlinkHome implements Home { } else { BroadlinkEntry broadlinkCommand = null; - if(anItem.getItem().isJsonObject()) - broadlinkCommand = aGsonHandler.fromJson(anItem.getItem(), BroadlinkEntry.class); - else - broadlinkCommand = aGsonHandler.fromJson(anItem.getItem().getAsString(), BroadlinkEntry.class); + broadlinkCommand = new Gson().fromJson(anItem.getItem().getAsString(), BroadlinkEntry.class); BLDevice theDevice = broadlinkMap.get(broadlinkCommand.getId()); if (theDevice == null) { log.warn("Should not get here, no BroadlinkDevices available"); @@ -149,6 +144,8 @@ public class BroadlinkHome implements Home { else changeState = false; try { + if(!isDevMode) + theDevice.auth(); ((MP1Device) theDevice).setState(Integer.parseInt(broadlinkCommand.getData()), changeState); } catch (NumberFormatException e1) { log.error("Call to " + _mp1 + " device failed with number format exception.", e1); @@ -178,6 +175,8 @@ public class BroadlinkHome implements Home { else changeState = false; try { + if(!isDevMode) + theDevice.auth(); ((SP2Device) theDevice).setState(changeState); } catch (Exception e1) { log.error("Call to " + _sp2 + " device failed with exception.", e1); @@ -192,6 +191,8 @@ public class BroadlinkHome implements Home { else changeState = false; try { + if(!isDevMode) + theDevice.auth(); ((SP1Device) theDevice).setPower(changeState); } catch (Exception e) { log.error("Call to " + _sp1 + " device failed with exception.", e); @@ -210,8 +211,9 @@ public class BroadlinkHome implements Home { case BLDevice.DEV_RM_2_PRO_PLUS_2_BL: case BLDevice.DEV_RM_MINI_SHATE: if(broadlinkCommand.getData() != null && !broadlinkCommand.getData().trim().isEmpty()) { + theStringData = broadlinkCommand.getData().trim(); if(targetBri != null || targetBriInc != null) { - theStringData = BrightnessDecode.calculateReplaceIntensityValue(broadlinkCommand.getData().trim(), intensity, targetBri, targetBriInc, true); + theStringData = BrightnessDecode.calculateReplaceIntensityValue(theStringData, intensity, targetBri, targetBriInc, true); } if(colorData != null) { theStringData = ColorDecode.replaceColorData(theStringData, colorData, BrightnessDecode.calculateIntensity(intensity, targetBri, targetBriInc), true); @@ -221,6 +223,8 @@ public class BroadlinkHome implements Home { byte[] theData = DatatypeConverter.parseHexBinary(theStringData); SendDataCmdPayload thePayload = new SendDataCmdPayload(theData); try { + if(!isDevMode) + theDevice.auth(); ((RM2Device) theDevice).sendCmdPkt(Configuration.BROADLINK_DISCONVER_TIMEOUT, thePayload); } catch (IOException e) { log.error("Call to " + _rm2 + " device failed with exception.", e); diff --git a/src/main/java/com/bwssystems/HABridge/plugins/broadlink/TestBLDevice.java b/src/main/java/com/bwssystems/HABridge/plugins/broadlink/TestBLDevice.java index 00b2ea7..adbf47d 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/broadlink/TestBLDevice.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/broadlink/TestBLDevice.java @@ -15,17 +15,9 @@ import com.github.mob41.blapi.pkt.CmdPayload; public class TestBLDevice extends BLDevice { private static final Logger log = LoggerFactory.getLogger(TestBLDevice.class); - short adeviceType; - String adeviceDesc; - String ahost; - Mac amac; protected TestBLDevice(short deviceType, String deviceDesc, String host, Mac mac) throws IOException { - super(deviceType, host, host, mac); - adeviceType = deviceType; - adeviceDesc = deviceDesc; - ahost = host; - + super(deviceType, deviceDesc, host, mac); } public void setState(boolean aState) { @@ -46,30 +38,30 @@ public class TestBLDevice extends BLDevice { } public static BLDevice[] discoverDevices(InetAddress theAddress, int aport, int timeout) { - TestBLDevice mp1Device = null; - TestBLDevice sp1Device = null; - TestBLDevice sp2Device = null; - TestBLDevice rm2Device = null; + TestMP1Device mp1Device = null; + TestSP1Device sp1Device = null; + TestSP2Device sp2Device = null; + TestRM2Device rm2Device = null; try { - mp1Device = new TestBLDevice(BLDevice.DEV_MP1, BLDevice.DESC_MP1, "mp1host", null); + mp1Device = new TestMP1Device("mp1host", null); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { - sp1Device = new TestBLDevice(BLDevice.DEV_SP1, BLDevice.DESC_SP1, "sp1host", null); + sp1Device = new TestSP1Device("sp1host", null); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { - sp2Device = new TestBLDevice(BLDevice.DEV_SP2, BLDevice.DESC_SP2, "sp2host", null); + sp2Device = new TestSP2Device("sp2host", null); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { - rm2Device = new TestBLDevice(BLDevice.DEV_RM_2, BLDevice.DESC_RM_2, "rm2host", null); + rm2Device = new TestRM2Device("rm2host", null); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); diff --git a/src/main/java/com/bwssystems/HABridge/plugins/broadlink/TestMP1Device.java b/src/main/java/com/bwssystems/HABridge/plugins/broadlink/TestMP1Device.java new file mode 100644 index 0000000..f4bcc7d --- /dev/null +++ b/src/main/java/com/bwssystems/HABridge/plugins/broadlink/TestMP1Device.java @@ -0,0 +1,29 @@ +package com.bwssystems.HABridge.plugins.broadlink; + +import java.io.IOException; +import java.net.DatagramPacket; +import javax.xml.bind.DatatypeConverter; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.github.mob41.blapi.MP1Device; +import com.github.mob41.blapi.mac.Mac; +import com.github.mob41.blapi.pkt.CmdPayload; + +public class TestMP1Device extends MP1Device { + private static final Logger log = LoggerFactory.getLogger(TestMP1Device.class); + + protected TestMP1Device(String host, Mac mac) throws IOException { + super(host, mac); + } + + public void setState(int anIndex, boolean aState) { + log.info("setState called with index " + anIndex + " and state " + aState); + } + + public DatagramPacket sendCmdPkt(int timeout, CmdPayload aCmd) { + log.info("sendCmdPkt called with " + DatatypeConverter.printHexBinary(aCmd.getPayload().getData())); + return null; + } +} diff --git a/src/main/java/com/bwssystems/HABridge/plugins/broadlink/TestRM2Device.java b/src/main/java/com/bwssystems/HABridge/plugins/broadlink/TestRM2Device.java new file mode 100644 index 0000000..46d30e0 --- /dev/null +++ b/src/main/java/com/bwssystems/HABridge/plugins/broadlink/TestRM2Device.java @@ -0,0 +1,27 @@ +package com.bwssystems.HABridge.plugins.broadlink; + +import java.io.IOException; +import java.net.DatagramPacket; + +import javax.xml.bind.DatatypeConverter; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.github.mob41.blapi.RM2Device; +import com.github.mob41.blapi.mac.Mac; +import com.github.mob41.blapi.pkt.CmdPayload; +import com.github.mob41.blapi.pkt.cmd.rm2.SendDataCmdPayload; + +public class TestRM2Device extends RM2Device { + private static final Logger log = LoggerFactory.getLogger(TestRM2Device.class); + + protected TestRM2Device(String host, Mac mac) throws IOException { + super(host, mac); + } + + public DatagramPacket sendCmdPkt(int timeout, CmdPayload aCmd) { + log.info("sendCmdPkt called with " + DatatypeConverter.printHexBinary(((SendDataCmdPayload)aCmd).getData())); + return null; + } +} diff --git a/src/main/java/com/bwssystems/HABridge/plugins/broadlink/TestSP1Device.java b/src/main/java/com/bwssystems/HABridge/plugins/broadlink/TestSP1Device.java new file mode 100644 index 0000000..6b441e8 --- /dev/null +++ b/src/main/java/com/bwssystems/HABridge/plugins/broadlink/TestSP1Device.java @@ -0,0 +1,30 @@ +package com.bwssystems.HABridge.plugins.broadlink; + +import java.io.IOException; +import java.net.DatagramPacket; + +import javax.xml.bind.DatatypeConverter; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.github.mob41.blapi.SP1Device; +import com.github.mob41.blapi.mac.Mac; +import com.github.mob41.blapi.pkt.CmdPayload; + +public class TestSP1Device extends SP1Device { + private static final Logger log = LoggerFactory.getLogger(TestSP1Device.class); + + protected TestSP1Device(String host, Mac mac) throws IOException { + super(host, mac); + } + + public void setPower(boolean aState) { + log.info("setPower called with " + aState); + } + + public DatagramPacket sendCmdPkt(int timeout, CmdPayload aCmd) { + log.info("sendCmdPkt called with " + DatatypeConverter.printHexBinary(aCmd.getPayload().getData())); + return null; + } +} diff --git a/src/main/java/com/bwssystems/HABridge/plugins/broadlink/TestSP2Device.java b/src/main/java/com/bwssystems/HABridge/plugins/broadlink/TestSP2Device.java new file mode 100644 index 0000000..daa7831 --- /dev/null +++ b/src/main/java/com/bwssystems/HABridge/plugins/broadlink/TestSP2Device.java @@ -0,0 +1,30 @@ +package com.bwssystems.HABridge.plugins.broadlink; + +import java.io.IOException; +import java.net.DatagramPacket; + +import javax.xml.bind.DatatypeConverter; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.github.mob41.blapi.SP2Device; +import com.github.mob41.blapi.mac.Mac; +import com.github.mob41.blapi.pkt.CmdPayload; + +public class TestSP2Device extends SP2Device { + private static final Logger log = LoggerFactory.getLogger(TestSP2Device.class); + + protected TestSP2Device(String host, Mac mac) throws IOException { + super(host, mac); + } + + public void setState(boolean aState) { + log.info("setState called with " + aState); + } + + public DatagramPacket sendCmdPkt(int timeout, CmdPayload aCmd) { + log.info("sendCmdPkt called with " + DatatypeConverter.printHexBinary(aCmd.getPayload().getData())); + return null; + } +} 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 6484be4..7c9d286 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/http/HTTPHandler.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/http/HTTPHandler.java @@ -99,6 +99,8 @@ public class HTTPHandler { } } if (response != null && response.getStatusLine().getStatusCode() >= 200 && response.getStatusLine().getStatusCode() < 300) { + if(theContent == null) + theContent = ""; log.debug("Successfull response - The http response is <<<" + theContent + ">>>"); retryCount = 2; } else if (response != null) { @@ -107,10 +109,9 @@ public class HTTPHandler { if (response.getStatusLine().getStatusCode() == 504) { log.warn("HTTP response code was 504, retrying..."); log.debug("The 504 error content is <<<" + theContent + ">>>"); + theContent = null; } else retryCount = 2; - - theContent = null; } } catch (ClientProtocolException e) { diff --git a/src/main/java/com/bwssystems/HABridge/plugins/openhab/OpenHABHome.java b/src/main/java/com/bwssystems/HABridge/plugins/openhab/OpenHABHome.java index fbafecb..e7cb4a0 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/openhab/OpenHABHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/openhab/OpenHABHome.java @@ -88,7 +88,13 @@ public class OpenHABHome implements Home { aCommand = TimeDecode.replaceTimeValue(aCommand); } try { - theHandler.callCommand(anUrl, aCommand, httpClient); + boolean success = theHandler.callCommand(anUrl, aCommand, httpClient); + if(!success) { + log.warn("Comand had error to OpenHAB"); + 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 OpenHAB", e); responseString = new Gson().toJson(HueErrorResponse.createResponse("6", "/lights/" + lightId, diff --git a/src/main/java/com/bwssystems/HABridge/plugins/openhab/OpenHABInstance.java b/src/main/java/com/bwssystems/HABridge/plugins/openhab/OpenHABInstance.java index 08831d1..1d6e7a5 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/openhab/OpenHABInstance.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/openhab/OpenHABInstance.java @@ -44,6 +44,8 @@ public class OpenHABInstance { aUrl = aUrl + theOpenHAB.getIp() + ":" + theOpenHAB.getPort() + "/" + aCommand; String theData = httpClient.doHttpRequest(aUrl, HttpPost.METHOD_NAME, "text/plain", commandData, headers); log.debug("call Command return is: <" + theData + ">"); + if(theData.contains("error") || theData.contains("ERROR") || theData.contains("Error")) + return false; return true; } diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index 6f6008e..67575c4 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -87,6 +87,10 @@ app.config (function ($locationProvider, $routeProvider) { templateUrl: 'views/fhemdevice.html', controller: 'FhemController', requiresAuthentication: true + }).when ('/broadlinkdevices', { + templateUrl: 'views/broadlinkdevice.html', + controller: 'BroadlinkController', + requiresAuthentication: true }).when ('/login', { templateUrl: 'views/login.html', controller: 'LoginController' @@ -155,7 +159,7 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n this.state = {base: "./api/devices", bridgelocation: ".", systemsbase: "./system", huebase: "./api", configs: [], backups: [], devices: [], device: {}, mapandid: [], type: "", settings: [], myToastMsg: [], logMsgs: [], loggerInfo: [], mapTypes: [], olddevicename: "", logShowAll: false, isInControl: false, showVera: false, showFibaro: false, showHarmony: false, showNest: false, showHue: false, showHal: false, showMqtt: false, showHass: false, - showHomeWizard: false, showDomoticz: false, showSomfy: false, showLifx: false, showOpenHAB: false, showFHEM: false, habridgeversion: {}, viewDevId: "", queueDevId: "", securityInfo: {}, filterDevicesByIpAddress: null, + showHomeWizard: false, showDomoticz: false, showSomfy: false, showLifx: false, showOpenHAB: false, showFHEM: false, showBroadlink: false, habridgeversion: {}, viewDevId: "", queueDevId: "", securityInfo: {}, filterDevicesByIpAddress: null, filterDevicesOnlyFiltered: false, filterDeviceType: null}; this.displayWarn = function(errorTitle, error) { @@ -576,6 +580,11 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n return; } + this.updateShowBroadlink = function () { + this.state.showBroadlink = self.state.settings.broadlinkconfigured; + return; + } + this.loadBridgeSettings = function () { return $http.get(this.state.systemsbase + "/settings").then( function (response) { @@ -594,6 +603,7 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n self.updateShowLifx(); self.updateShowOpenHAB(); self.updateShowFhem(); + self.updateShowBroadlink(); }, function (error) { if (error.status === 401) @@ -933,6 +943,22 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n ); }; + this.viewBroadlinkDevices = function () { + 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); + } + ); + }; + this.formatCallItem = function (currentItem) { if(!currentItem.startsWith("{\"item") && !currentItem.startsWith("[{\"item")) { if (currentItem.startsWith("[") || currentItem.startsWith("{")) @@ -1352,6 +1378,11 @@ app.service ('bridgeService', function ($rootScope, $http, $base64, $location, n 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') { @@ -3732,7 +3763,7 @@ app.controller('OpenHABController', function ($scope, $location, bridgeService, $scope.device = bridgeService.state.device; }; - $scope.buildDeviceUrls = function (openhabdevice, dim_control, ondeviceaction, oninputdeviceaction, offdeviceaction, offinputdeviceaction, buildonly) { + $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)) { @@ -3742,20 +3773,38 @@ app.controller('OpenHABController', function ($scope, $location, bridgeService, dimpayload = null; onpayload = "{\"url\":\"http://" + openhabdevice.address + preCmd + "\",\"command\":\"ON\"}"; offpayload = "{\"url\":\"http://" + openhabdevice.address + preCmd + "\",\"command\":\"OFF\"}"; + colorpayload = null; } else { - dimpayload = null; - if(ondeviceaction === 'other') - onpayload = "{\"url\":\"http://" + openhabdevice.address + preCmd + "\",\"command\":\"" + oninputdeviceaction + "\"}"; + if(onaction === 'other') + onpayload = "{\"url\":\"http://" + openhabdevice.address + preCmd + "\",\"command\":\"" + ondata + "\"}"; + else if(onaction !== undefined && onaction !== null && onaction !== '') + onpayload = "{\"url\":\"http://" + openhabdevice.address + preCmd + "\",\"command\":\"" + onaction + "\"}"; else - onpayload = "{\"url\":\"http://" + openhabdevice.address + preCmd + "\",\"command\":\"" + ondeviceaction + "\"}"; + onpayload = null; - if(offdeviceaction === 'other') - offpayload = "{\"url\":\"http://" + openhabdevice.address + preCmd + "\",\"command\":\"" + offinputdeviceaction + "\"}"; + if(dimaction === 'other') + dimpayload = "{\"url\":\"http://" + openhabdevice.address + preCmd + "\",\"command\":\"" + dimdata + "\"}"; + else if(dimaction !== undefined && dimaction !== null && dimaction !== '') + dimpayload = "{\"url\":\"http://" + openhabdevice.address + preCmd + "\",\"command\":\"" + dimaction + "\"}"; else - offpayload = "{\"url\":\"http://" + openhabdevice.address + preCmd + "\",\"command\":\"" + offdeviceaction + "\"}"; + dimpayload = null; + + if(offaction === 'other') + offpayload = "{\"url\":\"http://" + openhabdevice.address + preCmd + "\",\"command\":\"" + offdata + "\"}"; + else if(offaction !== undefined && offaction !== null && offaction !== '') + offpayload = "{\"url\":\"http://" + openhabdevice.address + preCmd + "\",\"command\":\"" + offaction + "\"}"; + else + offpayload = null; + + if(coloraction === 'other') + colorpayload = "{\"url\":\"http://" + openhabdevice.address + preCmd + "\",\"command\":\"" + colordata + "\"}"; + else if(coloraction !== undefined && coloraction !== null && coloraction !== '') + colorpayload = "{\"url\":\"http://" + openhabdevice.address + preCmd + "\",\"command\":\"" + coloraction + "\"}"; + else + colorpayload = null; } - bridgeService.buildUrls(onpayload, dimpayload, offpayload, null, 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); @@ -3769,7 +3818,7 @@ app.controller('OpenHABController', function ($scope, $location, bridgeService, 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,true); + $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, @@ -3996,6 +4045,156 @@ app.controller('FhemController', function ($scope, $location, bridgeService, ngD }; }); +app.controller('BroadlinkController', 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.viewBroadlinkDevices(); + $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; + $scope.buttonsVisible = false; + + $scope.clearDevice = function () { + bridgeService.clearDevice(); + $scope.device = bridgeService.state.device; + }; + + $scope.buildDeviceUrls = function (broadlinkdevice, dim_control, ondata, dimdata, offdata, colordata, buildonly) { + var preCmd = "{\"id\":\"" + broadlinkdevice.id + "\",\"name\":\"" + broadlinkdevice.name +"\",\"command\":\""; + if(broadlinkdevice.type === 'SP1' || broadlinkdevice.type === 'SP2') { + dimpayload = null; + colorpayload = null; + onpayload = preCmd + "on\"}"; + offpayload = preCmd + "off\"}"; + } + else if(broadlinkdevice.type === 'MP1') { + 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 + "\"}"; + else + onpayload = null; + 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 + "\"}"; + else + offpayload = null; + 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.type, "broadlinkDevice", null, null); + $scope.device = bridgeService.state.device; + if (!buildonly) { + bridgeService.editNewDevice($scope.device); + $location.path('/editdevice'); + } + }; + + $scope.bulkAddDevices = function(dim_control) { + var devicesList = []; + $scope.clearDevice(); + for(var i = 0; i < $scope.bulk.devices.length; i++) { + for(var x = 0; x < bridgeService.state.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 + }; + $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: [] }; + $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.broadlinkdevices.length; x++) { + if($scope.bulk.devices.indexOf(bridgeService.state.broadlinkdevices[x]) < 0) + $scope.bulk.devices.push(bridgeService.state.broadlinkdevices[x].devicename); + } + } + }; + + $scope.toggleButtons = function () { + $scope.buttonsVisible = !$scope.buttonsVisible; + if($scope.buttonsVisible) + $scope.imgButtonsUrl = "glyphicon glyphicon-minus"; + else + $scope.imgButtonsUrl = "glyphicon glyphicon-plus"; + }; + + $scope.deleteDevice = function (device) { + $scope.bridge.device = device; + ngDialog.open({ + template: 'deleteDialog', + controller: 'DeleteDialogCtrl', + className: 'ngdialog-theme-default' + }); + }; + + $scope.editDevice = function (device) { + bridgeService.editDevice(device); + $location.path('/editdevice'); + }; +}); + app.controller('EditController', function ($scope, $location, bridgeService) { $scope.bridge = bridgeService.state; $scope.device = bridgeService.state.device; @@ -4445,6 +4644,20 @@ app.filter('configuredFhemItems', function (bridgeService) { } }); +app.filter('configuredBroadlinkItems', function (bridgeService) { + return function(input) { + var out = []; + if(input === undefined || input === null || input.length === undefined) + return out; + for (var i = 0; i < input.length; i++) { + if (bridgeService.deviceContainsType(input[i], "broadlink")) { + out.push(input[i]); + } + } + return out; + } +}); + app.filter('filterDevicesByRequester', function () { return function(input,search,mustContain,deviceType) { var out = []; diff --git a/src/main/resources/public/views/broadlinkdevice.html b/src/main/resources/public/views/broadlinkdevice.html new file mode 100644 index 0000000..120db0e --- /dev/null +++ b/src/main/resources/public/views/broadlinkdevice.html @@ -0,0 +1,237 @@ + + +
+
+

Broadlink Device List + ({{bridge.broadlinkdevices.length}})

+
+
+

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

+

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

+

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

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row + IDDescriptionTypeOn ActionsDim ActionsOff ActionsColor ActionsBuild Actions
{{$index+1}} + {{broadlinkdevice.id}}{{broadlinkdevice.name}}{{broadlinkdevice.type}} + On + + Not Available + + Off + + Not Available + + +
{{$index+1}} + {{broadlinkdevice.id}}{{broadlinkdevice.name}}{{broadlinkdevice.type}} + On + + + Not Available + + Off + + + Not Available + + +
{{$index+1}} + {{broadlinkdevice.id}}{{broadlinkdevice.name}}{{broadlinkdevice.type}} + + + + + + + + + +
+
+ +
+
+
+
+

+ Already Configured Broadlink Devices +

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

+ + +

+
+
+
+
+ diff --git a/src/main/resources/public/views/configuration.html b/src/main/resources/public/views/configuration.html index d10eacd..4e19e96 100644 --- a/src/main/resources/public/views/configuration.html +++ b/src/main/resources/public/views/configuration.html @@ -20,6 +20,7 @@
  • HomeWizard Devices
  • OpenHAB Devices
  • FHEM Devices
  • +
  • Broadlink Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/domoticzdevice.html b/src/main/resources/public/views/domoticzdevice.html index 829f0da..c68282e 100644 --- a/src/main/resources/public/views/domoticzdevice.html +++ b/src/main/resources/public/views/domoticzdevice.html @@ -19,6 +19,7 @@
  • HomeWizard Devices
  • OpenHAB Devices
  • FHEM Devices
  • +
  • Broadlink Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/editdevice.html b/src/main/resources/public/views/editdevice.html index 0ed4991..a403228 100644 --- a/src/main/resources/public/views/editdevice.html +++ b/src/main/resources/public/views/editdevice.html @@ -21,6 +21,7 @@
  • OpenHAB Devices
  • FHEM Devices
  • +
  • Broadlink Devices
  • diff --git a/src/main/resources/public/views/fhemdevice.html b/src/main/resources/public/views/fhemdevice.html index 6ccd8de..84fe1ae 100644 --- a/src/main/resources/public/views/fhemdevice.html +++ b/src/main/resources/public/views/fhemdevice.html @@ -19,6 +19,7 @@
  • HomeWizard Devices
  • OpenHAB Devices
  • +
  • Broadlink Devices
  • Add/Edit
  • @@ -111,7 +112,7 @@ + ng-repeat="device in bridge.devices | configuredFhemItems"> {{$index+1}} {{device.name}} {{device.deviceType}} diff --git a/src/main/resources/public/views/fibarodevice.html b/src/main/resources/public/views/fibarodevice.html index 1ed4a29..cbe8cd7 100644 --- a/src/main/resources/public/views/fibarodevice.html +++ b/src/main/resources/public/views/fibarodevice.html @@ -19,6 +19,7 @@
  • HomeWizard Devices
  • OpenHAB Devices
  • FHEM Devices
  • +
  • Broadlink Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/fibaroscene.html b/src/main/resources/public/views/fibaroscene.html index 43d8759..cc41ce7 100644 --- a/src/main/resources/public/views/fibaroscene.html +++ b/src/main/resources/public/views/fibaroscene.html @@ -19,6 +19,7 @@
  • HomeWizard Devices
  • OpenHAB Devices
  • FHEM Devices
  • +
  • Broadlink Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/haldevice.html b/src/main/resources/public/views/haldevice.html index d0121bb..11a0a0d 100644 --- a/src/main/resources/public/views/haldevice.html +++ b/src/main/resources/public/views/haldevice.html @@ -19,6 +19,7 @@
  • HomeWizard Devices
  • OpenHAB Devices
  • FHEM Devices
  • +
  • Broadlink Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/harmonyactivity.html b/src/main/resources/public/views/harmonyactivity.html index 94fd1dc..eff91fc 100644 --- a/src/main/resources/public/views/harmonyactivity.html +++ b/src/main/resources/public/views/harmonyactivity.html @@ -19,6 +19,7 @@
  • HomeWizard Devices
  • OpenHAB Devices
  • FHEM Devices
  • +
  • Broadlink Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/harmonydevice.html b/src/main/resources/public/views/harmonydevice.html index 84131e1..475477d 100644 --- a/src/main/resources/public/views/harmonydevice.html +++ b/src/main/resources/public/views/harmonydevice.html @@ -19,6 +19,7 @@
  • HomeWizard Devices
  • OpenHAB Devices
  • FHEM Devices
  • +
  • Broadlink Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/hassdevice.html b/src/main/resources/public/views/hassdevice.html index 26a39bd..574609b 100644 --- a/src/main/resources/public/views/hassdevice.html +++ b/src/main/resources/public/views/hassdevice.html @@ -19,6 +19,7 @@
  • HomeWizard Devices
  • OpenHAB Devices
  • FHEM Devices
  • +
  • Broadlink Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/homewizarddevice.html b/src/main/resources/public/views/homewizarddevice.html index a683000..0096871 100644 --- a/src/main/resources/public/views/homewizarddevice.html +++ b/src/main/resources/public/views/homewizarddevice.html @@ -19,6 +19,7 @@
  • OpenHAB Devices
  • FHEM Devices
  • +
  • Broadlink Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/huedevice.html b/src/main/resources/public/views/huedevice.html index ed2eed3..7a992ae 100644 --- a/src/main/resources/public/views/huedevice.html +++ b/src/main/resources/public/views/huedevice.html @@ -19,6 +19,7 @@
  • HomeWizard Devices
  • OpenHAB Devices
  • FHEM Devices
  • +
  • Broadlink Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/lifxdevice.html b/src/main/resources/public/views/lifxdevice.html index 1fe1217..b40297b 100644 --- a/src/main/resources/public/views/lifxdevice.html +++ b/src/main/resources/public/views/lifxdevice.html @@ -19,6 +19,7 @@
  • HomeWizard Devices
  • OpenHAB Devices
  • FHEM Devices
  • +
  • Broadlink Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/logs.html b/src/main/resources/public/views/logs.html index 6be2fa9..fd051d4 100644 --- a/src/main/resources/public/views/logs.html +++ b/src/main/resources/public/views/logs.html @@ -19,6 +19,7 @@
  • HomeWizard Devices
  • OpenHAB Devices
  • FHEM Devices
  • +
  • Broadlink Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/mqttpublish.html b/src/main/resources/public/views/mqttpublish.html index 14a9de5..2c630d9 100644 --- a/src/main/resources/public/views/mqttpublish.html +++ b/src/main/resources/public/views/mqttpublish.html @@ -19,6 +19,7 @@
  • HomeWizard Devices
  • OpenHAB Devices
  • FHEM Devices
  • +
  • Broadlink Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/nestactions.html b/src/main/resources/public/views/nestactions.html index ade8efa..92355da 100644 --- a/src/main/resources/public/views/nestactions.html +++ b/src/main/resources/public/views/nestactions.html @@ -19,6 +19,7 @@
  • HomeWizard Devices
  • OpenHAB Devices
  • FHEM Devices
  • +
  • Broadlink Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/openhabdevice.html b/src/main/resources/public/views/openhabdevice.html index dacff76..3b658b4 100644 --- a/src/main/resources/public/views/openhabdevice.html +++ b/src/main/resources/public/views/openhabdevice.html @@ -19,6 +19,7 @@
  • HomeWizard Devices
  • FHEM Devices
  • +
  • Broadlink Devices
  • Add/Edit
  • @@ -64,11 +65,40 @@ Type OpenHAB On Actions + Dim Actions Off Actions + Color Actions Build Actions - + + {{$index+1}} + + {{openhabdevice.item.name}} + {{openhabdevice.item.type}} + {{openhabdevice.name}} + + On + + +
    Use Dim Control selection
    +
    Not Available
    + + + Off + + + Not Available + + + + + + {{$index+1}} {{openhabdevice.item.type}} {{openhabdevice.name}} - - - - + + + + + + + + + ng-click="buildDeviceUrls(openhabdevice, device_dim_control, onaction, ondata, dimaction, dimdata, offaction, offdata, coloraction, colordata, false)">Build Item diff --git a/src/main/resources/public/views/somfydevice.html b/src/main/resources/public/views/somfydevice.html index 06005f6..208555f 100644 --- a/src/main/resources/public/views/somfydevice.html +++ b/src/main/resources/public/views/somfydevice.html @@ -19,6 +19,7 @@
  • HomeWizard Devices
  • OpenHAB Devices
  • FHEM Devices
  • +
  • Broadlink Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/system.html b/src/main/resources/public/views/system.html index 84d4ed3..db665c4 100644 --- a/src/main/resources/public/views/system.html +++ b/src/main/resources/public/views/system.html @@ -19,6 +19,7 @@
  • HomeWizard Devices
  • OpenHAB Devices
  • FHEM Devices
  • +
  • Broadlink Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/veradevice.html b/src/main/resources/public/views/veradevice.html index cde55e8..b07e50c 100644 --- a/src/main/resources/public/views/veradevice.html +++ b/src/main/resources/public/views/veradevice.html @@ -19,6 +19,7 @@
  • HomeWizard Devices
  • OpenHAB Devices
  • FHEM Devices
  • +
  • Broadlink Devices
  • Add/Edit
  • diff --git a/src/main/resources/public/views/verascene.html b/src/main/resources/public/views/verascene.html index 697eff9..35644dc 100644 --- a/src/main/resources/public/views/verascene.html +++ b/src/main/resources/public/views/verascene.html @@ -19,6 +19,7 @@
  • HomeWizard Devices
  • OpenHAB Devices
  • FHEM Devices
  • +
  • Broadlink Devices
  • Add/Edit