Skip to content

Commit

Permalink
Revert "#262 don't forget starting current detected if timeframe inte…
Browse files Browse the repository at this point in the history
…rval is not sufficient"

This reverts commit 2b659a4.
  • Loading branch information
Axel Müller committed Jul 1, 2022
1 parent 8de40b5 commit d67dd82
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -62,9 +66,7 @@ public void init() {
});
}

@Override
public void remove() {
super.remove();
public void unsubscribeStartingCurrentEvents() {
getMqttClient().unsubscribe(MqttEventName.StartingCurrentDetected);
getMqttClient().unsubscribe(MqttEventName.FinishedCurrentDetected);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TimeframeInterval> prolongableTimeframeInterval = getProlongableTimeframeInterval(now);
prolongableTimeframeInterval.ifPresent(timeframeInterval -> {
int indexProlongableTimeframeInterval = queue.indexOf(timeframeInterval);
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit d67dd82

Please sign in to comment.