33import asyncio
44import logging
55from abc import ABC
6- from asyncio import Lock , TimerHandle , Transport
6+ from asyncio import Lock , TimerHandle , Transport , get_running_loop
77from collections .abc import Callable
88from dataclasses import dataclass
99
@@ -72,7 +72,8 @@ async def keep_alive_func(self, _=None):
7272 await self .ping ()
7373 except RoborockException :
7474 pass
75- self .keep_alive_task = self .event_loop .call_later (10 , lambda : asyncio .create_task (self .keep_alive_func ()))
75+ loop = asyncio .get_running_loop ()
76+ self .keep_alive_task = loop .call_later (10 , lambda : asyncio .create_task (self .keep_alive_func ()))
7677
7778 async def async_connect (self ) -> None :
7879 should_ping = False
@@ -82,7 +83,8 @@ async def async_connect(self) -> None:
8283 self ._sync_disconnect ()
8384 async with async_timeout .timeout (self .queue_timeout ):
8485 self ._logger .debug (f"Connecting to { self .host } " )
85- self .transport , _ = await self .event_loop .create_connection ( # type: ignore
86+ loop = get_running_loop ()
87+ self .transport , _ = await loop .create_connection ( # type: ignore
8688 lambda : self ._local_protocol , self .host , 58867
8789 )
8890 self ._logger .info (f"Connected to { self .host } " )
@@ -94,7 +96,8 @@ async def async_connect(self) -> None:
9496 await self .keep_alive_func ()
9597
9698 def _sync_disconnect (self ) -> None :
97- if self .transport and self .event_loop .is_running ():
99+ loop = asyncio .get_running_loop ()
100+ if self .transport and loop .is_running ():
98101 self ._logger .debug (f"Disconnecting from { self .host } " )
99102 self .transport .close ()
100103 if self .keep_alive_task :
0 commit comments