diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ThermostatController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ThermostatController.java index 49c31f2..099061a 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ThermostatController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ThermostatController.java @@ -36,7 +36,13 @@ public class ThermostatController { newT = thermostatRepository.save(newT); newT.setOn(t.isTurnOn()); +<<<<<<< Updated upstream return deviceService.saveAsOwner(newT, principal.getName()); +======= + newT = deviceService.saveAsOwner(newT, principal.getName()); + System.out.println(newT); + return newT; +>>>>>>> Stashed changes } @PostMapping diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ThermostatRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ThermostatRepository.java index 896e0ad..290ebf5 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ThermostatRepository.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/ThermostatRepository.java @@ -25,6 +25,6 @@ public interface ThermostatRepository extends DeviceRepository { * @return an optional big decimal, empty if none found */ @Query( - "SELECT AVG(s.value) FROM Sensor s JOIN s.room r WHERE s.sensor = 'TEMPERATURE' AND r.id = ?1") - Optional getAverageTemperature(Long thermostatRoomId); + "SELECT AVG(s.value) FROM Sensor s JOIN s.room r WHERE s.sensor = ?2 AND r.id = ?1") + Optional getAverageTemperature(Long thermostatRoomId, Sensor.SensorType sensorType); } 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 5cdee37..100d77d 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 @@ -77,7 +77,8 @@ public class ThermostatService { Optional average; if (thermostat.isUseExternalSensors()) { - average = thermostatRepository.getAverageTemperature(thermostat.getRoomId()); + average = thermostatRepository.getAverageTemperature(thermostat.getRoomId(), Sensor.SensorType.TEMPERATURE); + } else { return thermostat.getInternalSensorTemperature(); }