Skip to content

Commit

Permalink
Renamed variables for clarity (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
climategadgets committed Aug 4, 2024
1 parent 7855793 commit 504915f
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ public class Thermostat implements Addressable<String> {
*/
private final HysteresisController<Status<Double>> signalRenderer;

private final Sinks.Many<Signal<Double, Status<Double>>> stateSink = Sinks.many().unicast().onBackpressureBuffer();
private final Flux<Signal<Double, Status<Double>>> stateFlux = stateSink.asFlux();
/**
* Sink to accept feedback loop signals from {@link #raise()}.
*/
private final Sinks.Many<Signal<Double, Status<Double>>> raiseSink = Sinks.many().unicast().onBackpressureBuffer();
private final Flux<Signal<Double, Status<Double>>> raiseFlux = raiseSink.asFlux();

/**
* Create a thermostat with a default 10C..40C setpoint range, specified setpoint and PID values, and no sensitivity adjustment.
Expand Down Expand Up @@ -167,15 +170,15 @@ public Flux<Signal<Status<CallingStatus>, Void>> compute(Flux<Signal<Double, Voi
var stage1 = controller
.compute(pv)
.doOnNext(e -> logger.trace("controller/{}: {}", name, e))
.doOnComplete(stateSink::tryEmitComplete); // or it will hang forever
.doOnComplete(raiseSink::tryEmitComplete); // or it will hang forever

// Discard things the renderer doesn't understand.
// The PID controller output value becomes the extra payload to pass to the zone controller to calculate demand.
Flux<Signal<Double, Status<Double>>> stage2 = stage1
.map(s -> new Signal<>(s.timestamp, s.getValue().signal, s.getValue(), s.status, s.error));

// Inject signals from raise(), if any
var stage3 = Flux.merge(stage2, stateFlux);
var stage3 = Flux.merge(stage2, raiseFlux);

// Deliver the signal
// Might want to expose this as well
Expand Down Expand Up @@ -237,7 +240,7 @@ public void raise() {
logger.trace("{}: actual: {}", getAddress(), actual);
logger.trace("{}: adjusted: {}", getAddress(), adjusted);

stateSink.tryEmitNext(adjusted);
raiseSink.tryEmitNext(adjusted);

} finally {
ThreadContext.pop();
Expand Down

0 comments on commit 504915f

Please sign in to comment.