diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/ships.py | 8 | ||||
-rw-r--r-- | modules/task_type.py | 10 | ||||
-rw-r--r-- | modules/task_types.py | 21 |
3 files changed, 25 insertions, 14 deletions
diff --git a/modules/ships.py b/modules/ships.py index e35cdd2..05ce6c1 100644 --- a/modules/ships.py +++ b/modules/ships.py @@ -1,6 +1,6 @@ from typing import Dict -from . import task_type +from . import task_types from .database import cursor, conn @@ -20,10 +20,10 @@ class Ship: row = cursor.fetchone() if row is None: cursor.execute("INSERT INTO ships (symbol, task, params, name) VALUES (?, ?, ?, ?)", - (self.symbol, task_type.IDLE, None, self.symbol)) + (self.symbol, task_types.IDLE, None, self.symbol)) conn.commit() - self.task = task_type.IDLE + self.task = task_types.IDLE self.task = self.symbol else: self.name = row[0] @@ -31,7 +31,7 @@ class Ship: def set_task(self, task): self.task = task - if task != task_type.ERROR: + if task != task_types.ERROR: cursor.execute("UPDATE ships SET task = ? WHERE symbol = ?", (task, self.symbol)) conn.commit() diff --git a/modules/task_type.py b/modules/task_type.py deleted file mode 100644 index 7579ad0..0000000 --- a/modules/task_type.py +++ /dev/null @@ -1,10 +0,0 @@ -IDLE = 'IDLE' -MINING = 'MINING' - -MIA = 'MIA' -ERROR = 'ERROR' - -task_types = [ - IDLE, - MINING, -] diff --git a/modules/task_types.py b/modules/task_types.py new file mode 100644 index 0000000..d23ce55 --- /dev/null +++ b/modules/task_types.py @@ -0,0 +1,21 @@ +from typing import Annotated +from pydantic.functional_validators import AfterValidator + +IDLE = 'IDLE' +MINING = 'MINING' + +MIA = 'MIA' +ERROR = 'ERROR' + +task_types = [ + IDLE, + MINING, +] + + +def is_task_type(task: str): + assert task in task_types, f"'{task}' is not a valid task type." + return task + + +task_type = Annotated[str, AfterValidator(is_task_type)] |