#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""class definition"""

import logging
from datetime import datetime
from pathlib import Path
from time import time
from typing import Any

from eSaver_Data_App import App_Data


class XLS_Data:  # noqa: N801
    """Excel-Dateien-Data beinhaltet folgende Daten

    Note: Definitionen aus Excel übernehmen
    """

    def __init__(self):
        """Initialisierungs-Werte

        Args:

        :Returns:
            (self)
        :Raises:
            AttributeError

        """
        self.var_Value: Any = 0

        pass


pass

# MBS_Data End

# print(help(MBS_Data))


"""
Ab hier beginnt das Test Programm
"""


# * =============================================
# %% === Logger aktivieren und beenden
def logger_Settings():
    """Logger Settings

    Initialisierung der Bezeichnung-Namen (EN)
    """
    logging.debug('debug Beschreibung Test der Meldungen')
    logging.info('info')
    logging.warning('warning')
    logging.error('error')
    logging.critical('critical')
    logging.info('info ========================================')
    logging.info('_PRG')

    return


# %% === logger_On
def logger_On(parent: Path, loggerFileName: str):
    """Einschalten des Loggers open Logger-file"""
    cwd = Path.cwd()
    parent = cwd.parent

    try:
        logging.getLogger().removeHandler(logging.getLogger().handlers[0])
        logging.getLogger().removeHandler(logging.getLogger().handlers[0])
    except:  # noqa: E722
        pass

    strTimeFtime = datetime.now().strftime('%y%m%d_%H%M%S')

    logFileName = f'{loggerFileName}{strTimeFtime}.log'

    strFileLog = parent / logFileName
    print(f'>>> Log_FileName: {strFileLog}')
    logging.basicConfig(
        filename=strFileLog,
        filemode='w',  # default = 'a'
        format='%(asctime)s %(name)15s - %(levelname)8s: - %(message)s',
        datefmt='%d.%m.%y %H:%M:%S',
        level=logging.INFO,
    )
    return


# %% === logger_Off
def logger_Off():
    """Ausschalten des Loggers close Logger-file"""
    logging.shutdown()

    return


# ? =============================================
# %% === main_testen_XLS_Data
def main_testen_XLS_Data():
    """Test Programm"""
    logging.info('main_testen main_func')

    listMbDatas = []

    return


# %% === main
def main():
    """___

    ___
    """
    tStart = time()  # todo: Zeitmessung

    # ## === Variables Global anlegen
    app_data = App_Data()

    # ## === Path-Variablen holen ===
    cwd = Path.cwd()
    parent = cwd.parent

    # ========== logger aktivieren ==========
    # ?: Hier sollte der Dateiname aus der App_Data.xx gelesen werden.
    logger_On(parent, 'x_eSaver_Data_XLS_Log_')
    logger_Settings()

    strTimeFtime = datetime.now().strftime(app_data.strftime_format)
    logging.info('main_testen started                                           / Start {strTimeFtime}')

    pass  # ## ==========

    main_testen_XLS_Data()

    pass  # ## ==========

    tEnde = time()  # todo: Zeitmessung
    tDauer = tEnde - tStart
    logging.info(f'main_testen stopped                                          / tDauer {tDauer}')

    logger_Off()

    return


# ## ========== Testen eSaver_Data_ModBus ==========
# %% === Start __name__
if __name__ == '__main__':
    """Einsprung Start der Anlage

    """
    # ## === Variables Global anlegen
    pass

    main()

    pass  # ## ==========


# %%
# EOF                   // End of File
