From f1da2c5a4db0f3c89ab97773fadb85b9514a8997 Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Tue, 10 Nov 2020 16:41:01 +0100 Subject: [PATCH] Fixed build failures --- .../plugin/assistant/google/ReportState.java | 30 ++----------------- .../assistant/google/SmartHomeImpl.java | 25 +++++++++------- .../google/endpoint/AuthServlet.java | 2 +- 3 files changed, 19 insertions(+), 38 deletions(-) diff --git a/plugins/hal-assistant-google/src/se/hal/plugin/assistant/google/ReportState.java b/plugins/hal-assistant-google/src/se/hal/plugin/assistant/google/ReportState.java index e62e4597..df967309 100644 --- a/plugins/hal-assistant-google/src/se/hal/plugin/assistant/google/ReportState.java +++ b/plugins/hal-assistant-google/src/se/hal/plugin/assistant/google/ReportState.java @@ -28,6 +28,8 @@ import com.google.protobuf.Struct; import com.google.protobuf.Value; import com.google.protobuf.util.JsonFormat; import zutil.log.LogUtil; +import zutil.parser.DataNode; +import zutil.parser.json.JSONParser; /** * A singleton class to encapsulate state reporting behavior with changing ColorSetting state @@ -39,6 +41,7 @@ final class ReportState { private ReportState() {} + /** * Creates and completes a ReportStateAndNotification request * @@ -48,34 +51,7 @@ final class ReportState { * @param states A Map of state keys and their values for the provided device ID */ public static void makeRequest(SmartHomeApp actionsApp, String userId, String deviceId, Map states) { - // Convert a Map of states to a JsonObject - JsonObject jsonStates = (JsonObject) JsonParser.parseString(new Gson().toJson(states)); - ReportState.makeRequest(actionsApp, userId, deviceId, jsonStates); - } - - /** - * Creates and completes a ReportStateAndNotification request - * - * @param actionsApp The SmartHomeApp instance to use to make the gRPC request - * @param userId The agent user ID - * @param deviceId The device ID - * @param states A JSON object of state keys and their values for the provided device ID - */ - public static void makeRequest(SmartHomeApp actionsApp, String userId, String deviceId, JsonObject states) { - // Do state name replacement for ColorSetting trait - // See https://developers.google.com/assistant/smarthome/traits/colorsetting#device-states - JsonObject colorJson = states.getAsJsonObject("color"); - if (colorJson != null && colorJson.has("spectrumRgb")) { - colorJson.add("spectrumRGB", colorJson.get("spectrumRgb")); - colorJson.remove("spectrumRgb"); - } Struct.Builder statesStruct = Struct.newBuilder(); - try { - JsonFormat.parser().ignoringUnknownFields().merge(new Gson().toJson(states), statesStruct); - } catch (Exception e) { - logger.severe("Failed to build json"); - e.printStackTrace(); - } HomeGraphApiServiceProto.ReportStateAndNotificationDevice.Builder deviceBuilder = HomeGraphApiServiceProto.ReportStateAndNotificationDevice.newBuilder() diff --git a/plugins/hal-assistant-google/src/se/hal/plugin/assistant/google/SmartHomeImpl.java b/plugins/hal-assistant-google/src/se/hal/plugin/assistant/google/SmartHomeImpl.java index 3c683995..52c8a370 100644 --- a/plugins/hal-assistant-google/src/se/hal/plugin/assistant/google/SmartHomeImpl.java +++ b/plugins/hal-assistant-google/src/se/hal/plugin/assistant/google/SmartHomeImpl.java @@ -32,13 +32,16 @@ import se.hal.HalContext; import se.hal.plugin.assistant.google.endpoint.AuthServlet; import se.hal.plugin.assistant.google.endpoint.AuthTokenServlet; import se.hal.plugin.assistant.google.endpoint.SmartHomeServlet; +import zutil.io.file.FileUtil; import zutil.log.LogUtil; import zutil.net.http.HttpServer; public class SmartHomeImpl extends SmartHomeApp { private static final Logger logger = LogUtil.getLogger(); - private static final String PARAM_PORT = "assistant.google.api_port"; + private static final String PARAM_PORT = "assistant.google.port"; + private static final String PARAM_KEYSTORE_PATH = "assistant.google.keystore"; + private static final String PARAM_KEYSTORE_PASSWORD = "assistant.google.keystore_psw"; private HttpServer httpServer; @@ -52,7 +55,10 @@ public class SmartHomeImpl extends SmartHomeApp { throw new RuntimeException(e); } - httpServer = new HttpServer(HalContext.getIntegerProperty(PARAM_PORT)); + httpServer = new HttpServer( + HalContext.getIntegerProperty(PARAM_PORT), + FileUtil.find(HalContext.getStringProperty(PARAM_KEYSTORE_PATH)), + HalContext.getStringProperty(PARAM_KEYSTORE_PASSWORD)); httpServer.setPage(AuthServlet.ENDPOINT_URL, new AuthServlet(this)); httpServer.setPage(AuthTokenServlet.ENDPOINT_URL, new AuthTokenServlet(this)); httpServer.setPage(SmartHomeServlet.ENDPOINT_URL, new SmartHomeServlet(this)); @@ -67,7 +73,7 @@ public class SmartHomeImpl extends SmartHomeApp { int numOfDevices = 0; res.payload.devices = new SyncResponse.Payload.Device[numOfDevices]; - for (int i = 0; i < numOfDevices; i++) { +/* for (int i = 0; i < numOfDevices; i++) { SyncResponse.Payload.Device.Builder deviceBuilder = new SyncResponse.Payload.Device.Builder() .setId(device.getId()) @@ -112,7 +118,7 @@ public class SmartHomeImpl extends SmartHomeApp { } res.payload.devices[i] = deviceBuilder.build(); } - +*/ return res; } @@ -122,7 +128,7 @@ public class SmartHomeImpl extends SmartHomeApp { QueryResponse res = new QueryResponse(); res.setRequestId(queryRequest.requestId); res.setPayload(new QueryResponse.Payload()); - +/* Map> deviceStates = new HashMap<>(); for (QueryRequest.Inputs.Payload.Device device : devices) { try { @@ -137,7 +143,7 @@ public class SmartHomeImpl extends SmartHomeApp { deviceStates.put(device.id, failedDevice); } } - res.payload.setDevices(deviceStates); + res.payload.setDevices(deviceStates);*/ return res; } @@ -151,7 +157,7 @@ public class SmartHomeImpl extends SmartHomeApp { ExecuteRequest.Inputs.Payload.Commands[] commands = ((ExecuteRequest.Inputs) executeRequest.inputs[0]).payload.commands; - for (ExecuteRequest.Inputs.Payload.Commands command : commands) { +/* for (ExecuteRequest.Inputs.Payload.Commands command : commands) { for (ExecuteRequest.Inputs.Payload.Commands.Devices device : command.devices) { try { states = database.execute(userId, device.id, command.execution[0]); @@ -218,7 +224,7 @@ public class SmartHomeImpl extends SmartHomeApp { commandsResponse.add(failedDevice); } } - } + }*/ ExecuteResponse.Payload.Commands successfulCommands = new ExecuteResponse.Payload.Commands(); successfulCommands.status = "SUCCESS"; @@ -227,8 +233,7 @@ public class SmartHomeImpl extends SmartHomeApp { commandsResponse.add(successfulCommands); res.requestId = executeRequest.requestId; - ExecuteResponse.Payload payload = - new ExecuteResponse.Payload( + ExecuteResponse.Payload payload = new ExecuteResponse.Payload( commandsResponse.toArray(new ExecuteResponse.Payload.Commands[]{})); res.setPayload(payload); diff --git a/plugins/hal-assistant-google/src/se/hal/plugin/assistant/google/endpoint/AuthServlet.java b/plugins/hal-assistant-google/src/se/hal/plugin/assistant/google/endpoint/AuthServlet.java index 804128db..53a01c89 100644 --- a/plugins/hal-assistant-google/src/se/hal/plugin/assistant/google/endpoint/AuthServlet.java +++ b/plugins/hal-assistant-google/src/se/hal/plugin/assistant/google/endpoint/AuthServlet.java @@ -74,7 +74,7 @@ public class AuthServlet implements HttpPage { redirectURL.append("code=").append("xxxxxx"); redirectURL.append("state=").append(request.get("state")); - out.setStatusCode(302); + out.setResponseStatusCode(302); out.setHeader("Location", URLEncoder.encode("/login?responseurl=" + redirectURL.toString(), StandardCharsets.UTF_8)); } }