Updated configuration items for hue responses. ADded call thru for hue

devices configured for state info. added dim content body.
This commit is contained in:
Admin
2016-09-23 15:46:39 -05:00
parent bbce1f4235
commit faa67827c6
8 changed files with 117 additions and 8 deletions

View File

@@ -5,7 +5,7 @@
<groupId>com.bwssystems.HABridge</groupId> <groupId>com.bwssystems.HABridge</groupId>
<artifactId>ha-bridge</artifactId> <artifactId>ha-bridge</artifactId>
<version>3.1.0</version> <version>3.1.0a</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>HA Bridge</name> <name>HA Bridge</name>
@@ -43,7 +43,7 @@
<dependency> <dependency>
<groupId>com.github.bwssytems</groupId> <groupId>com.github.bwssytems</groupId>
<artifactId>nest-controller</artifactId> <artifactId>nest-controller</artifactId>
<version>1.0.8</version> <version>1.0.9</version>
<exclusions> <exclusions>
<exclusion> <exclusion>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>

View File

@@ -40,10 +40,10 @@ public class HueConfig
SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
dateFormatGmt.setTimeZone(TimeZone.getTimeZone("UTC")); dateFormatGmt.setTimeZone(TimeZone.getTimeZone("UTC"));
aConfig.setMac(HueConfig.getMacAddress(ipaddress)); aConfig.setMac(HueConfig.getMacAddress(ipaddress));
aConfig.setApiversion("1.10.0"); aConfig.setApiversion("1.14.0");
aConfig.setPortalservices(false); aConfig.setPortalservices(false);
aConfig.setGateway(ipaddress); aConfig.setGateway(ipaddress);
aConfig.setSwversion("01028090"); aConfig.setSwversion("01033989");
aConfig.setLinkbutton(false); aConfig.setLinkbutton(false);
aConfig.setIpaddress(ipaddress); aConfig.setIpaddress(ipaddress);
aConfig.setProxyport(0); aConfig.setProxyport(0);

View File

@@ -23,8 +23,8 @@ public class HuePublicConfig
public static HuePublicConfig createConfig(String name, String ipaddress) { public static HuePublicConfig createConfig(String name, String ipaddress) {
HuePublicConfig aConfig = new HuePublicConfig(); HuePublicConfig aConfig = new HuePublicConfig();
aConfig.setMac(HuePublicConfig.getMacAddress(ipaddress)); aConfig.setMac(HuePublicConfig.getMacAddress(ipaddress));
aConfig.setApiversion("1.10.0"); aConfig.setApiversion("1.14.0");
aConfig.setSwversion("01028090"); aConfig.setSwversion("01033989");
aConfig.setName(name); aConfig.setName(name);
aConfig.setBridgeid(HuePublicConfig.getBridgeIdFromMac(aConfig.getMac(), ipaddress)); aConfig.setBridgeid(HuePublicConfig.getBridgeIdFromMac(aConfig.getMac(), ipaddress));
aConfig.setModelid("BSB002"); aConfig.setModelid("BSB002");

View File

@@ -50,6 +50,9 @@ public class DeviceDescriptor{
@SerializedName("contentBodyOff") @SerializedName("contentBodyOff")
@Expose @Expose
private String contentBodyOff; private String contentBodyOff;
@SerializedName("contentBodyDim")
@Expose
private String contentBodyDim;
private DeviceState deviceState; private DeviceState deviceState;
@@ -165,6 +168,14 @@ public class DeviceDescriptor{
this.contentBodyOff = contentBodyOff; this.contentBodyOff = contentBodyOff;
} }
public String getContentBodyDim() {
return contentBodyDim;
}
public void setContentBodyDim(String contentBodyDim) {
this.contentBodyDim = contentBodyDim;
}
public DeviceState getDeviceState() { public DeviceState getDeviceState() {
if(deviceState == null) if(deviceState == null)
deviceState = DeviceState.createDeviceState(); deviceState = DeviceState.createDeviceState();

View File

@@ -280,7 +280,41 @@ public class HueMulator implements HueErrorStringSet {
List<DeviceDescriptor> deviceList = repository.findAll(); List<DeviceDescriptor> deviceList = repository.findAll();
Map<String, DeviceResponse> deviceResponseMap = new HashMap<>(); Map<String, DeviceResponse> deviceResponseMap = new HashMap<>();
for (DeviceDescriptor device : deviceList) { 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); deviceResponseMap.put(device.getId(), deviceResponse);
} }
return deviceResponseMap; return deviceResponseMap;
@@ -448,7 +482,41 @@ public class HueMulator implements HueErrorStringSet {
} else { } else {
log.debug("found device named: " + device.getName()); 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; return lightResponse;
}, new JsonTransformer()); }, new JsonTransformer());

View File

@@ -131,6 +131,7 @@ app.service('bridgeService', function ($http, $window, ngToast) {
self.state.device.httpVerb = null; self.state.device.httpVerb = null;
self.state.device.contentType = null; self.state.device.contentType = null;
self.state.device.contentBody = null; self.state.device.contentBody = null;
self.state.device.contentBodyDim = null;
self.state.device.contentBodyOff = null; self.state.device.contentBodyOff = null;
self.state.olddevicename = ""; self.state.olddevicename = "";
}; };
@@ -976,6 +977,7 @@ app.controller('VeraController', function ($scope, $location, $http, bridgeServi
httpVerb: $scope.device.httpVerb, httpVerb: $scope.device.httpVerb,
contentType: $scope.device.contentType, contentType: $scope.device.contentType,
contentBody: $scope.device.contentBody, contentBody: $scope.device.contentBody,
contentBodyDim: $scope.device.contentBodyDim,
contentBodyOff: $scope.device.contentBodyOff contentBodyOff: $scope.device.contentBodyOff
}; };
} }
@@ -1309,6 +1311,7 @@ app.controller('HueController', function ($scope, $location, $http, bridgeServic
httpVerb: $scope.device.httpVerb, httpVerb: $scope.device.httpVerb,
contentType: $scope.device.contentType, contentType: $scope.device.contentType,
contentBody: $scope.device.contentBody, contentBody: $scope.device.contentBody,
contentBodyDim: $scope.device.contentBodyDim,
contentBodyOff: $scope.device.contentBodyOff contentBodyOff: $scope.device.contentBodyOff
}; };
} }
@@ -1627,6 +1630,7 @@ app.controller('HalController', function ($scope, $location, $http, bridgeServic
httpVerb: $scope.device.httpVerb, httpVerb: $scope.device.httpVerb,
contentType: $scope.device.contentType, contentType: $scope.device.contentType,
contentBody: $scope.device.contentBody, contentBody: $scope.device.contentBody,
contentBodyDim: $scope.device.contentBodyDim,
contentBodyOff: $scope.device.contentBodyOff contentBodyOff: $scope.device.contentBodyOff
}; };
} }

View File

@@ -218,6 +218,19 @@
<div class="clearfix visible-xs"></div> <div class="clearfix visible-xs"></div>
</div> </div>
</div> </div>
<div ng-if="device.httpVerb" class="form-group">
<div class="row">
<label class="col-xs-12 col-sm-2 control-label"
for="device-content-body-dim">Content Body Dim</label>
<div class="col-xs-8 col-sm-7">
<textarea rows="3" class="form-control" id="device-content-body-dim"
ng-model="device.contentBodyDim"
placeholder="Content Body Dim for specific GET/PUT/POST type"></textarea>
</div>
<div class="clearfix visible-xs"></div>
</div>
</div>
<div ng-if="device.httpVerb" class="form-group"> <div ng-if="device.httpVerb" class="form-group">
<div class="row"> <div class="row">
<label class="col-xs-12 col-sm-2 control-label" <label class="col-xs-12 col-sm-2 control-label"

View File

@@ -233,6 +233,19 @@
<div class="clearfix visible-xs"></div> <div class="clearfix visible-xs"></div>
</div> </div>
</div> </div>
<div ng-if="device.httpVerb" class="form-group">
<div class="row">
<label class="col-xs-12 col-sm-2 control-label"
for="device-content-body-dim">Content Body Dim</label>
<div class="col-xs-8 col-sm-7">
<textarea rows="3" class="form-control" id="device-content-body-dim"
ng-model="device.contentBodyDim"
placeholder="Content Body Dim for specific GET/PUT/POST type"></textarea>
</div>
<div class="clearfix visible-xs"></div>
</div>
</div>
<div ng-if="device.httpVerb" class="form-group"> <div ng-if="device.httpVerb" class="form-group">
<div class="row"> <div class="row">
<label class="col-xs-12 col-sm-2 control-label" <label class="col-xs-12 col-sm-2 control-label"