Beispiel #1
0
def play_command(power_group):
    """CLI endpoints for managing assets' power states & wallpower"""
    play_subp = power_group.add_subparsers()

    folder_action = play_subp.add_parser(
        "folder", help="Update user-defined script folder")
    folder_action.add_argument(
        "-p",
        "--path",
        type=str,
        required=True,
        help="Path to the folder containing playback scripts",
    )

    list_action = play_subp.add_parser(
        "list", help="List scripts available for execution")
    exec_action = play_subp.add_parser("execute",
                                       help="Execute a specific script")
    exec_action.add_argument("-p",
                             "--play",
                             type=str,
                             required=True,
                             help="Name of the play to be executed")

    # cli actions/callbacks
    folder_action.set_defaults(func=lambda args: IStateManager.set_play_path(
        os.path.abspath(os.path.expanduser(args["path"]))))

    list_action.set_defaults(
        func=lambda args: display_plays(IStateManager.plays()))

    exec_action.set_defaults(func=lambda args: IStateManager.execute_play(
        args["play"])  # TODO: handle invalid play
                             )
Beispiel #2
0
 def _handle_play_request(self, details):
     """Playback request"""
     IStateManager.execute_play(details["payload"]["name"])