Skip to content

Commit

Permalink
Replaced field injections with constructor injections (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
climategadgets committed Sep 22, 2023
1 parent 161f684 commit 70f4be7
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,8 @@ private Map<Zone, Flux<Signal<Double, Void>>> flip(Map<Flux<Signal<Double, Void>

private CellAndPanel<HvacDeviceStatus, Void> createUnitPair(String address, Flux<Signal<HvacDeviceStatus, Void>> source) {

var cell = new UnitCell();
var panel = new UnitPanel(address, config.screen);

source.subscribe(cell::consumeSignal);
source.subscribe(panel::consumeSignal);
var cell = new UnitCell(source);
var panel = new UnitPanel(address, config.screen, source);

return new CellAndPanel<>(cell, panel);
}
Expand All @@ -149,8 +146,6 @@ private CellAndPanel<ZoneStatus, Void> createZonePair(
Flux<Map.Entry<String, Map.Entry<SchedulePeriod, ZoneSettings>>> scheduleFlux) {

var zoneName = zone.getAddress();
var cell = new ZoneCell(zoneName);
var panel = new ZonePanel(zone, config.screen, config.console().initialUnit());

var thisZoneFlux = aggregateZoneFlux
.filter(s -> zoneName.equals(s.payload))
Expand All @@ -162,18 +157,16 @@ private CellAndPanel<ZoneStatus, Void> createZonePair(
.filter(s -> zoneName.equals(s.getKey()))
.map(Map.Entry::getValue);

thisZoneFlux.subscribe(cell::consumeSignal);
thisZoneFlux.subscribe(panel::consumeSignal);

// Zones and zone controller have no business knowing about the sensor signal, but humans want it; inject it
sensorFlux.subscribe(panel::consumeSensorSignal);

// Zones and zone controller have no business knowing about HVAC mode; inject it
modeFlux.subscribe(cell::consumeMode);
modeFlux.subscribe(panel::consumeMode);

// Need to display schedule period and deviation, inject it
thisScheduleFlux.subscribe(panel::consumeSchedule);
var cell = new ZoneCell(
zoneName,
thisZoneFlux,
modeFlux);
var panel = new ZonePanel(
zone, config.screen, config.console().initialUnit(),
thisZoneFlux,
sensorFlux,
modeFlux,
thisScheduleFlux);

return new CellAndPanel<>(cell, panel);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package net.sf.dz3r.view.swing.unit;

import net.sf.dz3r.signal.Signal;
import net.sf.dz3r.signal.hvac.HvacDeviceStatus;
import net.sf.dz3r.view.swing.ColorScheme;
import net.sf.dz3r.view.swing.EntityCell;
import reactor.core.publisher.Flux;

import java.awt.Color;
import java.awt.Dimension;
Expand All @@ -11,8 +13,9 @@

public class UnitCell extends EntityCell<HvacDeviceStatus, Void> {

public UnitCell() {
public UnitCell(Flux<Signal<HvacDeviceStatus, Void>> signal) {
setPreferredSize(new Dimension(20, 70));
signal.subscribe(this::consumeSignal);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.sf.dz3r.view.swing.ColorScheme;
import net.sf.dz3r.view.swing.EntityPanel;
import net.sf.dz3r.view.swing.ScreenDescriptor;
import reactor.core.publisher.Flux;

import javax.swing.JLabel;
import javax.swing.JPanel;
Expand Down Expand Up @@ -32,12 +33,14 @@ public class UnitPanel extends EntityPanel<HvacDeviceStatus, Void> {

private final UnitChart unitChart = new UnitChart(Clock.systemUTC());

public UnitPanel(String name, ScreenDescriptor screenDescriptor) {
public UnitPanel(String name, ScreenDescriptor screenDescriptor, Flux<Signal<HvacDeviceStatus, Void>> signal) {

this.name = name;

setFontSize(screenDescriptor);
initGraphics();

signal.subscribe(this::consumeSignal);
}

@SuppressWarnings("squid:S1199")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.sf.dz3r.signal.hvac.ZoneStatus;
import net.sf.dz3r.view.swing.ColorScheme;
import net.sf.dz3r.view.swing.EntityCell;
import reactor.core.publisher.Flux;

import java.awt.Color;
import java.awt.Dimension;
Expand All @@ -21,9 +22,12 @@ public class ZoneCell extends EntityCell<ZoneStatus, Void> {

private HvacMode hvacMode;

public ZoneCell(String name) {
public ZoneCell(String name, Flux<Signal<ZoneStatus, Void>> zoneFlux, Flux<Signal<HvacMode, Void>> modeFlux) {
setPreferredSize(new Dimension(20, 70));
setToolTipText(name);

zoneFlux.subscribe(this::consumeSignal);
modeFlux.subscribe(this::consumeMode);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,18 @@ public class ZonePanel extends EntityPanel<ZoneStatus, Void> {
*/
private HvacMode hvacMode;

public ZonePanel(Zone zone, ScreenDescriptor screenDescriptor, TemperatureUnit defaultUnit) {
/**
* Create an instance.
*
* @param zone Zone to display the status of.
* @param defaultUnit Temperature unit at instantiation time.
*/
public ZonePanel(Zone zone, ScreenDescriptor screenDescriptor, TemperatureUnit defaultUnit,
Flux<Signal<ZoneStatus, Void>> zoneFlux,
Flux<Signal<Double, Void>> sensorFlux,
Flux<Signal<HvacMode, Void>> modeFlux,
Flux<Map.Entry<SchedulePeriod, ZoneSettings>> scheduleFlux) {

this.zone = zone;

needFahrenheit = defaultUnit == TemperatureUnit.F;
Expand All @@ -116,6 +127,12 @@ public ZonePanel(Zone zone, ScreenDescriptor screenDescriptor, TemperatureUnit d
setFontSize(screenDescriptor);

initGraphics();

zoneFlux.subscribe(this::consumeSignal);
sensorFlux.subscribe(this::consumeSensorSignal);
modeFlux.subscribe(this::consumeMode);
scheduleFlux.subscribe(this::consumeSchedule);

initKeyStream();
}

Expand Down

0 comments on commit 70f4be7

Please sign in to comment.