From d67dd8221ad4ca8342d1122d7a83bddcb9497309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20M=C3=BCller?= Date: Fri, 1 Jul 2022 13:44:30 +0200 Subject: [PATCH] Revert "#262 don't forget starting current detected if timeframe interval is not sufficient" This reverts commit 2b659a4fe7790ed49515198325b8e664c0aace5d. --- .../schedule/RuntimeRequest.java | 8 +++++--- .../schedule/TimeframeIntervalHandler.java | 16 ++-------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/main/java/de/avanux/smartapplianceenabler/schedule/RuntimeRequest.java b/src/main/java/de/avanux/smartapplianceenabler/schedule/RuntimeRequest.java index 5c678733..b7b62b70 100644 --- a/src/main/java/de/avanux/smartapplianceenabler/schedule/RuntimeRequest.java +++ b/src/main/java/de/avanux/smartapplianceenabler/schedule/RuntimeRequest.java @@ -50,6 +50,10 @@ public RuntimeRequest(Integer min, int max) { @Override public void init() { super.init(); + subscribeStartingCurrentEvents(); + } + + private void subscribeStartingCurrentEvents() { getMqttClient().subscribe(MqttEventName.StartingCurrentDetected, ControlMessage.class, (topic, message) -> { getLogger().debug("{} Handling event StartingCurrentDetected", getApplianceId()); resetRuntime(); @@ -62,9 +66,7 @@ public void init() { }); } - @Override - public void remove() { - super.remove(); + public void unsubscribeStartingCurrentEvents() { getMqttClient().unsubscribe(MqttEventName.StartingCurrentDetected); getMqttClient().unsubscribe(MqttEventName.FinishedCurrentDetected); } diff --git a/src/main/java/de/avanux/smartapplianceenabler/schedule/TimeframeIntervalHandler.java b/src/main/java/de/avanux/smartapplianceenabler/schedule/TimeframeIntervalHandler.java index f6813b97..510e8826 100644 --- a/src/main/java/de/avanux/smartapplianceenabler/schedule/TimeframeIntervalHandler.java +++ b/src/main/java/de/avanux/smartapplianceenabler/schedule/TimeframeIntervalHandler.java @@ -199,19 +199,6 @@ public void updateQueue(LocalDateTime now, boolean ignoreStartTime) { logger.debug("{}: Current Queue{}", applianceId, queue.size() > 0 ? ":" : " is empty"); logQueue(now); - if(control instanceof StartingCurrentSwitch) { - var activeTimeframeInterval = getActiveTimeframeInterval(); - if(activeTimeframeInterval != null && activeTimeframeInterval.getRequest().isEnabled() - && !activeTimeframeInterval.isIntervalSufficient(now)) { - logger.debug("{}: Handling insufficient timeframe interval with request enabled for starting current switch", applianceId); - // if starting current has been detected the request was enabled but the timeframe interval might - // be insufficient. Therefore we have to remove the timeframe interval an create and fill the queue again. - removeTimeframeInterval(now, activeTimeframeInterval); - fillQueue(now); - getFirstTimeframeInterval().getRequest().setEnabled(true); - } - } - Optional prolongableTimeframeInterval = getProlongableTimeframeInterval(now); prolongableTimeframeInterval.ifPresent(timeframeInterval -> { int indexProlongableTimeframeInterval = queue.indexOf(timeframeInterval); @@ -402,7 +389,8 @@ public void removeTimeframeInterval(LocalDateTime now, TimeframeInterval timefra queue.remove(timeframeInterval); removeTimeframeIntervalChangedListener(timeframeInterval.getRequest()); timeframeInterval.getRequest().remove(); - if(control instanceof StartingCurrentSwitch) { + if(control instanceof StartingCurrentSwitch && timeframeInterval.getRequest() instanceof RuntimeRequest) { + ((RuntimeRequest) timeframeInterval.getRequest()).unsubscribeStartingCurrentEvents(); fillQueue(now); } }