mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-18 08:13:23 +00:00
Updated group 0 handling to be per hue api requirements.
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<groupId>com.bwssystems.HABridge</groupId>
|
<groupId>com.bwssystems.HABridge</groupId>
|
||||||
<artifactId>ha-bridge</artifactId>
|
<artifactId>ha-bridge</artifactId>
|
||||||
<version>2.0.7-hal-j</version>
|
<version>2.0.7-hal-k</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>HA Bridge</name>
|
<name>HA Bridge</name>
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import com.bwssystems.HABridge.api.NameValue;
|
|||||||
import com.bwssystems.HABridge.api.UserCreateRequest;
|
import com.bwssystems.HABridge.api.UserCreateRequest;
|
||||||
import com.bwssystems.HABridge.api.hue.DeviceResponse;
|
import com.bwssystems.HABridge.api.hue.DeviceResponse;
|
||||||
import com.bwssystems.HABridge.api.hue.DeviceState;
|
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.HueApiResponse;
|
||||||
import com.bwssystems.HABridge.api.hue.HueError;
|
import com.bwssystems.HABridge.api.hue.HueError;
|
||||||
import com.bwssystems.HABridge.api.hue.HueErrorDetails;
|
import com.bwssystems.HABridge.api.hue.HueErrorDetails;
|
||||||
@@ -157,9 +158,10 @@ public class HueMulator implements HueErrorStringSet {
|
|||||||
|
|
||||||
return "{}";
|
return "{}";
|
||||||
});
|
});
|
||||||
// http://ip_address:port/api/{userId}/groups/0 returns json objects of all groups configured
|
// http://ip_address:port/api/{userId}/groups/{groupId} returns json object for specified group. Only 0 is supported
|
||||||
get(HUE_CONTEXT + "/:userid/groups/0", "application/json", (request, response) -> {
|
get(HUE_CONTEXT + "/:userid/groups/:groupid", "application/json", (request, response) -> {
|
||||||
String userId = request.params(":userid");
|
String userId = request.params(":userid");
|
||||||
|
String groupId = request.params(":groupid");
|
||||||
log.debug("hue group 0 list requested: " + userId + " from " + request.ip());
|
log.debug("hue group 0 list requested: " + userId + " from " + request.ip());
|
||||||
response.status(HttpStatus.SC_OK);
|
response.status(HttpStatus.SC_OK);
|
||||||
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
|
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
|
||||||
@@ -170,7 +172,19 @@ public class HueMulator implements HueErrorStringSet {
|
|||||||
return new Gson().toJson(theErrorResp.getTheErrors());
|
return new Gson().toJson(theErrorResp.getTheErrors());
|
||||||
}
|
}
|
||||||
|
|
||||||
return "[{\"error\":{\"type\":\"3\", \"address\": \"/api/" + userId + "/groups/" + "0" + "\",\"description\": \"Object not found\"}}]";
|
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\"}}]";
|
||||||
});
|
});
|
||||||
// http://ip_address:port/api/{userId}/scenes returns json objects of all scenes configured
|
// http://ip_address:port/api/{userId}/scenes returns json objects of all scenes configured
|
||||||
get(HUE_CONTEXT + "/:userid/scenes", "application/json", (request, response) -> {
|
get(HUE_CONTEXT + "/:userid/scenes", "application/json", (request, response) -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user