-
Notifications
You must be signed in to change notification settings - Fork 0
/
tank_control.py
39 lines (30 loc) · 1013 Bytes
/
tank_control.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# -*- coding: utf-8 -*-
import tank_measurement
import tank_alarm
import time
class TankControl:
def __init__(
self,
config=None,
tank_measure=None,
_tank_alarm=None,
error_handler=None):
if tank_measure is None:
self._tank_measurement = tank_measurement.TankMeasurement()
else:
self._tank_measurement = tank_measure
if _tank_alarm is None:
self._tank_alarm = tank_alarm.TankAlarm(config)
else:
self._tank_alarm = _tank_alarm
self._buzzer_alarm = error_handler
def tank_level_above_threshold(self):
return self._tank_measurement.get_tank_level() >= 0.2
def update(self):
status = self.tank_level_above_threshold()
self._tank_alarm.set_status(status)
if self._buzzer_alarm is not None:
self._buzzer_alarm.set_tank_status(status)
def run(self):
self.update()
return time.time() + 5