|
@@ -0,0 +1,46 @@
|
|
|
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices;
|
|
|
+
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.RoomStatus;
|
|
|
+
|
|
|
+public class SmartTemperatureProducer extends FloatSensorDevice {
|
|
|
+
|
|
|
+
|
|
|
+ private RoomStatus roomStatus;
|
|
|
+ private float tempChangePerHour = 0;
|
|
|
+ private float trueTemperature = 10f;
|
|
|
+
|
|
|
+ public SmartTemperatureProducer(String name, RoomStatus room, int updateInterval) {
|
|
|
+ super(name, updateInterval);
|
|
|
+ roomStatus = room;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void updateData() {
|
|
|
+ /**
|
|
|
+ * Slowly move room temperature to producer temperature
|
|
|
+ */
|
|
|
+ float cTemp = roomStatus.getTemperature();
|
|
|
+ if(tempChangePerHour > 0) {
|
|
|
+ roomStatus.setTemperature(Math.min(cTemp, cTemp + tempChangePerHour * (float)super.updateInterval/3600000f));
|
|
|
+ } else if(tempChangePerHour < 0) {
|
|
|
+ roomStatus.setTemperature(Math.max(cTemp, cTemp + tempChangePerHour * (float)super.updateInterval/3600000f));
|
|
|
+ }
|
|
|
+ if(roomStatus.getTemperature() == getFSval()) {
|
|
|
+ tempChangePerHour = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public float getTrueTemperature() {
|
|
|
+ return trueTemperature;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setTrueTemperature(float trueTemperature) {
|
|
|
+ this.trueTemperature = trueTemperature;
|
|
|
+ /*
|
|
|
+ * Change temperature in 1 hour to target temperature
|
|
|
+ */
|
|
|
+ tempChangePerHour = trueTemperature-roomStatus.getTemperature();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|