Fix Todoist custom project update (#17115)

* Fix Todoist custom project update

Custom projects were not refreshing the API state and were using
local/stored state. This resulted in invalid tasks being retained upon
update. This change resets the local Todoist API state, syncs it, and
then continues normal update operation(s) on the Todoist project data
object.

* Remove blank line after docstring

* Update logging call

* Simplify logging
This commit is contained in:
Philip Rosenberg-Watt 2018-10-06 17:38:25 -06:00 committed by Pascal Vizeli
parent 5d6562a73f
commit 8fda705377

View File

@ -518,6 +518,8 @@ class TodoistProjectData:
def update(self): def update(self):
"""Get the latest data.""" """Get the latest data."""
if self._id is None: if self._id is None:
self._api.reset_state()
self._api.sync()
project_task_data = [ project_task_data = [
task for task in self._api.state[TASKS] task for task in self._api.state[TASKS]
if not self._project_id_whitelist or if not self._project_id_whitelist or
@ -527,6 +529,7 @@ class TodoistProjectData:
# If we have no data, we can just return right away. # If we have no data, we can just return right away.
if not project_task_data: if not project_task_data:
_LOGGER.debug("No data for %s", self._name)
self.event = None self.event = None
return True return True
@ -541,6 +544,8 @@ class TodoistProjectData:
if not project_tasks: if not project_tasks:
# We had no valid tasks # We had no valid tasks
_LOGGER.debug("No valid tasks for %s", self._name)
self.event = None
return True return True
# Make sure the task collection is reset to prevent an # Make sure the task collection is reset to prevent an