From aad6cc52ce61a682abfe9863f0a8bbdc45f6c033 Mon Sep 17 00:00:00 2001 From: "Claudio Maggioni (maggicl)" Date: Sun, 3 May 2020 14:14:24 +0200 Subject: [PATCH] Fixed thermostat socket updates --- .../sanmarinoes/smarthut/models/Thermostat.java | 17 ++++------------- .../smarthut/service/ThermostatService.java | 12 +++++------- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Thermostat.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Thermostat.java index e501ba4..632dfd7 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Thermostat.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Thermostat.java @@ -24,14 +24,10 @@ public class Thermostat extends Switchable implements BooleanTriggerable { computeState(); } - /** - * Computes the new thermostat state, for when the thermostat is on; - * - * @return true if the state changed, false if not; - */ - public boolean computeState() { + /** Computes the new thermostat state, for when the thermostat is on */ + public void computeState() { if (mode == Thermostat.Mode.OFF) { - return false; + return; } BigDecimal measured = this.getMeasuredTemperature(); @@ -39,23 +35,18 @@ public class Thermostat extends Switchable implements BooleanTriggerable { if (measured == null) { this.setMode(Thermostat.Mode.IDLE); - return true; + return; } BigDecimal delta = target.subtract(measured); if (delta.abs().doubleValue() < 0.25) { - if (this.getMode() == Thermostat.Mode.IDLE) return false; this.setMode(Thermostat.Mode.IDLE); } else if (delta.signum() > 0) { - if (this.getMode() == Thermostat.Mode.HEATING) return false; this.setMode(Thermostat.Mode.HEATING); } else { - if (this.getMode() == Thermostat.Mode.COOLING) return false; this.setMode(Thermostat.Mode.COOLING); } - - return true; } @Override diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/ThermostatService.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/ThermostatService.java index cdbb92c..91d0b18 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/ThermostatService.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/ThermostatService.java @@ -45,18 +45,16 @@ public class ThermostatService { return Utils.toList(all); } - public boolean computeState(Thermostat t) { + public void computeState(Thermostat t) { populateMeasuredTemperature(t); - return t.computeState(); + t.computeState(); } private void updateState(Thermostat t) { - boolean shouldUpdate = this.computeState(t); + this.computeState(t); - if (shouldUpdate) { - deviceService.saveAsOwner(t, thermostatRepository.findUser(t.getId()).getUsername()); - endpoint.queueDeviceUpdate(t, thermostatRepository.findUser(t.getId())); - } + deviceService.saveAsOwner(t, thermostatRepository.findUser(t.getId()).getUsername()); + endpoint.queueDeviceUpdate(t, thermostatRepository.findUser(t.getId())); } public void updateStates() {