From ba9c7073a5dddcc844ac4d437a4c5e58fd9d52ee Mon Sep 17 00:00:00 2001 From: Guillaume <sagitta1618@gmail.com> Date: Wed, 2 Nov 2022 11:10:34 +0000 Subject: [PATCH] mqtt pure JSON --- http_interface.py | 1 + ohmpi.py | 43 ++++++++++++++++++++++--------------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/http_interface.py b/http_interface.py index 52b88317..7fd04e37 100644 --- a/http_interface.py +++ b/http_interface.py @@ -157,6 +157,7 @@ class MyServer(SimpleHTTPRequestHandler): # we pass the sequence as a list of list as this object is easier to parse for the json.loads() # of ohmpi._process_commands() payload = json.dumps({'cmd_id': cmd_id, 'cmd': 'set_sequence', 'kwargs': {'sequence': sequence}}) + print('payload ===', payload) publish.single(payload=payload, **publisher_config) payload = json.dumps({'cmd_id': cmd_id + '_settings', 'cmd': 'update_settings', 'kwargs': {'config': dic['config']}}) cdic = dic['config'] diff --git a/ohmpi.py b/ohmpi.py index 88fcb425..70c50dcc 100644 --- a/ohmpi.py +++ b/ohmpi.py @@ -510,27 +510,28 @@ class OhmPi(object): self.exec_logger.debug(f'Decoded message {decoded_message}') cmd_id = decoded_message.pop('cmd_id', None) cmd = decoded_message.pop('cmd', None) - args = decoded_message.pop('args', None) - if args is not None: - if len(args) != 0: - if args[0] != '[': - args = f'["{args}"]' - self.exec_logger.debug(f'args to decode: {args}') - args = json.loads(args) if args != '[]' else None - self.exec_logger.debug(f'Decoded args {args}') - else: - args = None + args = None + # args = decoded_message.pop('args', None) + # if args is not None: + # if len(args) != 0: + # if args[0] != '[': + # args = f'["{args}"]' + # self.exec_logger.debug(f'args to decode: {args}') + # args = json.loads(args) if args != '[]' else None + # self.exec_logger.debug(f'Decoded args {args}') + # else: + # args = None kwargs = decoded_message.pop('kwargs', None) - if kwargs is not None: - if len(kwargs) != 0: - if kwargs[0] != '{': - kwargs = '{"' + kwargs + '"}' - self.exec_logger.debug(f'kwargs to decode: {kwargs}') - kwargs = json.loads(kwargs) if kwargs != '' else None - self.exec_logger.debug(f'Decoded kwargs {kwargs}') - else: - kwargs = None - self.exec_logger.debug(f"Calling method {cmd}({str(args) + ', ' if args is not None else ''}" + # if kwargs is not None: + # if len(kwargs) != 0: + # if kwargs[0] != '{': + # kwargs = '{"' + kwargs + '"}' + # self.exec_logger.debug(f'kwargs to decode: {kwargs}') + # kwargs = json.loads(kwargs) if kwargs != '' else None + # self.exec_logger.debug(f'Decoded kwargs {kwargs}') + # else: + # kwargs = None + self.exec_logger.debug(f"Calling method {cmd}(" f"{str(kwargs) if kwargs is not None else ''})") if cmd_id is None: self.exec_logger.warning('You should use a unique identifier for cmd_id') @@ -549,7 +550,7 @@ class OhmPi(object): status = True except Exception as e: self.exec_logger.error( - f"Unable to execute {cmd}({str(args) + ', ' if args is not None else ''}" + f"Unable to execute {cmd}("#{str(args) + ', ' if args is not None else ''}" f"{str(kwargs) if kwargs is not None else ''}): {e}") status = False except Exception as e: -- GitLab