Skip to content

Commit

Permalink
Minor refactoring - removed redundant indirections (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
climategadgets committed Sep 22, 2023
1 parent 675e56e commit 0ed8d41
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void connect(UnitDirector.Feed feed) {
var zoneRenderer = new ZoneRenderer();

// Zones and zone controller have no business knowing about the sensor signal, but humans want it; inject it
zoneRenderer.subscribeSensor(getAggregateSensorFlux(feed.sensorFlux2zone));
getAggregateSensorFlux(feed.sensorFlux2zone).subscribe(zoneRenderer::consumeSensorSignal);

// Zones and zone controller have no business knowing about HVAC mode; inject it
var modeFlux = feed.hvacDeviceFlux
Expand All @@ -85,7 +85,7 @@ public void connect(UnitDirector.Feed feed) {
})
.filter(s -> s.getValue().command.mode != null)
.map(s -> new Signal<HvacMode, Void>(s.timestamp, s.getValue().command.mode, null, s.status, s.error));
zoneRenderer.subscribeMode(modeFlux);
modeFlux.subscribe(zoneRenderer::consumeMode);

// Zone ("thermostat" in its terminology) status feed is the only one supported
var zoneStatusFeed =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,12 @@ private ZoneState renderState(boolean on, boolean calling) {
HvacMode.HEATING, net.sf.dz3r.view.http.gae.v3.wire.HvacMode.HEATING
);

public void subscribeSensor(Flux<Signal<Double, String>> sensorFlux) {
sensorFlux.subscribe(this::consumeSensorSignal);
}

private void consumeSensorSignal(Signal<Double, String> sensorSignal) {
public void consumeSensorSignal(Signal<Double, String> sensorSignal) {
this.sensorSignal = sensorSignal;
logger.debug("sensorSignal: {}", sensorSignal);
}

public void subscribeMode(Flux<Signal<HvacMode, Void>> in) {
in.doOnNext(this::consumeMode).subscribe();
}

private void consumeMode(Signal<HvacMode, Void> signal) {
public void consumeMode(Signal<HvacMode, Void> signal) {
logger.debug("Mode: {}", signal.getValue());
this.hvacMode = signal.getValue();
}
Expand Down

0 comments on commit 0ed8d41

Please sign in to comment.