1 """Support to interact with Remember The Milk."""
5 from rtmapi
import Rtm, RtmRequestFailedException
11 _LOGGER = logging.getLogger(__name__)
15 """Representation of an interface to Remember The Milk."""
17 def __init__(self, name, api_key, shared_secret, token, rtm_config):
18 """Create new instance of Remember The Milk component."""
24 self.
_rtm_api_rtm_api = Rtm(api_key, shared_secret,
"delete", token)
27 _LOGGER.debug(
"Instance created for account %s", self.
_name_name)
30 """Check if the API token is still valid.
32 If it is not valid any more, delete it from the configuration. This
33 will trigger a new authentication process.
35 valid = self.
_rtm_api_rtm_api.token_valid()
38 "Token for account %s is invalid. You need to register again!",
48 """Create a new task on Remember The Milk.
50 You can use the smart syntax to define the attributes of a new task,
51 e.g. "my task #some_tag ^today" will add tag "some_tag" and set the
55 task_name = call.data[CONF_NAME]
56 hass_id = call.data.get(CONF_ID)
58 if hass_id
is not None:
60 result = self.
_rtm_api_rtm_api.rtm.timelines.create()
61 timeline = result.timeline.value
63 if hass_id
is None or rtm_id
is None:
64 result = self.
_rtm_api_rtm_api.rtm.tasks.add(
65 timeline=timeline, name=task_name, parse=
"1"
68 "Created new task '%s' in account %s", task_name, self.
namenamename
74 result.list.taskseries.id,
75 result.list.taskseries.task.id,
78 self.
_rtm_api_rtm_api.rtm.tasks.setName(
81 taskseries_id=rtm_id[1],
86 "Updated task with id '%s' in account %s to name %s",
91 except RtmRequestFailedException
as rtm_exception:
93 "Error creating new Remember The Milk task for account %s: %s",
99 """Complete a task that was previously created by this component."""
100 hass_id = call.data[CONF_ID]
105 "Could not find task with ID %s in account %s. "
106 "So task could not be closed"
113 result = self.
_rtm_api_rtm_api.rtm.timelines.create()
114 timeline = result.timeline.value
115 self.
_rtm_api_rtm_api.rtm.tasks.complete(
117 taskseries_id=rtm_id[1],
123 "Completed task with id %s in account %s", hass_id, self.
_name_name
125 except RtmRequestFailedException
as rtm_exception:
127 "Error creating new Remember The Milk task for account %s: %s",
134 """Return the name of the device."""
135 return self.
_name_name
139 """Return the state of the device."""
141 return "API token invalid"
None complete_task(self, ServiceCall call)
None create_task(self, ServiceCall call)
def __init__(self, name, api_key, shared_secret, token, rtm_config)
str|UndefinedType|None name(self)