Updated group 0 handling to be per hue api requirements.

This commit is contained in:
Admin
2016-07-15 16:27:53 -05:00
parent 9d84e2a180
commit 8ccb768391
3 changed files with 51 additions and 4 deletions

View File

@@ -5,7 +5,7 @@
<groupId>com.bwssystems.HABridge</groupId>
<artifactId>ha-bridge</artifactId>
<version>2.0.7-hal-j</version>
<version>2.0.7-hal-k</version>
<packaging>jar</packaging>
<name>HA Bridge</name>

View File

@@ -0,0 +1,33 @@
package com.bwssystems.HABridge.api.hue;
public class GroupResponse {
private DeviceState action;
private String[] lights;
private String name;
public DeviceState getAction() {
return action;
}
public void setAction(DeviceState action) {
this.action = action;
}
public String[] getLights() {
return lights;
}
public void setLights(String[] lights) {
this.lights = lights;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public static GroupResponse createGroupResponse(String[] theLights) {
GroupResponse theResponse = new GroupResponse();
theResponse.setAction(DeviceState.createDeviceState());
theResponse.setName("Lightset 0");
theResponse.setLights(theLights);
return theResponse;
}
}

View File

@@ -6,6 +6,7 @@ import com.bwssystems.HABridge.api.NameValue;
import com.bwssystems.HABridge.api.UserCreateRequest;
import com.bwssystems.HABridge.api.hue.DeviceResponse;
import com.bwssystems.HABridge.api.hue.DeviceState;
import com.bwssystems.HABridge.api.hue.GroupResponse;
import com.bwssystems.HABridge.api.hue.HueApiResponse;
import com.bwssystems.HABridge.api.hue.HueError;
import com.bwssystems.HABridge.api.hue.HueErrorDetails;
@@ -157,9 +158,10 @@ public class HueMulator implements HueErrorStringSet {
return "{}";
});
// http://ip_address:port/api/{userId}/groups/0 returns json objects of all groups configured
get(HUE_CONTEXT + "/:userid/groups/0", "application/json", (request, response) -> {
// http://ip_address:port/api/{userId}/groups/{groupId} returns json object for specified group. Only 0 is supported
get(HUE_CONTEXT + "/:userid/groups/:groupid", "application/json", (request, response) -> {
String userId = request.params(":userid");
String groupId = request.params(":groupid");
log.debug("hue group 0 list requested: " + userId + " from " + request.ip());
response.status(HttpStatus.SC_OK);
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
@@ -169,8 +171,20 @@ public class HueMulator implements HueErrorStringSet {
theErrorResp.addError(new HueError(new HueErrorDetails("1", "/api/" + userId, "unauthorized user", null, null, null)));
return new Gson().toJson(theErrorResp.getTheErrors());
}
if(groupId.equalsIgnoreCase("0")) {
List<DeviceDescriptor> deviceList = repository.findAll();
String[] theList = new String[deviceList.size()];
int i = 0;
for (DeviceDescriptor device : deviceList) {
theList[i] = device.getId();
i++;
}
GroupResponse theResponse = GroupResponse.createGroupResponse(theList);
return new Gson().toJson(theResponse, GroupResponse.class);
}
return "[{\"error\":{\"type\":\"3\", \"address\": \"/api/" + userId + "/groups/" + "0" + "\",\"description\": \"Object not found\"}}]";
return "[{\"error\":{\"type\":\"3\", \"address\": \"/api/" + userId + "/groups/" + "0" + "\",\"description\": \"Object not found\"}}]";
});
// http://ip_address:port/api/{userId}/scenes returns json objects of all scenes configured
get(HUE_CONTEXT + "/:userid/scenes", "application/json", (request, response) -> {