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:
Claudio Maggioni 2020-02-20 21:58:23 +01:00
parent 4cf93e28db
commit 6fc17052c6
15 changed files with 136 additions and 20 deletions

Binary file not shown.

Binary file not shown.

View File

@ -14,7 +14,10 @@ repositories {
dependencies {
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') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}

View File

@ -1,5 +1,6 @@
#Thu Feb 20 21:04:58 CET 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip

View File

@ -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!";
}
}

View File

@ -5,9 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SmarthutApplication {
public static void main(String[] args) {
SpringApplication.run(SmarthutApplication.class, args);
}
}

View File

@ -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());
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1,7 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
public class Dimmer extends Device {
public Dimmer() {
super("dimmer", FlowType.INPUT);
}
}

View File

@ -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);
}
}

View File

@ -0,0 +1,7 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
public class MotionSensor extends Device {
public MotionSensor() {
super("motion-sensor", FlowType.INPUT);
}
}

View File

@ -0,0 +1,7 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
public class Sensor extends Device {
public Sensor() {
super("sensor", FlowType.INPUT);
}
}

View File

@ -0,0 +1,7 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
public class SmartPlug extends Device {
public SmartPlug() {
super("smart-plug", FlowType.OUTPUT);
}
}

View File

@ -0,0 +1,7 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
public class Switch extends Device {
public Switch() {
super("switch", FlowType.INPUT);
}
}

View File

@ -1 +1 @@
spring.http.converters.preferred-json-mapper=gson