fix thermostat

This commit is contained in:
britea 2020-05-08 09:59:42 +02:00
parent 7c1d010805
commit c9f53f0c97
3 changed files with 10 additions and 3 deletions

View file

@ -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

View file

@ -25,6 +25,6 @@ public interface ThermostatRepository extends DeviceRepository<Thermostat> {
* @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<BigDecimal> getAverageTemperature(Long thermostatRoomId);
"SELECT AVG(s.value) FROM Sensor s JOIN s.room r WHERE s.sensor = ?2 AND r.id = ?1")
Optional<BigDecimal> getAverageTemperature(Long thermostatRoomId, Sensor.SensorType sensorType);
}

View file

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