From 5a843f7569580c8bdda5fc7a69e1d5fae79431ea Mon Sep 17 00:00:00 2001 From: Admin Date: Thu, 3 Dec 2015 14:36:23 -0600 Subject: [PATCH] Fixed handling when no harmony hub is given. dev.mode was updated as well. This closes #14. --- pom.xml | 2 +- .../devicemanagmeent/DeviceResource.java | 5 +- .../bwssystems/HABridge/hue/HueMulator.java | 5 +- .../HABridge/upnp/UpnpSettingsResource.java | 14 ++++- .../com/bwssystems/harmony/HarmonyHome.java | 13 +++++ .../com/bwssystems/harmony/HarmonyServer.java | 2 +- src/main/resources/public/scripts/app.js | 57 ++++++++++--------- 7 files changed, 64 insertions(+), 34 deletions(-) diff --git a/pom.xml b/pom.xml index b71e46b..3b5804f 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.bwssystems.HABridge ha-bridge - 1.2.0 + 1.2.1 jar HA Bridge diff --git a/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java b/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java index 34ac8b0..0f3fa55 100644 --- a/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java +++ b/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java @@ -41,7 +41,10 @@ public class DeviceResource { public DeviceResource(BridgeSettings theSettings, Version theVersion, HarmonyHome theHarmonyHome) { this.deviceRepository = new DeviceRepository(theSettings.getUpnpDeviceDb()); this.veraInfo = new VeraInfo(theSettings.getVeraAddress(), theSettings.isValidVera()); - this.myHarmonyHome = theHarmonyHome; + if(theSettings.isValidHarmony()) + this.myHarmonyHome = theHarmonyHome; + else + this.myHarmonyHome = null; this.version = theVersion; setupEndpoints(); } diff --git a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java index 8ef49a3..dfb2e2a 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java +++ b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java @@ -68,7 +68,10 @@ public class HueMulator { mapper = new ObjectMapper(); //armzilla: work around Echo incorrect content type and breaking mapping. Map manually mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); repository = aDeviceRepository; - myHarmonyHome = theHarmonyHome; + if(theBridgeSettings.isValidHarmony()) + this.myHarmonyHome = theHarmonyHome; + else + this.myHarmonyHome = null; bridgeSettings = theBridgeSettings; } diff --git a/src/main/java/com/bwssystems/HABridge/upnp/UpnpSettingsResource.java b/src/main/java/com/bwssystems/HABridge/upnp/UpnpSettingsResource.java index 01b0acd..5a4d669 100644 --- a/src/main/java/com/bwssystems/HABridge/upnp/UpnpSettingsResource.java +++ b/src/main/java/com/bwssystems/HABridge/upnp/UpnpSettingsResource.java @@ -40,9 +40,19 @@ public class UpnpSettingsResource { + "24\n" + "hue_logo_3.png\n" + "\n" + "\n" + "\n" + "\n"; - public UpnpSettingsResource(BridgeSettings theSettings) { + public UpnpSettingsResource(BridgeSettings theBridgeSettings) { super(); - this.theSettings = theSettings; + this.theSettings = new BridgeSettings(); + this.theSettings.setDevMode(theBridgeSettings.isDevMode()); + this.theSettings.setHarmonyAddress(theBridgeSettings.getHarmonyAddress()); + this.theSettings.setServerPort(theBridgeSettings.getServerPort()); + this.theSettings.setTraceupnp(theBridgeSettings.isTraceupnp()); + this.theSettings.setUpnpConfigAddress(theBridgeSettings.getUpnpConfigAddress()); + this.theSettings.setUpnpDeviceDb(theBridgeSettings.getUpnpDeviceDb()); + this.theSettings.setUpnpResponseDevices(theBridgeSettings.getUpnpResponseDevices()); + this.theSettings.setUpnpResponsePort(theBridgeSettings.getUpnpResponsePort()); + this.theSettings.setUpnpStrict(theBridgeSettings.isUpnpStrict()); + this.theSettings.setVeraAddress(theBridgeSettings.getVeraAddress()); } public void setupServer() { diff --git a/src/main/java/com/bwssystems/harmony/HarmonyHome.java b/src/main/java/com/bwssystems/harmony/HarmonyHome.java index 8ee8afc..ba23adb 100644 --- a/src/main/java/com/bwssystems/harmony/HarmonyHome.java +++ b/src/main/java/com/bwssystems/harmony/HarmonyHome.java @@ -11,6 +11,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.bwssystems.HABridge.BridgeSettings; +import com.bwssystems.HABridge.IpList; import com.bwssystems.HABridge.NamedIP; import net.whistlingfish.harmony.config.Activity; @@ -23,6 +24,18 @@ public class HarmonyHome { public HarmonyHome(BridgeSettings bridgeSettings) { super(); hubs = new HashMap(); + if(!bridgeSettings.isValidHarmony() && !bridgeSettings.isDevMode()) + return; + if(bridgeSettings.isDevMode()) { + NamedIP devModeIp = new NamedIP(); + devModeIp.setIp("10.10.10.10"); + devModeIp.setName("devMode"); + List theList = new ArrayList(); + theList.add(devModeIp); + IpList thedevList = new IpList(); + thedevList.setDevices(theList); + bridgeSettings.setHarmonyAddress(thedevList); + } Iterator theList = bridgeSettings.getHarmonyAddress().getDevices().iterator(); while(theList.hasNext()) { NamedIP aHub = theList.next(); diff --git a/src/main/java/com/bwssystems/harmony/HarmonyServer.java b/src/main/java/com/bwssystems/harmony/HarmonyServer.java index 43d0dcf..5b46c70 100644 --- a/src/main/java/com/bwssystems/harmony/HarmonyServer.java +++ b/src/main/java/com/bwssystems/harmony/HarmonyServer.java @@ -37,7 +37,7 @@ public class HarmonyServer { } public static HarmonyServer setup(BridgeSettings bridgeSettings, NamedIP theHarmonyAddress) throws Exception { - if(!bridgeSettings.isValidHarmony()) { + if(!bridgeSettings.isValidHarmony() && !bridgeSettings.isDevMode()) { return new HarmonyServer(theHarmonyAddress); } Injector injector = null; diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index 6bddf4a..74dc0e9 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -124,6 +124,31 @@ app.service('bridgeService', function ($http, $window, BridgeSettings) { ); }; + this.aContainsB = function (a, b) { + return a.indexOf(b) >= 0; + } + + this.updateShowVera = function () { + if(this.aContainsB(self.BridgeSettings.veraaddress, "1.1.1.1") || self.BridgeSettings.veraaddress == "" || self.BridgeSettings.veraaddress == null) + this.state.showVera = false; + else + this.state.showVera = true; + return; + } + + this.updateShowHarmony = function () { + if(self.BridgeSettings.harmonyaddress.devices) { + if(this.aContainsB(self.BridgeSettings.harmonyaddress.devices[0].ip, "1.1.1.1") || self.BridgeSettings.harmonyaddress == "" || self.BridgeSettings.harmonyaddress == null) + this.state.showHarmony = false; + else + this.state.showHarmony = true; + } + else + this.state.showHarmony = false; + return; + } + + this.loadBridgeSettings = function () { this.state.error = ""; return $http.get(this.state.upnpbase).then( @@ -137,14 +162,6 @@ app.service('bridgeService', function ($http, $window, BridgeSettings) { self.BridgeSettings.settraceupnp(response.data.traceupnp); self.BridgeSettings.setupnpstrict(response.data.upnpstrict); self.BridgeSettings.setdevmode(response.data.devmode); - if(self.BridgeSettings.veraaddress == "1.1.1.1" || self.BridgeSettings.veraaddress == "") - self.state.showVera = false; - else - self.state.showVera = true; - if(self.BridgeSettings.harmonyaddress == "1.1.1.1" || self.BridgeSettings.harmonyaddress == "") - self.state.showHarmony = false; - else - self.state.showHarmony = true; }, function (error) { if (error.data) { @@ -157,22 +174,6 @@ app.service('bridgeService', function ($http, $window, BridgeSettings) { ); }; - this.updateShowVera = function () { - if(self.BridgeSettings.veraaddress == "1.1.1.1" || self.BridgeSettings.veraaddress == "") - this.state.showVera = false; - else - this.state.showVera = true; - return; - } - - this.updateShowHarmony = function () { - if(self.BridgeSettings.harmonyaddress == "1.1.1.1" || self.BridgeSettings.harmonyaddress == "") - this.state.showHarmony = false; - else - this.state.showHarmony = true; - return; - } - this.viewVeraDevices = function () { this.state.error = ""; if(!this.state.showVera) @@ -632,7 +633,7 @@ app.filter('availableVeraDeviceId', function(bridgeService) { if(input == null) return out; for (var i = 0; i < input.length; i++) { - if(!bridgeService.findDeviceByMapId(input[i].id, "veraDevice")){ + if(!bridgeService.findDeviceByMapId(input[i].id, null, "veraDevice")){ out.push(input[i]); } } @@ -646,7 +647,7 @@ return function(input) { if(input == null) return out; for (var i = 0; i < input.length; i++) { - if(bridgeService.findDeviceByMapId(input[i].id, "veraDevice")){ + if(bridgeService.findDeviceByMapId(input[i].id, null, "veraDevice")){ out.push(input[i]); } } @@ -660,7 +661,7 @@ app.filter('availableVeraSceneId', function(bridgeService) { if(input == null) return out; for (var i = 0; i < input.length; i++) { - if(!bridgeService.findDeviceByMapId(input[i].id, "veraScene")){ + if(!bridgeService.findDeviceByMapId(input[i].id, null, "veraScene")){ out.push(input[i]); } } @@ -674,7 +675,7 @@ return function(input) { if(input == null) return out; for (var i = 0; i < input.length; i++) { - if(bridgeService.findDeviceByMapId(input[i].id, "veraScene")){ + if(bridgeService.findDeviceByMapId(input[i].id, null, "veraScene")){ out.push(input[i]); } }