HomeAssistant continuation

This commit is contained in:
Admin
2016-12-16 16:10:49 -06:00
parent 74cccd6de3
commit 74c15db202
7 changed files with 98 additions and 71 deletions

View File

@@ -195,7 +195,7 @@ public class HueMulator implements HueErrorStringSet {
return new Gson().toJson(theResponse, GroupResponse.class);
}
return "[{\"error\":{\"type\":\"3\", \"address\": \"/api/" + userId + "/groups/" + "0"
return "[{\"error\":{\"type\":\"3\", \"address\": \"/api/" + userId + "/groups/" + groupId
+ "\",\"description\": \"Object not found\"}}]";
});
// http://ip_address:port/api/{userId}/scenes returns json objects of
@@ -495,6 +495,37 @@ public class HueMulator implements HueErrorStringSet {
return apiResponse;
} , new JsonTransformer());
// http://ip_address:port/api/{userId}/ returns json objects for the full
// state
get(HUE_CONTEXT + "/:userid/", "application/json", (request, response) -> {
String userId = request.params(":userid");
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
response.type("application/json");
response.status(HttpStatus.SC_OK);
log.debug("hue api full state requested: " + userId + " from " + request.ip());
if (validateWhitelistUser(userId, false) == null) {
log.debug("Valudate user, No User supplied");
HueErrorResponse theErrorResp = new HueErrorResponse();
theErrorResp.addError(new HueError(
new HueErrorDetails("1", "/api/" + userId, "unauthorized user", null, null, null)));
return theErrorResp.getTheErrors();
}
List<DeviceDescriptor> descriptorList = repository.findAll();
HueApiResponse apiResponse = new HueApiResponse("Philips hue", bridgeSettings.getUpnpConfigAddress(),
bridgeSettings.getWhitelist());
Map<String, DeviceResponse> deviceList = new HashMap<>();
if (descriptorList != null) {
descriptorList.forEach(descriptor -> {
DeviceResponse deviceResponse = DeviceResponse.createResponse(descriptor);
deviceList.put(descriptor.getId(), deviceResponse);
});
apiResponse.setLights(deviceList);
}
return apiResponse;
} , new JsonTransformer());
// http://ip_address:port/api/{userId}/lights/{lightId} returns json
// object for a given light
get(HUE_CONTEXT + "/:userid/lights/:id", "application/json", (request, response) -> {

View File

@@ -2,6 +2,8 @@ package com.bwssystems.hass;
public class HassDevice {
private State deviceState;
private String deviceName;
private String domain;
private String hassaddress;
private String hassname;
public State getDeviceState() {
@@ -10,6 +12,18 @@ public class HassDevice {
public void setDeviceState(State deviceState) {
this.deviceState = deviceState;
}
public String getDeviceName() {
return deviceName;
}
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}
public String getDomain() {
return domain;
}
public void setDomain(String domain) {
this.domain = domain;
}
public String getHassaddress() {
return hassaddress;
}

View File

@@ -59,6 +59,8 @@ public class HassHome {
aNewHassDevice.setDeviceState(theDevice);
aNewHassDevice.setHassaddress(hassMap.get(theKey).getHassAddress().getIp());
aNewHassDevice.setHassname(theKey);
aNewHassDevice.setDeviceName(theDevice.getAttributes().get("friendly_name").getAsString());
aNewHassDevice.setDomain(theDevice.getEntityId().substring(0, theDevice.getEntityId().indexOf(".")));
theDeviceList.add(aNewHassDevice);
}
return true;