Skip to content

Commit

Permalink
docs: extend docs (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinHjelmare authored Jan 14, 2023
1 parent 8f31d6f commit 90e8499
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
6 changes: 4 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 51 additions & 3 deletions docs/usage.md
Original file line number Diff line number Diff line change
@@ -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
```

0 comments on commit 90e8499

Please sign in to comment.