#!/usr/bin/env python

# -*- coding: UTF-8 -*-

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
#                                                                         #
#  Copyright (C) 2015 - 2022 Simon Stuerz <simon.stuerz@nymea.io>         #
#                                                                         #
#  This file is part of nymea-cli.                                        #
#                                                                         #
#  nymea-cli is free software: you can redistribute it and/or modify      #
#  it under the terms of the GNU General Public License as published by   #
#  the Free Software Foundation, version 2 of the License.                #
#                                                                         #
#  nymea-cli is distributed in the hope that it will be useful,           #
#  but WITHOUT ANY WARRANTY; without even the implied warranty of         #
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the           #
#  GNU General Public License for more details.                           #
#                                                                         #
#  You should have received a copy of the GNU General Public License      #
#  along with nymea-cli. If not, see <http://www.gnu.org/licenses/>.      #
#                                                                         #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 

import sys
import os
import traceback
import curses
import argparse

from nymea import __version__
from nymea import nymea
from nymea import mainmenu


###########################################################
# Main 
###########################################################

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='The nymea-cli (command line interface) is an admin tool written in python2 to communicate with the nymea daemon JSON-RPC API and test functionality of nymea.')
    parser.add_argument('-v','--version', action='version', version=__version__)
    parser.add_argument('--host', type=str, default='localhost', help='the location of the nymea daemon (default 127.0.0.1)')
    parser.add_argument('--port', type=int, default=2222, help='the port of the the nymea daemon (default 2222)')

    args = parser.parse_args()

    # check connection
    if not nymea.init_connection(args.host, args.port):
        exit()

    os.system('clear')
    screen = curses.initscr()
    try:
        # run main menu
        mainmenu.start(args.host, args.port)
    finally:
        curses.endwin()
        os.system('clear')
        print "Bye, have a nice day! :)"    



