From b58b1f0ac98ef49445c8e8d60a0883dd99438092 Mon Sep 17 00:00:00 2001 From: Philipp Grimm Date: Mon, 26 Feb 2024 22:04:27 +0100 Subject: [PATCH] Small tool added to check EEP values of a data set. --- changes.md | 3 + eo_man/__main__.py | 3 +- eo_man/data/data_helper.py | 7 ++ eo_man/data/data_manager.py | 7 +- eo_man/view/eep_checker.py | 169 ++++++++++++++++++++++++++++++++++ eo_man/view/menu_presenter.py | 7 ++ setup.py | 2 +- 7 files changed, 191 insertions(+), 7 deletions(-) create mode 100644 eo_man/view/eep_checker.py diff --git a/changes.md b/changes.md index 102fecf..a55150c 100644 --- a/changes.md +++ b/changes.md @@ -1,5 +1,8 @@ # Change Log +## 0.1.11 EEP Checker added +* Small tool added to check EEP values of a data set. + ## v0.1.10 Logs are sent into file * Logs are now written to log file in application folder. * Added Flag to see values from incomming telegrams. diff --git a/eo_man/__main__.py b/eo_man/__main__.py index 34e64e7..4ea8a88 100644 --- a/eo_man/__main__.py +++ b/eo_man/__main__.py @@ -37,7 +37,7 @@ def cli_argument(): def init_logger(app_bus:AppBus, log_level:int=logging.INFO): - file_handler = RotatingFileHandler(os.path.join(PROJECT_DIR, "enocean-device-manager.log"), + file_handler = RotatingFileHandler(os.path.join(PROJECT_DIR, "enocean-device-manager.log"), mode='a', maxBytes=10*1024*1024, backupCount=2, encoding=None, delay=0) logging.basicConfig(format='%(asctime)s %(name)s %(levelname)s %(message)s ', #'%(message)s ', @@ -46,6 +46,7 @@ def init_logger(app_bus:AppBus, log_level:int=logging.INFO): global LOGGER LOGGER = logging.getLogger(PACKAGE_NAME) LOGGER.setLevel(log_level) + file_handler.setLevel(logging.DEBUG) LOGGER.info("Start Application eo_man") LOGGER.info(ApplicationInfo.get_app_info_as_str()) # add print log messages for log message view on command line as debug diff --git a/eo_man/data/data_helper.py b/eo_man/data/data_helper.py index beeb454..34ebcec 100644 --- a/eo_man/data/data_helper.py +++ b/eo_man/data/data_helper.py @@ -74,6 +74,13 @@ def find_eep_by_name(eep_name:str) -> EEP: return sub_child return None +def get_values_for_eep(eep:EEP, message:EltakoMessage) -> list[str]: + properties_as_str = [] + for k, v in eep.decode_message(message).__dict__.items(): + properties_as_str.append(f"{str(k)[1:] if str(k).startswith('_') else str(k)}: {str(v)}") + + return properties_as_str + def a2s(address:int, length:int=4): """address to string""" if address is None: diff --git a/eo_man/data/data_manager.py b/eo_man/data/data_manager.py index e930bdc..688c0bf 100644 --- a/eo_man/data/data_manager.py +++ b/eo_man/data/data_manager.py @@ -287,14 +287,11 @@ def get_values_from_message_to_string(self, message:EltakoMessage, base_id:str=N device = self.devices[ext_id_str] try: eep:EEP = data_helper.find_eep_by_name(device.eep) - properties_as_str = [] - for k, v in eep.decode_message(message).__dict__.items(): - properties_as_str.append(f"{str(k)[1:] if str(k).startswith('_') else str(k)}: {str(v)}") - - return eep, ', '.join(properties_as_str) + return eep, ', '.join(data_helper.get_values_for_eep(eep, message)) except: pass return eep, None + \ No newline at end of file diff --git a/eo_man/view/eep_checker.py b/eo_man/view/eep_checker.py new file mode 100644 index 0000000..8702605 --- /dev/null +++ b/eo_man/view/eep_checker.py @@ -0,0 +1,169 @@ + +from tkinter import * +import tkinter as tk +from tkinter import Tk, ttk + +from eltakobus.message import * +from eltakobus.eep import A5_08_01 + +from ..data import data_helper + + +class EepChecker(): + + def __init__(self, main:Tk): + popup = Toplevel(main, padx=4, pady=4) + popup.wm_title("EEP Checker") + self.popup = popup + + row = 0 + self.l_telegram = ttk.Label(popup, text="A5 5A") + self.l_telegram.grid(row=row, column=0, sticky=EW, columnspan=2) + + row += 1 + l = ttk.Label(popup, text="EEP: ") + l.grid(row=row, column=0, sticky=W) + + self.cb_eep = ttk.Combobox(popup, state="readonly", width="14") + self.cb_eep['values'] = data_helper.get_all_eep_names() + self.cb_eep.set(A5_08_01.eep_string) + self.cb_eep.grid(row=row, column=1, sticky=W) + self.cb_eep.bind('<>', lambda e: [self.set_message_type(), self.show_eep_values(e)]) + + + row += 1 + l = ttk.Label(popup, text="Message Type: ") + l.grid(row=row, column=0, sticky=W) + + self.l_msg_type = ttk.Label(popup, text='') + self.l_msg_type.grid(row=row, column=1, sticky=W) + # self.cb_msg_type = ttk.Combobox(popup, state="readonly", width="14") + # self.cb_msg_type['values'] = ['RPS (Org = 0x05)', '1BS (Org = 0x06)', '4BS (Org = 0x7)'] + # self.cb_msg_type.set('4BS (Org = 0x7)') + # self.cb_msg_type.grid(row=row, column=1, sticky=W) + # self.cb_msg_type.bind('<>', self.show_message) + + + row += 1 + l = ttk.Label(popup, text="Data: ") + l.grid(row=row, column=0, sticky=W) + + self.e_data = ttk.Entry(popup, width="12") + self.e_data.insert(END, "aa 80 76 0f") + self.e_data.bind_all('', self.show_eep_values) + self.e_data.grid(row=row, column=1, sticky=W) + + + row += 1 + l = ttk.Label(popup, text="EEP Values: ") + l.grid(row=row, column=0, sticky=W, columnspan=2) + + + row += 1 + self.l_result = ttk.Label(popup, text="", font=("Arial", 11)) + self.l_result.grid(row=row, column=0, sticky=W, columnspan=2) + + + row += 1 + l = ttk.Label(popup, text="") + l.grid(row=row, column=0, sticky=W, columnspan=2) + + + row += 1 + b = ttk.Button(popup, text="Close", command=popup.destroy) + b.bind('', lambda e: popup.destroy()) + b.grid(row=row, column=0, columnspan=2, sticky=E) + + self.show_eep_values(None) + + popup.wm_attributes('-toolwindow', 'True') + # popup.resizable (width=False, height=False) + # popup.transient(main) + # popup.grab_set() + + # center + # w = 260 + # h = 260 + # x = main.winfo_x() + main.winfo_width()/2 - w/2 + # y = main.winfo_y() + main.winfo_height()/2 - h/2 + # popup.geometry('%dx%d+%d+%d' % (w, h, x, y)) + + main.wait_window(popup) + + + def enable_disable_data_fields(self): + msg_type = self.cb_msg_type.get() + if '4BS' in msg_type: + self.e_data2.config(state=NORMAL) + self.e_data1.config(state=NORMAL) + self.e_data0.config(state=NORMAL) + else: + self.e_data2.config(state=DISABLED) + self.e_data1.config(state=DISABLED) + self.e_data0.config(state=DISABLED) + + + def set_message_type(self): + try: + msg = Regular4BSMessage(b'\x00\x00\x00\x00', 0x00, b'\x00\x00\x00\x00', False) + eep = data_helper.find_eep_by_name(self.cb_eep.get()) + eep_values = data_helper.get_values_for_eep(eep, msg) + self.l_msg_type.config(text= '4BS (Org = 0x7)') + return '4BS (Org = 0x7)' + except: + pass + + try: + msg = Regular1BSMessage(b'\x00\x00\x00\x00', 0x00, b'\x00', False) + eep = data_helper.find_eep_by_name(self.cb_eep.get()) + eep_values = data_helper.get_values_for_eep(eep, msg) + self.l_msg_type.config(text= '1BS (Org = 0x06)') + return '1BS (Org = 0x06)' + except: + pass + + try: + msg = RPSMessage(b'\x00\x00\x00\x00', 0x00, b'\x00', False) + eep = data_helper.find_eep_by_name(self.cb_eep.get()) + eep_values = data_helper.get_values_for_eep(eep, msg) + self.l_msg_type.config(text= 'RPS (Org = 0x05)') + return 'RPS (Org = 0x05)' + except: + pass + + + def get_data_from_entry(self): + text = self.e_data.get().upper() + hex_string = '0x' + for c in text: + if c in ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F']: + hex_string += c + return int(hex_string, 16).to_bytes(4, 'big') + + + def show_eep_values(self, event): + msg_type = self.set_message_type() + try: + data = self.get_data_from_entry() + + if '4BS' in msg_type: + msg = Regular4BSMessage(b'\x00\x00\x00\x00', 0x00, data, False) + elif '1BS' in msg_type: + data = data[0:1] + msg = Regular1BSMessage(b'\x00\x00\x00\x00', 0x00, data, False) + elif 'RPS' in msg_type: + msg = RPSMessage(b'\x00\x00\x00\x00', 0x00, data, False) + data = data[0:1] + + msg_text = b2a(msg.serialize()).upper() + self.l_telegram.config(text=msg_text) + except: + self.l_telegram.config(text='') + + try: + eep = data_helper.find_eep_by_name(self.cb_eep.get()) + eep_values = data_helper.get_values_for_eep(eep, msg) + self.l_result.config(text='\n'.join(eep_values).replace('_',' ')) + + except: + self.l_result.config(text='') \ No newline at end of file diff --git a/eo_man/view/menu_presenter.py b/eo_man/view/menu_presenter.py index 725a9cc..d9352c3 100644 --- a/eo_man/view/menu_presenter.py +++ b/eo_man/view/menu_presenter.py @@ -15,6 +15,7 @@ from ..icons.image_gallary import ImageGallery +from .eep_checker import EepChecker from .about_window import AboutWindow from . import DEFAULT_WINDOW_TITLE @@ -81,6 +82,12 @@ def __init__(self, main: Tk, app_bus: AppBus, data_manager: DataManager): command=self.reset_to_suggested_ha_properties) + tool_menu = Menu(menu_bar, tearoff=False) + menu_bar.add_cascade(label="Tools", menu=tool_menu) + tool_menu.add_command(label="EEP Checker", + command=lambda: EepChecker(main)) + + help_menu = Menu(menu_bar, tearoff=False) menu_bar.add_cascade(label="Help", menu=help_menu) diff --git a/setup.py b/setup.py index 702576b..abea214 100644 --- a/setup.py +++ b/setup.py @@ -25,7 +25,7 @@ setup( name='eo_man', - version='0.1.10', + version='0.1.11', package_dir={'eo_man':"eo_man"}, # packages=find_packages("./eo-man"), #package_data={'': ['*.png']},