Skip to content

Commit

Permalink
Implemented get-bootstrap command (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
climategadgets committed Sep 6, 2024
1 parent 4ca2456 commit d8fe57e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class HccCLI implements CommandLineRunner {
private static final String COMMAND_GET_ZONES = "get-zones";
private static final String COMMAND_GET_ZONES_HTTP = "get-zones-http";
private static final String COMMAND_GET_ZONES_RSOCKET = "get-zones-rsocket";
private static final String COMMAND_GET_BOOTSTRAP = "get-bootstrap";

private final ObjectMapper objectMapper = new ObjectMapper();
private final HttpClient httpClient = new HttpClient();
Expand All @@ -42,6 +43,10 @@ public class CommandGetMeta extends CommandBase {

}

public class CommandGetBootstrap extends CommandBase {

}

public class CommandGetZonesHTTP extends CommandBase {

}
Expand Down Expand Up @@ -82,13 +87,15 @@ public void run(String... args) throws Exception {
var commandGetMeta = new CommandGetMeta();
var commandGetZonesHTTP = new CommandGetZonesHTTP();
var commandGetZonesRSocket = new CommandGetZonesRSocket();
var commandGetBootstrap = new CommandGetBootstrap();

var jc = JCommander
.newBuilder()
.addCommand(COMMAND_MDNS_SCAN, commandMdnsScan)
.addCommand(COMMAND_GET_META, commandGetMeta)
.addCommand(COMMAND_GET_ZONES, commandGetZonesHTTP)
.addCommand(COMMAND_GET_ZONES_RSOCKET, commandGetZonesRSocket)
.addCommand(COMMAND_GET_BOOTSTRAP, commandGetBootstrap)
.build();

try {
Expand All @@ -106,6 +113,7 @@ public void run(String... args) throws Exception {
case COMMAND_GET_ZONES -> getZonesHTTP(commandGetZonesHTTP.url);
case COMMAND_GET_ZONES_HTTP -> getZonesHTTP(commandGetZonesHTTP.url);
case COMMAND_GET_ZONES_RSOCKET -> getZonesRSocket(commandGetZonesRSocket.url, commandGetZonesRSocket.serialization);
case COMMAND_GET_BOOTSTRAP -> getBootstrap(commandGetBootstrap.url);
}

} catch (ParameterException ex) {
Expand Down Expand Up @@ -173,6 +181,19 @@ private void getZonesRSocket(String url, String serialization) throws IOExceptio
}
}

private void getBootstrap(String url) throws IOException {
ThreadContext.push("getBootstrap");
try {
logger.info("url={}", url);
var bootstrap = httpClient.getBootstrap(new URL(url));
var bootstrapPrint = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(bootstrap);
logger.info("BOOTSTRAP/parsed: {}", bootstrapPrint);

} finally {
ThreadContext.pop();
}
}

private static void terminate(JCommander jc, String message, Throwable t) {

logger.fatal(message, t);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.homeclimatecontrol.hcc.client.http;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.homeclimatecontrol.hcc.ClientBootstrap;
import com.homeclimatecontrol.hcc.meta.EndpointMeta;
import com.homeclimatecontrol.hcc.signal.hvac.ZoneStatus;
import net.sf.dz3r.instrumentation.Marker;
Expand Down Expand Up @@ -69,6 +70,11 @@ public Map<String, ZoneStatus> getZones(URL targetUrl) throws IOException {
return objectMapper.readValue(get(targetUrl, "getZones"), Map.class);
}

public ClientBootstrap getBootstrap(URL targetUrl) throws IOException {

return objectMapper.readValue(get(targetUrl, "getBootstrap"), ClientBootstrap.class);
}

private String get(URL targetUrl, String marker) throws IOException {

var m = new Marker(marker);
Expand Down

0 comments on commit d8fe57e

Please # to comment.