Skip to content

Commit

Permalink
Now logging and asserting switch positions (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
climategadgets committed May 18, 2021
1 parent 73f27c5 commit a04a0c4
Showing 1 changed file with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class THTest {

private final Logger logger = LogManager.getLogger(getClass());
private static final String WRONG_POSITION = "wrong position";
private static final String WRONG_STATE = "wrong switch state";

@Test
public void testSync() throws InterruptedException, ExecutionException, IOException {
Expand All @@ -53,6 +54,14 @@ public void testSync() throws InterruptedException, ExecutionException, IOExcept
Switch switchWestDamper = new NullSwitch("switch_west_damper");
Switch switchWestBoosterFan = new NullSwitch("switch_west_boosterfan");

Set<Switch> switches = new LinkedHashSet<>();

switches.add(switchLivingRoom);
switches.add(switchKitchen);
switches.add(switchWestBathroom);
switches.add(switchWestDamper);
switches.add(switchWestBoosterFan);

Damper damperLivingRoom = new SwitchDamper("damper_livingroom", switchLivingRoom, 0.8, 1.0);
Damper damperKitchen = new SwitchDamper("damper_kitchen", switchKitchen, 0.8, 1.0);
Damper damperWestBathroom = new SwitchDamper("damper_westbathroom", switchWestBathroom, 0.8, 1.0);
Expand Down Expand Up @@ -100,7 +109,7 @@ public void testSync() throws InterruptedException, ExecutionException, IOExcept

// The unit is off, dampers are parked

logPositions(dampers);
logStatus(dampers, switches);

assertEquals(WRONG_POSITION, damperLivingRoom.getParkPosition(), damperLivingRoom.getPosition(), 0.0001);
assertEquals(WRONG_POSITION, damperKitchen.getParkPosition(), damperKitchen.getPosition(), 0.0001);
Expand All @@ -109,12 +118,16 @@ public void testSync() throws InterruptedException, ExecutionException, IOExcept
assertEquals(WRONG_POSITION, damperWest.getParkPosition(), damperWest.getPosition(), 0.0001);
assertEquals(WRONG_POSITION, damperWestBoosterFan.getParkPosition(), damperWestBoosterFan.getPosition(), 0.0001);

// To be continued...
assertEquals(WRONG_STATE, true, switchLivingRoom.getState());
assertEquals(WRONG_STATE, true, switchKitchen.getState());
assertEquals(WRONG_STATE, true, switchWestBathroom.getState());
assertEquals(WRONG_STATE, true, switchWestDamper.getState());
assertEquals(WRONG_STATE, false, switchWestBoosterFan.getState());

// VT: FIXME: Assert and log switch states
// To be continued...
}

private void logPositions(Set<Damper> dampers) {
private void logStatus(Set<Damper> dampers, Set<Switch> switches) {
ThreadContext.push("position");

dampers.stream().forEach(d -> {
Expand All @@ -125,6 +138,17 @@ private void logPositions(Set<Damper> dampers) {
}
});

ThreadContext.pop();
ThreadContext.push("state");

switches.stream().forEach(s -> {
try {
logger.info("{}: {}", s.getAddress(), s.getState());
} catch (IOException ex) {
// This damper won't throw it
}
});

ThreadContext.pop();
}

Expand Down

0 comments on commit a04a0c4

Please sign in to comment.