thermostat

Just a TDD exercise
git clone https://git.tronto.net/thermostat
Download | Log | Files | Refs | README

commit ac6e625811682b96f4b1a73ab53a163dab806e6c
parent c19d6fd991cee4fd41e6127e259ef0ccb35b1b50
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Sun, 28 May 2023 22:23:54 +0200

[GREEN] Add two set points -> ok (actually works for more than 2)

Diffstat:
Mthermostat.py | 18++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/thermostat.py b/thermostat.py @@ -4,24 +4,30 @@ from datetime import datetime class Thermostat: def __init__(self): - self.setPoint = None + self.setPoints = [] def GetCurrentTime(self): return int(datetime.now().strftime("%H")) def GetCurrentRequiredTemperature(self): - if self.setPoint != None and self.GetCurrentTime() >= self.setPoint[0]: - return self.setPoint[1] - return 10 + time = self.GetCurrentTime() + lastTemp = 10 + if len(self.setPoints) > 0: + for sp in self.setPoints: + if sp[0] <= time: + lastTemp = sp[1] + else: + return lastTemp + return lastTemp def AddSetPoint(self, hour, temperature): - self.setPoint = (hour, temperature) + self.setPoints.append((hour, temperature)) class TestableThermostat(Thermostat): def __init__(self, hour): self.hour = hour - self.setPoint = None + self.setPoints = [] def GetCurrentTime(self): return self.hour