From 90e84997fff26047ab2aaafad5ea6a241f9745c3 Mon Sep 17 00:00:00 2001 From: Martin Hjelmare Date: Sat, 14 Jan 2023 02:54:28 +0100 Subject: [PATCH] docs: extend docs (#212) --- docs/conf.py | 6 ++++-- docs/usage.md | 54 ++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 8899e96..e3cca00 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -4,11 +4,13 @@ # -- Project information ----------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information +from aiovlc import __version__ project = "aiovlc" -copyright = "2023, Martin Hjelmare" +project_copyright = "2023, Martin Hjelmare" author = "Martin Hjelmare" -release = "0.2.1" +version = __version__ +release = __version__ # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration diff --git a/docs/usage.md b/docs/usage.md index 9878f18..8044bac 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -1,9 +1,57 @@ # Usage -To use this package, import it: +Here's an example of how to use the library to connect to a VLC instance: ```python -import aiovlc +from aiovlc.client import Client +from aiovlc.exceptions import AIOVLCError +from aiovlc.model.command import Info, Status + +LOGGER = logging.getLogger("aiovlc") + + +def run_client() -> None: + """Run a VLC client.""" + LOGGER.info("Starting client") + host = "localhost" + password = "a1ve3ry4ha6rd7pas9wo1rd" + port = 4212 + try: + asyncio.run(start_client(host, password, port)) + except KeyboardInterrupt: + pass + finally: + LOGGER.info("Stopped client") + + +async def start_client(host: str, password: str, port: int) -> None: + """Start the client.""" + try: + async with Client(password, host=host, port=port) as vlc_client: + await vlc_client.login() + await handle_client(vlc_client) + except AIOVLCError as err: + LOGGER.error("Error '%s'", err) + + +async def handle_client(vlc_client: Client) -> None: + """Handle the client calls.""" + while True: + command = Status() + output = await command.send(vlc_client) + LOGGER.debug("Received: %s", output) + info_command = Info() + info_output = await info_command.send(vlc_client) + LOGGER.debug("Received: %s", info_output) + await asyncio.sleep(10) + + +if __name__ == "__main__": + run_client() ``` -TODO: Document usage +There's also a CLI to test the library. + +```sh +aiovlc --debug client +```