rewrite the temperature collector

after a quick test I don't think I need the complicated way to calculate the
temperature
This commit is contained in:
Andreas Zweili 2019-10-20 13:35:29 +02:00
parent 7411bdd70e
commit 16050cc176
2 changed files with 8 additions and 12 deletions

View File

@ -7,18 +7,10 @@ else:
sense = SenseHat()
def _get_cpu_temperature():
res = os.popen('vcgencmd measure_temp').readline()
return float(res.replace('temp=', '').replace("'C\n", ''))
def get_temperature():
humidity_temp = self._sense_hat.get_temperature_from_humidity()
pressure_temp = self._sense_hat.get_temperature_from_pressure()
cpu_temp = _get_cpu_temperature()
avg_temp = ((humidity_temp + pressure_temp)
/ 2 if pressure_temp else humidity_temp)
adj_temp = avg_temp - (cpu_temp - avg_temp) / 0.69
return adj_temp
raw_temp = sense.get_temperature()
return round(raw_temp, 1)
def get_pressure():

View File

@ -8,5 +8,9 @@ from collector import collector
pytestmark=pytest.mark.django_db
def test_collector():
print(str(collector.get_temperature()))
def test_temp_collector(monkeypatch):
def mock_temp():
return 25.345
monkeypatch.setattr(collector.sense, 'get_temperature', mock_temp)
assert collector.get_temperature() == 25.3