thermostat

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

commit 983c6d61b011e705b0e2765bb8b7d64119874aeb
parent bfcd604688bab3fc11d1a2c8b95789bae4f62507
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Sun, 28 May 2023 22:30:53 +0200

[REFACTOR] Made more pythonic :-)

Diffstat:
Mthermostat.py | 10+++-------
1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/thermostat.py b/thermostat.py @@ -11,13 +11,9 @@ class Thermostat: def GetCurrentRequiredTemperature(self): time = self.GetCurrentTime() - lastTemp = 10 - for sp in self.setPoints: - if sp[0] <= time: - lastTemp = sp[1] - else: - return lastTemp - return lastTemp + passedSetPoints = [sp for sp in self.setPoints if sp[0] <= time] + lastPassedSetPoint = max(passedSetPoints, default = (0, 10), key = lambda sp: sp[0]) + return lastPassedSetPoint[1] def AddSetPoint(self, hour, temperature): self.setPoints.append((hour, temperature))