Skip to content

Commit

Permalink
Merge pull request #142 from leonlowzd/master
Browse files Browse the repository at this point in the history
Updated Developer Guide
  • Loading branch information
leonlowzd authored Oct 28, 2020
2 parents fbab85f + 24aa371 commit 417b5af
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 50 deletions.
120 changes: 104 additions & 16 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,49 +63,98 @@ The rest of the App consists of four components.


### Model Component

![Model Component](images/diagrams/ClassDiagram_DataOverview.png)


## Implementation

### Model Component
![Summarised Model Component](images/diagrams/SummarisedClassDiagram.png)
### Data Component
### Detailed Model Component
The *Model Component* shown above explains the summarised model of SmartHomeBot. The four appliances classes are extended
from the abstract appliance class.

The *Model Component* shown above explains the summarised model of SmartHomeBot. The four appliances classes are extended from the abstract appliance class.
![Detailed Model Component](images/diagrams/ClassDiagram_DetailedData.png)

### Detailed Model Component
![Detailed Model Component](images/diagrams/FullDataClassDiagram.png)
The *Detailed Model Component* shown above explains the full detailed model of SmartHomeBot; which includes all of their variables and methods.
To create an Appliance, we pass the name, location, wattage, power and the entire locationList. We first check from the
locationList if the name of the appliance is inside the locationList, and the location exists within the locationList.
If all these conditions are met, the Appliance will be created. It will be appended into the ApplianceList with the
`addAppliance()` method.

The Power class is responsible for computing the appliance’s power consumption.

The public methods in the Appliances accessible via the ApplianceList are used to manipulate the appliances such as
turning `ON` and `OFF`. From the appliance class, the program will be able to retrieving the name, location, statuses of
the appliances.

### Command Component

#### Create Command
![Sequence of Create Command](images/diagrams/Sequence_CreateCommand.png) <br>
The *Create Command* shown above explains the Sequence Diagram of the Create Command.
The *CreateCommand* shown above explains the Sequence Diagram of the Create Command.
#### Remove Command
![Sequence of Remove Command](images/diagrams/Sequence_RemoveCommand.png) <br>
The *Remove Command* shown above explains the Sequence Diagram of the Remove Command.
The *RemoveCommand* shown above explains the Sequence Diagram of the Remove Command.
#### Add Command
![Sequence of Add Command](images/diagrams/Sequence_AddCommand.png) <br>
The *Add Command* shown above explains the Sequence Diagram of the Add Command.
The *AddCommand* shown above explains the Sequence Diagram of the Add Command.
#### Delete Command
![Sequence of Delete Command](images/diagrams/Sequence_DeleteCommand.png) <br>
The *Delete Command* shown above explains the Sequence Diagram of the Delete Command.
The *DeleteCommand* shown above explains the Sequence Diagram of the Delete Command.
#### On Command

The *OnCommand* shown below explains the Sequence Diagram of the On Command. When the Main class calls the execute() function there will be are 2 cases for on command to flow:
1. OnByLocation
2. OnByAppliance

![Sequence of On Command](images/diagrams/Sequence_OnCommand.png) <br>
The *On Command* shown above explains the Sequence Diagram of the On Command.

The program will determine if the user inputted: key is a name of an appliance, or a location.THis is done by checking the key in the LocationList, if it exists, the program will deem it as 'OnByLocation' vice versa.

##### 1. OnByLocation
The first condition checks if the user types in any parameter into the command, if so, the program will be unable to turn on
the appliances in the location. This is done as not all parameters are accepted by every appliance, for example,
setTemperature is only accepted for Air Conditioner. Thus, the parameter option is only opened to the OnByAppliance method.
Then, onByApplianceLoop will be called to turn on all appliances in the location.

##### 2. OnByAppliance
The first condition checks the index of the tagged appliance in the applianceList. If the index is negative, this signifies
that that key does not exist in the location or appliance list. Else, we will call the onAppliance method.

##### CommandResult
Each condition will correspond to a reciprocal CommandResult printout.


#### Off Command

The *OffCommand* shown below explains the Sequence Diagram of the Off Command. When the Main class calls the `execute()`
function there are 2 cases for off command:
1. OnByLocation
2. OnByAppliance

![Sequence of Off Command](images/diagrams/Sequence_OffCommand.png) <br>
The *Off Command* shown above explains the Sequence Diagram of the Off Command.

The program will determine if the user inputted: key is a name of an appliance or a location. This is done by checking
the key in the LocationList, if it exists, the program will deem it as 'OffByLocation' vice versa.

##### 1. OffByLocation
This method will call offByApplianceLoop which turns off every appliance in that location.

##### 2. OffByAppliance
The first condition checks the index of the tagged appliance in the applianceList. If the index is negative, this signifies that that key does not exist in the location or appliance list. Else, we will call the offAppliance method.

##### CommandResult
Each condition will correspond to a reciprocal CommandResult printout.


#### Invalid Command
![Sequence of Invalid Command](images/diagrams/Sequence_InvalidCommand.png) <br>
The *Invalid Command* shown above explains the Sequence Diagram of the Invalid Command.
The *InvalidCommand* shown above explains the Sequence Diagram of the Invalid Command.
#### Help Command
![Sequence of Help Command](images/diagrams/Sequence_HelpCommand.png) <br>
The *Help Command* shown above explains the Sequence Diagram of the Help Command.
The *HelpCommand* shown above explains the Sequence Diagram of the Help Command.
#### Exit Command
![Sequence of Off Command](images/diagrams/Sequence_ExitCommand.png) <br>
The *Exit Command* shown above explains the Sequence Diagram of the Exit Command.
The *ExitCommand* shown above explains the Sequence Diagram of the Exit Command.
#### CommandResult Command
![Sequence of CommandResult Command](images/diagrams/Sequence_CommandResult.png) <br>
The *CommandResult* shown above explains the Sequence Diagram of the CommandResult.
Expand Down Expand Up @@ -223,3 +272,42 @@ respective CommandObject to execute the command.
Sequence Diagram for `default`

![Parser Model Component](images/diagrams/Sequence_Parser_Default.png)



## Product scope

### Target user profile

Disabled Home Users who want to automate/monitor their home with smart home devices.

### Value proposition

This program consolidates all the home appliance’s control into a centralised system. Users can also review and
monitor electricity usage; having a clearer picture of their electrical usage patterns. We can extract the latest
electricity price to calculate users’ utility bills. A backlog of the usage can also be recorded.

## User Stories

|Version| As a(n) ... | I want to ... | So that I can ...|
|--------|----------|---------------|------------------|
|v1.0|Inexperienced user|list all the functions of the app |To see what he can do. |
|v1.0|New user |add new locations into SmartHomeBot|Tag these locations into appliances |
|v1.0|New user |add new appliances|Manipulate and view his appliances usage|
|v1.0|disabled user |On/Off appliances|Turn on and off appliances without moving much|
|v1.0|Lazy user|list all the appliances in SmartHomeBot|Remove unnecessary locations and appliances|
|v1.0|Calculative user |View usage of his appliances|View all the appliances and see their status|
|v2.0|Lazy user|Change the temperature of the air-conditioner and the speed of the fan from SmartHomeBot|Monitor his smart home appliances|
|v2.0|Experienced SmartHomeBot user|On/OFF appliances by location and list appliances by location|Easily view and manipulate appliances by location|

## Non-Functional Requirements

{Give non-functional requirements}

## Glossary

* *glossary item* - Definition

## Instructions for manual testing

{Give instructions on how to do a manual product testing e.g., how to load sample data to be used for testing}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/diagrams/FullDataClassDiagram.png
Binary file not shown.
Binary file modified docs/images/diagrams/Sequence_OffCommand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/diagrams/Sequence_OnCommand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/main/java/seedu/smarthomebot/commons/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public class Messages {
public static final String MESSAGE_APPLIANCE_PREVIOUSLY_ON = "The appliance is already ON. ";
public static final String MESSAGE_APPLIANCE_PREVIOUSLY_OFF = "The appliance is already OFF. ";
public static final String MESSAGE_FILE_CORRUPTED = "Data file is corrupted, some data will not be entered";
public static final String MESSAGE_APPLIANCE_NOT_EXIST = "Appliance does not exist in the list.";
public static final String MESSAGE_APPLIANCE_OR_LOCATION_NOT_EXIST =
"Appliance or Location does not exist in the list.";
public static final String MESSAGE_INVALID_TEMPERATURE_AC =
"Invalid Temperature is inputted, ensure that it is within 16-30 degrees. \n"
+ "Previous set temperature will be set.";
Expand Down
30 changes: 13 additions & 17 deletions src/main/java/seedu/smarthomebot/logic/commands/OffCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.ArrayList;

import static java.util.stream.Collectors.toList;
import static seedu.smarthomebot.commons.Messages.MESSAGE_APPLIANCE_NOT_EXIST;
import static seedu.smarthomebot.commons.Messages.MESSAGE_APPLIANCE_OR_LOCATION_NOT_EXIST;
import static seedu.smarthomebot.commons.Messages.MESSAGE_APPLIANCE_PREVIOUSLY_OFF;
import static seedu.smarthomebot.commons.Messages.LINE;

Expand All @@ -16,15 +16,15 @@ public class OffCommand extends Command {
+ " [APPLIANCE_NAME] \n\t\t b. " + COMMAND_WORD + " [LOCATION_NAME]";
private static final String APPLIANCE_TYPE = "appliance";
private static final String LOCATION_TYPE = "location";
private final String name;
private final String key;

public OffCommand(String name) {
this.name = name;
public OffCommand(String key) {
this.key = key;
}

private int getApplianceToOffIndex() {
for (Appliance appliance : applianceList.getAllAppliance()) {
if (appliance.getName().equals((this.name))) {
if (appliance.getName().equals((this.key))) {
return applianceList.getAllAppliance().indexOf(appliance);
}
}
Expand All @@ -36,7 +36,7 @@ public CommandResult execute() {
String type = APPLIANCE_TYPE;
ArrayList<Appliance> filterApplianceList =
(ArrayList<Appliance>) applianceList.getAllAppliance().stream()
.filter((s) -> s.getLocation().equals(this.name))
.filter((s) -> s.getLocation().equals(this.key))
.collect(toList());
if (!filterApplianceList.isEmpty()) {
type = LOCATION_TYPE;
Expand All @@ -55,7 +55,7 @@ private CommandResult offByAppliance() {
int toOffApplianceIndex = getApplianceToOffIndex();
if (toOffApplianceIndex < 0) {
assert toOffApplianceIndex < 0 : "Index should be negative.";
return new CommandResult(MESSAGE_APPLIANCE_NOT_EXIST);
return new CommandResult(MESSAGE_APPLIANCE_OR_LOCATION_NOT_EXIST);
} else {
assert toOffApplianceIndex > 0 : "Index should be positive.";
Appliance toOffAppliance = applianceList.getAppliance(toOffApplianceIndex);
Expand All @@ -65,19 +65,15 @@ private CommandResult offByAppliance() {
}

private CommandResult offByLocation() {
if (locationList.isLocationCreated(this.name)) {
String outputResults = LINE;
outputResults = offByApplianceLoop(outputResults);
outputResults = outputResults.concat("All appliance in \"" + this.name + "\" are turned off ");
return new CommandResult(outputResults);
} else {
return new CommandResult("No appliance in this location");
}
String outputResults = offByApplianceLoop();
outputResults = outputResults.concat("All appliance in \"" + this.key + "\" are turned off ");
return new CommandResult(outputResults);
}

private String offByApplianceLoop(String outputResults) {
private String offByApplianceLoop() {
String outputResults = LINE;
for (Appliance toOffAppliance : applianceList.getAllAppliance()) {
if (toOffAppliance.getLocation().equals(this.name)) {
if (toOffAppliance.getLocation().equals(this.key)) {
outputResults = offAppliance(toOffAppliance, outputResults, true);
}
}
Expand Down
26 changes: 12 additions & 14 deletions src/main/java/seedu/smarthomebot/logic/commands/OnCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.ArrayList;

import static java.util.stream.Collectors.toList;
import static seedu.smarthomebot.commons.Messages.MESSAGE_APPLIANCE_NOT_EXIST;
import static seedu.smarthomebot.commons.Messages.MESSAGE_APPLIANCE_OR_LOCATION_NOT_EXIST;
import static seedu.smarthomebot.commons.Messages.LINE;
import static seedu.smarthomebot.commons.Messages.MESSAGE_APPLIANCE_PREVIOUSLY_ON;

Expand All @@ -19,22 +19,23 @@ public class OnCommand extends Command {
+ COMMAND_WORD + " [LOCATION_NAME]";
private static final String APPLIANCE_TYPE = "appliance";
private static final String LOCATION_TYPE = "location";
private final String name;
private final String key;
private final String parameter;

public OnCommand(String name, String parameter) {
this.name = name;
public OnCommand(String key, String parameter) {
this.key = key;
this.parameter = parameter;
}

@Override
public CommandResult execute() {
String onByType = APPLIANCE_TYPE;
// To determine if the keyword is a location, if so, append that selected appliance into a list
// To check if any of the appliances contains the name of the location
ArrayList<Appliance> filterApplianceList =
(ArrayList<Appliance>) applianceList.getAllAppliance().stream()
.filter((s) -> s.getLocation().equals(name))
.filter((s) -> s.getLocation().equals(this.key))
.collect(toList());

// if list is empty
if (!filterApplianceList.isEmpty()) {
onByType = LOCATION_TYPE;
Expand All @@ -51,7 +52,7 @@ public CommandResult execute() {

private int getApplianceToOnIndex() {
for (Appliance appliance : applianceList.getAllAppliance()) {
if (appliance.getName().equals((this.name))) {
if (appliance.getName().equals((this.key))) {
return applianceList.getAllAppliance().indexOf(appliance);
}
}
Expand All @@ -74,20 +75,17 @@ private String setParameter(String parameter, Appliance appliance) {
private CommandResult onByLocation() {
if (!parameter.isEmpty()) {
return new CommandResult("There should be no parameter for on by location.");
}
if (locationList.isLocationCreated(this.name)) {
} else {
String outputResults = LINE;
outputResults = onApplianceByLoop(outputResults);
return new CommandResult(outputResults);
} else {
return new CommandResult("No appliances found in this location");
}
}

private CommandResult onByAppliance() {
int toOnApplianceIndex = getApplianceToOnIndex();
if (toOnApplianceIndex < 0) {
return new CommandResult(MESSAGE_APPLIANCE_NOT_EXIST);
return new CommandResult(MESSAGE_APPLIANCE_OR_LOCATION_NOT_EXIST);
} else {
Appliance toOnAppliance = applianceList.getAppliance(toOnApplianceIndex);
String outputResult = onAppliance(toOnAppliance, "", false);
Expand All @@ -97,11 +95,11 @@ private CommandResult onByAppliance() {

private String onApplianceByLoop(String outputResults) {
for (Appliance toOnAppliance : applianceList.getAllAppliance()) {
if (toOnAppliance.getLocation().equals(this.name)) {
if (toOnAppliance.getLocation().equals(this.key)) {
outputResults = onAppliance(toOnAppliance, outputResults, true);
}
}
outputResults = "All appliance in \"" + this.name + "\" are turned on ";
outputResults = "All appliance in \"" + this.key + "\" are turned on ";
return outputResults;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import seedu.smarthomebot.commons.exceptions.InvalidRemovalLocationException;

import static seedu.smarthomebot.commons.Messages.LINE;
import static seedu.smarthomebot.commons.Messages.MESSAGE_APPLIANCE_NOT_EXIST;
import static seedu.smarthomebot.commons.Messages.MESSAGE_APPLIANCE_OR_LOCATION_NOT_EXIST;
import static seedu.smarthomebot.commons.Messages.MESSAGE_LOCATION_NOT_EXIST;

public class RemoveCommand extends Command {
Expand All @@ -27,7 +27,7 @@ public CommandResult execute() {
} catch (InvalidRemovalLocationException e) {
return new CommandResult(MESSAGE_LOCATION_NOT_EXIST + " Nothing will be deleted.");
} catch (ApplianceNotFoundException e) {
return new CommandResult(MESSAGE_APPLIANCE_NOT_EXIST + " Nothing will be deleted.");
return new CommandResult(MESSAGE_APPLIANCE_OR_LOCATION_NOT_EXIST + " Nothing will be deleted.");
}
}
}

0 comments on commit 417b5af

Please sign in to comment.