From f61b7c4ce0e9e734a4ac416a5c6d2c673ca44f81 Mon Sep 17 00:00:00 2001 From: Philipp Grimm Date: Thu, 23 May 2024 12:11:14 +0200 Subject: [PATCH] Added MGW support --- changes.md | 2 +- eo_man/controller/serial_controller.py | 21 ++++++++++++++++++--- eo_man/data/const.py | 2 +- eo_man/view/serial_communication_bar.py | 4 ++-- requirements.txt | 2 +- setup.py | 4 ++-- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/changes.md b/changes.md index 6013d65..d38a936 100644 --- a/changes.md +++ b/changes.md @@ -1,6 +1,6 @@ # Change Log -## v0.1.22 Support for MGW Gateway +## v0.1.23 Support for MGW Gateway * Added support for [MGW Gateway](https://www.piotek.de/PioTek-MGW-POE) (ESP3 over LAN) ## v0.1.21 EEP representation bug fixes diff --git a/eo_man/controller/serial_controller.py b/eo_man/controller/serial_controller.py index 05bc3ab..49d8570 100644 --- a/eo_man/controller/serial_controller.py +++ b/eo_man/controller/serial_controller.py @@ -217,14 +217,18 @@ def establish_serial_connection(self, serial_port:str, device_type:str) -> None: delay_message=delay_message, auto_reconnect=False) self._serial_bus.start() - self._serial_bus.is_serial_connected.wait(timeout=10) + self._serial_bus.is_serial_connected.wait(timeout=2) if not self._serial_bus.is_active(): self._serial_bus.stop() if self._serial_bus.is_active(): self.connected_gateway_type = device_type - self.app_bus.fire_event(AppBusEventType.LOG_MESSAGE, {'msg': f"Serial connection established. serial port: {serial_port}, baudrate: {baudrate}", 'color':'green'}) + if device_type == GDN[GDT.LAN]: + msg = f"TCP to Serial connection established. Server: {serial_port}:5100" + else: + msg = f"Serial connection established. serial port: {serial_port}, baudrate: {baudrate}" + self.app_bus.fire_event(AppBusEventType.LOG_MESSAGE, {'msg': msg, 'color':'green'}) if device_type == GDN[GDT.EltakoFAM14]: @@ -248,11 +252,22 @@ def run(): AppBusEventType.CONNECTION_STATUS_CHANGE, {'serial_port': serial_port, 'baudrate': baudrate, 'connected': self._serial_bus.is_active()}) + else: + self.app_bus.fire_event(AppBusEventType.CONNECTION_STATUS_CHANGE, {'serial_port': serial_port, 'baudrate': baudrate, 'connected': False}) + if device_type == GDN[GDT.LAN]: + msg = f"Couldn't establish connection to {serial_port}:5100! Try to restart device." + else: + msg = f"Establish connection for {device_type} on port {serial_port} failed! Device not ready." + self.app_bus.fire_event(AppBusEventType.LOG_MESSAGE, {'msg': msg, 'log-level': 'ERROR', 'color': 'red'}) + except Exception as e: self._serial_bus.stop() self.connected_gateway_type = None self.app_bus.fire_event(AppBusEventType.CONNECTION_STATUS_CHANGE, {'serial_port': serial_port, 'baudrate': baudrate, 'connected': False}) - msg = f"Establish connection for {device_type} on port {serial_port} failed!!!" + if device_type == GDN[GDT.LAN]: + msg = f"Establish connection for {device_type} to {serial_port}:5100 failed! Retry later." + else: + msg = f"Establish connection for {device_type} on port {serial_port} failed!" self.app_bus.fire_event(AppBusEventType.LOG_MESSAGE, {'msg': msg, 'log-level': 'ERROR', 'color': 'red'}) logging.exception(msg, exc_info=True) diff --git a/eo_man/data/const.py b/eo_man/data/const.py index 4127003..99f16c8 100644 --- a/eo_man/data/const.py +++ b/eo_man/data/const.py @@ -120,7 +120,7 @@ def is_esp2_gateway(cls, dev_type) -> bool: GatewayDeviceType.EltakoFAMUSB: 'FAM-USB (ESP2)', GatewayDeviceType.USB300: 'ESP3 Gateway', GatewayDeviceType.ESP3: 'ESP3 Gateway', - GatewayDeviceType.LAN: 'MGW LAN/Wifi', + GatewayDeviceType.LAN: 'LAN Gateway (ESP3)', } def get_display_names(): diff --git a/eo_man/view/serial_communication_bar.py b/eo_man/view/serial_communication_bar.py index 64b2a4e..2c4bf65 100644 --- a/eo_man/view/serial_communication_bar.py +++ b/eo_man/view/serial_communication_bar.py @@ -36,7 +36,7 @@ def __init__(self, main: Tk, app_bus:AppBus, data_manager:DataManager, serial_co l = Label(f, text="Gateway Type: ") l.pack(side=tk.LEFT, padx=(0, 5), pady=5) - self.cb_device_type = ttk.Combobox(f, state="readonly", width="12") + self.cb_device_type = ttk.Combobox(f, state="readonly", width="18") self.cb_device_type.pack(side=tk.LEFT, padx=(0, 5), pady=5) self.cb_device_type['values'] = get_display_names() # ['FAM14', 'FGW14-USB', 'FAM-USB', 'USB300', 'LAN Gateway'] self.cb_device_type.set(self.cb_device_type['values'][0]) @@ -45,7 +45,7 @@ def __init__(self, main: Tk, app_bus:AppBus, data_manager:DataManager, serial_co l = ttk.Label(f, text="Serial Port: ") l.pack(side=tk.LEFT, padx=(0, 5), pady=5) - self.cb_serial_ports = ttk.Combobox(f, state="readonly", width="10") + self.cb_serial_ports = ttk.Combobox(f, state="readonly", width="14") self.cb_serial_ports.pack(side=tk.LEFT, padx=(0, 5), pady=5) self.b_connect = ttk.Button(f, text="Connect", state=DISABLED, command=self.toggle_serial_connection_command) diff --git a/requirements.txt b/requirements.txt index 3310bce..e8c92a3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,5 +10,5 @@ termcolor==2.4.0 tkinterhtml==0.7 requests==2.31.0 enocean==0.60.1 -esp2_gateway_adapter>=0.2.1 +esp2_gateway_adapter>=0.2.2 zeroconf==0.132.2 \ No newline at end of file diff --git a/setup.py b/setup.py index aab1fe8..bd394ab 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ license = f.read() required = ['eltako14bus==0.0.53', 'requests==2.31.0', 'enocean==0.60.1', 'pyserial', 'pyserial-asyncio', 'aiocoap', - 'esp2_gateway_adapter==0.2.1', + 'esp2_gateway_adapter==0.2.2', # 'homeassistant', 'zeroconf==0.132.2', 'pyyaml', @@ -27,7 +27,7 @@ setup( name='eo_man', - version='0.1.22', + version='0.1.23', package_dir={'eo_man':"eo_man"}, # packages=find_packages("./eo-man"), #package_data={'': ['*.png']},