backend/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Thermostat.java

86 lines
2.4 KiB
Java
Raw Normal View History

2020-04-09 09:30:05 +00:00
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
2020-04-13 14:42:48 +00:00
import com.google.gson.annotations.SerializedName;
2020-04-09 09:30:05 +00:00
import java.math.BigDecimal;
import javax.persistence.Column;
2020-04-09 13:25:34 +00:00
import javax.persistence.Entity;
2020-04-13 14:42:48 +00:00
import javax.persistence.Transient;
2020-04-09 09:30:05 +00:00
import javax.validation.constraints.NotNull;
/** A thermostat capable of controlling cooling and heating. */
2020-04-09 13:25:34 +00:00
@Entity
2020-04-13 14:42:48 +00:00
public class Thermostat extends OutputDevice {
2020-04-09 09:30:05 +00:00
2020-04-13 13:36:29 +00:00
public enum ThermostatState {
2020-04-13 14:42:48 +00:00
@SerializedName("OFF")
2020-04-09 09:30:05 +00:00
OFF,
2020-04-13 14:42:48 +00:00
@SerializedName("IDLE")
2020-04-09 09:30:05 +00:00
IDLE,
2020-04-13 14:42:48 +00:00
@SerializedName("COOLING")
2020-04-09 09:30:05 +00:00
COOLING,
2020-04-13 14:42:48 +00:00
@SerializedName("HEATING")
2020-04-09 09:30:05 +00:00
HEATING
}
2020-04-13 13:36:29 +00:00
/** Temperature to be reached */
2020-04-09 09:30:05 +00:00
@Column @NotNull private BigDecimal targetTemperature;
2020-04-13 14:42:48 +00:00
/** The temperature detected by the embedded sensor */
@Column(nullable = false, precision = 4, scale = 1)
2020-04-15 15:55:04 +00:00
private BigDecimal internalSensorTemperature =
Sensor.TYPICAL_VALUES.get(Sensor.SensorType.TEMPERATURE);
2020-04-09 09:30:05 +00:00
2020-04-13 13:36:29 +00:00
/** State of this thermostat */
2020-04-09 09:30:05 +00:00
@Column @NotNull private ThermostatState state;
2020-04-15 13:10:02 +00:00
@Transient private BigDecimal measuredTemperature;
2020-04-13 14:42:48 +00:00
2020-04-15 15:55:04 +00:00
@Column private boolean useExternalSensors = false;
2020-04-13 14:42:48 +00:00
2020-04-09 09:30:05 +00:00
/** Creates a thermostat with a temperature sensor and its initial OFF state */
public Thermostat() {
super("thermostat");
this.state = ThermostatState.OFF;
}
public void setState(ThermostatState state) {
this.state = state;
}
2020-04-13 13:36:29 +00:00
public ThermostatState getState() {
return this.state;
}
public BigDecimal getTargetTemperature() {
return this.targetTemperature;
}
2020-04-14 11:24:36 +00:00
public BigDecimal getInternalSensorTemperature() {
return internalSensorTemperature;
}
public boolean isUseExternalSensors() {
return useExternalSensors;
}
2020-04-15 13:10:02 +00:00
public BigDecimal getMeasuredTemperature() {
return measuredTemperature;
}
2020-04-14 11:24:36 +00:00
public void setMeasuredTemperature(BigDecimal measuredTemperature) {
this.measuredTemperature = measuredTemperature;
}
public void setTargetTemperature(BigDecimal targetTemperature) {
this.targetTemperature = targetTemperature;
2020-04-13 13:36:29 +00:00
}
2020-04-15 15:55:04 +00:00
public void setInternalSensorTemperature(BigDecimal internalSensorTemperature) {
this.internalSensorTemperature = internalSensorTemperature;
}
2020-04-09 09:30:05 +00:00
2020-04-15 15:55:04 +00:00
public void setUseExternalSensors(boolean useExternalSensors) {
this.useExternalSensors = useExternalSensors;
}
2020-04-09 09:30:05 +00:00
}