From faa67827c636065def014d4e877c42879f378eda Mon Sep 17 00:00:00 2001 From: Admin Date: Fri, 23 Sep 2016 15:46:39 -0500 Subject: [PATCH] Updated configuration items for hue responses. ADded call thru for hue devices configured for state info. added dim content body. --- pom.xml | 4 +- .../HABridge/api/hue/HueConfig.java | 4 +- .../HABridge/api/hue/HuePublicConfig.java | 4 +- .../HABridge/dao/DeviceDescriptor.java | 11 +++ .../bwssystems/HABridge/hue/HueMulator.java | 72 ++++++++++++++++++- src/main/resources/public/scripts/app.js | 4 ++ .../resources/public/views/editdevice.html | 13 ++++ src/main/resources/public/views/editor.html | 13 ++++ 8 files changed, 117 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index f28f523..29fddc2 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.bwssystems.HABridge ha-bridge - 3.1.0 + 3.1.0a jar HA Bridge @@ -43,7 +43,7 @@ com.github.bwssytems nest-controller - 1.0.8 + 1.0.9 org.slf4j diff --git a/src/main/java/com/bwssystems/HABridge/api/hue/HueConfig.java b/src/main/java/com/bwssystems/HABridge/api/hue/HueConfig.java index 4562a26..2cec13b 100644 --- a/src/main/java/com/bwssystems/HABridge/api/hue/HueConfig.java +++ b/src/main/java/com/bwssystems/HABridge/api/hue/HueConfig.java @@ -40,10 +40,10 @@ public class HueConfig SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); dateFormatGmt.setTimeZone(TimeZone.getTimeZone("UTC")); aConfig.setMac(HueConfig.getMacAddress(ipaddress)); - aConfig.setApiversion("1.10.0"); + aConfig.setApiversion("1.14.0"); aConfig.setPortalservices(false); aConfig.setGateway(ipaddress); - aConfig.setSwversion("01028090"); + aConfig.setSwversion("01033989"); aConfig.setLinkbutton(false); aConfig.setIpaddress(ipaddress); aConfig.setProxyport(0); diff --git a/src/main/java/com/bwssystems/HABridge/api/hue/HuePublicConfig.java b/src/main/java/com/bwssystems/HABridge/api/hue/HuePublicConfig.java index c927446..b731d92 100644 --- a/src/main/java/com/bwssystems/HABridge/api/hue/HuePublicConfig.java +++ b/src/main/java/com/bwssystems/HABridge/api/hue/HuePublicConfig.java @@ -23,8 +23,8 @@ public class HuePublicConfig public static HuePublicConfig createConfig(String name, String ipaddress) { HuePublicConfig aConfig = new HuePublicConfig(); aConfig.setMac(HuePublicConfig.getMacAddress(ipaddress)); - aConfig.setApiversion("1.10.0"); - aConfig.setSwversion("01028090"); + aConfig.setApiversion("1.14.0"); + aConfig.setSwversion("01033989"); aConfig.setName(name); aConfig.setBridgeid(HuePublicConfig.getBridgeIdFromMac(aConfig.getMac(), ipaddress)); aConfig.setModelid("BSB002"); diff --git a/src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java b/src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java index 2090b7c..6ed7b95 100644 --- a/src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java +++ b/src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java @@ -50,6 +50,9 @@ public class DeviceDescriptor{ @SerializedName("contentBodyOff") @Expose private String contentBodyOff; + @SerializedName("contentBodyDim") + @Expose + private String contentBodyDim; private DeviceState deviceState; @@ -165,6 +168,14 @@ public class DeviceDescriptor{ this.contentBodyOff = contentBodyOff; } + public String getContentBodyDim() { + return contentBodyDim; + } + + public void setContentBodyDim(String contentBodyDim) { + this.contentBodyDim = contentBodyDim; + } + public DeviceState getDeviceState() { if(deviceState == null) deviceState = DeviceState.createDeviceState(); diff --git a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java index 416ef68..b99303e 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java +++ b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java @@ -280,7 +280,41 @@ public class HueMulator implements HueErrorStringSet { List deviceList = repository.findAll(); Map deviceResponseMap = new HashMap<>(); for (DeviceDescriptor device : deviceList) { - DeviceResponse deviceResponse = DeviceResponse.createResponse(device); + DeviceResponse deviceResponse = null; + String responseString; + if((device.getMapType() != null && device.getMapType().equalsIgnoreCase("hueDevice"))) { + HueDeviceIdentifier deviceId = new Gson().fromJson(device.getOnUrl(), HueDeviceIdentifier.class); + if(myHueHome.getTheHUERegisteredUser() == null) { + hueUser = HueUtil.registerWithHue(httpClient, deviceId.getIpAddress(), device.getName(), myHueHome.getTheHUERegisteredUser(), this); + if(hueUser == null) { + return errorString; + } + myHueHome.setTheHUERegisteredUser(hueUser); + } + // make call + responseString = doHttpRequest("http://"+deviceId.getIpAddress()+"/api/"+myHueHome.getTheHUERegisteredUser()+"/lights/"+deviceId.getDeviceId(), HttpGet.METHOD_NAME, device.getContentType(), null, null); + if (responseString == null) { + log.warn("Error on calling hue device to get state: " + device.getName()); + deviceResponse = DeviceResponse.createResponse(device); + } + else if(responseString.contains("[{\"error\":") && responseString.contains("unauthorized user")) { + myHueHome.setTheHUERegisteredUser(null); + hueUser = HueUtil.registerWithHue(httpClient, deviceId.getIpAddress(), device.getName(), myHueHome.getTheHUERegisteredUser(), this); + if(hueUser == null) { + return errorString; + } + myHueHome.setTheHUERegisteredUser(hueUser); + deviceResponse = DeviceResponse.createResponse(device); + } + else { + deviceResponse = new Gson().fromJson(responseString, DeviceResponse.class); + if(deviceResponse == null) + deviceResponse = DeviceResponse.createResponse(device); + } + + } + else + deviceResponse = DeviceResponse.createResponse(device); deviceResponseMap.put(device.getId(), deviceResponse); } return deviceResponseMap; @@ -448,7 +482,41 @@ public class HueMulator implements HueErrorStringSet { } else { log.debug("found device named: " + device.getName()); } - DeviceResponse lightResponse = DeviceResponse.createResponse(device); + DeviceResponse lightResponse = null; + String responseString; + if((device.getMapType() != null && device.getMapType().equalsIgnoreCase("hueDevice"))) { + HueDeviceIdentifier deviceId = new Gson().fromJson(device.getOnUrl(), HueDeviceIdentifier.class); + if(myHueHome.getTheHUERegisteredUser() == null) { + hueUser = HueUtil.registerWithHue(httpClient, deviceId.getIpAddress(), device.getName(), myHueHome.getTheHUERegisteredUser(), this); + if(hueUser == null) { + return errorString; + } + myHueHome.setTheHUERegisteredUser(hueUser); + } + // make call + responseString = doHttpRequest("http://"+deviceId.getIpAddress()+"/api/"+myHueHome.getTheHUERegisteredUser()+"/lights/"+deviceId.getDeviceId(), HttpGet.METHOD_NAME, device.getContentType(), null, null); + if (responseString == null) { + log.warn("Error on calling hue device to get state: " + device.getName()); + lightResponse = DeviceResponse.createResponse(device); + } + else if(responseString.contains("[{\"error\":") && responseString.contains("unauthorized user")) { + myHueHome.setTheHUERegisteredUser(null); + hueUser = HueUtil.registerWithHue(httpClient, deviceId.getIpAddress(), device.getName(), myHueHome.getTheHUERegisteredUser(), this); + if(hueUser == null) { + return errorString; + } + myHueHome.setTheHUERegisteredUser(hueUser); + lightResponse = DeviceResponse.createResponse(device); + } + else { + lightResponse = new Gson().fromJson(responseString, DeviceResponse.class); + if(lightResponse == null) + lightResponse = DeviceResponse.createResponse(device); + } + + } + else + lightResponse = DeviceResponse.createResponse(device); return lightResponse; }, new JsonTransformer()); diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index 6fe822b..b6c2cf1 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -131,6 +131,7 @@ app.service('bridgeService', function ($http, $window, ngToast) { self.state.device.httpVerb = null; self.state.device.contentType = null; self.state.device.contentBody = null; + self.state.device.contentBodyDim = null; self.state.device.contentBodyOff = null; self.state.olddevicename = ""; }; @@ -976,6 +977,7 @@ app.controller('VeraController', function ($scope, $location, $http, bridgeServi httpVerb: $scope.device.httpVerb, contentType: $scope.device.contentType, contentBody: $scope.device.contentBody, + contentBodyDim: $scope.device.contentBodyDim, contentBodyOff: $scope.device.contentBodyOff }; } @@ -1309,6 +1311,7 @@ app.controller('HueController', function ($scope, $location, $http, bridgeServic httpVerb: $scope.device.httpVerb, contentType: $scope.device.contentType, contentBody: $scope.device.contentBody, + contentBodyDim: $scope.device.contentBodyDim, contentBodyOff: $scope.device.contentBodyOff }; } @@ -1627,6 +1630,7 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic httpVerb: $scope.device.httpVerb, contentType: $scope.device.contentType, contentBody: $scope.device.contentBody, + contentBodyDim: $scope.device.contentBodyDim, contentBodyOff: $scope.device.contentBodyOff }; } diff --git a/src/main/resources/public/views/editdevice.html b/src/main/resources/public/views/editdevice.html index 0d42a26..d11e6ca 100644 --- a/src/main/resources/public/views/editdevice.html +++ b/src/main/resources/public/views/editdevice.html @@ -218,6 +218,19 @@
+
+
+ + +
+ +
+
+
+
+
+
+ + +
+ +
+
+
+