return return codes for login/logout

This commit is contained in:
onyx-and-iris 2022-07-21 23:14:42 +01:00
parent a4fd61ceab
commit c105115458

View File

@ -6,7 +6,8 @@ from threading import Thread
from typing import Iterable, NoReturn, Optional, Self, Union from typing import Iterable, NoReturn, Optional, Self, Union
from .cbindings import CBindings from .cbindings import CBindings
from .error import VMError from .error import CAPIError, VMError
from .inst import bits
from .kinds import KindId from .kinds import KindId
from .subject import Subject from .subject import Subject
from .util import comp, polling, script from .util import comp, polling, script
@ -74,16 +75,17 @@ class Remote(CBindings):
def login(self) -> NoReturn: def login(self) -> NoReturn:
"""Login to the API, initialize dirty parameters""" """Login to the API, initialize dirty parameters"""
res = self.vm_login() res = self.vm_login()
if res == 0: if res == 1:
print(f"Successfully logged into {self}")
elif res == 1:
self.run_voicemeeter(self.kind.name) self.run_voicemeeter(self.kind.name)
elif res != 0:
raise CAPIError(f"VBVMR_Login returned {res}")
print(f"Successfully logged into {self}")
self.clear_dirty() self.clear_dirty()
def run_voicemeeter(self, kind_id: str) -> NoReturn: def run_voicemeeter(self, kind_id: str) -> NoReturn:
if kind_id not in (kind.name.lower() for kind in KindId): if kind_id not in (kind.name.lower() for kind in KindId):
raise VMError(f"Unexpected Voicemeeter type: '{kind_id}'") raise VMError(f"Unexpected Voicemeeter type: '{kind_id}'")
if kind_id == "potato" and ct.sizeof(ct.c_voidp) == 8: if kind_id == "potato" and bits == 8:
value = KindId[kind_id.upper()].value + 3 value = KindId[kind_id.upper()].value + 3
else: else:
value = KindId[kind_id.upper()].value value = KindId[kind_id.upper()].value
@ -102,11 +104,12 @@ class Remote(CBindings):
"""Returns Voicemeeter's version as a string""" """Returns Voicemeeter's version as a string"""
ver = ct.c_long() ver = ct.c_long()
self.vm_get_version(ct.byref(ver)) self.vm_get_version(ct.byref(ver))
v1 = (ver.value & 0xFF000000) >> 24 return "{}.{}.{}.{}".format(
v2 = (ver.value & 0x00FF0000) >> 16 (ver.value & 0xFF000000) >> 24,
v3 = (ver.value & 0x0000FF00) >> 8 (ver.value & 0x00FF0000) >> 16,
v4 = ver.value & 0x000000FF (ver.value & 0x0000FF00) >> 8,
return f"{v1}.{v2}.{v3}.{v4}" ver.value & 0x000000FF,
)
@property @property
def pdirty(self) -> bool: def pdirty(self) -> bool:
@ -250,8 +253,7 @@ class Remote(CBindings):
return getattr(self, obj)[index] return getattr(self, obj)[index]
elif obj == "vban": elif obj == "vban":
return getattr(getattr(self, obj), f"{m2}stream")[index] return getattr(getattr(self, obj), f"{m2}stream")[index]
else: raise ValueError(obj)
raise ValueError(obj)
[param(key).apply(datum).then_wait() for key, datum in data.items()] [param(key).apply(datum).then_wait() for key, datum in data.items()]
@ -272,8 +274,9 @@ class Remote(CBindings):
self.clear_dirty() self.clear_dirty()
time.sleep(0.1) time.sleep(0.1)
res = self.vm_logout() res = self.vm_logout()
if res == 0: if res != 0:
print(f"Successfully logged out of {self}") raise CAPIError(f"VBVMR_Logout returned {res}")
print(f"Successfully logged out of {self}")
def end_thread(self): def end_thread(self):
self.running = False self.running = False