moonraker-api-2.0.6


توضیحات

Async websocket API client for Moonraker
ویژگی مقدار
سیستم عامل OS Independent
نام فایل moonraker-api-2.0.6
نام moonraker-api
نسخه کتابخانه 2.0.6
نگهدارنده []
ایمیل نگهدارنده []
نویسنده Clifford Roche
ایمیل نویسنده -
آدرس صفحه اصلی https://github.com/cmroche/moonraker-api
آدرس اینترنتی https://pypi.org/project/moonraker-api/
مجوز -
![Python package](https://github.com/cmroche/moonraker-api/workflows/Python%20package/badge.svg) ## Moonracker Websocket API Client Connect, request and subscribe to the Moonraker Websockets API without polling. **moonraker-api** is a ***fully async*** Python 3 based package for interfacing with Moonraker's API. ## Getting the package The easiest way to grab **moonraker-api** is through PyPI `pip3 install moonraker-api` ## Use Moonraker-API ### Connect and Disconnect ```python class APIConnector(MoonrakerListener): def __init__(): self.running = False self.client = MoonrakerClient( self, HOST, PORT, API-KEY, ) 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() ``` ### Query the API ```python api_connector = APIConnector() response = await api_connector.client.request("printer.info") ``` ### Handle Push Notifications ```python class APIConnector(MoonrakerListener): # Other class details, see above ... async def state_changed(self, state: str) -> None: """Notifies of changing websocket state.""" _LOGGER.debug("Stated changed to %s", state) if state == WEBSOCKET_STATE_CONNECTING: pass elif state == WEBSOCKET_STATE_CONNECTED: pass elif state == WEBSOCKET_STATE_READY: pass elif state == WEBSOCKET_STATE_PAUSED: pass elif state == WEBSOCKET_STATE_STOPPED: pass async def on_exception(self, exception: BaseException) -> None: """Notifies of exceptions from the websocket run loop.""" _LOGGER.debug("Received exception from API websocket %s", str(exception)) if isinstance(exception, ClientNotAuthenticatedError): self.entry.async_start_reauth(self.hass) else: raise exception async def on_notification(self, method: str, data: Any) -> None: """Notifies of state updates.""" _LOGGER.debug("Received notification %s -> %s", method, data) # Subscription notifications if method == "notify_status_update": message = data[0] timestamp = data[1] # Do stuff ... ```


نیازمندی

مقدار نام
- aiohttp~=3.8
- async-timeout~=4.0


زبان مورد نیاز

مقدار نام
>=3.8 Python


نحوه نصب


نصب پکیج whl moonraker-api-2.0.6:

    pip install moonraker-api-2.0.6.whl


نصب پکیج tar.gz moonraker-api-2.0.6:

    pip install moonraker-api-2.0.6.tar.gz