|
|
|
|
@@ -44,7 +44,8 @@ import java.util.Map;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Based on Armzilla's HueMulator - a Philips Hue emulator using sparkjava rest server
|
|
|
|
|
* Based on Armzilla's HueMulator - a Philips Hue emulator using sparkjava rest
|
|
|
|
|
* server
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public class HueMulator {
|
|
|
|
|
@@ -60,7 +61,8 @@ public class HueMulator {
|
|
|
|
|
private Gson aGsonHandler;
|
|
|
|
|
private DeviceMapTypes validMapTypes;
|
|
|
|
|
|
|
|
|
|
public HueMulator(BridgeSettings bridgeMaster, DeviceRepository aDeviceRepository, GroupRepository aGroupRepository, HomeManager aHomeManager) {
|
|
|
|
|
public HueMulator(BridgeSettings bridgeMaster, DeviceRepository aDeviceRepository, GroupRepository aGroupRepository,
|
|
|
|
|
HomeManager aHomeManager) {
|
|
|
|
|
repository = aDeviceRepository;
|
|
|
|
|
groupRepository = aGroupRepository;
|
|
|
|
|
validMapTypes = new DeviceMapTypes();
|
|
|
|
|
@@ -81,7 +83,8 @@ public class HueMulator {
|
|
|
|
|
// if (path.endsWith("/")) { // it should work with or without a trailing slash
|
|
|
|
|
// response.redirect(path.substring(0, path.length() - 1));
|
|
|
|
|
// }
|
|
|
|
|
log.debug("HueMulator " + request.requestMethod() + " called on api/* with request <<<" + request.pathInfo() + ">>>, and body <<<" + request.body() + ">>>");
|
|
|
|
|
log.debug("HueMulator " + request.requestMethod() + " called on api/* with request <<<" + request.pathInfo()
|
|
|
|
|
+ ">>>, and body <<<" + request.body() + ">>>");
|
|
|
|
|
if (bridgeSettingMaster.getBridgeSecurity().isSecure()) {
|
|
|
|
|
String pathInfo = request.pathInfo();
|
|
|
|
|
if (pathInfo != null && pathInfo.contains(HUE_CONTEXT + "/devices")) {
|
|
|
|
|
@@ -152,7 +155,8 @@ public class HueMulator {
|
|
|
|
|
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
|
|
|
|
|
response.type("application/json");
|
|
|
|
|
response.status(HttpStatus.SC_OK);
|
|
|
|
|
return changeGroupState(request.params(":userid"), request.params(":groupid"), request.body(), request.ip(), false);
|
|
|
|
|
return changeGroupState(request.params(":userid"), request.params(":groupid"), request.body(), request.ip(),
|
|
|
|
|
false);
|
|
|
|
|
});
|
|
|
|
|
// http://ip_address:port/api/{userId}/scenes returns json objects of
|
|
|
|
|
// all scenes configured
|
|
|
|
|
@@ -177,7 +181,8 @@ public class HueMulator {
|
|
|
|
|
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
|
|
|
|
|
response.type("application/json");
|
|
|
|
|
response.status(HttpStatus.SC_OK);
|
|
|
|
|
log.debug("scene add requested from " + request.ip() + " user " + request.params(":userid") + " with body " + request.body());
|
|
|
|
|
log.debug("scene add requested from " + request.ip() + " user " + request.params(":userid") + " with body "
|
|
|
|
|
+ request.body());
|
|
|
|
|
return "[{\"success\":{\"id\":\"1\"}}]";
|
|
|
|
|
});
|
|
|
|
|
// http://ip_address:port/api/{userId}/schedules returns json objects of
|
|
|
|
|
@@ -203,7 +208,8 @@ public class HueMulator {
|
|
|
|
|
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
|
|
|
|
|
response.type("application/json");
|
|
|
|
|
response.status(HttpStatus.SC_OK);
|
|
|
|
|
log.debug("schedules add requested from " + request.ip() + " user " + request.params(":userid") + " with body " + request.body());
|
|
|
|
|
log.debug("schedules add requested from " + request.ip() + " user " + request.params(":userid")
|
|
|
|
|
+ " with body " + request.body());
|
|
|
|
|
return "[{\"success\":{\"id\":\"1\"}}]";
|
|
|
|
|
});
|
|
|
|
|
// http://ip_address:port/api/{userId}/sensors returns json objects of
|
|
|
|
|
@@ -229,7 +235,8 @@ public class HueMulator {
|
|
|
|
|
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
|
|
|
|
|
response.type("application/json");
|
|
|
|
|
response.status(HttpStatus.SC_OK);
|
|
|
|
|
log.debug("sensors add requested from " + request.ip() + " user " + request.params(":userid") + " with body " + request.body());
|
|
|
|
|
log.debug("sensors add requested from " + request.ip() + " user " + request.params(":userid")
|
|
|
|
|
+ " with body " + request.body());
|
|
|
|
|
return "[{\"success\":{\"id\":\"1\"}}]";
|
|
|
|
|
});
|
|
|
|
|
// http://ip_address:port/api/{userId}/rules returns json objects of all
|
|
|
|
|
@@ -255,7 +262,8 @@ public class HueMulator {
|
|
|
|
|
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
|
|
|
|
|
response.type("application/json");
|
|
|
|
|
response.status(HttpStatus.SC_OK);
|
|
|
|
|
log.debug("rules add requested from " + request.ip() + " user " + request.params(":userid") + " with body " + request.body());
|
|
|
|
|
log.debug("rules add requested from " + request.ip() + " user " + request.params(":userid") + " with body "
|
|
|
|
|
+ request.body());
|
|
|
|
|
return "[{\"success\":{\"id\":\"1\"}}]";
|
|
|
|
|
});
|
|
|
|
|
// http://ip_address:port/api/{userId}/resourcelinks returns json
|
|
|
|
|
@@ -281,7 +289,8 @@ public class HueMulator {
|
|
|
|
|
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
|
|
|
|
|
response.type("application/json");
|
|
|
|
|
response.status(HttpStatus.SC_OK);
|
|
|
|
|
log.debug("resourcelinks add requested from " + request.ip() + " user " + request.params(":userid") + " with body " + request.body());
|
|
|
|
|
log.debug("resourcelinks add requested from " + request.ip() + " user " + request.params(":userid")
|
|
|
|
|
+ " with body " + request.body());
|
|
|
|
|
return "[{\"success\":{\"id\":\"1\"}}]";
|
|
|
|
|
});
|
|
|
|
|
// http://ip_address:port/api/{userId}/lights returns json objects of
|
|
|
|
|
@@ -370,7 +379,8 @@ public class HueMulator {
|
|
|
|
|
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
|
|
|
|
|
response.type("application/json");
|
|
|
|
|
response.status(HttpStatus.SC_OK);
|
|
|
|
|
log.debug("Config change requested from " + request.ip() + " user " + request.params(":userid") + " with body " + request.body());
|
|
|
|
|
log.debug("Config change requested from " + request.ip() + " user " + request.params(":userid")
|
|
|
|
|
+ " with body " + request.body());
|
|
|
|
|
HueConfig aConfig = aGsonHandler.fromJson(request.body(), HueConfig.class);
|
|
|
|
|
if (aConfig.getPortalservices() != null) {
|
|
|
|
|
return "[{\"success\":{\"/config/portalservices\":true}}]";
|
|
|
|
|
@@ -471,8 +481,8 @@ public class HueMulator {
|
|
|
|
|
if (body.contains("\"bri\"")) {
|
|
|
|
|
if (notFirstChange)
|
|
|
|
|
responseString = responseString + ",";
|
|
|
|
|
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/bri\":" + stateChanges.getBri()
|
|
|
|
|
+ "}}";
|
|
|
|
|
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/bri\":"
|
|
|
|
|
+ stateChanges.getBri() + "}}";
|
|
|
|
|
if (deviceState != null)
|
|
|
|
|
deviceState.setBri(stateChanges.getBri());
|
|
|
|
|
notFirstChange = true;
|
|
|
|
|
@@ -494,16 +504,16 @@ public class HueMulator {
|
|
|
|
|
if (body.contains("\"xy\"")) {
|
|
|
|
|
if (notFirstChange)
|
|
|
|
|
responseString = responseString + ",";
|
|
|
|
|
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/xy\":" + stateChanges.getXy()
|
|
|
|
|
+ "}}";
|
|
|
|
|
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/xy\":"
|
|
|
|
|
+ stateChanges.getXy() + "}}";
|
|
|
|
|
if (deviceState != null)
|
|
|
|
|
deviceState.setXy(stateChanges.getXy());
|
|
|
|
|
notFirstChange = true;
|
|
|
|
|
} else if (body.contains("\"ct\"")) {
|
|
|
|
|
if (notFirstChange)
|
|
|
|
|
responseString = responseString + ",";
|
|
|
|
|
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/ct\":" + stateChanges.getCt()
|
|
|
|
|
+ "}}";
|
|
|
|
|
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/ct\":"
|
|
|
|
|
+ stateChanges.getCt() + "}}";
|
|
|
|
|
if (deviceState != null)
|
|
|
|
|
deviceState.setCt(stateChanges.getCt());
|
|
|
|
|
notFirstChange = true;
|
|
|
|
|
@@ -511,8 +521,8 @@ public class HueMulator {
|
|
|
|
|
if (body.contains("\"hue\"")) {
|
|
|
|
|
if (notFirstChange)
|
|
|
|
|
responseString = responseString + ",";
|
|
|
|
|
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/hue\":" + stateChanges.getHue()
|
|
|
|
|
+ "}}";
|
|
|
|
|
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/hue\":"
|
|
|
|
|
+ stateChanges.getHue() + "}}";
|
|
|
|
|
if (deviceState != null)
|
|
|
|
|
deviceState.setHue(stateChanges.getHue());
|
|
|
|
|
notFirstChange = true;
|
|
|
|
|
@@ -521,8 +531,8 @@ public class HueMulator {
|
|
|
|
|
if (body.contains("\"sat\"")) {
|
|
|
|
|
if (notFirstChange)
|
|
|
|
|
responseString = responseString + ",";
|
|
|
|
|
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/sat\":" + stateChanges.getSat()
|
|
|
|
|
+ "}}";
|
|
|
|
|
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/sat\":"
|
|
|
|
|
+ stateChanges.getSat() + "}}";
|
|
|
|
|
if (deviceState != null)
|
|
|
|
|
deviceState.setSat(stateChanges.getSat());
|
|
|
|
|
notFirstChange = true;
|
|
|
|
|
@@ -600,7 +610,8 @@ public class HueMulator {
|
|
|
|
|
if ((deviceState != null) && deviceState.isOn() && deviceState.getBri() <= 0)
|
|
|
|
|
deviceState.setBri(254);
|
|
|
|
|
|
|
|
|
|
// if((deviceState != null) && !deviceState.isOn() && (targetBri != null || targetBriInc != null))
|
|
|
|
|
// if((deviceState != null) && !deviceState.isOn() && (targetBri != null ||
|
|
|
|
|
// targetBriInc != null))
|
|
|
|
|
// deviceState.setOn(true);
|
|
|
|
|
|
|
|
|
|
responseString = responseString + "]";
|
|
|
|
|
@@ -628,7 +639,8 @@ public class HueMulator {
|
|
|
|
|
|
|
|
|
|
private String basicListHandler(String type, String userId, String requestIp) {
|
|
|
|
|
log.debug("hue " + type + " list requested by user: " + userId + " from address: " + requestIp);
|
|
|
|
|
HueError[] theErrors = bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(userId, null, bridgeSettingMaster.getBridgeSecurity().isUseLinkButton());
|
|
|
|
|
HueError[] theErrors = bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(userId, null,
|
|
|
|
|
bridgeSettingMaster.getBridgeSecurity().isUseLinkButton());
|
|
|
|
|
if (theErrors != null) {
|
|
|
|
|
if (bridgeSettingMaster.getBridgeSecurity().isSettingsChanged())
|
|
|
|
|
bridgeSettingMaster.updateConfigFile();
|
|
|
|
|
@@ -642,7 +654,8 @@ public class HueMulator {
|
|
|
|
|
private Object addGroup(String userId, String ip, String body) {
|
|
|
|
|
HueError[] theErrors = null;
|
|
|
|
|
log.debug("group add requested from " + ip + " user " + userId + " with body " + body);
|
|
|
|
|
theErrors = bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(userId, null, bridgeSettingMaster.getBridgeSecurity().isUseLinkButton());
|
|
|
|
|
theErrors = bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(userId, null,
|
|
|
|
|
bridgeSettingMaster.getBridgeSecurity().isUseLinkButton());
|
|
|
|
|
if (theErrors == null) {
|
|
|
|
|
if (bridgeSettingMaster.getBridgeSecurity().isSettingsChanged())
|
|
|
|
|
bridgeSettingMaster.updateConfigFile();
|
|
|
|
|
@@ -655,8 +668,9 @@ public class HueMulator {
|
|
|
|
|
}
|
|
|
|
|
if (theGroup == null) {
|
|
|
|
|
log.warn("Could not parse add group body. No group created.");
|
|
|
|
|
return aGsonHandler.toJson(HueErrorResponse.createResponse("5", "/groups/lights",
|
|
|
|
|
"invalid/missing parameters in body", null, null, null).getTheErrors(), HueError[].class);
|
|
|
|
|
return aGsonHandler.toJson(HueErrorResponse
|
|
|
|
|
.createResponse("5", "/groups/lights", "invalid/missing parameters in body", null, null, null)
|
|
|
|
|
.getTheErrors(), HueError[].class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<GroupDescriptor> groups = groupRepository.findAll();
|
|
|
|
|
@@ -681,8 +695,10 @@ public class HueMulator {
|
|
|
|
|
if (groupClass == null || groupClass.trim().equals("")) {
|
|
|
|
|
groupClass = GroupClassTypes.OTHER;
|
|
|
|
|
} else if (!new GroupClassTypes().validateType(groupClass)) {
|
|
|
|
|
return aGsonHandler.toJson(HueErrorResponse.createResponse("7", "/groups/class",
|
|
|
|
|
"invalid value, " + groupClass + ", for parameter, class", null, null, null).getTheErrors(), HueError[].class);
|
|
|
|
|
return aGsonHandler.toJson(HueErrorResponse
|
|
|
|
|
.createResponse("7", "/groups/class",
|
|
|
|
|
"invalid value, " + groupClass + ", for parameter, class", null, null, null)
|
|
|
|
|
.getTheErrors(), HueError[].class);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
String name = theGroup.getName();
|
|
|
|
|
@@ -706,15 +722,19 @@ public class HueMulator {
|
|
|
|
|
private Object deleteGroup(String userId, String groupId, String ip) {
|
|
|
|
|
HueError[] theErrors = null;
|
|
|
|
|
log.debug("group delete requested from " + ip + " user " + userId);
|
|
|
|
|
theErrors = bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(userId, null, bridgeSettingMaster.getBridgeSecurity().isUseLinkButton());
|
|
|
|
|
theErrors = bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(userId, null,
|
|
|
|
|
bridgeSettingMaster.getBridgeSecurity().isUseLinkButton());
|
|
|
|
|
if (theErrors == null) {
|
|
|
|
|
if (bridgeSettingMaster.getBridgeSecurity().isSettingsChanged())
|
|
|
|
|
bridgeSettingMaster.updateConfigFile();
|
|
|
|
|
|
|
|
|
|
GroupDescriptor group = groupRepository.findOne(groupId);
|
|
|
|
|
if (group == null || group.isInactive()) {
|
|
|
|
|
return aGsonHandler.toJson(HueErrorResponse.createResponse("3", "/groups/" + groupId,
|
|
|
|
|
"resource, /groups/" + groupId + ", not available", null, null, null).getTheErrors(), HueError[].class);
|
|
|
|
|
return aGsonHandler
|
|
|
|
|
.toJson(HueErrorResponse
|
|
|
|
|
.createResponse("3", "/groups/" + groupId,
|
|
|
|
|
"resource, /groups/" + groupId + ", not available", null, null, null)
|
|
|
|
|
.getTheErrors(), HueError[].class);
|
|
|
|
|
} else {
|
|
|
|
|
groupRepository.delete(group);
|
|
|
|
|
return "[{\"success\":\"/groups/" + groupId + " deleted\"}}]";
|
|
|
|
|
@@ -726,15 +746,19 @@ public class HueMulator {
|
|
|
|
|
private Object modifyGroup(String userId, String groupId, String ip, String body) {
|
|
|
|
|
HueError[] theErrors = null;
|
|
|
|
|
log.debug("group modify requested from " + ip + " user " + userId + " with body " + body);
|
|
|
|
|
theErrors = bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(userId, null, bridgeSettingMaster.getBridgeSecurity().isUseLinkButton());
|
|
|
|
|
theErrors = bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(userId, null,
|
|
|
|
|
bridgeSettingMaster.getBridgeSecurity().isUseLinkButton());
|
|
|
|
|
if (theErrors == null) {
|
|
|
|
|
if (bridgeSettingMaster.getBridgeSecurity().isSettingsChanged())
|
|
|
|
|
bridgeSettingMaster.updateConfigFile();
|
|
|
|
|
|
|
|
|
|
GroupDescriptor group = groupRepository.findOne(groupId);
|
|
|
|
|
if (group == null || group.isInactive()) {
|
|
|
|
|
return aGsonHandler.toJson(HueErrorResponse.createResponse("3", "/groups/" + groupId,
|
|
|
|
|
"resource, /groups/" + groupId + ", not available", null, null, null).getTheErrors(), HueError[].class);
|
|
|
|
|
return aGsonHandler
|
|
|
|
|
.toJson(HueErrorResponse
|
|
|
|
|
.createResponse("3", "/groups/" + groupId,
|
|
|
|
|
"resource, /groups/" + groupId + ", not available", null, null, null)
|
|
|
|
|
.getTheErrors(), HueError[].class);
|
|
|
|
|
} else {
|
|
|
|
|
String successString = "[";
|
|
|
|
|
GroupResponse theGroup = null;
|
|
|
|
|
@@ -757,37 +781,48 @@ public class HueMulator {
|
|
|
|
|
}
|
|
|
|
|
if (!group.getGroupType().equals("Room")) {
|
|
|
|
|
if (!(groupClass == null || groupClass.trim().equals(""))) {
|
|
|
|
|
return aGsonHandler.toJson(HueErrorResponse.createResponse("6", "/groups/" + groupId + "/class",
|
|
|
|
|
"parameter, /groups/" + groupId + "/class, not available", null, null, null).getTheErrors(), HueError[].class);
|
|
|
|
|
return aGsonHandler.toJson(HueErrorResponse
|
|
|
|
|
.createResponse("6", "/groups/" + groupId + "/class",
|
|
|
|
|
"parameter, /groups/" + groupId + "/class, not available", null, null, null)
|
|
|
|
|
.getTheErrors(), HueError[].class);
|
|
|
|
|
}
|
|
|
|
|
if (theGroup.getLights() != null) {
|
|
|
|
|
if (theGroup.getLights().length == 0) {
|
|
|
|
|
return aGsonHandler.toJson(HueErrorResponse.createResponse("7", "/groups/" + groupId + "/lights",
|
|
|
|
|
"invalid value, " + Arrays.toString(theGroup.getLights()) + ", for parameter, /groups" + groupId + "/lights", null, null, null).getTheErrors(), HueError[].class);
|
|
|
|
|
return aGsonHandler
|
|
|
|
|
.toJson(HueErrorResponse.createResponse("7", "/groups/" + groupId + "/lights",
|
|
|
|
|
"invalid value, " + Arrays.toString(theGroup.getLights())
|
|
|
|
|
+ ", for parameter, /groups" + groupId + "/lights",
|
|
|
|
|
null, null, null).getTheErrors(), HueError[].class);
|
|
|
|
|
} else {
|
|
|
|
|
group.setLights(theGroup.getLights());
|
|
|
|
|
successString += "{\"success\":{\"/groups/" + groupId + "/lights\":\"" + Arrays.toString(theGroup.getLights()) + "\"}},";
|
|
|
|
|
successString += "{\"success\":{\"/groups/" + groupId + "/lights\":\""
|
|
|
|
|
+ Arrays.toString(theGroup.getLights()) + "\"}},";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else { // check room class if it's a room
|
|
|
|
|
if (!(groupClass == null || groupClass.trim().equals(""))) {
|
|
|
|
|
if (!new GroupClassTypes().validateType(groupClass)) {
|
|
|
|
|
return aGsonHandler.toJson(HueErrorResponse.createResponse("7", "/groups/class",
|
|
|
|
|
"invalid value, " + groupClass + ", for parameter, class", null, null, null).getTheErrors(), HueError[].class);
|
|
|
|
|
return aGsonHandler.toJson(HueErrorResponse
|
|
|
|
|
.createResponse("7", "/groups/class",
|
|
|
|
|
"invalid value, " + groupClass + ", for parameter, class", null, null, null)
|
|
|
|
|
.getTheErrors(), HueError[].class);
|
|
|
|
|
} else {
|
|
|
|
|
group.setGroupClass(groupClass);
|
|
|
|
|
successString += "{\"success\":{\"/groups/" + groupId + "/class\":\"" + groupClass + "\"}},";
|
|
|
|
|
successString += "{\"success\":{\"/groups/" + groupId + "/class\":\"" + groupClass
|
|
|
|
|
+ "\"}},";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (theGroup.getLights() != null) {
|
|
|
|
|
group.setLights(theGroup.getLights());
|
|
|
|
|
successString += "{\"success\":{\"/groups/" + groupId + "/lights\":\"" + Arrays.toString(theGroup.getLights()) + "\"}},";
|
|
|
|
|
successString += "{\"success\":{\"/groups/" + groupId + "/lights\":\""
|
|
|
|
|
+ Arrays.toString(theGroup.getLights()) + "\"}},";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
groupRepository.save();
|
|
|
|
|
return (successString.length() == 1) ? "[]" : successString.substring(0, successString.length()-1) + "]";
|
|
|
|
|
return (successString.length() == 1) ? "[]"
|
|
|
|
|
: successString.substring(0, successString.length() - 1) + "]";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return theErrors;
|
|
|
|
|
@@ -799,7 +834,8 @@ public class HueMulator {
|
|
|
|
|
if (bridgeSettings.isTraceupnp())
|
|
|
|
|
log.info("Traceupnp: hue group list requested: " + userId + " from " + requestIp);
|
|
|
|
|
log.debug("hue group list requested: " + userId + " from " + requestIp);
|
|
|
|
|
theErrors = bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(userId, null, bridgeSettingMaster.getBridgeSecurity().isUseLinkButton());
|
|
|
|
|
theErrors = bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(userId, null,
|
|
|
|
|
bridgeSettingMaster.getBridgeSecurity().isUseLinkButton());
|
|
|
|
|
if (theErrors == null) {
|
|
|
|
|
if (bridgeSettingMaster.getBridgeSecurity().isSettingsChanged())
|
|
|
|
|
bridgeSettingMaster.updateConfigFile();
|
|
|
|
|
@@ -809,7 +845,8 @@ public class HueMulator {
|
|
|
|
|
for (GroupDescriptor group : groupList) {
|
|
|
|
|
GroupResponse groupResponse = null;
|
|
|
|
|
if (!group.isInactive()) {
|
|
|
|
|
Map<String, DeviceResponse> lights = repository.findAllByGroupWithState(group.getLights(), requestIp, myHueHome, aGsonHandler);
|
|
|
|
|
Map<String, DeviceResponse> lights = repository.findAllByGroupWithState(group.getLights(),
|
|
|
|
|
requestIp, myHueHome, aGsonHandler);
|
|
|
|
|
groupResponse = GroupResponse.createResponse(group, lights);
|
|
|
|
|
groupResponseMap.put(group.getId(), groupResponse);
|
|
|
|
|
}
|
|
|
|
|
@@ -822,26 +859,30 @@ public class HueMulator {
|
|
|
|
|
return groupResponseMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Object groupsIdHandler(String groupId, String userId, String requestIp) {
|
|
|
|
|
log.debug("hue group id: <" + groupId + "> requested: " + userId + " from " + requestIp);
|
|
|
|
|
HueError[] theErrors = null;
|
|
|
|
|
theErrors = bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(userId, null, bridgeSettingMaster.getBridgeSecurity().isUseLinkButton());
|
|
|
|
|
theErrors = bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(userId, null,
|
|
|
|
|
bridgeSettingMaster.getBridgeSecurity().isUseLinkButton());
|
|
|
|
|
if (theErrors == null) {
|
|
|
|
|
if (bridgeSettingMaster.getBridgeSecurity().isSettingsChanged())
|
|
|
|
|
bridgeSettingMaster.updateConfigFile();
|
|
|
|
|
|
|
|
|
|
if (groupId.equalsIgnoreCase("0")) {
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
GroupResponse theResponse = GroupResponse.createDefaultGroupResponse((Map<String, DeviceResponse>)lightsListHandler(userId, requestIp));
|
|
|
|
|
GroupResponse theResponse = GroupResponse
|
|
|
|
|
.createDefaultGroupResponse((Map<String, DeviceResponse>) lightsListHandler(userId, requestIp));
|
|
|
|
|
return theResponse;
|
|
|
|
|
} else {
|
|
|
|
|
GroupDescriptor group = groupRepository.findOne(groupId);
|
|
|
|
|
if (group == null || group.isInactive()) {
|
|
|
|
|
return aGsonHandler.toJson(HueErrorResponse.createResponse("3", "/groups/" + groupId,
|
|
|
|
|
"resource, /groups/" + groupId + ", not available", null, null, null).getTheErrors(), HueError[].class);
|
|
|
|
|
return aGsonHandler.toJson(HueErrorResponse
|
|
|
|
|
.createResponse("3", "/groups/" + groupId,
|
|
|
|
|
"resource, /groups/" + groupId + ", not available", null, null, null)
|
|
|
|
|
.getTheErrors(), HueError[].class);
|
|
|
|
|
} else {
|
|
|
|
|
Map<String, DeviceResponse> lights = repository.findAllByGroupWithState(group.getLights(), requestIp, myHueHome, aGsonHandler);
|
|
|
|
|
Map<String, DeviceResponse> lights = repository.findAllByGroupWithState(group.getLights(),
|
|
|
|
|
requestIp, myHueHome, aGsonHandler);
|
|
|
|
|
GroupResponse theResponse = GroupResponse.createResponse(group, lights);
|
|
|
|
|
return theResponse;
|
|
|
|
|
}
|
|
|
|
|
@@ -858,7 +899,8 @@ public class HueMulator {
|
|
|
|
|
if (bridgeSettings.isTraceupnp())
|
|
|
|
|
log.info("Traceupnp: hue lights list requested by user: " + userId + " from address: " + requestIp);
|
|
|
|
|
log.debug("hue lights list requested: " + userId + " from " + requestIp);
|
|
|
|
|
theErrors = bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(userId, null, bridgeSettingMaster.getBridgeSecurity().isUseLinkButton());
|
|
|
|
|
theErrors = bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(userId, null,
|
|
|
|
|
bridgeSettingMaster.getBridgeSecurity().isUseLinkButton());
|
|
|
|
|
if (theErrors == null) {
|
|
|
|
|
if (bridgeSettingMaster.getBridgeSecurity().isSettingsChanged())
|
|
|
|
|
bridgeSettingMaster.updateConfigFile();
|
|
|
|
|
@@ -874,13 +916,15 @@ public class HueMulator {
|
|
|
|
|
if (device.getOnUrl() != null)
|
|
|
|
|
callItems = aGsonHandler.fromJson(device.getOnUrl(), CallItem[].class);
|
|
|
|
|
} catch (JsonSyntaxException e) {
|
|
|
|
|
log.warn("Could not decode Json for url items to get Hue state for device: " + device.getName());
|
|
|
|
|
log.warn("Could not decode Json for url items to get Hue state for device: "
|
|
|
|
|
+ device.getName());
|
|
|
|
|
callItems = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; callItems != null && i < callItems.length; i++) {
|
|
|
|
|
if((callItems[i].getType() != null && callItems[i].getType().equals(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex])) ||
|
|
|
|
|
(callItems[i].getItem().getAsString().contains("hueName"))) {
|
|
|
|
|
if ((callItems[i].getType() != null && callItems[i].getType()
|
|
|
|
|
.equals(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex]))
|
|
|
|
|
|| (callItems[i].getItem().getAsString().contains("hueName"))) {
|
|
|
|
|
deviceResponse = myHueHome.getHueDeviceInfo(callItems[i], device);
|
|
|
|
|
i = callItems.length;
|
|
|
|
|
}
|
|
|
|
|
@@ -893,7 +937,8 @@ public class HueMulator {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handle groups which shall be exposed as fake lights to selected devices like amazon echos
|
|
|
|
|
// handle groups which shall be exposed as fake lights to selected devices like
|
|
|
|
|
// amazon echos
|
|
|
|
|
List<GroupDescriptor> groups = groupRepository.findVirtualLights(requestIp);
|
|
|
|
|
for (GroupDescriptor group : groups) {
|
|
|
|
|
deviceResponseMap.put(String.valueOf(Integer.parseInt(group.getId()) + 10000),
|
|
|
|
|
@@ -918,7 +963,8 @@ public class HueMulator {
|
|
|
|
|
else
|
|
|
|
|
log.debug("hue api user create requested: " + body + " from address: " + ipAddress);
|
|
|
|
|
|
|
|
|
|
if(bridgeSettingMaster.getBridgeSecurity().isUseLinkButton() && bridgeSettingMaster.getBridgeControl().isLinkButton())
|
|
|
|
|
if (bridgeSettingMaster.getBridgeSecurity().isUseLinkButton()
|
|
|
|
|
&& bridgeSettingMaster.getBridgeControl().isLinkButton())
|
|
|
|
|
toContinue = true;
|
|
|
|
|
else if (!bridgeSettingMaster.getBridgeSecurity().isUseLinkButton())
|
|
|
|
|
toContinue = true;
|
|
|
|
|
@@ -931,8 +977,9 @@ public class HueMulator {
|
|
|
|
|
aNewUser = aGsonHandler.fromJson(body, UserCreateRequest.class);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.warn("Could not add user. Request garbled: " + body);
|
|
|
|
|
return aGsonHandler.toJson(HueErrorResponse.createResponse("2", "/",
|
|
|
|
|
"Could not add user.", null, null, null).getTheErrors(), HueError[].class);
|
|
|
|
|
return aGsonHandler.toJson(HueErrorResponse
|
|
|
|
|
.createResponse("2", "/", "Could not add user.", null, null, null).getTheErrors(),
|
|
|
|
|
HueError[].class);
|
|
|
|
|
}
|
|
|
|
|
newUser = aNewUser.getUsername();
|
|
|
|
|
aDeviceType = aNewUser.getDevicetype();
|
|
|
|
|
@@ -945,8 +992,7 @@ public class HueMulator {
|
|
|
|
|
|
|
|
|
|
if (newUser == null) {
|
|
|
|
|
newUser = bridgeSettingMaster.getBridgeSecurity().createWhitelistUser(aDeviceType);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
} else {
|
|
|
|
|
bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(newUser, aDeviceType, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -956,19 +1002,22 @@ public class HueMulator {
|
|
|
|
|
if (bridgeSettings.isTraceupnp() && !aDeviceType.equals("test_ha_bridge"))
|
|
|
|
|
log.info("Traceupnp: hue api user create requested for device type: " + aDeviceType + " and username: "
|
|
|
|
|
+ newUser + (followingSlash ? " /api/ called" : ""));
|
|
|
|
|
log.debug("hue api user create requested for device type: " + aDeviceType + " and username: " + newUser + (followingSlash ? " /api/ called" : ""));
|
|
|
|
|
log.debug("hue api user create requested for device type: " + aDeviceType + " and username: " + newUser
|
|
|
|
|
+ (followingSlash ? " /api/ called" : ""));
|
|
|
|
|
return "[{\"success\":{\"username\":\"" + newUser + "\"}}]";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
} else
|
|
|
|
|
log.debug("user add toContinue was false, returning not authorized");
|
|
|
|
|
return aGsonHandler.toJson(HueErrorResponse.createResponse("101", "/api/", "link button not pressed", null, null, null).getTheErrors());
|
|
|
|
|
return aGsonHandler.toJson(HueErrorResponse
|
|
|
|
|
.createResponse("101", "/api/", "link button not pressed", null, null, null).getTheErrors());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Object getConfig(String userId, String ipAddress) {
|
|
|
|
|
if (bridgeSettings.isTraceupnp())
|
|
|
|
|
log.info("Traceupnp: hue api/:userid/config config requested from user: " + userId + " from address: " + ipAddress);
|
|
|
|
|
log.info("Traceupnp: hue api/:userid/config config requested from user: " + userId + " from address: "
|
|
|
|
|
+ ipAddress);
|
|
|
|
|
log.debug("hue api config requested: " + userId + " from " + ipAddress);
|
|
|
|
|
if (bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(userId, null, bridgeSettingMaster.getBridgeSecurity().isUseLinkButton()) != null) {
|
|
|
|
|
if (bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(userId, null,
|
|
|
|
|
bridgeSettingMaster.getBridgeSecurity().isUseLinkButton()) != null) {
|
|
|
|
|
log.debug("hue api config requested, User invalid, returning public config");
|
|
|
|
|
HuePublicConfig apiResponse = HuePublicConfig.createConfig("HA-Bridge",
|
|
|
|
|
bridgeSettings.getUpnpConfigAddress(), bridgeSettings.getHubversion(), bridgeSettings.getHubmac());
|
|
|
|
|
@@ -976,7 +1025,8 @@ public class HueMulator {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HueApiResponse apiResponse = new HueApiResponse("HA-Bridge", bridgeSettings.getUpnpConfigAddress(),
|
|
|
|
|
bridgeSettingMaster.getBridgeSecurity().getWhitelist(), bridgeSettings.getHubversion(), bridgeSettingMaster.getBridgeControl().isLinkButton(), bridgeSettings.getHubmac());
|
|
|
|
|
bridgeSettingMaster.getBridgeSecurity().getWhitelist(), bridgeSettings.getHubversion(),
|
|
|
|
|
bridgeSettingMaster.getBridgeControl().isLinkButton(), bridgeSettings.getHubmac());
|
|
|
|
|
log.debug("api response config <<<" + aGsonHandler.toJson(apiResponse.getConfig()) + ">>>");
|
|
|
|
|
return apiResponse.getConfig();
|
|
|
|
|
}
|
|
|
|
|
@@ -984,14 +1034,16 @@ public class HueMulator {
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
private Object getFullState(String userId, String ipAddress) {
|
|
|
|
|
log.debug("hue api full state requested: " + userId + " from " + ipAddress);
|
|
|
|
|
HueError[] theErrors = bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(userId, null, bridgeSettingMaster.getBridgeSecurity().isUseLinkButton());
|
|
|
|
|
HueError[] theErrors = bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(userId, null,
|
|
|
|
|
bridgeSettingMaster.getBridgeSecurity().isUseLinkButton());
|
|
|
|
|
if (theErrors != null) {
|
|
|
|
|
log.debug("full state error occurred <<<" + aGsonHandler.toJson(theErrors) + ">>>");
|
|
|
|
|
return theErrors;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HueApiResponse apiResponse = new HueApiResponse("HA-Bridge", bridgeSettings.getUpnpConfigAddress(),
|
|
|
|
|
bridgeSettingMaster.getBridgeSecurity().getWhitelist(), bridgeSettings.getHubversion(), bridgeSettingMaster.getBridgeControl().isLinkButton(), bridgeSettings.getHubmac());
|
|
|
|
|
bridgeSettingMaster.getBridgeSecurity().getWhitelist(), bridgeSettings.getHubversion(),
|
|
|
|
|
bridgeSettingMaster.getBridgeControl().isLinkButton(), bridgeSettings.getHubmac());
|
|
|
|
|
apiResponse.setLights((Map<String, DeviceResponse>) this.lightsListHandler(userId, ipAddress));
|
|
|
|
|
apiResponse.setGroups((Map<String, GroupResponse>) this.groupsListHandler(userId, ipAddress));
|
|
|
|
|
|
|
|
|
|
@@ -1000,7 +1052,8 @@ public class HueMulator {
|
|
|
|
|
|
|
|
|
|
private Object getLight(String userId, String lightId, String ipAddress) {
|
|
|
|
|
log.debug("hue light requested: " + lightId + " for user: " + userId + " from " + ipAddress);
|
|
|
|
|
HueError[] theErrors = bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(userId, null, bridgeSettingMaster.getBridgeSecurity().isUseLinkButton());
|
|
|
|
|
HueError[] theErrors = bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(userId, null,
|
|
|
|
|
bridgeSettingMaster.getBridgeSecurity().isUseLinkButton());
|
|
|
|
|
if (theErrors != null)
|
|
|
|
|
return theErrors;
|
|
|
|
|
|
|
|
|
|
@@ -1012,7 +1065,9 @@ public class HueMulator {
|
|
|
|
|
DeviceDescriptor device = repository.findOne(lightId);
|
|
|
|
|
if (device == null) {
|
|
|
|
|
// response.status(HttpStatus.SC_NOT_FOUND);
|
|
|
|
|
return HueErrorResponse.createResponse("3", "/api/" + userId + "/lights/" + lightId, "Object not found", null, null, null).getTheErrors();
|
|
|
|
|
return HueErrorResponse
|
|
|
|
|
.createResponse("3", "/api/" + userId + "/lights/" + lightId, "Object not found", null, null, null)
|
|
|
|
|
.getTheErrors();
|
|
|
|
|
} else {
|
|
|
|
|
log.debug("found device named: " + device.getName());
|
|
|
|
|
}
|
|
|
|
|
@@ -1028,7 +1083,9 @@ public class HueMulator {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; callItems != null && i < callItems.length; i++) {
|
|
|
|
|
if((callItems[i].getType() != null && callItems[i].getType().equals(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex])) || callItems[i].getItem().getAsString().startsWith("{\"ipAddress\":\"")) {
|
|
|
|
|
if ((callItems[i].getType() != null
|
|
|
|
|
&& callItems[i].getType().equals(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex]))
|
|
|
|
|
|| callItems[i].getItem().getAsString().startsWith("{\"ipAddress\":\"")) {
|
|
|
|
|
lightResponse = myHueHome.getHueDeviceInfo(callItems[i], device);
|
|
|
|
|
i = callItems.length;
|
|
|
|
|
}
|
|
|
|
|
@@ -1050,9 +1107,13 @@ public class HueMulator {
|
|
|
|
|
Integer targetBriInc = null;
|
|
|
|
|
ColorData colorData = null;
|
|
|
|
|
|
|
|
|
|
if (bridgeSettings.isTracestate())
|
|
|
|
|
log.info("Tracestate: Update state requested: " + userId + " from " + ipAddress + " body: " + body);
|
|
|
|
|
|
|
|
|
|
log.debug("Update state requested: " + userId + " from " + ipAddress + " body: " + body);
|
|
|
|
|
|
|
|
|
|
HueError[] theErrors = bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(userId, null, bridgeSettingMaster.getBridgeSecurity().isUseLinkButton());
|
|
|
|
|
HueError[] theErrors = bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(userId, null,
|
|
|
|
|
bridgeSettingMaster.getBridgeSecurity().isUseLinkButton());
|
|
|
|
|
if (theErrors != null)
|
|
|
|
|
return aGsonHandler.toJson(theErrors);
|
|
|
|
|
|
|
|
|
|
@@ -1060,8 +1121,9 @@ public class HueMulator {
|
|
|
|
|
theStateChanges = aGsonHandler.fromJson(body, StateChangeBody.class);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.warn("Could not parse state change body. Light state not changed.");
|
|
|
|
|
return aGsonHandler.toJson(HueErrorResponse.createResponse("2", "/lights/" + lightId,
|
|
|
|
|
"Could not parse state change body.", null, null, null).getTheErrors(), HueError[].class);
|
|
|
|
|
return aGsonHandler.toJson(HueErrorResponse
|
|
|
|
|
.createResponse("2", "/lights/" + lightId, "Could not parse state change body.", null, null, null)
|
|
|
|
|
.getTheErrors(), HueError[].class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DeviceDescriptor device = repository.findOne(lightId);
|
|
|
|
|
@@ -1082,26 +1144,10 @@ public class HueMulator {
|
|
|
|
|
if (state == null)
|
|
|
|
|
state = DeviceState.createDeviceState(device.isColorDevice());
|
|
|
|
|
|
|
|
|
|
if (body.contains("\"xy\"") || body.contains("\"ct\"") || body.contains("\"hue\"") || body.contains("\"xy_inc\"") || body.contains("\"ct_inc\"") || body.contains("\"hue_inc\"")) {
|
|
|
|
|
List<Double> xy = theStateChanges.getXy();
|
|
|
|
|
List<Double> xyInc = theStateChanges.getXy_inc();
|
|
|
|
|
Integer ct = theStateChanges.getCt();
|
|
|
|
|
Integer ctInc = theStateChanges.getCt_inc();
|
|
|
|
|
if (xy != null && xy.size() == 2) {
|
|
|
|
|
colorData = new ColorData(ColorData.ColorMode.XY, xy);
|
|
|
|
|
} else if (xyInc != null && xyInc.size() == 2) {
|
|
|
|
|
List<Double> current = state.getXy();
|
|
|
|
|
current.set(0, current.get(0) + xyInc.get(0));
|
|
|
|
|
current.set(1, current.get(1) + xyInc.get(1));
|
|
|
|
|
colorData = new ColorData(ColorData.ColorMode.XY, current);
|
|
|
|
|
} else if (ct != null && ct != 0) {
|
|
|
|
|
colorData = new ColorData(ColorData.ColorMode.CT, ct);
|
|
|
|
|
} else if (ctInc != null && ctInc != 0) {
|
|
|
|
|
colorData = new ColorData(ColorData.ColorMode.CT, state.getCt() + ctInc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
colorData = parseColorInfo(body, theStateChanges, state, targetBri, targetBriInc);
|
|
|
|
|
|
|
|
|
|
responseString = this.formatSuccessHueResponse(theStateChanges, body, lightId, state, targetBri, targetBriInc, colorData, device.isOffState());
|
|
|
|
|
responseString = this.formatSuccessHueResponse(theStateChanges, body, lightId, state, targetBri, targetBriInc,
|
|
|
|
|
colorData, device.isOffState());
|
|
|
|
|
device.setDeviceState(state);
|
|
|
|
|
|
|
|
|
|
return responseString;
|
|
|
|
|
@@ -1121,8 +1167,12 @@ public class HueMulator {
|
|
|
|
|
boolean isDimRequest = false;
|
|
|
|
|
boolean isOnRequest = false;
|
|
|
|
|
ColorData colorData = null;
|
|
|
|
|
if (bridgeSettings.isTracestate())
|
|
|
|
|
log.info("Tracestate: hue state change requested: " + userId + " from " + ipAddress + " body: " + body);
|
|
|
|
|
|
|
|
|
|
log.debug("hue state change requested: " + userId + " from " + ipAddress + " body: " + body);
|
|
|
|
|
HueError[] theErrors = bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(userId, null, bridgeSettingMaster.getBridgeSecurity().isUseLinkButton());
|
|
|
|
|
HueError[] theErrors = bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(userId, null,
|
|
|
|
|
bridgeSettingMaster.getBridgeSecurity().isUseLinkButton());
|
|
|
|
|
if (theErrors != null) {
|
|
|
|
|
log.warn("Errors in security: <<<" + aGsonHandler.toJson(theErrors) + ">>>");
|
|
|
|
|
return aGsonHandler.toJson(theErrors);
|
|
|
|
|
@@ -1134,8 +1184,9 @@ public class HueMulator {
|
|
|
|
|
}
|
|
|
|
|
if (theStateChanges == null) {
|
|
|
|
|
log.warn("Could not parse state change body. Light state not changed.");
|
|
|
|
|
return aGsonHandler.toJson(HueErrorResponse.createResponse("2", "/lights/" + lightId,
|
|
|
|
|
"Could not parse state change body.", null, null, null).getTheErrors(), HueError[].class);
|
|
|
|
|
return aGsonHandler.toJson(HueErrorResponse
|
|
|
|
|
.createResponse("2", "/lights/" + lightId, "Could not parse state change body.", null, null, null)
|
|
|
|
|
.getTheErrors(), HueError[].class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DeviceDescriptor device = repository.findOne(lightId);
|
|
|
|
|
@@ -1155,32 +1206,14 @@ public class HueMulator {
|
|
|
|
|
if (body.contains("\"bri_inc\"")) {
|
|
|
|
|
targetBriInc = Integer.valueOf(theStateChanges.getBri_inc());
|
|
|
|
|
isDimRequest = true;
|
|
|
|
|
}
|
|
|
|
|
else if (body.contains("\"bri\"")) {
|
|
|
|
|
} else if (body.contains("\"bri\"")) {
|
|
|
|
|
targetBri = Integer.valueOf(theStateChanges.getBri());
|
|
|
|
|
isDimRequest = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (body.contains("\"xy\"") || body.contains("\"ct\"") || body.contains("\"hue\"") || body.contains("\"xy_inc\"") || body.contains("\"ct_inc\"") || body.contains("\"hue_inc\"")) {
|
|
|
|
|
List<Double> xy = theStateChanges.getXy();
|
|
|
|
|
List<Double> xyInc = theStateChanges.getXy_inc();
|
|
|
|
|
Integer ct = theStateChanges.getCt();
|
|
|
|
|
Integer ctInc = theStateChanges.getCt_inc();
|
|
|
|
|
if (xy != null && xy.size() == 2) {
|
|
|
|
|
colorData = new ColorData(ColorData.ColorMode.XY, xy);
|
|
|
|
|
} else if (xyInc != null && xyInc.size() == 2) {
|
|
|
|
|
List<Double> current = state.getXy();
|
|
|
|
|
current.set(0, current.get(0) + xyInc.get(0));
|
|
|
|
|
current.set(1, current.get(1) + xyInc.get(1));
|
|
|
|
|
colorData = new ColorData(ColorData.ColorMode.XY, current);
|
|
|
|
|
} else if (ct != null && ct != 0) {
|
|
|
|
|
colorData = new ColorData(ColorData.ColorMode.CT, ct);
|
|
|
|
|
} else if (ctInc != null && ctInc != 0) {
|
|
|
|
|
colorData = new ColorData(ColorData.ColorMode.CT, state.getCt() + ctInc);
|
|
|
|
|
}
|
|
|
|
|
colorData = parseColorInfo(body, theStateChanges, state, targetBri, targetBriInc);
|
|
|
|
|
if (colorData != null)
|
|
|
|
|
isColorRequest = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (body.contains("\"on\"")) {
|
|
|
|
|
isOnRequest = true;
|
|
|
|
|
@@ -1212,6 +1245,9 @@ public class HueMulator {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isOnRequest) {
|
|
|
|
|
if (bridgeSettings.isTracestate())
|
|
|
|
|
log.info("Tracestate: Calling on-off as requested.");
|
|
|
|
|
|
|
|
|
|
log.debug("Calling on-off as requested.");
|
|
|
|
|
if (theStateChanges.isOn()) {
|
|
|
|
|
url = device.getOnUrl();
|
|
|
|
|
@@ -1220,25 +1256,31 @@ public class HueMulator {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// code for backwards compatibility
|
|
|
|
|
if(device.getMapType() != null && device.getMapType().equalsIgnoreCase(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex])) {
|
|
|
|
|
if (device.getMapType() != null
|
|
|
|
|
&& device.getMapType().equalsIgnoreCase(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex])) {
|
|
|
|
|
if (url == null)
|
|
|
|
|
url = device.getOnUrl();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (url != null && !url.equals("")) {
|
|
|
|
|
responseString = callUrl(url, device, userId, lightId, body, ipAddress, ignoreRequester, targetBri, targetBriInc, colorData);
|
|
|
|
|
responseString = callUrl(url, device, userId, lightId, body, ipAddress, ignoreRequester, targetBri,
|
|
|
|
|
targetBriInc, colorData);
|
|
|
|
|
} else {
|
|
|
|
|
log.info("On/off url not available for state change, lightId: " + lightId + ", userId: " + userId + ", from IP: "
|
|
|
|
|
+ ipAddress + ", body: " + body);
|
|
|
|
|
log.info("On/off url not available for state change, lightId: " + lightId + ", userId: " + userId
|
|
|
|
|
+ ", from IP: " + ipAddress + ", body: " + body);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isDimRequest) {
|
|
|
|
|
if (bridgeSettings.isTracestate())
|
|
|
|
|
log.info("Tracestate: Calling dim as requested.");
|
|
|
|
|
|
|
|
|
|
log.debug("Calling dim as requested.");
|
|
|
|
|
url = device.getDimUrl();
|
|
|
|
|
|
|
|
|
|
// code for backwards compatibility
|
|
|
|
|
if(device.getMapType() != null && device.getMapType().equalsIgnoreCase(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex])) {
|
|
|
|
|
if (device.getMapType() != null
|
|
|
|
|
&& device.getMapType().equalsIgnoreCase(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex])) {
|
|
|
|
|
if (url == null)
|
|
|
|
|
url = device.getOnUrl();
|
|
|
|
|
}
|
|
|
|
|
@@ -1251,18 +1293,23 @@ public class HueMulator {
|
|
|
|
|
// ignore
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
responseString = callUrl(url, device, userId, lightId, body, ipAddress, ignoreRequester, targetBri, targetBriInc, colorData);
|
|
|
|
|
responseString = callUrl(url, device, userId, lightId, body, ipAddress, ignoreRequester, targetBri,
|
|
|
|
|
targetBriInc, colorData);
|
|
|
|
|
} else {
|
|
|
|
|
log.info("Dim url not available for state change, lightId: " + lightId + ", userId: " + userId + ", from IP: "
|
|
|
|
|
+ ipAddress + ", body: " + body);
|
|
|
|
|
log.info("Dim url not available for state change, lightId: " + lightId + ", userId: " + userId
|
|
|
|
|
+ ", from IP: " + ipAddress + ", body: " + body);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isColorRequest) {
|
|
|
|
|
if (bridgeSettings.isTracestate())
|
|
|
|
|
log.info("Tracestate: Calling color as requested. With " + colorData);
|
|
|
|
|
|
|
|
|
|
log.debug("Calling color as requested.");
|
|
|
|
|
url = device.getColorUrl();
|
|
|
|
|
// code for backwards compatibility
|
|
|
|
|
if(device.getMapType() != null && device.getMapType().equalsIgnoreCase(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex])) {
|
|
|
|
|
if (device.getMapType() != null
|
|
|
|
|
&& device.getMapType().equalsIgnoreCase(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex])) {
|
|
|
|
|
if (url == null)
|
|
|
|
|
url = device.getOnUrl();
|
|
|
|
|
}
|
|
|
|
|
@@ -1275,20 +1322,23 @@ public class HueMulator {
|
|
|
|
|
// ignore
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
responseString = callUrl(url, device, userId, lightId, body, ipAddress, ignoreRequester, targetBri, targetBriInc, colorData);
|
|
|
|
|
responseString = callUrl(url, device, userId, lightId, body, ipAddress, ignoreRequester, targetBri,
|
|
|
|
|
targetBriInc, colorData);
|
|
|
|
|
} else {
|
|
|
|
|
log.info("Color url not available for state change, lightId: " + lightId + ", userId: " + userId + ", from IP: "
|
|
|
|
|
+ ipAddress + ", body: " + body);
|
|
|
|
|
log.info("Color url not available for state change, lightId: " + lightId + ", userId: " + userId
|
|
|
|
|
+ ", from IP: " + ipAddress + ", body: " + body);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (responseString == null || !responseString.contains("[{\"error\":")) {
|
|
|
|
|
if (!device.isNoState()) {
|
|
|
|
|
responseString = this.formatSuccessHueResponse(theStateChanges, body, lightId, state, targetBri, targetBriInc, colorData, device.isOffState());
|
|
|
|
|
responseString = this.formatSuccessHueResponse(theStateChanges, body, lightId, state, targetBri,
|
|
|
|
|
targetBriInc, colorData, device.isOffState());
|
|
|
|
|
device.setDeviceState(state);
|
|
|
|
|
} else {
|
|
|
|
|
DeviceState dummyState = DeviceState.createDeviceState(device.isColorDevice());
|
|
|
|
|
responseString = this.formatSuccessHueResponse(theStateChanges, body, lightId, dummyState, targetBri, targetBriInc, colorData, device.isOffState());
|
|
|
|
|
responseString = this.formatSuccessHueResponse(theStateChanges, body, lightId, dummyState, targetBri,
|
|
|
|
|
targetBriInc, colorData, device.isOffState());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1296,13 +1346,120 @@ public class HueMulator {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ColorData parseColorInfo(String body, StateChangeBody theStateChanges, DeviceState state, Integer targetBri, Integer targetBriInc) {
|
|
|
|
|
ColorData colorData = null;
|
|
|
|
|
List<Double> xy = null;
|
|
|
|
|
List<Double> xyInc = null;
|
|
|
|
|
Integer ct = null;
|
|
|
|
|
Integer ctInc = null;
|
|
|
|
|
HueSatBri anHSL = null;
|
|
|
|
|
Integer hue = null;
|
|
|
|
|
Integer sat = null;
|
|
|
|
|
Integer hueInc = null;
|
|
|
|
|
Integer satInc = null;
|
|
|
|
|
|
|
|
|
|
if (body.contains("\"xy\"")) {
|
|
|
|
|
xy = theStateChanges.getXy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (body.contains("\"ct\"")) {
|
|
|
|
|
ct = theStateChanges.getCt();
|
|
|
|
|
}
|
|
|
|
|
if (body.contains("\"hue\"")) {
|
|
|
|
|
hue = theStateChanges.getHue();
|
|
|
|
|
}
|
|
|
|
|
if (body.contains("\"sat\"")) {
|
|
|
|
|
sat = theStateChanges.getSat();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (body.contains("\"xy_inc\"")) {
|
|
|
|
|
xyInc = theStateChanges.getXy_inc();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (body.contains("\"ct_inc\"")) {
|
|
|
|
|
ctInc = theStateChanges.getCt_inc();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (body.contains("\"hue_inc\"")) {
|
|
|
|
|
hueInc = theStateChanges.getHue_inc();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (body.contains("\"sat_inc\"")) {
|
|
|
|
|
satInc = theStateChanges.getSat_inc();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (xy != null && xy.size() == 2) {
|
|
|
|
|
colorData = new ColorData(ColorData.ColorMode.XY, xy);
|
|
|
|
|
} else if (xyInc != null && xyInc.size() == 2) {
|
|
|
|
|
List<Double> current = state.getXy();
|
|
|
|
|
current.set(0, current.get(0) + xyInc.get(0));
|
|
|
|
|
current.set(1, current.get(1) + xyInc.get(1));
|
|
|
|
|
colorData = new ColorData(ColorData.ColorMode.XY, current);
|
|
|
|
|
} else if (ct != null) {
|
|
|
|
|
colorData = new ColorData(ColorData.ColorMode.CT, ct);
|
|
|
|
|
} else if (ctInc != null) {
|
|
|
|
|
colorData = new ColorData(ColorData.ColorMode.CT, state.getCt() + ctInc);
|
|
|
|
|
} else if (hue != null || sat != null) {
|
|
|
|
|
anHSL = new HueSatBri();
|
|
|
|
|
int bri = 0;
|
|
|
|
|
if(targetBriInc != null) {
|
|
|
|
|
bri = state.getBri() - targetBriInc;
|
|
|
|
|
if(bri < 0)
|
|
|
|
|
bri = 0;
|
|
|
|
|
} else if (targetBri != null) {
|
|
|
|
|
bri = targetBri;
|
|
|
|
|
} else {
|
|
|
|
|
bri = state.getBri();
|
|
|
|
|
}
|
|
|
|
|
anHSL.setBri(bri);
|
|
|
|
|
if(hue != null)
|
|
|
|
|
anHSL.setHue(hue);
|
|
|
|
|
else
|
|
|
|
|
anHSL.setHue(state.getHue());
|
|
|
|
|
|
|
|
|
|
if(sat != null)
|
|
|
|
|
anHSL.setSat(sat);
|
|
|
|
|
else
|
|
|
|
|
anHSL.setSat(state.getSat());
|
|
|
|
|
log.info("hue/sat request - " + anHSL);
|
|
|
|
|
colorData = new ColorData(ColorData.ColorMode.HS, anHSL);
|
|
|
|
|
} else if (hueInc != null || satInc != null) {
|
|
|
|
|
anHSL = new HueSatBri();
|
|
|
|
|
int bri = 0;
|
|
|
|
|
if(targetBriInc != null) {
|
|
|
|
|
bri = state.getBri() - targetBriInc;
|
|
|
|
|
if(bri < 0)
|
|
|
|
|
bri = 0;
|
|
|
|
|
} else if (targetBri != null) {
|
|
|
|
|
bri = targetBri;
|
|
|
|
|
} else {
|
|
|
|
|
bri = state.getBri();
|
|
|
|
|
}
|
|
|
|
|
anHSL.setBri(bri);
|
|
|
|
|
if(hueInc != null)
|
|
|
|
|
anHSL.setHue(state.getHue() - hueInc);
|
|
|
|
|
else
|
|
|
|
|
anHSL.setHue(state.getHue());
|
|
|
|
|
|
|
|
|
|
if(satInc != null)
|
|
|
|
|
anHSL.setSat(state.getSat() - satInc);
|
|
|
|
|
else
|
|
|
|
|
anHSL.setSat(state.getSat());
|
|
|
|
|
log.info("hue/sat inc request - " + anHSL);
|
|
|
|
|
colorData = new ColorData(ColorData.ColorMode.HS, anHSL);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return colorData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
private String changeGroupState(String userId, String groupId, String body, String ipAddress, boolean fakeLightResponse) {
|
|
|
|
|
private String changeGroupState(String userId, String groupId, String body, String ipAddress,
|
|
|
|
|
boolean fakeLightResponse) {
|
|
|
|
|
ColorData colorData = null;
|
|
|
|
|
log.debug("PUT action to group " + groupId + " from " + ipAddress + " user " + userId + " with body " + body);
|
|
|
|
|
HueError[] theErrors = null;
|
|
|
|
|
theErrors = bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(userId, null, bridgeSettingMaster.getBridgeSecurity().isUseLinkButton());
|
|
|
|
|
theErrors = bridgeSettingMaster.getBridgeSecurity().validateWhitelistUser(userId, null,
|
|
|
|
|
bridgeSettingMaster.getBridgeSecurity().isUseLinkButton());
|
|
|
|
|
if (theErrors == null) {
|
|
|
|
|
if (bridgeSettingMaster.getBridgeSecurity().isSettingsChanged())
|
|
|
|
|
bridgeSettingMaster.updateConfigFile();
|
|
|
|
|
@@ -1317,13 +1474,17 @@ public class HueMulator {
|
|
|
|
|
} else {
|
|
|
|
|
group = groupRepository.findOne(groupId);
|
|
|
|
|
if (group == null || group.isInactive()) {
|
|
|
|
|
return aGsonHandler.toJson(HueErrorResponse.createResponse("3", "/groups/" + groupId,
|
|
|
|
|
"resource, /groups/" + groupId + ", not available", null, null, null).getTheErrors(), HueError[].class);
|
|
|
|
|
return aGsonHandler.toJson(HueErrorResponse
|
|
|
|
|
.createResponse("3", "/groups/" + groupId,
|
|
|
|
|
"resource, /groups/" + groupId + ", not available", null, null, null)
|
|
|
|
|
.getTheErrors(), HueError[].class);
|
|
|
|
|
} else {
|
|
|
|
|
if (fakeLightResponse) {
|
|
|
|
|
lights = repository.findAllByGroupWithState(group.getLights(), ipAddress, myHueHome, aGsonHandler, true);
|
|
|
|
|
lights = repository.findAllByGroupWithState(group.getLights(), ipAddress, myHueHome,
|
|
|
|
|
aGsonHandler, true);
|
|
|
|
|
} else {
|
|
|
|
|
lights = repository.findAllByGroupWithState(group.getLights(), ipAddress, myHueHome, aGsonHandler);
|
|
|
|
|
lights = repository.findAllByGroupWithState(group.getLights(), ipAddress, myHueHome,
|
|
|
|
|
aGsonHandler);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -1337,15 +1498,16 @@ public class HueMulator {
|
|
|
|
|
}
|
|
|
|
|
if (theStateChanges == null) {
|
|
|
|
|
log.warn("Could not parse state change body. Light state not changed.");
|
|
|
|
|
return aGsonHandler.toJson(HueErrorResponse.createResponse("2", "/groups/" + groupId + "/action",
|
|
|
|
|
"Could not parse state change body.", null, null, null).getTheErrors(), HueError[].class);
|
|
|
|
|
return aGsonHandler.toJson(
|
|
|
|
|
HueErrorResponse.createResponse("2", "/groups/" + groupId + "/action",
|
|
|
|
|
"Could not parse state change body.", null, null, null).getTheErrors(),
|
|
|
|
|
HueError[].class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (group != null) {
|
|
|
|
|
if (body.contains("\"bri_inc\"")) {
|
|
|
|
|
targetBriInc = Integer.valueOf(theStateChanges.getBri_inc());
|
|
|
|
|
}
|
|
|
|
|
else if (body.contains("\"bri\"")) {
|
|
|
|
|
} else if (body.contains("\"bri\"")) {
|
|
|
|
|
targetBri = Integer.valueOf(theStateChanges.getBri());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1356,7 +1518,6 @@ public class HueMulator {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean turnOn = false;
|
|
|
|
|
boolean turnOff = false;
|
|
|
|
|
if (!(body.contains("\"bri_inc\"") || body.contains("\"bri\""))) {
|
|
|
|
|
@@ -1369,7 +1530,8 @@ public class HueMulator {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (Map.Entry<String, DeviceResponse> light : lights.entrySet()) {
|
|
|
|
|
log.debug("Processing light" + light.getKey() + ": " + turnOn + " " + turnOff + " " + light.getValue().getState().isOn());
|
|
|
|
|
log.debug("Processing light" + light.getKey() + ": " + turnOn + " " + turnOff + " "
|
|
|
|
|
+ light.getValue().getState().isOn());
|
|
|
|
|
// ignore on/off for devices that are already on/off
|
|
|
|
|
if (turnOff && !light.getValue().getState().isOn())
|
|
|
|
|
continue;
|
|
|
|
|
@@ -1377,10 +1539,12 @@ public class HueMulator {
|
|
|
|
|
continue;
|
|
|
|
|
changeState(userId, light.getKey(), body, ipAddress, fakeLightResponse);
|
|
|
|
|
}
|
|
|
|
|
// construct success response: one success message per changed property, but not per light
|
|
|
|
|
// construct success response: one success message per changed property, but not
|
|
|
|
|
// per light
|
|
|
|
|
if (group != null) { // if not group 0
|
|
|
|
|
String response = formatSuccessHueResponse(theStateChanges, body, String.valueOf(Integer.parseInt(groupId) + 10000),
|
|
|
|
|
state, targetBri, targetBriInc, colorData, true);
|
|
|
|
|
String response = formatSuccessHueResponse(theStateChanges, body,
|
|
|
|
|
String.valueOf(Integer.parseInt(groupId) + 10000), state, targetBri, targetBriInc,
|
|
|
|
|
colorData, true);
|
|
|
|
|
group.setAction(state);
|
|
|
|
|
if (fakeLightResponse) {
|
|
|
|
|
return response;
|
|
|
|
|
@@ -1391,20 +1555,24 @@ public class HueMulator {
|
|
|
|
|
for (String pairStr : body.replaceAll("[{|}]", "").split(",\\s*\"")) {
|
|
|
|
|
String[] pair = pairStr.split(":");
|
|
|
|
|
if (fakeLightResponse) {
|
|
|
|
|
successString += "{\"success\":{ \"/lights/" + String.valueOf(Integer.parseInt(groupId) + 10000) + "/state/" + pair[0].replaceAll("\"", "").trim() + "\": " + pair[1].trim() + "}},";
|
|
|
|
|
successString += "{\"success\":{ \"/lights/" + String.valueOf(Integer.parseInt(groupId) + 10000)
|
|
|
|
|
+ "/state/" + pair[0].replaceAll("\"", "").trim() + "\": " + pair[1].trim() + "}},";
|
|
|
|
|
} else {
|
|
|
|
|
successString += "{\"success\":{ \"address\": \"/groups/" + groupId + "/action/" + pair[0].replaceAll("\"", "").trim() + "\", \"value\": " + pair[1].trim() + "}},";
|
|
|
|
|
successString += "{\"success\":{ \"address\": \"/groups/" + groupId + "/action/"
|
|
|
|
|
+ pair[0].replaceAll("\"", "").trim() + "\", \"value\": " + pair[1].trim() + "}},";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return (successString.length() == 1) ? "[]" : successString.substring(0, successString.length()-1) + "]";
|
|
|
|
|
return (successString.length() == 1) ? "[]"
|
|
|
|
|
: successString.substring(0, successString.length() - 1) + "]";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return aGsonHandler.toJson(theErrors);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected String callUrl(String url, DeviceDescriptor device, String userId, String lightId, String body, String ipAddress, boolean ignoreRequester, Integer targetBri, Integer targetBriInc, ColorData colorData) {
|
|
|
|
|
protected String callUrl(String url, DeviceDescriptor device, String userId, String lightId, String body,
|
|
|
|
|
String ipAddress, boolean ignoreRequester, Integer targetBri, Integer targetBriInc, ColorData colorData) {
|
|
|
|
|
String responseString = null;
|
|
|
|
|
MultiCommandUtil aMultiUtil = new MultiCommandUtil();
|
|
|
|
|
aMultiUtil.setTheDelay(bridgeSettings.getButtonsleep());
|
|
|
|
|
@@ -1428,16 +1596,18 @@ public class HueMulator {
|
|
|
|
|
try {
|
|
|
|
|
callItems = aGsonHandler.fromJson(url, CallItem[].class);
|
|
|
|
|
} catch (JsonSyntaxException e) {
|
|
|
|
|
log.warn("Could not decode Json for url items: " + lightId + " for hue state change request: " + userId + " from "
|
|
|
|
|
+ ipAddress + " body: " + body + " url items: " + url);
|
|
|
|
|
log.warn("Could not decode Json for url items: " + lightId + " for hue state change request: " + userId
|
|
|
|
|
+ " from " + ipAddress + " body: " + body + " url items: " + url);
|
|
|
|
|
return aGsonHandler.toJson(HueErrorResponse.createResponse("3", "/lights/" + lightId,
|
|
|
|
|
"Could decode json in request", "/lights/" + lightId, null, null).getTheErrors(), HueError[].class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; callItems != null && i < callItems.length; i++) {
|
|
|
|
|
if (!ignoreRequester) {
|
|
|
|
|
if(!filterByRequester(device.getRequesterAddress(), ipAddress) || !filterByRequester(callItems[i].getFilterIPs(), ipAddress)) {
|
|
|
|
|
log.warn("filter for requester address not present in: (device)" + device.getRequesterAddress() + " OR then (item)" + callItems[i].getFilterIPs() + " with request ip of: " + ipAddress);
|
|
|
|
|
if (!filterByRequester(device.getRequesterAddress(), ipAddress)
|
|
|
|
|
|| !filterByRequester(callItems[i].getFilterIPs(), ipAddress)) {
|
|
|
|
|
log.warn("filter for requester address not present in: (device)" + device.getRequesterAddress()
|
|
|
|
|
+ " OR then (item)" + callItems[i].getFilterIPs() + " with request ip of: " + ipAddress);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -1471,13 +1641,14 @@ public class HueMulator {
|
|
|
|
|
aMultiUtil.setTheDelay(aMultiUtil.getDelayDefault());
|
|
|
|
|
|
|
|
|
|
log.debug("Calling Home device handler for type : " + callItems[i].getType().trim());
|
|
|
|
|
responseString = homeManager.findHome(callItems[i].getType().trim()).deviceHandler(callItems[i], aMultiUtil, lightId, device.getDeviceState().getBri(), targetBri, targetBriInc, colorData, device, body);
|
|
|
|
|
responseString = homeManager.findHome(callItems[i].getType().trim()).deviceHandler(callItems[i],
|
|
|
|
|
aMultiUtil, lightId, device.getDeviceState().getBri(), targetBri, targetBriInc, colorData,
|
|
|
|
|
device, body);
|
|
|
|
|
if (responseString != null && responseString.contains("{\"error\":")) {
|
|
|
|
|
x = aMultiUtil.getSetCount();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
} else
|
|
|
|
|
log.warn("Call Items type is null <<<" + callItems[i] + ">>>");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|