Skip to content

Commit

Permalink
Merge pull request #15 from grimmpp/feature-branch
Browse files Browse the repository at this point in the history
Small tool added to check EEP values of a data set.
  • Loading branch information
grimmpp authored Feb 26, 2024
2 parents 66b6db6 + b58b1f0 commit a024810
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 7 deletions.
3 changes: 3 additions & 0 deletions changes.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 2 additions & 1 deletion eo_man/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ',
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions eo_man/data/data_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 2 additions & 5 deletions eo_man/data/data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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




169 changes: 169 additions & 0 deletions eo_man/view/eep_checker.py
Original file line number Diff line number Diff line change
@@ -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('<<ComboboxSelected>>', 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('<<ComboboxSelected>>', 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('<Key>', 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('<Return>', 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='')
7 changes: 7 additions & 0 deletions eo_man/view/menu_presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']},
Expand Down

0 comments on commit a024810

Please sign in to comment.