Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Documentation] Example #9

Open
phigjm opened this issue Sep 1, 2024 · 0 comments
Open

[Documentation] Example #9

phigjm opened this issue Sep 1, 2024 · 0 comments

Comments

@phigjm
Copy link

phigjm commented Sep 1, 2024

It would be cool to have a complet example code.
E.g. i tried this so far:

from moonraker_api import MoonrakerClient, MoonrakerListener


class APIConnector(MoonrakerListener):
    def __init__(self):
        self.running = False
        self.client = MoonrakerClient(
            self,
            "yourURL.local",
            "7125",
            "",
        )

    async def start(self) -> None:
        """Start the websocket connection."""
        self.running = True
        return await self.client.connect()

    async def stop(self) -> None:
        """Stop the websocket connection."""
        self.running = False
        await self.client.disconnect()


async def get_printer_info():
    api_connector = APIConnector()
    await api_connector.start()
    response = await api_connector.client.request("printer.info")
    return response


printer_info = asyncio.run(get_printer_info())

print(printer_info)

but I always get the error:

response = await api_connector.client.request("printer.info")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: object AwaitableTaskContext can't be used in 'await' expression
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x0000024C10544290>```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant