From c3c424778d12cc5e6c36b0f79a080427993f68e7 Mon Sep 17 00:00:00 2001 From: Vadim Tkachenko Date: Fri, 5 Apr 2024 20:12:39 -0700 Subject: [PATCH] Renamed classes for consistency (#311) --- .../config/model/ZoneConfigurationParser.java | 6 +- .../economizer/AbstractEconomizer.java | 14 +-- .../actuator/economizer/EconomizerConfig.java | 104 ++++++++++++++++++ .../economizer/EconomizerContext.java | 6 +- .../economizer/EconomizerSettings.java | 97 ++++------------ .../EconomizerTransientSettings.java | 53 --------- .../economizer/v1/SimpleEconomizer.java | 4 +- .../actuator/economizer/v2/PidEconomizer.java | 4 +- .../sf/dz3r/signal/hvac/EconomizerStatus.java | 6 +- .../economizer/AbstractEconomizerTest.java | 6 +- .../economizer/v1/SimpleEconomizerTest.java | 6 +- 11 files changed, 153 insertions(+), 153 deletions(-) create mode 100644 modules/hcc-model/src/main/java/net/sf/dz3r/device/actuator/economizer/EconomizerConfig.java delete mode 100644 modules/hcc-model/src/main/java/net/sf/dz3r/device/actuator/economizer/EconomizerTransientSettings.java diff --git a/modules/hcc-bootstrap/src/main/java/net/sf/dz3r/runtime/config/model/ZoneConfigurationParser.java b/modules/hcc-bootstrap/src/main/java/net/sf/dz3r/runtime/config/model/ZoneConfigurationParser.java index a8fd6e221..2a32c5bb0 100644 --- a/modules/hcc-bootstrap/src/main/java/net/sf/dz3r/runtime/config/model/ZoneConfigurationParser.java +++ b/modules/hcc-bootstrap/src/main/java/net/sf/dz3r/runtime/config/model/ZoneConfigurationParser.java @@ -1,8 +1,8 @@ package net.sf.dz3r.runtime.config.model; import net.sf.dz3r.common.HCCObjects; +import net.sf.dz3r.device.actuator.economizer.EconomizerConfig; import net.sf.dz3r.device.actuator.economizer.EconomizerContext; -import net.sf.dz3r.device.actuator.economizer.EconomizerSettings; import net.sf.dz3r.model.Range; import net.sf.dz3r.model.Thermostat; import net.sf.dz3r.model.Zone; @@ -49,7 +49,7 @@ private Map.Entry createZone(ZoneConfig cf) { return new ImmutablePair<>(cf.id(), zone); } - private EconomizerContext createEconomizer(String zoneName, EconomizerConfig cf) { + private EconomizerContext createEconomizer(String zoneName, net.sf.dz3r.runtime.config.model.EconomizerConfig cf) { if (cf == null) { return null; @@ -76,7 +76,7 @@ private EconomizerContext createEconomizer(String zoneName, EconomizerConfig cf) } return new EconomizerContext( - new EconomizerSettings( + new EconomizerConfig( cf.mode(), cf.settings().changeoverDelta(), cf.settings().targetTemperature(), diff --git a/modules/hcc-model/src/main/java/net/sf/dz3r/device/actuator/economizer/AbstractEconomizer.java b/modules/hcc-model/src/main/java/net/sf/dz3r/device/actuator/economizer/AbstractEconomizer.java index 24c42cf29..ed9867edb 100644 --- a/modules/hcc-model/src/main/java/net/sf/dz3r/device/actuator/economizer/AbstractEconomizer.java +++ b/modules/hcc-model/src/main/java/net/sf/dz3r/device/actuator/economizer/AbstractEconomizer.java @@ -38,7 +38,7 @@ public abstract class AbstractEconomizer implements SignalProcessor logger.debug("{}: HVAC device state/done: {}", getAddress(), s)); this.economizerStatus = new EconomizerStatus( - new EconomizerTransientSettings(settings), + new EconomizerSettings(settings), null, 0, false, null); // Don't forget to connect fluxes; this can only be done in subclasses after all the @@ -119,7 +119,7 @@ private void checkModes(HvacMode mode, HvacDevice device) { } } - public void setSettings(EconomizerSettings settings) { + public void setSettings(EconomizerConfig settings) { if (settings == null) { throw new IllegalArgumentException("settings can't be null"); } @@ -206,7 +206,7 @@ private Boolean recordDeviceState(SignalVadim Tkachenko 2001-2024 + */ +public class EconomizerConfig extends EconomizerSettings { + + /** + * Which mode this device is active in. This mode may be different from the zone mode; it is the user's + * responsibility to make sure the system doesn't enter a runaway loop. + */ + public final HvacMode mode; + + public final Double P; + + public final Double I; + + public final Double saturationLimit; + + /** + * All except {@code enabled} argument constructor (defaults to {@code true}, for common sense. + * + * @param keepHvacOn See {@link #keepHvacOn}. Think twice before setting this to {@code true}. + * @param P Internal {@link net.sf.dz3r.controller.pid.PidController} P component. + * @param I Internal {@link net.sf.dz3r.controller.pid.PidController} I component. + * @param saturationLimit Internal {@link net.sf.dz3r.controller.pid.PidController} saturation limit. + */ + public EconomizerConfig(HvacMode mode, + Double changeoverDelta, Double targetTemperature, + Boolean keepHvacOn, + Double P, Double I, Double saturationLimit) { + this(mode, true, changeoverDelta, targetTemperature, keepHvacOn, P, I, saturationLimit); + } + + /** + * All argument constructor. + * + * @param keepHvacOn See {@link #keepHvacOn}. Think twice before setting this to {@code true}. + * @param P Internal {@link net.sf.dz3r.controller.pid.PidController} P component. + * @param I Internal {@link net.sf.dz3r.controller.pid.PidController} I component. + * @param saturationLimit Internal {@link net.sf.dz3r.controller.pid.PidController} saturation limit. + */ + public EconomizerConfig(HvacMode mode, + Boolean enabled, + Double changeoverDelta, Double targetTemperature, + Boolean keepHvacOn, + Double P, Double I, Double saturationLimit) { + super(enabled, changeoverDelta, targetTemperature, keepHvacOn); + + this.mode = mode; + + this.P = P; + this.I = I; + this.saturationLimit = saturationLimit; + + checkArgs(); + } + + protected void checkArgs() { + + if (mode == null) { + throw new IllegalArgumentException("mode can't be null"); + } + + if (changeoverDelta < 0) { + throw new IllegalArgumentException("changeoverDelta must be non-negative"); + } + } + + /** + * Merge this instance with an update. + * + * @param from Adjustment instance. Non-null values take precedence over this object's values. + */ + public EconomizerConfig merge(EconomizerConfig from) { + + return new EconomizerConfig( + from.mode != null ? from.mode : mode, + from.enabled != null ? from.enabled : enabled, + from.changeoverDelta != null ? from.changeoverDelta : changeoverDelta, + from.targetTemperature != null ? from.targetTemperature : targetTemperature, + from.keepHvacOn != null ? from.keepHvacOn : keepHvacOn, + from.P != null ? from.P : P, + from.I != null ? from.I : I, + from.saturationLimit != null ? from.saturationLimit : saturationLimit); + } + + @Override + public String toString() { + return "{mode=" + mode + + ", enabled=" + enabled + + ", changeoverDelta=" + changeoverDelta + + ", targetTemperature=" + targetTemperature + + ", keepHvacOn=" + keepHvacOn + + ", P=" + P + + ", I=" + I + + ", saturationLimit=" + saturationLimit + + "}"; + } +} diff --git a/modules/hcc-model/src/main/java/net/sf/dz3r/device/actuator/economizer/EconomizerContext.java b/modules/hcc-model/src/main/java/net/sf/dz3r/device/actuator/economizer/EconomizerContext.java index cebd0cd60..8aa4627e4 100644 --- a/modules/hcc-model/src/main/java/net/sf/dz3r/device/actuator/economizer/EconomizerContext.java +++ b/modules/hcc-model/src/main/java/net/sf/dz3r/device/actuator/economizer/EconomizerContext.java @@ -7,16 +7,16 @@ import java.time.Duration; /** - * A bridge between {@link EconomizerSettings}, {@link AbstractEconomizer economizer}, and {@link net.sf.dz3r.model.Zone}. + * A bridge between {@link EconomizerConfig}, {@link AbstractEconomizer economizer}, and {@link net.sf.dz3r.model.Zone}. */ public class EconomizerContext { - public final EconomizerSettings settings; + public final EconomizerConfig settings; public final Flux> ambientFlux; public final HvacDevice device; public final Duration timeout; - public EconomizerContext(EconomizerSettings settings, Flux> ambientFlux, HvacDevice device, Duration timeout) { + public EconomizerContext(EconomizerConfig settings, Flux> ambientFlux, HvacDevice device, Duration timeout) { this.settings = settings; this.ambientFlux = ambientFlux; this.device = device; diff --git a/modules/hcc-model/src/main/java/net/sf/dz3r/device/actuator/economizer/EconomizerSettings.java b/modules/hcc-model/src/main/java/net/sf/dz3r/device/actuator/economizer/EconomizerSettings.java index 951775d77..a37826402 100644 --- a/modules/hcc-model/src/main/java/net/sf/dz3r/device/actuator/economizer/EconomizerSettings.java +++ b/modules/hcc-model/src/main/java/net/sf/dz3r/device/actuator/economizer/EconomizerSettings.java @@ -1,104 +1,53 @@ package net.sf.dz3r.device.actuator.economizer; -import net.sf.dz3r.model.HvacMode; - /** - * Full set of economizer settings. + * Set of user changeable economizer settings. * * @author Copyright © Vadim Tkachenko 2001-2024 */ -public class EconomizerSettings extends EconomizerTransientSettings { +public class EconomizerSettings { + + public final Boolean enabled; /** - * Which mode this device is active in. This mode may be different from the zone mode; it is the user's - * responsibility to make sure the system doesn't enter a runaway loop. + * Temperature difference between indoor and outdoor temperature necessary to turn the device on. */ - public final HvacMode mode; - - public final Double P; - - public final Double I; - - public final Double saturationLimit; + public final Double changeoverDelta; /** - * All except {@code enabled} argument constructor (defaults to {@code true}, for common sense. - * - * @param keepHvacOn See {@link #keepHvacOn}. Think twice before setting this to {@code true}. - * @param P Internal {@link net.sf.dz3r.controller.pid.PidController} P component. - * @param I Internal {@link net.sf.dz3r.controller.pid.PidController} I component. - * @param saturationLimit Internal {@link net.sf.dz3r.controller.pid.PidController} saturation limit. + * When this temperature is reached, the device is shut off. */ - public EconomizerSettings(HvacMode mode, - Double changeoverDelta, Double targetTemperature, - Boolean keepHvacOn, - Double P, Double I, Double saturationLimit) { - this(mode, true, changeoverDelta, targetTemperature, keepHvacOn, P, I, saturationLimit); - } + public final Double targetTemperature; /** - * All argument constructor. - * - * @param keepHvacOn See {@link #keepHvacOn}. Think twice before setting this to {@code true}. - * @param P Internal {@link net.sf.dz3r.controller.pid.PidController} P component. - * @param I Internal {@link net.sf.dz3r.controller.pid.PidController} I component. - * @param saturationLimit Internal {@link net.sf.dz3r.controller.pid.PidController} saturation limit. + * {@code true} means that turning on the device will NOT turn the HVAC off. + * You probably want to keep this at {@code false}, unless the indoor temperature is measured at HVAC return + * and fresh air is injected into HVAC return. */ - public EconomizerSettings(HvacMode mode, - Boolean enabled, - Double changeoverDelta, Double targetTemperature, - Boolean keepHvacOn, - Double P, Double I, Double saturationLimit) { - super(enabled, changeoverDelta, targetTemperature, keepHvacOn); - - this.mode = mode; + public final Boolean keepHvacOn; - this.P = P; - this.I = I; - this.saturationLimit = saturationLimit; + public EconomizerSettings(Boolean enabled, Double changeoverDelta, Double targetTemperature, Boolean keepHvacOn) { - checkArgs(); + this.enabled = enabled; + this.changeoverDelta = changeoverDelta; + this.targetTemperature = targetTemperature; + this.keepHvacOn = keepHvacOn; } - protected void checkArgs() { - - if (mode == null) { - throw new IllegalArgumentException("mode can't be null"); - } - - if (changeoverDelta < 0) { - throw new IllegalArgumentException("changeoverDelta must be non-negative"); - } - } - - /** - * Merge this instance with an update. - * - * @param from Adjustment instance. Non-null values take precedence over this object's values. - */ - public EconomizerSettings merge(EconomizerSettings from) { + public EconomizerSettings(EconomizerConfig source) { - return new EconomizerSettings( - from.mode != null ? from.mode : mode, - from.enabled != null ? from.enabled : enabled, - from.changeoverDelta != null ? from.changeoverDelta : changeoverDelta, - from.targetTemperature != null ? from.targetTemperature : targetTemperature, - from.keepHvacOn != null ? from.keepHvacOn : keepHvacOn, - from.P != null ? from.P : P, - from.I != null ? from.I : I, - from.saturationLimit != null ? from.saturationLimit : saturationLimit); + this.enabled = source.enabled; + this.changeoverDelta = source.changeoverDelta; + this.targetTemperature = source.targetTemperature; + this.keepHvacOn = source.keepHvacOn; } @Override public String toString() { - return "{mode=" + mode - + ", enabled=" + enabled + return "{enabled=" + enabled + ", changeoverDelta=" + changeoverDelta + ", targetTemperature=" + targetTemperature + ", keepHvacOn=" + keepHvacOn - + ", P=" + P - + ", I=" + I - + ", saturationLimit=" + saturationLimit + "}"; } } diff --git a/modules/hcc-model/src/main/java/net/sf/dz3r/device/actuator/economizer/EconomizerTransientSettings.java b/modules/hcc-model/src/main/java/net/sf/dz3r/device/actuator/economizer/EconomizerTransientSettings.java deleted file mode 100644 index 010d194f6..000000000 --- a/modules/hcc-model/src/main/java/net/sf/dz3r/device/actuator/economizer/EconomizerTransientSettings.java +++ /dev/null @@ -1,53 +0,0 @@ -package net.sf.dz3r.device.actuator.economizer; - -/** - * Set of economizer settings that can change over time by the user. - * - * @author Copyright © Vadim Tkachenko 2001-2024 - */ -public class EconomizerTransientSettings { - - public final Boolean enabled; - - /** - * Temperature difference between indoor and outdoor temperature necessary to turn the device on. - */ - public final Double changeoverDelta; - - /** - * When this temperature is reached, the device is shut off. - */ - public final Double targetTemperature; - - /** - * {@code true} means that turning on the device will NOT turn the HVAC off. - * You probably want to keep this at {@code false}, unless the indoor temperature is measured at HVAC return - * and fresh air is injected into HVAC return. - */ - public final Boolean keepHvacOn; - - public EconomizerTransientSettings(Boolean enabled, Double changeoverDelta, Double targetTemperature, Boolean keepHvacOn) { - - this.enabled = enabled; - this.changeoverDelta = changeoverDelta; - this.targetTemperature = targetTemperature; - this.keepHvacOn = keepHvacOn; - } - - public EconomizerTransientSettings(EconomizerSettings source) { - - this.enabled = source.enabled; - this.changeoverDelta = source.changeoverDelta; - this.targetTemperature = source.targetTemperature; - this.keepHvacOn = source.keepHvacOn; - } - - @Override - public String toString() { - return "{enabled=" + enabled - + ", changeoverDelta=" + changeoverDelta - + ", targetTemperature=" + targetTemperature - + ", keepHvacOn=" + keepHvacOn - + "}"; - } -} diff --git a/modules/hcc-model/src/main/java/net/sf/dz3r/device/actuator/economizer/v1/SimpleEconomizer.java b/modules/hcc-model/src/main/java/net/sf/dz3r/device/actuator/economizer/v1/SimpleEconomizer.java index c61cf25b4..104e4897e 100644 --- a/modules/hcc-model/src/main/java/net/sf/dz3r/device/actuator/economizer/v1/SimpleEconomizer.java +++ b/modules/hcc-model/src/main/java/net/sf/dz3r/device/actuator/economizer/v1/SimpleEconomizer.java @@ -3,7 +3,7 @@ import net.sf.dz3r.controller.ProcessController; import net.sf.dz3r.device.actuator.HvacDevice; import net.sf.dz3r.device.actuator.economizer.AbstractEconomizer; -import net.sf.dz3r.device.actuator.economizer.EconomizerSettings; +import net.sf.dz3r.device.actuator.economizer.EconomizerConfig; import net.sf.dz3r.signal.Signal; import org.apache.logging.log4j.ThreadContext; import reactor.core.publisher.Flux; @@ -30,7 +30,7 @@ public class SimpleEconomizer> extends AbstractEconomize */ public SimpleEconomizer( String name, - EconomizerSettings settings, + EconomizerConfig settings, Flux> ambientFlux, HvacDevice device, Duration timeout) { diff --git a/modules/hcc-model/src/main/java/net/sf/dz3r/device/actuator/economizer/v2/PidEconomizer.java b/modules/hcc-model/src/main/java/net/sf/dz3r/device/actuator/economizer/v2/PidEconomizer.java index be2775ea9..69fae8db0 100644 --- a/modules/hcc-model/src/main/java/net/sf/dz3r/device/actuator/economizer/v2/PidEconomizer.java +++ b/modules/hcc-model/src/main/java/net/sf/dz3r/device/actuator/economizer/v2/PidEconomizer.java @@ -6,7 +6,7 @@ import net.sf.dz3r.controller.pid.SimplePidController; import net.sf.dz3r.device.actuator.HvacDevice; import net.sf.dz3r.device.actuator.economizer.AbstractEconomizer; -import net.sf.dz3r.device.actuator.economizer.EconomizerSettings; +import net.sf.dz3r.device.actuator.economizer.EconomizerConfig; import net.sf.dz3r.model.Thermostat; import net.sf.dz3r.signal.Signal; import org.apache.logging.log4j.ThreadContext; @@ -52,7 +52,7 @@ public class PidEconomizer> extends AbstractEconomizer { public PidEconomizer( Clock clock, String name, - EconomizerSettings settings, + EconomizerConfig settings, Flux> ambientFlux, HvacDevice device, Duration timeout) { diff --git a/modules/hcc-model/src/main/java/net/sf/dz3r/signal/hvac/EconomizerStatus.java b/modules/hcc-model/src/main/java/net/sf/dz3r/signal/hvac/EconomizerStatus.java index a43ff8393..31a0aa15a 100644 --- a/modules/hcc-model/src/main/java/net/sf/dz3r/signal/hvac/EconomizerStatus.java +++ b/modules/hcc-model/src/main/java/net/sf/dz3r/signal/hvac/EconomizerStatus.java @@ -1,6 +1,6 @@ package net.sf.dz3r.signal.hvac; -import net.sf.dz3r.device.actuator.economizer.EconomizerTransientSettings; +import net.sf.dz3r.device.actuator.economizer.EconomizerSettings; import net.sf.dz3r.signal.Signal; /** @@ -12,11 +12,11 @@ */ public class EconomizerStatus { - public final EconomizerTransientSettings settings; + public final EconomizerSettings settings; public final CallingStatus callingStatus; public final Signal ambient; - public EconomizerStatus(EconomizerTransientSettings settings, Double sample, double demand, boolean calling, Signal ambient) { + public EconomizerStatus(EconomizerSettings settings, Double sample, double demand, boolean calling, Signal ambient) { this.settings = settings; this.callingStatus = new CallingStatus(sample, demand, calling); diff --git a/modules/hcc-model/src/test/java/net/sf/dz3r/device/actuator/economizer/AbstractEconomizerTest.java b/modules/hcc-model/src/test/java/net/sf/dz3r/device/actuator/economizer/AbstractEconomizerTest.java index 0dd6d302b..20d16421e 100644 --- a/modules/hcc-model/src/test/java/net/sf/dz3r/device/actuator/economizer/AbstractEconomizerTest.java +++ b/modules/hcc-model/src/test/java/net/sf/dz3r/device/actuator/economizer/AbstractEconomizerTest.java @@ -19,13 +19,13 @@ class AbstractEconomizerTest { /** - * Make sure that control signal is computed properly as the indoor temperature is approaching the {@link EconomizerSettings#targetTemperature}. + * Make sure that control signal is computed properly as the indoor temperature is approaching the {@link EconomizerConfig#targetTemperature}. */ @ParameterizedTest @MethodSource("targetAdjustmentProvider") void targetAdjustmentTest(TargetAdjustmentTestData source) { - var settings = new EconomizerSettings( + var settings = new EconomizerConfig( source.mode, source.changeoverDelta, source.targetTemperature, @@ -59,7 +59,7 @@ private class TestEconomizer extends AbstractEconomizer { * * @param device HVAC device acting as the economizer. */ - protected TestEconomizer(String name, EconomizerSettings settings, HvacDevice device) { + protected TestEconomizer(String name, EconomizerConfig settings, HvacDevice device) { super(Clock.systemUTC(), name, settings, device, Duration.ofSeconds(90)); } diff --git a/modules/hcc-model/src/test/java/net/sf/dz3r/device/actuator/economizer/v1/SimpleEconomizerTest.java b/modules/hcc-model/src/test/java/net/sf/dz3r/device/actuator/economizer/v1/SimpleEconomizerTest.java index 3b96b87d9..423aefe52 100644 --- a/modules/hcc-model/src/test/java/net/sf/dz3r/device/actuator/economizer/v1/SimpleEconomizerTest.java +++ b/modules/hcc-model/src/test/java/net/sf/dz3r/device/actuator/economizer/v1/SimpleEconomizerTest.java @@ -2,7 +2,7 @@ import net.sf.dz3r.device.actuator.NullCqrsSwitch; import net.sf.dz3r.device.actuator.SwitchableHvacDevice; -import net.sf.dz3r.device.actuator.economizer.EconomizerSettings; +import net.sf.dz3r.device.actuator.economizer.EconomizerConfig; import net.sf.dz3r.model.HvacMode; import net.sf.dz3r.signal.Signal; import org.apache.logging.log4j.LogManager; @@ -37,7 +37,7 @@ void dropToOnAndBack() { // Target temperature is below the lowest in the ambient flux, // the economizer will just turn on and off - var settings = new EconomizerSettings( + var settings = new EconomizerConfig( HvacMode.COOLING, true, 2.0, @@ -91,7 +91,7 @@ void dropToBelowTargetAndBack() { // Target temperature is within the range of the ambient flux, // the economizer will turn on, then off, then on and off again - var settings = new EconomizerSettings( + var settings = new EconomizerConfig( HvacMode.COOLING, true, 2.0,