Fix update_event and cancel_event methods

====  Tech Notes ====
update_event and cancel_event did not use a name unique to the skill
forcing the user to build it themselves. Now the unique name is
constructed in the method _unique_name() for all event scheduling
methods.
pull/1099/merge
Åke Forslund 2017-09-24 12:25:19 +02:00 committed by Steve Penrod
parent 0709aa8b9e
commit 1d0e65dfb1
1 changed files with 18 additions and 7 deletions

View File

@ -566,6 +566,18 @@ class MycroftSkill(object):
LOG.error("Failed to stop skill: {}".format(self.name),
exc_info=True)
def _unique_name(self, name):
"""
Return a name unique to this skill using the format
[skill_id]:[name].
Args:
name: Name to use internally
returns: name unique to this skill
"""
return str(self.skill_id) + ':' + name
def _schedule_event(self, handler, when, data=None, name=None,
repeat=None):
"""
@ -575,7 +587,8 @@ class MycroftSkill(object):
data = data or {}
if not name:
name = self.name + handler.__name__
name = str(self.skill_id) + ':' + name
name = self._unique_name(name)
self.add_event(name, handler, False)
event_data = {}
event_data['time'] = time.mktime(when.timetuple())
@ -622,11 +635,10 @@ class MycroftSkill(object):
"""
data = data or {}
data = {
'event': name,
'event': self._unique_name(name),
'data': data
}
self.emitter.emit(Message('mycroft.schedule.update_event',
data=data))
self.emitter.emit(Message('mycroft.schedule.update_event', data=data))
def cancel_event(self, name):
"""
@ -636,9 +648,8 @@ class MycroftSkill(object):
Args:
name (str): Name of event
"""
data = {'event': name}
self.emitter.emit(Message('mycroft.scheduler.remove_event',
data=data))
data = {'event': self._unique_name(name)}
self.emitter.emit(Message('mycroft.scheduler.remove_event', data=data))
class FallbackSkill(MycroftSkill):