@@ -60,7 +60,7 @@ class MfColour(StrEnum):
6060
6161class MobiFlightClient :
6262 def __init__ (self , websocket_uri : str , max_retries : int = 3 ) -> None :
63- self .websocket : Optional [ws_client .WebSocketClientProtocol ] = None
63+ self .websocket : Optional [ws_client .ClientConnection ] = None
6464 self .connected : asyncio .Event = asyncio .Event ()
6565 self .websocket_uri : str = websocket_uri
6666 self .retries : int = 0
@@ -420,50 +420,6 @@ async def connect_to_mcdu(self):
420420 await asyncio .sleep (5 ) # Wait before retry
421421 return False
422422
423- async def run (self ):
424- """Main processing loop"""
425- logging .info ("Starting FlyByWire SimBridge client" )
426- while True :
427- try :
428- # Wait for messages from the MCDU
429- if self .fbw_websocket is None :
430- if not await self .connect_to_mcdu ():
431- logging .info ("Max SimBridge attempts reached. Waiting for new attempts." )
432- await asyncio .sleep (
433- 10
434- ) # Wait longer between retries if we can't connect
435- continue
436-
437- msg = await self .fbw_websocket .recv ()
438-
439- # Process any update messages
440- if msg .startswith ("update:" ):
441- data_json = json .loads (msg [msg .index (":" ) + 1 :])
442-
443- for side in ("left" , "right" ):
444- mobiflight = self .mobiflight .get (side )
445- mcdu_data = data_json .get (side )
446- if mobiflight is not None and mobiflight .is_connected ():
447- # only update if there is new data to display
448- if (
449- mcdu_data is not None
450- and self .last_mcdu_data .get (side ) != mcdu_data
451- ):
452- self .last_mcdu_data [side ] = mcdu_data
453- await mobiflight .send (create_mobi_json (mcdu_data ))
454- elif mcdu_data is None :
455- self .last_mcdu_data [side ] = None
456- # clear the display
457- await mobiflight .send (create_mobi_json (dict ()))
458- else :
459- # make sure we get a refresh if we later connect
460- self .last_mcdu_data [side ] = None
461-
462- except Exception as e :
463- logging .error (f"Error processing MCDU data: { e } " )
464- self .fbw_websocket = None
465- await asyncio .sleep (5 )
466-
467423 async def request_update (self ):
468424 if self .fbw_websocket is not None :
469425 await self .fbw_websocket .send ("requestUpdate" )
0 commit comments