diff --git a/documentation/task state flow.md b/documentation/task state flow.md
index 5e0a173..5bf764f 100644
--- a/documentation/task state flow.md
+++ b/documentation/task state flow.md
@@ -2,25 +2,27 @@
```mermaid
graph TD
- start([START]) --> generic_task{generic_task?}
- generic_task -->|None| deleted{Deleted?}
- generic_task -->|found| state_in{state in
HIDDEN,
HABITICA_*
?}
- deleted -->|False| todoist_task_checked{todoist_task
checked?}
- deleted -->|True| initial{initial?}
- todoist_task_checked -->|False| todoist_active[TODOIST ACTIVE]
- todoist_task_checked -->|True| initial
- todoist_active --> habitica_new[HABITICA NEW]
- habitica_new --> habitica_created[HABITICA CREATED]
- habitica_created --> habitica_finished[HABITICA FINISHED]
- habitica_finished --> recurring{recurring?}
- recurring -->|False| hidden([HIDDEN])
- recurring -->|True| todoist_active
- initial -->|True| hidden
- initial -->|False| should_score_points{should
score
points?}
- should_score_points -->|False| todoist_active
- should_score_points -->|True| assigned_to_me{Assigned
to me?}
- assigned_to_me -->|True| habitica_new
- assigned_to_me -->|False| hidden
- state_in -->|True| skip([SKIP])
- state_in -->|False| deleted
-```
\ No newline at end of file
+ start([START]) --> TodoistNew
+ TodoistNew --> is_td_deleted{Is TD task\ndeleted?}
+ is_td_deleted -- No --> is_td_checked{Is TD task\nchecked?}
+ is_td_deleted -- Yes --> Hidden
+ is_td_checked -- No --> TodoistActive
+ is_td_checked -- Yes --> is_td_initial_sync{Initial\nsync?}
+ is_td_initial_sync -- No --> TodoistActive
+ is_td_initial_sync -- Yes --> Hidden
+ TodoistActive --> is_td_deleted_active{Is TD task\ndeleted?}
+ is_td_deleted_active -- Yes --> Hidden
+ is_td_deleted_active -- No --> should_td_score_points{Should\nTD task score\npoints?}
+ should_td_score_points -- Yes --> is_td_owned_by_me{Is TD task\nowned by me?}
+ should_td_score_points -- No --> TodoistActive
+ is_td_owned_by_me -- Yes --> HabiticaNew
+ is_td_owned_by_me -- No --> Hidden
+ HabiticaNew --> HabiticaCreated
+ HabiticaCreated --> HabiticaFinished
+ HabiticaFinished --> is_task_recurring{Is task\nrecurring?}
+ is_task_recurring -- Yes --> is_task_completed{Is task\ncompleted\nforever?}
+ is_task_completed -- No --> TodoistActive
+ is_task_completed -- Yes --> Hidden
+ is_task_recurring -- No --> Hidden
+ Hidden --> finish([END])
+```
diff --git a/src/main.py b/src/main.py
index 9be975e..0316225 100644
--- a/src/main.py
+++ b/src/main.py
@@ -70,19 +70,12 @@ def _owned_by_me(self) -> bool:
class StateTodoistNew(StateTodoist):
def next_state(self) -> None:
- if self.todoist_task.is_deleted:
- self._set_state(StateHidden)
- elif not self.todoist_task.checked:
- self._set_state(StateTodoistActive)
- elif self.context.initial_sync: # ignore completed tasks during initial sync
+ if self.todoist_task.is_deleted or (self.todoist_task.checked and self.context.initial_sync):
+ # Task has been already deleted or checked previously and this is an initial sync
self._set_state(StateHidden)
- elif self.todoist_task.checked: # task has been completed since last sync
- if self._owned_by_me(): # task is owned by me, it should score points
- self._set_state(StateHabiticaNew)
- else: # task is owned by someone else, it should not score points
- self._set_state(StateHidden)
else:
- self._set_state(StateTodoistActive)
+ # task has not been completed ever or since last sync
+ self._set_state(StateHabiticaNew)
class StateTodoistActive(StateTodoist):
@@ -201,7 +194,7 @@ def __init__(self):
settings.sync_delay_seconds, "Next check in {delay:.0f} seconds."
)
- def run_forever(self):
+ def run_forever(self) -> None:
while True:
try:
self._todoist.sync()
@@ -221,7 +214,7 @@ def set_state(self, state: FSMState) -> None:
state.generic_task.state = new_state
self._task_cache.save_task(state.generic_task)
- def create_habitica_task(self, generic_task: GenericTask):
+ def create_habitica_task(self, generic_task: GenericTask) -> None:
previous_habitica_id = generic_task.habitica_task_id
generic_task.habitica_task_id = self.habitica.create_task(
generic_task.content, TODOIST_PRIORITY_TO_HABITICA_DIFFICULTY[generic_task.priority]
@@ -236,7 +229,7 @@ def initial_sync(self) -> bool:
def todoist_user_id(self) -> str | None:
return self._todoist_user_id
- def _next_tasks_state(self):
+ def _next_tasks_state(self) -> None:
for todoist_task in self._todoist.state.items.values(): # pylint: disable=no-member
generic_task = self._task_cache.get_task_by_todoist_task_id(todoist_task)
diff --git a/src/models/generic_task.py b/src/models/generic_task.py
index 88b8762..85dbfdb 100644
--- a/src/models/generic_task.py
+++ b/src/models/generic_task.py
@@ -1,6 +1,5 @@
-from __future__ import annotations
-
from dataclasses import dataclass
+from typing import Self
from models.todoist import TodoistTask
@@ -16,9 +15,9 @@ class GenericTask:
habitica_task_id: str | None = None
completed_at: str | None = None
- @staticmethod
- def from_todoist_task(todoist_task: TodoistTask, state: str) -> GenericTask:
- return GenericTask(
+ @classmethod
+ def from_todoist_task(cls, todoist_task: TodoistTask, state: str) -> Self:
+ return cls(
todoist_task_id=todoist_task.id,
content=todoist_task.content,
priority=todoist_task.priority,
diff --git a/src/tasks_cache.py b/src/tasks_cache.py
index 21eed77..cd2c4ab 100644
--- a/src/tasks_cache.py
+++ b/src/tasks_cache.py
@@ -23,7 +23,7 @@ def __init__(self, habitica_dirty_states: set[str]):
self._task_cache = tiny_db.table("tasks_cache")
self._log = logging.getLogger(self.__class__.__name__)
- def __len__(self):
+ def __len__(self) -> int:
return len(self._task_cache)
def get_task_by_todoist_task_id(self, todoist_task: TodoistTask) -> GenericTask | None:
@@ -34,7 +34,7 @@ def get_task_by_todoist_task_id(self, todoist_task: TodoistTask) -> GenericTask
return GenericTask(**task) if task else None
- def save_task(self, generic_task: GenericTask, previous_habitica_id: str | None = ""):
+ def save_task(self, generic_task: GenericTask, previous_habitica_id: str | None = "") -> None:
if previous_habitica_id != "":
habitica_id = previous_habitica_id
else: