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(); }