Integration for multifunctional worker microcontroller connected over serial


I have an Arduino board which has sensors and an rf transmitter connected in it’s GPIO pins. The board is connected to the RPi running over (usb) serial connection.

I am planning to write an integration in Home Assistant to

  • Read various sensor values transmitted by the Arduino as JSON (this is currently working using the normal Serial integration and some template sensors)
  • Control several light fixtures by transmitting commands at 433Mhz using the rf transmitter. This is already written and working in the Arduino, it is controlled by sending simple commands over the serial link such as NEXA ON 1 1 to turn on the first light in the first channel.

How should I model the integration as it is composed of 2 totally different components which must share state (the serial connection)?
Is it possible to create a service that holds the serial connection and exposes the incoming serial data as it’s state (just like the current serial integration) and then create several entities for each light fixture that call the service to transmit the required serial data over the connection?
Or do I just need to resort to reading by polling, opening and then closing the serial connection each time, allowing the transmitting service access to the serial connection?

Any pointers to pre-existing code with a similar case of having a stateful service that other entities call?

Thanks for any help!