fix: move mutable object initialization to constructor
This commit is contained in:
parent
526597decf
commit
4ec4bb9aac
@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "sati-ac"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
authors = [
|
||||
{ name="sati.ac", email="sati.ac@proton.me" }
|
||||
]
|
||||
|
@ -25,7 +25,7 @@ class Sati:
|
||||
|
||||
_socket: SatiSocket
|
||||
_project_id: int
|
||||
_awaited_tasks: dict = {}
|
||||
_awaited_tasks: dict
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@ -35,6 +35,7 @@ class Sati:
|
||||
project_id: int = 0,
|
||||
debug = False
|
||||
):
|
||||
self._awaited_tasks = {}
|
||||
self._socket = SatiSocket(token, reconnection_interval, url, debug)
|
||||
self._project_id = project_id
|
||||
self._socket.on('taskUpdate', self._process_task)
|
||||
@ -63,8 +64,8 @@ class Sati:
|
||||
else:
|
||||
fut.set_exception(UnableToSolveTask(task))
|
||||
|
||||
def destroy(self):
|
||||
self._socket.close()
|
||||
async def destroy(self):
|
||||
await self._socket.close()
|
||||
|
||||
async def get_balance(self) -> float:
|
||||
return (await self._socket.call('getBalance')).balance
|
||||
|
@ -36,11 +36,11 @@ class SatiSocket:
|
||||
__reconnection_interval: float
|
||||
__connector_ref: asyncio.Task
|
||||
__id_counter: int = 0
|
||||
__awaited_replies: dict = {}
|
||||
__awaited_replies: dict
|
||||
__error = None
|
||||
__queue = []
|
||||
__queue: list
|
||||
__url: str
|
||||
__event_handlers = {}
|
||||
__event_handlers: dict
|
||||
__debug: bool
|
||||
|
||||
def __init__(
|
||||
@ -50,6 +50,9 @@ class SatiSocket:
|
||||
url = 'wss://api.sati.ac/ws',
|
||||
debug = False
|
||||
):
|
||||
self.__awaited_replies = {}
|
||||
self.__queue = []
|
||||
self.__event_handlers = {}
|
||||
self.__token = token
|
||||
self.__reconnection_interval = reconnection_interval
|
||||
self.__url = url
|
||||
@ -117,7 +120,9 @@ class SatiSocket:
|
||||
if msg_type in ( 'auth', 'call' ):
|
||||
return await fut
|
||||
|
||||
async def call(self, method: str, data: dict = {}) -> SatiDict:
|
||||
async def call(self, method: str, data: dict | None = None) -> SatiDict:
|
||||
if data == None: data = {}
|
||||
|
||||
if self.__state == STATE_CONNECTED:
|
||||
resp = await self.__send('call', {
|
||||
'method': method,
|
||||
@ -154,8 +159,9 @@ class SatiSocket:
|
||||
del self.__awaited_replies[key]
|
||||
raise ex
|
||||
|
||||
def close(self):
|
||||
async def close(self):
|
||||
self.__connector_ref.cancel()
|
||||
await self.__socket.close()
|
||||
|
||||
def on(self, event: str, handler: typing.Callable[[SatiDict], None]):
|
||||
if event not in self.__event_handlers:
|
||||
|
Loading…
x
Reference in New Issue
Block a user