\n# Crescience Websocket Client
Websocket client for Crescience devices written in python.
## Requirements
- python>=3.7
- pip
## Installation
You can install the client using `pip`:
```bash
pip install crescience-websocket-py
```
## Usage
The client provides two different usage cases:
### Callback
```python
from crescience_websocket_py import WebsocketClient, Message, ConnectionMessageType
def callback(msg_type: ConnectionMessageType, msg: Message | None, error:ConnectionErrorReason | None) -> None:
if msg_type==ConnectionMessageType.TEXT:
print(f"Received message: {str(msg)}")
elif msg_type==ConnectionMessageType.OPEN:
print("Connection opened")
elif msg_type==ConnectionMessageType.ERROR:
print(f"Connection error: {error}")
elif msg_type==ConnectionMessageType.CLOSE:
print("Connection closed")
client=WebsocketClient(
host="<IP_OR_DOMAIN>",
port=81,
verify_ssl=False,
callback=callback
)
```
### Class inheritance
```python
from crescience_websocket_py import WebsocketClient, Message, ConnectionMessageType
class MyCrescienceClient(WebsocketClient):
def __init__(self, host:str) -> None:
super().__init__(host=host, port=81, verify_ssl=False)
async def received(self, msg: Message) -> None:
print(f"Received message: {str(msg)}")
async def on_open(self) -> None:
print("Connection opened")
async def on_close(self) -> None:
print("Connection closed")
async def on_error(self, error:ConnectionMessageType) -> None:
print(f"Connection error: {error}")
client=MyCrescienceClient("<IP_OR_DOMAIN>")
```
## Check for firmware-updates
You can check if firmware updates are available using the following command:
```python
from crescience_websocket_py import get_latest_version
latest_version = get_latest_version(device_type="crescontrol")
print(latest_version["version"])
```
Raw data
{
"_id": null,
"home_page": "https://github.com/cre-science/crescience-websocket-py",
"name": "crescience-websocket-py",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "pypi,crescience,python",
"author": "Crescience",
"author_email": "development@cre.science",
"download_url": "https://files.pythonhosted.org/packages/02/a3/8ae79cd7213c4c85567996bf0381eb4c5a5de56ac8822ea98946d0501429/crescience_websocket_py-0.0.3.tar.gz",
"platform": null,
"description": "\\n# Crescience Websocket Client\n\nWebsocket client for Crescience devices written in python.\n\n## Requirements\n\n- python>=3.7\n- pip\n\n## Installation\n\nYou can install the client using `pip`:\n\n```bash\npip install crescience-websocket-py\n```\n\n## Usage\n\nThe client provides two different usage cases:\n\n### Callback\n\n```python\nfrom crescience_websocket_py import WebsocketClient, Message, ConnectionMessageType\n\n\ndef callback(msg_type: ConnectionMessageType, msg: Message | None, error:ConnectionErrorReason | None) -> None:\n if msg_type==ConnectionMessageType.TEXT:\n print(f\"Received message: {str(msg)}\")\n elif msg_type==ConnectionMessageType.OPEN:\n print(\"Connection opened\")\n elif msg_type==ConnectionMessageType.ERROR:\n print(f\"Connection error: {error}\")\n elif msg_type==ConnectionMessageType.CLOSE:\n print(\"Connection closed\")\n\nclient=WebsocketClient(\n host=\"<IP_OR_DOMAIN>\",\n port=81,\n verify_ssl=False,\n callback=callback\n)\n```\n\n### Class inheritance\n\n```python\nfrom crescience_websocket_py import WebsocketClient, Message, ConnectionMessageType\n\n\nclass MyCrescienceClient(WebsocketClient):\n def __init__(self, host:str) -> None:\n super().__init__(host=host, port=81, verify_ssl=False)\n\n async def received(self, msg: Message) -> None:\n print(f\"Received message: {str(msg)}\")\n\n async def on_open(self) -> None:\n print(\"Connection opened\")\n\n async def on_close(self) -> None:\n print(\"Connection closed\")\n\n async def on_error(self, error:ConnectionMessageType) -> None:\n print(f\"Connection error: {error}\")\n\nclient=MyCrescienceClient(\"<IP_OR_DOMAIN>\")\n```\n\n## Check for firmware-updates\n\nYou can check if firmware updates are available using the following command:\n\n```python\nfrom crescience_websocket_py import get_latest_version\n\nlatest_version = get_latest_version(device_type=\"crescontrol\")\n\nprint(latest_version[\"version\"])\n```\n",
"bugtrack_url": null,
"license": "",
"summary": "Websocket Client for Crescience devices",
"version": "0.0.3",
"project_urls": {
"Homepage": "https://github.com/cre-science/crescience-websocket-py"
},
"split_keywords": [
"pypi",
"crescience",
"python"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8feb7bd7b109f2ca7704ee9d3993ef615eaf9c5669b6f32f2db752f2a3dc036d",
"md5": "817ad64cf91306d5fb1ae6f8d4c893d8",
"sha256": "f54340ea43a7f4efd31284248fab3b7abfadaa1064cf7cb521acea327b487f3c"
},
"downloads": -1,
"filename": "crescience_websocket_py-0.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "817ad64cf91306d5fb1ae6f8d4c893d8",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 13193,
"upload_time": "2023-12-07T15:32:26",
"upload_time_iso_8601": "2023-12-07T15:32:26.876019Z",
"url": "https://files.pythonhosted.org/packages/8f/eb/7bd7b109f2ca7704ee9d3993ef615eaf9c5669b6f32f2db752f2a3dc036d/crescience_websocket_py-0.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "02a38ae79cd7213c4c85567996bf0381eb4c5a5de56ac8822ea98946d0501429",
"md5": "0172d4fa10a3a006651d12ece56d5e93",
"sha256": "b605fcb8fb29f2b6b9d09b92ba777715d5ee1d40bf121bd841a542c58cb01313"
},
"downloads": -1,
"filename": "crescience_websocket_py-0.0.3.tar.gz",
"has_sig": false,
"md5_digest": "0172d4fa10a3a006651d12ece56d5e93",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 12693,
"upload_time": "2023-12-07T15:32:31",
"upload_time_iso_8601": "2023-12-07T15:32:31.551781Z",
"url": "https://files.pythonhosted.org/packages/02/a3/8ae79cd7213c4c85567996bf0381eb4c5a5de56ac8822ea98946d0501429/crescience_websocket_py-0.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-07 15:32:31",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "cre-science",
"github_project": "crescience-websocket-py",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "crescience-websocket-py"
}