Create async loop to get data from tinytuya

Hi all!

Can any one give me some suggestions regarding a custom component that Im trying to implement for my local tuya sensors with tinytuya py library? More specific what is the problem that I have and I cannot find any solution on the forum/github is: I am trying to start a task that is listen the communication of sensors with the gateway the working py code is:

while (True):
        if (pingtime <= time.time()):
            payload = gw.generate_payload(tinytuya.HEART_BEAT)
            gw.send(payload)
            pingtime = time.time() + 9

        # receive from the gateway object to get updates for all sub-devices
        print('recv:')
        data = gw.receive()
        print(data)

What I need and I cannot find a solution is to start a background job that is running this while and parse the data that I receive there and put the dps in the entity state
I have tried to implement some solutions but it is not working

Here you have one of my attempts:

        try:
            self.loop = asyncio.get_event_loop()
        except:
            self.loop = asyncio.new_event_loop()
        finally:
            self.loop.call_soon(self.asyncGetDataFromTuya)

        try:
            self.loop.run_forever()
        finally:
            self.loop.close()

Please keep in mind that I’m new in HA and python so any explicit documentation examples that can help me would be pretty low level of knowledge.

Thanks!