Polling TCP server

I’m creating a custom component to integrate an alarm platform.
I can query the alarm system via tcp/ip to get the status of the the different sensors

import socket
import time
import binascii

    client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
    print('Failed to create socket')

E_IP= ""
E_PORT = 10002

payload = bytes.fromhex( "02010800003f004803")

    msg = client.recv(4096)
except socket.error:
    print('Failed to send data')


The component will need to poll the alarm system every 0.5 sec / 1sec.
What’s the best method to implement it? Can you point me to an existing component that is using this mechanism?


Maybe the pyscript integration?

I haven’t needed to do anything like what you describe, but I found this comment which seems like it may point you in the right direction.