HomeAssistant OS or Raspberry OS

I’d say go back to Home Assistant OS and check out the AppDaemon addon. Or the pyscript custom integration if you like that better. Both will let you run your own python code and pass information back to HA.

Or if those don’t work for you, consider making an addon. Addons are essentially just docker containers, can run your python code in one.