2023-06-20 19:39:06 +03:00
|
|
|
/*
|
|
|
|
* %W% %E% Dymik739
|
|
|
|
* Email: dymik739@109.86.70.81
|
|
|
|
*
|
|
|
|
* Copyright (C) 2023 FIOT Dev Team
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class which represents the behaviour of a dishwasher.
|
|
|
|
*
|
|
|
|
* @author Dymik739
|
|
|
|
* @since 0.3
|
|
|
|
*/
|
2023-06-18 20:08:19 +03:00
|
|
|
public class Dishwasher extends Appliance {
|
2023-06-20 19:39:06 +03:00
|
|
|
/** Defines power usage at different stages of washing dishes. */
|
2023-06-18 20:08:19 +03:00
|
|
|
private float[] powerStates = {400f, 60f, 130f, 350f};
|
2023-06-20 19:39:06 +03:00
|
|
|
|
|
|
|
/** Shows how much time should pass before switching to the next stage */
|
2023-06-18 20:08:19 +03:00
|
|
|
private float nextPowerStateIn = 20f;
|
2023-06-20 19:39:06 +03:00
|
|
|
|
|
|
|
/** Shows current stage the dishwasher is performing, -1 for none */
|
2023-06-18 20:08:19 +03:00
|
|
|
private int currentState = -1;
|
|
|
|
|
2023-06-20 19:39:06 +03:00
|
|
|
/**
|
|
|
|
* Constructor for this class.
|
|
|
|
*
|
|
|
|
* @param plugged sets the starting power state of this device
|
|
|
|
*/
|
2023-06-18 20:08:19 +03:00
|
|
|
public Dishwasher(boolean plugged) {
|
|
|
|
super(plugged);
|
2023-06-20 19:39:06 +03:00
|
|
|
super.setType("Dishwasher");
|
2023-06-18 20:08:19 +03:00
|
|
|
}
|
|
|
|
|
2023-06-20 19:39:06 +03:00
|
|
|
/**
|
|
|
|
* Method for simulating the devices' behaviour.
|
|
|
|
* Once started, it goes through every stage until it finishes washing
|
|
|
|
* the dishes (every stage has it's own power usage level. After that,
|
|
|
|
* it resets the device and turns it off automatically.
|
|
|
|
*
|
|
|
|
* @param seconds delta time to simulate for
|
|
|
|
* @param ventRPM air flow created by the vent
|
|
|
|
*/
|
2023-06-18 20:08:19 +03:00
|
|
|
public void step(float seconds, float ventRPM) {
|
|
|
|
if (!super.getPowerState()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nextPowerStateIn -= seconds;
|
|
|
|
|
|
|
|
if (nextPowerStateIn <= 0) {
|
|
|
|
nextPowerStateIn += 20f;
|
|
|
|
currentState++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentState > 3) {
|
|
|
|
unplug();
|
|
|
|
}
|
|
|
|
}
|
2023-06-20 19:39:06 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Overridden method for turning on this device.
|
|
|
|
* It automatically sets it to the correct stage and delay.
|
|
|
|
*/
|
2023-06-18 20:08:19 +03:00
|
|
|
@Override
|
|
|
|
public void plug() {
|
|
|
|
super.plug();
|
|
|
|
|
|
|
|
currentState = 0;
|
|
|
|
nextPowerStateIn = 20f;
|
|
|
|
}
|
|
|
|
|
2023-06-20 19:39:06 +03:00
|
|
|
/**
|
|
|
|
* Overridden method for turning this device off.
|
|
|
|
* It automatically resets the current washing stage to -1.
|
|
|
|
*/
|
2023-06-18 20:08:19 +03:00
|
|
|
@Override
|
|
|
|
public void unplug() {
|
|
|
|
super.unplug();
|
|
|
|
|
|
|
|
currentState = -1;
|
|
|
|
}
|
|
|
|
|
2023-06-20 19:39:06 +03:00
|
|
|
/**
|
|
|
|
* Method for calculating the power consumption of this device.
|
|
|
|
* Power usage depends on the current washing stage.
|
|
|
|
*
|
|
|
|
* @return float showing current power consumption
|
|
|
|
*/
|
2023-06-18 20:08:19 +03:00
|
|
|
public float getPowerConsumption() {
|
|
|
|
if (super.getPowerState()) {
|
|
|
|
return powerStates[currentState];
|
|
|
|
} else {
|
|
|
|
return 0f;
|
|
|
|
}
|
|
|
|
}
|
2023-06-20 19:39:06 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Method for printing this devices' object in a nice way.
|
|
|
|
*
|
|
|
|
* @return String containing text description of this devices' state
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return String.format("Dishwasher(%s, %4.1fW, %2.1fs)",
|
|
|
|
super.getPowerState() ? "on" : "off", getPowerConsumption(),
|
|
|
|
super.getPowerState()
|
|
|
|
? (3 - currentState) * 20 + nextPowerStateIn
|
|
|
|
: 0f);
|
|
|
|
}
|
2023-06-18 20:08:19 +03:00
|
|
|
}
|