Skip to content

Commit

Permalink
Implicit schedule settings are no longer overriden by leftover explic…
Browse files Browse the repository at this point in the history
…it (#240)
  • Loading branch information
climategadgets committed Apr 22, 2024
1 parent a99ae35 commit 8bd2771
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public String toString() {
return "{changeoverDelta=" + changeoverDelta
+ ", targetTemperature=" + targetTemperature
+ ", keepHvacOn=" + keepHvacOn
+ ", maxPower=" + maxPower
+ "}";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ public boolean isVoting() {
return Optional.ofNullable(voting).orElse(true);
}

@JsonIgnore
public boolean isOnHold() {
return Optional.ofNullable(hold).orElse(false);
}

@JsonIgnore
public int getDumpPriority() {
return Optional.ofNullable(dumpPriority).orElse(0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.sf.dz3r.scheduler;

import net.sf.dz3r.device.actuator.economizer.EconomizerSettings;
import net.sf.dz3r.model.PeriodSettings;
import net.sf.dz3r.model.SchedulePeriod;
import net.sf.dz3r.model.Zone;
Expand All @@ -16,6 +17,7 @@
import java.time.temporal.ChronoUnit;
import java.util.AbstractMap;
import java.util.Map;
import java.util.Optional;
import java.util.SortedMap;
import java.util.TimeZone;
import java.util.TreeMap;
Expand Down Expand Up @@ -137,9 +139,32 @@ private Flux<Map.Entry<String, Map.Entry<SchedulePeriod, ZoneSettings>>> applySc
}

if (period != null) {
var settings = source.getValue().get(period);

if (Boolean.TRUE.equals(zone.getSettings().hold)) {
var parsedSettings = source.getValue().get(period);

// Have to be careful here. Some settings may have been missing from the source JSON, they have defaults.
// ZoneSettings#merge will not calculate the outcome correctly, it will treat null settings as unchanged.

var settings = new ZoneSettings(
parsedSettings.isEnabled(),
parsedSettings.setpoint,
parsedSettings.isVoting(),
parsedSettings.isOnHold(),
parsedSettings.getDumpPriority(),
Optional
.ofNullable(parsedSettings.economizerSettings)
.map(s -> new EconomizerSettings(
s.changeoverDelta,
s.targetTemperature,
s.isKeepHvacOn(),
s.getMaxPower()
))
.orElse(null)
);

logger.trace("{}: settings/parsed: {}", zoneName, parsedSettings);
logger.trace("{}: settings/actual: {}", zoneName, settings);

if (zone.getSettings().isOnHold()) {
logger.trace("{}: on hold, left alone", zoneName);

// However... need to record the period. The zone will be smart enough not to touch the settings.
Expand Down

0 comments on commit 8bd2771

Please sign in to comment.