1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-13 07:47:14 +03:00

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()`.
This commit is contained in:
Athanasius 2022-12-08 11:17:52 +00:00
parent b754ef8700
commit b6fe115ea7
No known key found for this signature in database
GPG Key ID: 772697E181BB2767
2 changed files with 11 additions and 4 deletions

View File

@ -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

12
plug.py
View File

@ -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