From c9f53f0c970ca6b1b7205a62865c74c2cf571070 Mon Sep 17 00:00:00 2001 From: britea Date: Fri, 8 May 2020 09:59:42 +0200 Subject: [PATCH 1/2] fix thermostat --- .../smarthut/controller/ThermostatController.java | 6 ++++++ .../sanmarinoes/smarthut/models/ThermostatRepository.java | 4 ++-- .../sa4/sanmarinoes/smarthut/service/ThermostatService.java | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) 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(); } From 501b9219b91689dba6325dcff12c6fa46b69154d Mon Sep 17 00:00:00 2001 From: britea Date: Fri, 8 May 2020 10:03:31 +0200 Subject: [PATCH 2/2] resolve conflict --- .../smarthut/controller/ThermostatController.java | 6 ------ 1 file changed, 6 deletions(-) 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 099061a..49c31f2 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,13 +36,7 @@ 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