feat(emulator): docstrings

This commit is contained in:
Laureηt 2021-11-02 19:32:54 +01:00
parent 0473db2a28
commit eadc64b036
No known key found for this signature in database
GPG key ID: D88C6B294FD40994
2 changed files with 18 additions and 12 deletions

View file

@ -39,7 +39,12 @@ mgba.log.silence()
logging.basicConfig(level=logging.DEBUG)
async def parse_message(message: dict[str, str]):
def parse_message(message: dict[str, str]):
"""Parse the server's reponse.
Args:
message (dict[str, str]): the data received (through the websocket).
"""
if "action" in message:
data = message["action"]
if data in KEYMAP:
@ -69,6 +74,7 @@ async def parse_message(message: dict[str, str]):
async def main():
"""Start the emulator."""
with pyvirtualcam.Camera(width=WIDTH, height=HEIGHT, fps=FPS) as cam:
logging.debug(f"Using virtual camera: {cam.device}")
async with websockets.connect(URI) as websocket:

View file

@ -16,15 +16,15 @@ VOTES: Votes = Votes()
USERS: Users = Users()
async def parse_message(user: User, msg: dict[str, str]):
"""Parse the `user`'s `msg`.
async def parse_message(user: User, message: dict[str, str]):
"""Parse the user's message.
Args:
user (User): the sender of the message.
msg (dict[str, str]): the data received (through the websocket).
message (dict[str, str]): the data received (through the websocket).
"""
if "auth" in msg:
data = msg["auth"]
if "auth" in message:
data = message["auth"]
if USERS.emulator is None and data == PASSWORD_EMU:
USERS.emulator = user
logging.debug(f"emulator authenticated: {user}")
@ -32,8 +32,8 @@ async def parse_message(user: User, msg: dict[str, str]):
USERS.admin = user
logging.debug(f"admin authenticated: {user}")
if "action" in msg:
data = msg["action"]
if "action" in message:
data = message["action"]
if data in VOTES:
VOTES[data] += 1
user.last_message = time.time()
@ -41,8 +41,8 @@ async def parse_message(user: User, msg: dict[str, str]):
else:
logging.error(f"unsupported action: {data}")
if "admin" in msg:
data = msg["admin"]
if "admin" in message:
data = message["admin"]
if USERS.emulator is not None and user == USERS.admin:
if data == "save":
await USERS.emulator.send('{"admin":"save"}')
@ -53,8 +53,8 @@ async def parse_message(user: User, msg: dict[str, str]):
else:
logging.error(f"user is not admin: {user}")
if "emu" in msg:
data = msg["emu"]
if "emu" in message:
data = message["emu"]
if user == USERS.emulator:
if data == "get":
await USERS.emulator.send(f'{{"action":"{VOTES.next_vote()}"}}')