The api methods are now much easier to use, almost transparent. The
current caveat is that only "standarad" python types are acceptable
(int, float, str, list, bool, None) due to the json serialization.
- api methods are now created with the skill_api_method decorator
- both arguments and keyword arguments are sent to the api method
instead of the message object
- api methods now uses a normal return statement instead of having to
handle creating response messages on the bus.
For example if the datetime skill wants to make the datetime string
fetchable simply add the skill_api_method decorator to the
get_display_date method.
@skill_api_method
def get_display_date(self, day=None, location=None):
"""Returns the date and time as a string."""
[...]
The methods return value will be sent back to the caller and can be used
from a skill through
datetime = SkillApi.get('mycroft-date-time.mycroftai')
self.log.info(datetime.get_display_date())
The skill api allows skills to define a public api which can easily be
accessed by other skills over the message bus just as easy as working
with a normal object.
The skill api object is generated from the skill's public_api property. It's a dict where each key is turned into a method on the api object. The method is defined as
"api_method": {
"type": message type string
"func": handler method
"help": help string for cli
}
Example skill:
class Test2(MycroftSkill):
def __init__(self):
MycroftSkill.__init__(self)
self.public_api = {
'speak': {
'type': 't2.speak',
'func': self.handle_speak,
'help': 'speak the test sentence\nand another line\n\nlast'
},
'speak2': {
'type': 't2.speak2',
'func': self.handle_speak2,
'help': 'speak the other sentence'
}
}
def handle_speak(self, message):
self.speak('This is a test')
self.bus.emit(message.response(data=None))
def handle_speak2(self, message):
self.speak('This is another test')
self.bus.emit(message.response(data=None))