From 88b3dc27e583ce3eb79e3f48d831e1cada41980d Mon Sep 17 00:00:00 2001
From: Gareth Harper <spansh@users.noreply.github.com>
Date: Wed, 25 May 2022 14:01:54 +0000
Subject: [PATCH] Added fssbodysignals

---
 plugins/eddn.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 60 insertions(+), 1 deletion(-)

diff --git a/plugins/eddn.py b/plugins/eddn.py
index c7cd4059..0bca62a9 100644
--- a/plugins/eddn.py
+++ b/plugins/eddn.py
@@ -1213,6 +1213,57 @@ class EDDN:
         this.eddn.export_journal_entry(cmdr, entry, msg)
         return None
 
+    def export_journal_fssbodysignals(
+        self, cmdr: str, system_name: str, system_starpos: list, is_beta: bool, entry: MutableMapping[str, Any]
+    ) -> Optional[str]:
+        """
+        Send an FSSBodySignals message to EDDN on the correct schema.
+
+        :param cmdr: the commander under which this upload is made
+        :param system_name: Name of current star system
+        :param system_starpos: Coordinates of current star system
+        :param is_beta: whether or not we are in beta mode
+        :param entry: the journal entry to send
+        """
+        # {
+        #   "timestamp" : "2022-03-15T13:07:51Z",
+        #   "event" : "FSSBodySignals",
+        #   "BodyName" : "Phroi Blou BQ-Y d1162 1 a",
+        #   "BodyID" : 12,
+        #   "SystemAddress" : 39935704602251,
+        #   "Signals" : [
+        #     {
+        #       "Type" : "$SAA_SignalType_Geological;",
+        #       "Type_Localised" : "Geological",
+        #       "Count" : 3
+        #     }
+        #   ]
+        # }
+
+        #######################################################################
+        # Elisions
+        entry = filter_localised(entry)
+        #######################################################################
+
+        #######################################################################
+        # Augmentations
+        #######################################################################
+        # In this case should add StarPos
+        ret = this.eddn.entry_augment_system_data(entry, system_name, system_starpos)
+        if isinstance(ret, str):
+            return ret
+
+        entry = ret
+        #######################################################################
+
+        msg = {
+            '$schemaRef': f'https://eddn.edcd.io/schemas/fssbodysignals/1{"/test" if is_beta else ""}',
+            'message': entry
+        }
+
+        this.eddn.export_journal_entry(cmdr, entry, msg)
+        return None
+
     def canonicalise(self, item: str) -> str:
         """
         Canonicalise the given commodity name.
@@ -1545,7 +1596,7 @@ def journal_entry(  # noqa: C901, CCR001
 
         # NB: If adding FSSSignalDiscovered these absolutely come in at login
         #     time **BEFORE** the `Location` event, so we won't yet know things
-        #     like SystemNane, or StarPos.
+        #     like SystemName, or StarPos.
         #     We can either have the "now send the batch" code add such (but
         #     that has corner cases around changing systems in the meantime),
         #     drop those events, or if the schema allows, send without those
@@ -1559,6 +1610,14 @@ def journal_entry(  # noqa: C901, CCR001
                 is_beta,
                 entry
             )
+        elif event_name == 'fssbodysignals':
+            return this.eddn.export_journal_fssbodysignals(
+                cmdr,
+                system,
+                state['StarPos'],
+                is_beta,
+                entry
+            )
 
     # Send journal schema events to EDDN, but not when on a crew
     if (config.get_int('output') & config.OUT_SYS_EDDN and not state['Captain'] and