68 lines
1.9 KiB
Java
68 lines
1.9 KiB
Java
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
|
|
|
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanTrigger;
|
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RangeTrigger;
|
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ScenePriority;
|
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Trigger;
|
|
import java.util.List;
|
|
import javax.validation.constraints.Min;
|
|
import javax.validation.constraints.NotEmpty;
|
|
import javax.validation.constraints.NotNull;
|
|
import lombok.Data;
|
|
|
|
@Data
|
|
public class AutomationFastUpdateRequest {
|
|
public abstract static class TriggerDTO {
|
|
@NotNull public long deviceId;
|
|
|
|
public abstract Trigger<?> toModel();
|
|
}
|
|
|
|
public static class BooleanTriggerDTO extends TriggerDTO {
|
|
@NotNull public boolean on;
|
|
|
|
@Override
|
|
public Trigger<?> toModel() {
|
|
BooleanTrigger<?> t = new BooleanTrigger<>();
|
|
t.setDeviceId(this.deviceId);
|
|
t.setOn(this.on);
|
|
return t;
|
|
}
|
|
}
|
|
|
|
public static class RangeTriggerDTO extends TriggerDTO {
|
|
@NotNull RangeTrigger.Operator operator;
|
|
@NotNull double range;
|
|
|
|
@Override
|
|
public Trigger<?> toModel() {
|
|
RangeTrigger<?> t = new RangeTrigger<>();
|
|
t.setDeviceId(this.deviceId);
|
|
t.setOperator(this.operator);
|
|
t.setRange(this.range);
|
|
return t;
|
|
}
|
|
}
|
|
|
|
public static class ScenePriorityDTO {
|
|
@NotNull public long sceneId;
|
|
|
|
@NotNull
|
|
@Min(0)
|
|
public Integer priority;
|
|
|
|
public ScenePriority toModel() {
|
|
ScenePriority s = new ScenePriority();
|
|
s.setSceneId(sceneId);
|
|
s.setPriority(priority);
|
|
return s;
|
|
}
|
|
}
|
|
|
|
@NotNull private List<ScenePriorityDTO> scenes;
|
|
@NotNull private List<TriggerDTO> triggers;
|
|
@NotNull private long id;
|
|
|
|
@NotNull @NotEmpty private String name;
|
|
}
|