diff --git a/pom.xml b/pom.xml index 42070b0..bd5296c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.2.1 + 3.2.4 @@ -62,17 +62,17 @@ org.springframework.security spring-security-web - 6.2.2 + 6.2.3 org.springframework.security spring-security-config - 6.2.2 + 6.2.3 org.springframework.security spring-security-core - 6.2.2 + 6.2.3 com.google.code.gson diff --git a/src/main/java/com/bigboxer23/lights/controllers/garage/GarageController.java b/src/main/java/com/bigboxer23/lights/controllers/garage/GarageController.java index 73ddfea..cdced6c 100755 --- a/src/main/java/com/bigboxer23/lights/controllers/garage/GarageController.java +++ b/src/main/java/com/bigboxer23/lights/controllers/garage/GarageController.java @@ -49,7 +49,7 @@ public String doAction( @Parameter(description = "used with SetAutoCloseDelay. Seconds to set delay for", required = false) @PathVariable(value = "delay", required = false) Long delay) { - myLogger.error("Garage Door change requested: " + command); + myLogger.info("Garage Door change requested: " + command); myGarageData = fromJson(myGarageURL + "/" + command + (delay != null ? "/" + delay : ""), VeraDeviceVO.class); myGarageData.setName("Garage Opener"); myGarageData.setStatus(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz").format(new Date())); diff --git a/src/main/java/com/bigboxer23/lights/controllers/govee/GoveeHumidifierController.java b/src/main/java/com/bigboxer23/lights/controllers/govee/GoveeHumidifierController.java index a9dc145..9fa8d0f 100644 --- a/src/main/java/com/bigboxer23/lights/controllers/govee/GoveeHumidifierController.java +++ b/src/main/java/com/bigboxer23/lights/controllers/govee/GoveeHumidifierController.java @@ -28,7 +28,7 @@ public class GoveeHumidifierController implements InitializingBean { @Value("${humidfier_to_pump_map}") private String MAP_KEY; - private JsonObject humidifierToPumpMap; + private HumidifierData data; private static final Logger logger = LoggerFactory.getLogger(GoveeHumidifierController.class); @@ -40,19 +40,21 @@ public GoveeHumidifierController(SwitchBotController switchbotController) { private void setupListeners() { logger.warn("starting govee event listener"); - humidifierToPumpMap = JsonParser.parseString(MAP_KEY).getAsJsonObject(); + data = new GsonBuilder().create().fromJson(MAP_KEY, HumidifierData.class); GoveeApi.getInstance(API_KEY).subscribeToGoveeEvents(new GoveeEventSubscriber() { @Override public void messageReceived(GoveeEvent event) { if (event.isLackWaterEvent()) { logger.warn( "no water: " + event.getModel() + " " + event.getDeviceId() + " " + event.getDeviceName()); - JsonPrimitive pump = humidifierToPumpMap.getAsJsonPrimitive(event.getDeviceId()); - if (pump == null) { - logger.warn("No pump for " + event.getDeviceId()); + HumidifierCluster cluster = data.get(event.getDeviceId()); + if (cluster == null) { + logger.warn("No cluster for " + event.getDeviceId()); return; } - new Thread(new RefillAction(pump.getAsString(), event.getModel(), event.getDeviceId())).start(); + new Thread(new RefillAction( + cluster.getPump(), event.getModel(), event.getDeviceId(), cluster.getOutlet())) + .start(); } } }); @@ -68,15 +70,28 @@ private class RefillAction implements Runnable { private final String humidifierModel; private final String humidifierId; - public RefillAction(String pumpId, String humidifierModel, String humidifierId) { + private final String humidifierOutletId; + + public RefillAction(String pumpId, String humidifierModel, String humidifierId, String humidifierOutletId) { this.pumpId = pumpId; this.humidifierModel = humidifierModel; this.humidifierId = humidifierId; + this.humidifierOutletId = humidifierOutletId; } @Override public void run() { try { + logger.info("manual turn off of humidifier " + humidifierOutletId); + RetryingCommand.execute( + () -> { + switchbotController + .getSwitchbotAPI() + .getDeviceApi() + .sendDeviceControlCommands(humidifierOutletId, IDeviceCommands.PLUG_MINI_OFF); + return null; + }, + humidifierOutletId); logger.info("starting pump " + pumpId); RetryingCommand.execute( () -> { @@ -89,10 +104,23 @@ public void run() { pumpId); Thread.sleep(5 * 1000); + logger.info("manual turn on of humidifier " + humidifierOutletId); + RetryingCommand.execute( + () -> { + switchbotController + .getSwitchbotAPI() + .getDeviceApi() + .sendDeviceControlCommands(humidifierOutletId, IDeviceCommands.PLUG_MINI_ON); + return null; + }, + humidifierOutletId); + + Thread.sleep(60 * 1000); // 1 min logger.info("starting humidifier " + humidifierId); GoveeDeviceCommandResponse response = GoveeApi.getInstance(API_KEY) .sendDeviceCommand(IHumidifierCommands.turnOn(humidifierModel, humidifierId)); - Thread.sleep(2 * 60 * 1000); // 2 min + + Thread.sleep(60 * 1000); // 1 min logger.info("stopping pump " + pumpId); RetryingCommand.execute( diff --git a/src/main/java/com/bigboxer23/lights/controllers/govee/HumidifierCluster.java b/src/main/java/com/bigboxer23/lights/controllers/govee/HumidifierCluster.java new file mode 100644 index 0000000..9cd019f --- /dev/null +++ b/src/main/java/com/bigboxer23/lights/controllers/govee/HumidifierCluster.java @@ -0,0 +1,13 @@ +package com.bigboxer23.lights.controllers.govee; + +import lombok.Data; + +/** */ +@Data +public class HumidifierCluster { + private String pump; + + private String humidifier; + + private String outlet; +} diff --git a/src/main/java/com/bigboxer23/lights/controllers/govee/HumidifierData.java b/src/main/java/com/bigboxer23/lights/controllers/govee/HumidifierData.java new file mode 100644 index 0000000..ef32d22 --- /dev/null +++ b/src/main/java/com/bigboxer23/lights/controllers/govee/HumidifierData.java @@ -0,0 +1,6 @@ +package com.bigboxer23.lights.controllers.govee; + +import java.util.HashMap; + +/** */ +public class HumidifierData extends HashMap {} diff --git a/src/main/java/com/bigboxer23/lights/servlets/TokenDistributionServlet.java b/src/main/java/com/bigboxer23/lights/servlets/TokenDistributionServlet.java index 8186377..9abe5e7 100644 --- a/src/main/java/com/bigboxer23/lights/servlets/TokenDistributionServlet.java +++ b/src/main/java/com/bigboxer23/lights/servlets/TokenDistributionServlet.java @@ -87,7 +87,7 @@ public void enableTokenRequest(HttpServletRequest theRequest) { }) public TokenResponse getToken(HttpServletResponse theResponse, HttpServletRequest theRequest) throws IOException { if (myTokenValidTime + kTokenValidTime > System.currentTimeMillis()) { - myLogger.error("Token distributed to " + theRequest.getRemoteAddr()); + myLogger.warn("Token distributed to " + theRequest.getRemoteAddr()); Cookie anAuthCookie = new Cookie("t", myToken); anAuthCookie.setHttpOnly(true); anAuthCookie.setSecure(true);