Only show missing temperature once
This commit is contained in:
parent
e8ad3e3062
commit
73fda1111c
|
@ -7,18 +7,21 @@ class WeatherDisplay:
|
||||||
self.topRow = topRow
|
self.topRow = topRow
|
||||||
self.twoDigitStartColumn = 9
|
self.twoDigitStartColumn = 9
|
||||||
self.oneDigitStartColumn = 13
|
self.oneDigitStartColumn = 13
|
||||||
self.currentTemperature = [9, 9]
|
self.currentTemperature = ''
|
||||||
self.color = colors.GREEN
|
self.color = colors.GREEN
|
||||||
self.weatherFile = 'weather.txt'
|
self.weatherFile = 'weather.txt'
|
||||||
|
|
||||||
def showWeather(self):
|
def showWeather(self):
|
||||||
temperature = self.getTemperature()
|
temperature = self.getTemperature()
|
||||||
|
|
||||||
if self.isTemperatureMissing(temperature):
|
if temperature != self.currentTemperature:
|
||||||
self.characterDisplay.clearRow(self.topRow)
|
self.characterDisplay.clearRow(self.topRow)
|
||||||
else:
|
|
||||||
|
if self.isTemperatureValid(temperature):
|
||||||
self.showTemperature(list(temperature))
|
self.showTemperature(list(temperature))
|
||||||
|
|
||||||
|
self.currentTemperature = temperature
|
||||||
|
|
||||||
def getTemperature(self):
|
def getTemperature(self):
|
||||||
try:
|
try:
|
||||||
with open(self.weatherFile) as file:
|
with open(self.weatherFile) as file:
|
||||||
|
@ -27,27 +30,30 @@ class WeatherDisplay:
|
||||||
print(e, flush=True)
|
print(e, flush=True)
|
||||||
return 'error'
|
return 'error'
|
||||||
|
|
||||||
def isTemperatureMissing(self, temperature):
|
def isTemperatureValid(self, temperature):
|
||||||
return temperature == 'error' or temperature == 'init' or temperature == 'halted'
|
return not (temperature == 'error' or temperature == 'init' or temperature == 'halted')
|
||||||
|
|
||||||
def showTemperature(self, temperature):
|
def showTemperature(self, temperature):
|
||||||
if temperature != self.currentTemperature:
|
start = self.getStartColumn(temperature)
|
||||||
self.characterDisplay.clearRow(self.topRow)
|
|
||||||
|
|
||||||
start = self.oneDigitStartColumn if (
|
|
||||||
self.isOneDigit(temperature)
|
|
||||||
) else self.twoDigitStartColumn
|
|
||||||
|
|
||||||
for c in temperature:
|
for c in temperature:
|
||||||
if c == '-':
|
if c == '-':
|
||||||
self.characterDisplay.displayNegative(
|
self.characterDisplay.displayNegative(
|
||||||
start-3, self.topRow, self.color)
|
x=start-3,
|
||||||
|
y=self.topRow,
|
||||||
|
color=self.color
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self.characterDisplay.displayDigit(
|
self.characterDisplay.displayDigit(
|
||||||
start, self.topRow, c, self.color)
|
x=start,
|
||||||
|
y=self.topRow,
|
||||||
|
digit=c,
|
||||||
|
color=self.color
|
||||||
|
)
|
||||||
start = start + 4
|
start = start + 4
|
||||||
|
|
||||||
self.currentTemperature = temperature
|
def getStartColumn(self, temperature):
|
||||||
|
return self.oneDigitStartColumn if (self.isOneDigit(temperature)) else self.twoDigitStartColumn
|
||||||
|
|
||||||
def isOneDigit(self, temperature):
|
def isOneDigit(self, temperature):
|
||||||
return (len(temperature) == 2 and temperature[0] == '-') or len(temperature) == 1
|
return (len(temperature) == 2 and temperature[0] == '-') or len(temperature) == 1
|
||||||
|
|
Loading…
Reference in New Issue