Python sensor reading ws://<localnetwork>/ws and where to put refresh interval?

I am new to home assistant and have run in to my first hurdle. My most important integration is reading State of Charge from my Battery Management System on my local network.

I had hoped to use Scrape integration to pull the information from the http page, but it is dynamic data so beautifulSoup based tools only get the placeholder, not the real values updated by javascript.

I can see the page uses a websocket ws://localnetworkIPaddress/ws broadcasting two JSON responses every second, I can get these remotely using Postman.

Now my plan is to define a sensor as a python script using asyncio and websockets libraries.

Three questions

(1) have I missed some existing integration that reads websockets or a simpler method?

(2) has anyone got a similar sensor script I can use as my starting point?

(3) where does the sensor refresh belong, (a) defined in home-assistant somehow and my python script runs, prints and exits or (b) in the python so the script prints output every time it processes a JSON response and runs continuously?

Hoping for some wisdom of the community before I start learning new (to me) language and libraries.

Thanks

Can you just use the shell command integration and use CURL to get the info?

Edit: see this thread for details

Thank you, I like that idea, less tools in the chain. I will do some playing with cURL

Edit 1; having just spent an hour trying to get cURL to upgrade the connection to websocket from http, I saw enough mentions of websocat ( GitHub - vi/websocat: Command-line client for WebSockets, like netcat (or curl) for ws:// with advanced socat-like functions · GitHub ) to try it

websocat = just works™

Now I am up to catching and parsing my json response

Edit 2; then I moved to my home-assistant docker and remembered that adding tools to an image is not good practice so it is worth spending a bit more time trying to get this with the built in cURL

Edit 3: all my problems with cURL were my network vLANs, it really is as simple as

curl --include --no-buffer ws://192.168.1.184/ws