From 567a274cdb8f666ae9f5b565b74f2342d04a60c2 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Sun, 16 May 2021 17:09:15 +0300 Subject: minor fix (fix missing space between value and unit) --- inverter-bot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inverter-bot') diff --git a/inverter-bot b/inverter-bot index b9937e4..03bf192 100755 --- a/inverter-bot +++ b/inverter-bot @@ -112,7 +112,7 @@ def msg_status(update: Update, context: CallbackContext) -> None: html += ' (%s%%)' % (gs['output_load_percent']['value']) if gs['pv1_input_power']['value'] > 0: - html += '\nInput power: %s%s' % (gs['pv1_input_power']['value'], gs['pv1_input_power']['unit']) + html += '\nInput power: %s %s' % (gs['pv1_input_power']['value'], gs['pv1_input_power']['unit']) if gs['grid_voltage']['value'] > 0 or gs['grid_freq']['value'] > 0: html += '\nGenerator: %s %s' % (gs['grid_voltage']['unit'], gs['grid_voltage']['value']) -- cgit v1.2.3 From 8a15b9fb6b29461f2b3f0890c172ba25c0e37287 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Sun, 23 May 2021 00:01:24 +0300 Subject: handle exception --- inverter-bot | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'inverter-bot') diff --git a/inverter-bot b/inverter-bot index 03bf192..edae9a5 100755 --- a/inverter-bot +++ b/inverter-bot @@ -80,6 +80,16 @@ def reply(update: Update, text: str) -> None: parse_mode=ParseMode.HTML) +def handle_exc(update: Update, e) -> None: + logging.exception(str(e)) + + if isinstance(e, InverterError): + err = json.loads(str(e))['message'] + reply(update, f'Error: {err}') + + elif not isinstance(e, TimedOut): + reply(update, 'exception: ' + str(e)) + # # command/message handlers # @@ -121,9 +131,7 @@ def msg_status(update: Update, context: CallbackContext) -> None: # send response reply(update, html) except Exception as e: - logging.exception(str(e)) - if not isinstance(e, TimedOut): - reply(update, 'exception: ' + str(e)) + handle_exc(update, e) def msg_generation(update: Update, context: CallbackContext) -> None: @@ -162,9 +170,7 @@ def msg_generation(update: Update, context: CallbackContext) -> None: # send response reply(update, html) except Exception as e: - logging.exception(str(e)) - if not isinstance(e, TimedOut): - reply(update, 'exception: ' + str(e)) + handle_exc(update, e) def msg_gs(update: Update, context: CallbackContext) -> None: @@ -172,9 +178,7 @@ def msg_gs(update: Update, context: CallbackContext) -> None: status = inverter.exec('get-status', format=Format.TABLE) reply(update, status) except Exception as e: - logging.exception(str(e)) - if not isinstance(e, TimedOut): - reply(update, 'exception: ' + str(e)) + handle_exc(update, e) def msg_ri(update: Update, context: CallbackContext) -> None: @@ -182,9 +186,7 @@ def msg_ri(update: Update, context: CallbackContext) -> None: rated = inverter.exec('get-rated', format=Format.TABLE) reply(update, rated) except Exception as e: - logging.exception(str(e)) - if not isinstance(e, TimedOut): - reply(update, 'exception: ' + str(e)) + handle_exc(update, e) def msg_errors(update: Update, context: CallbackContext) -> None: @@ -192,9 +194,7 @@ def msg_errors(update: Update, context: CallbackContext) -> None: errors = inverter.exec('get-errors', format=Format.TABLE) reply(update, errors) except Exception as e: - logging.exception(str(e)) - if not isinstance(e, TimedOut): - reply(update, 'exception: ' + str(e)) + handle_exc(update, e) def msg_all(update: Update, context: CallbackContext) -> None: -- cgit v1.2.3