From b6fe115ea7f1b597689724b6217e0aa2daf7dd01 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 8 Dec 2022 11:17:52 +0000 Subject: [PATCH] CAPI: Add support for plugin `cmdr_data_legacy()` * Renames `plug.notify_newdata()` to the more precise `notify_capidata()`. * If CAPI data was from SERVER_LEGACY, then use plugin `cmdr_data_legacy()` instead of `cmdr_data()`. --- EDMarketConnector.py | 3 +-- plug.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index ced2ed33..64d0aee2 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1210,8 +1210,7 @@ class AppWindow(object): monitor.state['Loan'] = capi_response.capi_data['commander'].get('debt', 0) # stuff we can do when not docked - # TODO: Use plug.notify_capi_legacy if Legacy host - err = plug.notify_newdata(capi_response.capi_data, monitor.is_beta) + err = plug.notify_capidata(capi_response.capi_data, monitor.is_beta) self.status['text'] = err and err or '' if err: play_bad = True diff --git a/plug.py b/plug.py index b1c0d3da..deeb6ebe 100644 --- a/plug.py +++ b/plug.py @@ -370,7 +370,7 @@ def notify_dashboard_entry( return error -def notify_newdata( +def notify_capidata( data: companion.CAPIData, is_beta: bool ) -> Optional[str]: @@ -383,13 +383,21 @@ def notify_newdata( """ error = None for plugin in PLUGINS: - cmdr_data = plugin._get_func('cmdr_data') + # TODO: Handle it being Legacy data + if data.source_host == companion.SERVER_LEGACY: + cmdr_data = plugin._get_func('cmdr_data_legacy') + + else: + cmdr_data = plugin._get_func('cmdr_data') + if cmdr_data: try: newerror = cmdr_data(data, is_beta) error = error or newerror + except Exception: logger.exception(f'Plugin "{plugin.name}" failed') + return error