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 = thermostatRepository.save(newT);
newT.setOn(t.isTurnOn()); newT.setOn(t.isTurnOn());
<<<<<<< Updated upstream
return deviceService.saveAsOwner(newT, principal.getName()); return deviceService.saveAsOwner(newT, principal.getName());
=======
newT = deviceService.saveAsOwner(newT, principal.getName());
System.out.println(newT);
return newT;
>>>>>>> Stashed changes
} }
@PostMapping @PostMapping

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