Commit 69959877 authored by Jan Wagemakers's avatar Jan Wagemakers

don't allow temp<lowTemp

parent dca49b35
package be.janwagemakers.controlthermostatbluetooth.Entity;
import org.springframework.stereotype.Component;
import javax.persistence.*;
import java.util.List;
@Entity
public class Configuration {
......
......@@ -90,6 +90,13 @@ public class StartupRunner implements CommandLineRunner {
boolean isHome = user.isHome();
for (Rule rule : ruleRepository.findAll(new Sort(Sort.Direction.ASC, "hour", "min"))) {
if (rule.getUser().getId() == user.getId()) {
// check if value rule < lowTemp, fix db : no values lower then lowTemp
if (rule.getTemp()<config.getLowTemp()) {
rule.setTemp(config.getLowTemp());
ruleRepository.save(rule);
}
if (isHome) {
int rday = rule.getDay();
int rhm = 100 * rule.getHour() + rule.getMin();
......
......@@ -38,7 +38,8 @@ public class HTMLController {
@Autowired private Outside outside;
@Autowired private DataList data;
private User user = new User("New User");//= userRepository.findById(1).get();
private Configuration config;
private User user = new User("New User");
@GetMapping("/")
public String index(Model model) {
......@@ -95,6 +96,8 @@ public class HTMLController {
}
model.addAttribute("newRule", new Rule(user,0,0,0,16.0f));
model.addAttribute("user", user.getName());
config = configurationRepository.findById(1).get();
model.addAttribute("min", config.getLowTemp());
model.addAttribute("rules", rules);
return "rules";
}
......
......@@ -57,7 +57,7 @@
h&nbsp;:&nbsp;
<input style="width: 10%" type="number" min="0" max="59" name="min" th:value="${rule.min}">
m&nbsp;=&nbsp;
<input style="width: 10%" type="number" min="0" max="30" step="0.1" name="temp" th:value="${rule.temp}">
<input style="width: 10%" type="number" th:min="${min}" max="30" step="0.1" name="temp" th:value="${rule.temp}">
°C
</p>
<p><input type="hidden" name="user" th:value="${rule.user.id}" readonly/></p>
......@@ -89,7 +89,7 @@
h&nbsp;:&nbsp;
<input style="width: 10%" type="number" min="0" max="59" th:field="*{min}"/>
m&nbsp;=&nbsp;
<input style="width: 10%" type="number" min="0" max="30" step="0.1" th:field="*{temp}"/>
<input style="width: 10%" type="number" th:min="${min}" max="30" step="0.1" th:field="*{temp}"/>
°C
</p>
<p><input type="hidden" th:field="*{user.id}" readonly/></p>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment