Merge branch 'dev' of lab.si.usi.ch:sa4-2020/the-sanmarinoes/backend into guests-fix
This commit is contained in:
commit
4a963115bb
2 changed files with 9 additions and 20 deletions
|
@ -24,14 +24,10 @@ public class Thermostat extends Switchable implements BooleanTriggerable {
|
||||||
computeState();
|
computeState();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Computes the new thermostat state, for when the thermostat is on */
|
||||||
* Computes the new thermostat state, for when the thermostat is on;
|
public void computeState() {
|
||||||
*
|
|
||||||
* @return true if the state changed, false if not;
|
|
||||||
*/
|
|
||||||
public boolean computeState() {
|
|
||||||
if (mode == Thermostat.Mode.OFF) {
|
if (mode == Thermostat.Mode.OFF) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BigDecimal measured = this.getMeasuredTemperature();
|
BigDecimal measured = this.getMeasuredTemperature();
|
||||||
|
@ -39,23 +35,18 @@ public class Thermostat extends Switchable implements BooleanTriggerable {
|
||||||
|
|
||||||
if (measured == null) {
|
if (measured == null) {
|
||||||
this.setMode(Thermostat.Mode.IDLE);
|
this.setMode(Thermostat.Mode.IDLE);
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BigDecimal delta = target.subtract(measured);
|
BigDecimal delta = target.subtract(measured);
|
||||||
|
|
||||||
if (delta.abs().doubleValue() < 0.25) {
|
if (delta.abs().doubleValue() < 0.25) {
|
||||||
if (this.getMode() == Thermostat.Mode.IDLE) return false;
|
|
||||||
this.setMode(Thermostat.Mode.IDLE);
|
this.setMode(Thermostat.Mode.IDLE);
|
||||||
} else if (delta.signum() > 0) {
|
} else if (delta.signum() > 0) {
|
||||||
if (this.getMode() == Thermostat.Mode.HEATING) return false;
|
|
||||||
this.setMode(Thermostat.Mode.HEATING);
|
this.setMode(Thermostat.Mode.HEATING);
|
||||||
} else {
|
} else {
|
||||||
if (this.getMode() == Thermostat.Mode.COOLING) return false;
|
|
||||||
this.setMode(Thermostat.Mode.COOLING);
|
this.setMode(Thermostat.Mode.COOLING);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -45,19 +45,17 @@ public class ThermostatService {
|
||||||
return Utils.toList(all);
|
return Utils.toList(all);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean computeState(Thermostat t) {
|
public void computeState(Thermostat t) {
|
||||||
populateMeasuredTemperature(t);
|
populateMeasuredTemperature(t);
|
||||||
return t.computeState();
|
t.computeState();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateState(Thermostat t) {
|
private void updateState(Thermostat t) {
|
||||||
boolean shouldUpdate = this.computeState(t);
|
this.computeState(t);
|
||||||
|
|
||||||
if (shouldUpdate) {
|
|
||||||
deviceService.saveAsOwner(t, thermostatRepository.findUser(t.getId()).getUsername());
|
deviceService.saveAsOwner(t, thermostatRepository.findUser(t.getId()).getUsername());
|
||||||
endpoint.queueDeviceUpdate(t, thermostatRepository.findUser(t.getId()));
|
endpoint.queueDeviceUpdate(t, thermostatRepository.findUser(t.getId()));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void updateStates() {
|
public void updateStates() {
|
||||||
Iterable<Thermostat> ts = thermostatRepository.findAll();
|
Iterable<Thermostat> ts = thermostatRepository.findAll();
|
||||||
|
|
Loading…
Reference in a new issue