From 224627828644798fb2dd3ecadac4b2f0f85f919b Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 13 Apr 2021 12:12:51 +0100 Subject: [PATCH] Odyssey Suits: Store available data from CAPI. I've gone with 'None' for when there's no data, rather than {}. That makes for simpler checks on if there is data (a dict.get('foo') only checks for that, not the dict structure otherwise). If no 'suit' in the data we assume no Odyssey, but otherwise plough on with dict.get() statements as they'll default to None if it's not present. *Users* of this monitor.state[] extra data get to choose what to do if some data is present but not other. --- companion.py | 23 +++++++++++++++++ edmc_data.py | 5 ++++ monitor.py | 72 +++++++++++++++++++++++++++------------------------- 3 files changed, 66 insertions(+), 34 deletions(-) diff --git a/companion.py b/companion.py index 7702d046..6c71080a 100644 --- a/companion.py +++ b/companion.py @@ -589,6 +589,10 @@ class Session(object): # logger.trace('timestamp not in data, adding from response headers') data['timestamp'] = time.strftime('%Y-%m-%dT%H:%M:%SZ', parsedate(r.headers['Date'])) # type: ignore + # Update Odyssey Suit data + if endpoint == URL_QUERY: + self.suit_update(data) + return data def profile(self) -> CAPIData: @@ -632,6 +636,25 @@ class Session(object): return data + def suit_update(self, data: CAPIData) -> None: + """ + Update monitor.state suit data. + + :param data: CAPI data to extra suit data from. + """ + if (current_suit := data.get('suit')) is None: + # Probably no Odyssey on the account, so point attempting more. + return + + monitor.state['SuitCurrent'] = current_suit + monitor.state['Suits'] = data.get('suits') + + if (suit_loadouts := data.get('loadouts')) is None: + logger.warning('CAPI data had "suit" but no (suit) "loadouts"') + + monitor.state['SuitLoadoutCurrent'] = data.get('loadout') + monitor.state['SuitLoadouts'] = suit_loadouts + def close(self) -> None: """Close CAPI authorization session.""" self.state = Session.STATE_INIT diff --git a/edmc_data.py b/edmc_data.py index 1d51d185..61c72bd2 100644 --- a/edmc_data.py +++ b/edmc_data.py @@ -23,6 +23,11 @@ companion_category_map = { 'NonMarketable': False, # Don't appear in the in-game market so don't report } +# Map suit symbol names to English localised names +companion_suit_type_map = { + 'TacticalSuit_Class1': 'Dominator Suit', +} + # Map Coriolis's names to names displayed in the in-game shipyard. coriolis_ship_map = { 'Cobra Mk III': 'Cobra MkIII', diff --git a/monitor.py b/monitor.py index 5aa9838a..7d2e14b3 100644 --- a/monitor.py +++ b/monitor.py @@ -114,42 +114,46 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below # Cmdr state shared with EDSM and plugins # If you change anything here update PLUGINS.md documentation! self.state: Dict = { - 'Captain': None, # On a crew - 'Cargo': defaultdict(int), - 'Credits': None, - 'FID': None, # Frontier Cmdr ID - 'Horizons': None, # Does this user have Horizons? - 'Loan': None, - 'Raw': defaultdict(int), - 'Manufactured': defaultdict(int), - 'Encoded': defaultdict(int), - 'Engineers': {}, - 'Rank': {}, - 'Reputation': {}, - 'Statistics': {}, - 'Role': None, # Crew role - None, Idle, FireCon, FighterCon - 'Friends': set(), # Online friends - 'ShipID': None, - 'ShipIdent': None, - 'ShipName': None, - 'ShipType': None, - 'HullValue': None, - 'ModulesValue': None, - 'Rebuy': None, - 'Modules': None, - 'CargoJSON': None, # The raw data from the last time cargo.json was read - 'Route': None, # Last plotted route from Route.json file - 'OnFoot': False, # Whether we think you're on-foot - 'Component': defaultdict(int), # Odyssey Components in Ship Locker - 'Item': defaultdict(int), # Odyssey Items in Ship Locker - 'Consumable': defaultdict(int), # Odyssey Consumables in Ship Locker - 'Data': defaultdict(int), # Odyssey Data in Ship Locker + 'Captain': None, # On a crew + 'Cargo': defaultdict(int), + 'Credits': None, + 'FID': None, # Frontier Cmdr ID + 'Horizons': None, # Does this user have Horizons? + 'Loan': None, + 'Raw': defaultdict(int), + 'Manufactured': defaultdict(int), + 'Encoded': defaultdict(int), + 'Engineers': {}, + 'Rank': {}, + 'Reputation': {}, + 'Statistics': {}, + 'Role': None, # Crew role - None, Idle, FireCon, FighterCon + 'Friends': set(), # Online friends + 'ShipID': None, + 'ShipIdent': None, + 'ShipName': None, + 'ShipType': None, + 'HullValue': None, + 'ModulesValue': None, + 'Rebuy': None, + 'Modules': None, + 'CargoJSON': None, # The raw data from the last time cargo.json was read + 'Route': None, # Last plotted route from Route.json file + 'OnFoot': False, # Whether we think you're on-foot + 'Component': defaultdict(int), # Odyssey Components in Ship Locker + 'Item': defaultdict(int), # Odyssey Items in Ship Locker + 'Consumable': defaultdict(int), # Odyssey Consumables in Ship Locker + 'Data': defaultdict(int), # Odyssey Data in Ship Locker 'BackPack': { # Odyssey BackPack contents - 'Component': defaultdict(int), # BackPack Components - 'Consumable': defaultdict(int), # BackPack Consumables - 'Item': defaultdict(int), # BackPack Items - 'Data': defaultdict(int), # Backpack Data + 'Component': defaultdict(int), # BackPack Components + 'Consumable': defaultdict(int), # BackPack Consumables + 'Item': defaultdict(int), # BackPack Items + 'Data': defaultdict(int), # Backpack Data }, + 'SuitCurrent': None, + 'Suits': None, + 'SuitLoadoutCurrent': None, + 'SuitLoadouts': None, } def start(self, root: 'tkinter.Tk') -> bool: # noqa: CCR001