-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'gh271-heatpump' into gh47 (#271)
- Loading branch information
Showing
19 changed files
with
963 additions
and
647 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
dz3r-bootstrap/src/test/java/net/sf/dz3r/device/actuator/MqttHeatPumpTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package net.sf.dz3r.device.actuator; | ||
|
||
import net.sf.dz3r.device.esphome.v1.ESPHomeSwitch; | ||
import net.sf.dz3r.model.HvacMode; | ||
import net.sf.dz3r.signal.Signal; | ||
import net.sf.dz3r.signal.hvac.HvacCommand; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; | ||
import reactor.core.publisher.Flux; | ||
|
||
import java.io.IOException; | ||
import java.time.Duration; | ||
import java.time.Instant; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatCode; | ||
|
||
/** | ||
* Test MQTT switch race conditions when controlled by a heat pump. | ||
* | ||
* VT: NOTE: Careful, this works on real hardware, disconnect before testing. | ||
*/ | ||
@EnabledIfEnvironmentVariable( | ||
named = "TEST_DZ_ESPHOME_HEATPUMP", | ||
matches = "safe", | ||
disabledReason = "Only execute this test if a suitable MQTT broker and ESPHome switch device are available" | ||
)class ESPHomeHeatPumpTest { | ||
|
||
private final Logger logger = LogManager.getLogger(); | ||
|
||
private final String MQTT_BROKER = "mqtt-esphome"; | ||
|
||
private final String ESPHOME_SWITCH_TOPIC_ROOT = "/esphome/0156AC/switch/"; | ||
|
||
@Test | ||
void cycle() throws IOException { | ||
|
||
var switchFan = new ESPHomeSwitch(MQTT_BROKER, ESPHOME_SWITCH_TOPIC_ROOT + "t-relay-2-r0-fan"); | ||
var switchRunning = new ESPHomeSwitch(MQTT_BROKER, ESPHOME_SWITCH_TOPIC_ROOT + "t-relay-2-r1-condenser"); | ||
var switchMode = new ESPHomeSwitch(MQTT_BROKER, ESPHOME_SWITCH_TOPIC_ROOT + "t-relay-2-r2-mode"); | ||
var delay = Duration.ofSeconds(1); | ||
|
||
// This should throw a wrench into everything... | ||
Flux | ||
.just(true, true, true) | ||
.delayElements(delay) | ||
.map(switchMode::setState) | ||
.blockLast(); | ||
|
||
logger.info("set mode to 1"); | ||
|
||
try (var hp = new HeatPump( | ||
"heatpump", | ||
switchMode, true, | ||
switchRunning, false, | ||
switchFan, false, | ||
Duration.ofSeconds(3))) { | ||
|
||
var commands = Flux | ||
.just( | ||
new HvacCommand(HvacMode.COOLING, 0d, 0d), | ||
new HvacCommand(null, 1d, 1d), | ||
new HvacCommand(HvacMode.HEATING, 0d, 0d), | ||
new HvacCommand(null, 1d, 1d), | ||
new HvacCommand(null, 0d, 0d)) | ||
.delayElements(delay) | ||
.doOnNext(command -> logger.info("command: {}", command)) | ||
.map(c -> new Signal<HvacCommand, Void>(Instant.now(), c)); | ||
|
||
assertThatCode(() -> { | ||
hp | ||
.compute(commands) | ||
.doOnNext(s -> logger.info("output: {}", s)) | ||
.doOnNext(s -> { | ||
if (s.isError()) { | ||
throw new IllegalStateException("Failure output received: " + s); | ||
} | ||
}) | ||
.blockLast(); | ||
|
||
logger.info("done"); | ||
}) | ||
.doesNotThrowAnyException(); | ||
|
||
// Should close() here automatically | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Configuration status="WARN"> | ||
<Appenders> | ||
<Console name="CONSOLE" target="SYSTEM_OUT"> | ||
<PatternLayout pattern="%highlight{%d{HH:mm:ss,SSS} %level %class{1} %t %NDC %message%n}"/> | ||
</Console> | ||
</Appenders> | ||
<Loggers> | ||
<Root level="DEBUG"> | ||
<AppenderRef ref="CONSOLE"/> | ||
</Root> | ||
</Loggers> | ||
</Configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.