Merge branch '74-thermostat-fix' into 'dev'

Resolve "thermostat-fix"

Closes #74

See merge request sa4-2020/the-sanmarinoes/backend!119
This commit is contained in:
Claudio Maggioni 2020-05-08 16:10:13 +02:00
commit b2f4805ef3
2 changed files with 4 additions and 3 deletions

View file

@ -25,6 +25,6 @@ public interface ThermostatRepository extends DeviceRepository<Thermostat> {
* @return an optional big decimal, empty if none found * @return an optional big decimal, empty if none found
*/ */
@Query( @Query(
"SELECT AVG(s.value) FROM Sensor s JOIN s.room r WHERE s.sensor = 'TEMPERATURE' AND r.id = ?1") "SELECT AVG(s.value) FROM Sensor s JOIN s.room r WHERE s.sensor = ?2 AND r.id = ?1")
Optional<BigDecimal> getAverageTemperature(Long thermostatRoomId); Optional<BigDecimal> getAverageTemperature(Long thermostatRoomId, Sensor.SensorType sensorType);
} }

View file

@ -77,7 +77,8 @@ public class ThermostatService {
Optional<BigDecimal> average; Optional<BigDecimal> average;
if (thermostat.isUseExternalSensors()) { if (thermostat.isUseExternalSensors()) {
average = thermostatRepository.getAverageTemperature(thermostat.getRoomId()); average = thermostatRepository.getAverageTemperature(thermostat.getRoomId(), Sensor.SensorType.TEMPERATURE);
} else { } else {
return thermostat.getInternalSensorTemperature(); return thermostat.getInternalSensorTemperature();
} }