def addSugar(self, spoons, current=None): check_if_off(self.power_mode) if spoons not in range(1, 5): error_time = generate_time() raise SmartHouse.OutOfRangeExc(error_time, "Choose between 1 and 5 spoons") if self.sugar - spoons < 0: error_time = generate_time() raise SmartHouse.LackOfIngredientExc(error_time, "Not enough sugar in machine") self.sugar -= spoons
def addMilk(self, mililitres, current=None): check_if_off(self.power_state) if mililitres not in range(10, 181): time_of_day = generate_time_of_the_day() raise SmartHouse.OutOfRangeError( time_of_day, "Amount of milk out of range 10 - 180 ml") if self.milk_amount - mililitres < 0: time_of_day = generate_time_of_the_day() raise SmartHouse.NoIngredientsError(time_of_day, "Not enough milk in machine") self.milk_amount -= mililitres
def addSugar(self, spoons, current=None): check_if_off(self.power_state) if spoons not in range(1, 11): time_of_day = generate_time_of_the_day() raise SmartHouse.OutOfRangeError( time_of_day, "Amount of sugar out of range 1 - 10") if self.sugar_amount - spoons < 0: time_of_day = generate_time_of_the_day() raise SmartHouse.NoIngredientsError(time_of_day, "Not enough sugar in machine") self.sugar_amount -= spoons
def makeTea(self, tea_type, current=None): check_if_off(self.power_state) if self.water_amount - 150 < 0: time_of_day = generate_time_of_the_day() raise SmartHouse.NoIngredientsError(time_of_day, "Not enough water in machine") if self.tea_amount - 20 < 0: time_of_day = generate_time_of_the_day() raise SmartHouse.NoIngredientsError(time_of_day, "Not enough tea in machine") self.water_amount -= 150 self.tea_amount -= 20
def setTemperature(self, temperature, current=None): check_if_off(self.power_state) if temperature not in range(-20, 10): time_of_day = generate_time_of_the_day() raise SmartHouse.OutOfRangeError(time_of_day, "Temperature out of range") self.temperature = temperature
def makeCoffee(self, coffee_type, current=None): check_if_off(self.power_mode) if coffee_type == SmartHouse.CoffeeType.ESPRESSO: if self.coffee - 25 < 0: error_time = generate_time() raise SmartHouse.LackOfIngredientExc(error_time, "Not enough coffee in machine") self.coffee -= 25 if coffee_type == SmartHouse.CoffeeType.AMERICANO: if self.coffee - 25 < 0: error_time = generate_time() raise SmartHouse.LackOfIngredientExc(error_time, "Not enough coffee in machine") if self.water - 60 < 0: error_time = generate_time() raise SmartHouse.LackOfIngredientExc(error_time, "Not enough water in machine") self.coffee -= 25 self.water -= 60 if coffee_type == SmartHouse.CoffeeType.FLATWHITE: if self.coffee - 60 < 0: error_time = generate_time() raise SmartHouse.LackOfIngredientExc(error_time, "Not enough coffee in machine") if self.milk - 120 < 0: error_time = generate_time() raise SmartHouse.LackOfIngredientExc(error_time, "Not enough milk in machine") self.coffee -= 60 self.milk -= 120 if coffee_type == SmartHouse.CoffeeType.CAPPUCCINO: if self.coffee - 25 < 0: error_time = generate_time() raise SmartHouse.LackOfIngredientExc(error_time, "Not enough coffee in machine") if self.milk - 100 < 0: error_time = generate_time() raise SmartHouse.LackOfIngredientExc(error_time, "Not enough milk in machine") self.coffee -= 25 self.milk -= 100 if coffee_type == SmartHouse.CoffeeType.LATTE: if self.coffee - 50 < 0: error_time = generate_time() raise SmartHouse.LackOfIngredientExc(error_time, "Not enough coffee in machine") if self.milk - 150 < 0: error_time = generate_time() raise SmartHouse.LackOfIngredientExc(error_time, "Not enough milk in machine") self.coffee -= 50 self.milk -= 150
def check_if_off(power_state): if power_state == SmartHouse.PowerState.OFF: time_of_day = generate_time_of_the_day() raise SmartHouse.IsOffError(time_of_day, "Device is off. Turn it on first")
def turnOff(self, current=None): if self.power_state == SmartHouse.PowerState.OFF: time_of_day = generate_time_of_the_day() raise SmartHouse.AlreadyOnError(time_of_day, "Device was already off") self.power_state = SmartHouse.PowerState.OFF
def generate_time_of_the_day(): timestamp = datetime.datetime.now() return SmartHouse.TimeOfDay(timestamp.hour, timestamp.minute, timestamp.second)
def setEndTime(self, time, current=None): check_if_off(self.power_mode) if time.hour not in range(0, 23) or time.minute not in range(0, 59) or time.second not in range(0, 59): error_time = generate_time() raise SmartHouse.OutOfRangeExc(error_time, "Time out of range") self.end_time = time
def __init__(self): super().__init__() self.start_time = SmartHouse.Time(8, 0, 0) self.end_time = SmartHouse.Time(20, 0, 0)
def setTemperature(self, temperature, current=None): check_if_off(self.power_mode) if temperature not in range(16, 31): error_time = generate_time() raise SmartHouse.OutOfRangeExc(error_time, "Temperature out of range") self.temperature = temperature
def turnOff(self, current=None): if self.power_mode == SmartHouse.PowerMode.OFF: error_time = generate_time() raise SmartHouse.AlreadyTurnedOnExc(error_time, "Device is already off") self.power_mode = SmartHouse.PowerMode.OFF
def check_if_off(power_mode): if power_mode == SmartHouse.PowerMode.OFF: error_time = generate_time() raise SmartHouse.IsOffExc(error_time, "Device is off. Turn it on first")
def generate_time(): timestamp = datetime.datetime.now() return SmartHouse.Time(timestamp.hour, timestamp.minute, timestamp.second)