Source code for mycroft.skills.mycroft_skill.decorators

# Copyright 2019 Mycroft AI Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Decorators for use with MycroftSkill methods"""


[docs]def intent_handler(intent_parser): """Decorator for adding a method as an intent handler.""" def real_decorator(func): # Store the intent_parser inside the function # This will be used later to call register_intent if not hasattr(func, 'intents'): func.intents = [] func.intents.append(intent_parser) return func return real_decorator
[docs]def intent_file_handler(intent_file): """Decorator for adding a method as an intent file handler. This decorator is deprecated, use intent_handler for the same effect. """ def real_decorator(func): # Store the intent_file inside the function # This will be used later to call register_intent_file if not hasattr(func, 'intent_files'): func.intent_files = [] func.intent_files.append(intent_file) return func return real_decorator
def resting_screen_handler(name): """Decorator for adding a method as an resting screen handler. If selected will be shown on screen when device enters idle mode. """ def real_decorator(func): # Store the resting information inside the function # This will be used later in register_resting_screen if not hasattr(func, 'resting_handler'): func.resting_handler = name return func return real_decorator def skill_api_method(func): """Decorator for adding a method to the skill's public api. Methods with this decorator will be registered on the message bus and an api object can be created for interaction with the skill. """ # tag the method by adding an api_method member to it if not hasattr(func, 'api_method') and hasattr(func, '__name__'): func.api_method = True return func