Added a sketch of the data model
Added a rough hint of the class structure needed to store the application state
This commit is contained in:
parent
4cf93e28db
commit
6fc17052c6
15 changed files with 136 additions and 20 deletions
BIN
.gradle/6.0.1/executionHistory/executionHistory.bin
Normal file
BIN
.gradle/6.0.1/executionHistory/executionHistory.bin
Normal file
Binary file not shown.
BIN
.gradle/6.0.1/executionHistory/executionHistory.lock
Normal file
BIN
.gradle/6.0.1/executionHistory/executionHistory.lock
Normal file
Binary file not shown.
|
@ -14,7 +14,10 @@ repositories {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'org.springframework.boot:spring-boot-starter'
|
implementation 'org.springframework.boot:spring-boot-starter'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
implementation('org.springframework.boot:spring-boot-starter-web') {
|
||||||
|
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-json'
|
||||||
|
}
|
||||||
|
implementation 'com.google.code.gson:gson:2.8.4'
|
||||||
testImplementation('org.springframework.boot:spring-boot-starter-test') {
|
testImplementation('org.springframework.boot:spring-boot-starter-test') {
|
||||||
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
|
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
|
||||||
}
|
}
|
||||||
|
|
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -1,5 +1,6 @@
|
||||||
|
#Thu Feb 20 21:04:58 CET 2020
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip
|
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
|
||||||
|
|
||||||
import org.springframework.boot.*;
|
|
||||||
import org.springframework.boot.autoconfigure.*;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@EnableAutoConfiguration
|
|
||||||
public class HelloWorld {
|
|
||||||
|
|
||||||
@RequestMapping("/")
|
|
||||||
String home() {
|
|
||||||
return "Hello World!";
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,9 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class SmarthutApplication {
|
public class SmarthutApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(SmarthutApplication.class, args);
|
SpringApplication.run(SmarthutApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
||||||
|
|
||||||
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
|
||||||
|
import org.springframework.boot.autoconfigure.*;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@EnableAutoConfiguration
|
||||||
|
@Controller
|
||||||
|
public class WelcomeController {
|
||||||
|
|
||||||
|
@GetMapping("/")
|
||||||
|
List<Device> testDevices() {
|
||||||
|
return Arrays.asList(new Dimmer(), new Light(), new MotionSensor(), new Sensor(), new SmartPlug(), new Switch());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.Expose;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic abstraction for a smart home device
|
||||||
|
*/
|
||||||
|
public abstract class Device {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ways a device can behave in the automation flow. For now only input/output
|
||||||
|
*/
|
||||||
|
public enum FlowType {
|
||||||
|
INPUT,
|
||||||
|
OUTPUT
|
||||||
|
}
|
||||||
|
|
||||||
|
private static long nextId = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Device identifier
|
||||||
|
*/
|
||||||
|
@Expose
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name for the category of this particular device (e.g 'dimmer').
|
||||||
|
*/
|
||||||
|
@Expose
|
||||||
|
private final String kind;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The way this device behaves in the automation flow.
|
||||||
|
*/
|
||||||
|
@Expose
|
||||||
|
private final FlowType flowType;
|
||||||
|
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Device(String kind, FlowType flowType) {
|
||||||
|
synchronized (Device.class) {
|
||||||
|
id = nextId;
|
||||||
|
nextId++;
|
||||||
|
}
|
||||||
|
this.kind = kind;
|
||||||
|
this.flowType = flowType;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
|
|
||||||
|
public class Dimmer extends Device {
|
||||||
|
public Dimmer() {
|
||||||
|
super("dimmer", FlowType.INPUT);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
|
|
||||||
|
public class Light extends Device {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the light bulb is dimmable. If set to true, the only valid intensity values are 0 (off) or 100 (on)
|
||||||
|
*/
|
||||||
|
private final boolean dimmable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The light intensity value. Goes from 0 (off) to 100 (on)
|
||||||
|
*/
|
||||||
|
private int intensity = 0;
|
||||||
|
|
||||||
|
public Light(int intensity, boolean dimmable) {
|
||||||
|
super("light", FlowType.OUTPUT);
|
||||||
|
this.intensity = intensity;
|
||||||
|
this.dimmable = dimmable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Light() {
|
||||||
|
this(0, false);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
|
|
||||||
|
public class MotionSensor extends Device {
|
||||||
|
public MotionSensor() {
|
||||||
|
super("motion-sensor", FlowType.INPUT);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
|
|
||||||
|
public class Sensor extends Device {
|
||||||
|
public Sensor() {
|
||||||
|
super("sensor", FlowType.INPUT);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
|
|
||||||
|
public class SmartPlug extends Device {
|
||||||
|
public SmartPlug() {
|
||||||
|
super("smart-plug", FlowType.OUTPUT);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
|
|
||||||
|
public class Switch extends Device {
|
||||||
|
public Switch() {
|
||||||
|
super("switch", FlowType.INPUT);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1 +1 @@
|
||||||
|
spring.http.converters.preferred-json-mapper=gson
|
Loading…
Reference in a new issue