uns-kit 0.0.3__py3-none-any.whl → 0.0.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- uns_kit/cli.py +19 -0
- uns_kit/templates/default/README.md +10 -0
- uns_kit/templates/default/pyproject.toml +17 -0
- uns_kit/templates/default/src/main.py +27 -0
- {uns_kit-0.0.3.dist-info → uns_kit-0.0.4.dist-info}/METADATA +9 -1
- uns_kit-0.0.4.dist-info/RECORD +13 -0
- uns_kit-0.0.3.dist-info/RECORD +0 -10
- {uns_kit-0.0.3.dist-info → uns_kit-0.0.4.dist-info}/WHEEL +0 -0
- {uns_kit-0.0.3.dist-info → uns_kit-0.0.4.dist-info}/entry_points.txt +0 -0
uns_kit/cli.py
CHANGED
|
@@ -2,6 +2,9 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import asyncio
|
|
4
4
|
import json
|
|
5
|
+
import os
|
|
6
|
+
import shutil
|
|
7
|
+
import importlib.resources
|
|
5
8
|
from pathlib import Path
|
|
6
9
|
from typing import Optional
|
|
7
10
|
|
|
@@ -120,6 +123,22 @@ async def _run_subscribe(
|
|
|
120
123
|
print(f"{msg.topic} <binary {len(msg.payload)} bytes>")
|
|
121
124
|
|
|
122
125
|
|
|
126
|
+
@cli.command("create", help="Create a new UNS Python app (default template).")
|
|
127
|
+
@click.argument("dest")
|
|
128
|
+
def create(dest: str):
|
|
129
|
+
template_root = importlib.resources.files("uns_kit").joinpath("templates/default")
|
|
130
|
+
dest_path = os.path.abspath(dest)
|
|
131
|
+
if os.path.exists(dest_path):
|
|
132
|
+
raise click.ClickException(f"Destination already exists: {dest_path}")
|
|
133
|
+
shutil.copytree(template_root, dest_path)
|
|
134
|
+
click.echo(f"Created UNS Python app at {dest_path}")
|
|
135
|
+
click.echo("Next steps:")
|
|
136
|
+
click.echo(f" 1) cd {dest_path}")
|
|
137
|
+
click.echo(" 2) poetry install")
|
|
138
|
+
click.echo(" 3) poetry run python src/main.py")
|
|
139
|
+
click.echo(" 4) Edit config.json with your MQTT host/credentials")
|
|
140
|
+
|
|
141
|
+
|
|
123
142
|
@cli.command("write-config", help="Write a minimal config.json scaffold.")
|
|
124
143
|
@click.option("--path", default="config.json", show_default=True)
|
|
125
144
|
def write_config(path: str):
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "uns-py-app"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Example UNS Python application"
|
|
5
|
+
authors = ["Your Name <you@example.com>"]
|
|
6
|
+
package-mode = false
|
|
7
|
+
|
|
8
|
+
[tool.poetry.dependencies]
|
|
9
|
+
python = "^3.10"
|
|
10
|
+
uns-kit = "*"
|
|
11
|
+
|
|
12
|
+
[tool.poetry.group.dev.dependencies]
|
|
13
|
+
pytest = "^8.3.3"
|
|
14
|
+
|
|
15
|
+
[build-system]
|
|
16
|
+
requires = ["poetry-core"]
|
|
17
|
+
build-backend = "poetry.core.masonry.api"
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import json
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from uns_kit import UnsMqttClient, TopicBuilder, UnsPacket
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
async def main():
|
|
8
|
+
cfg = json.loads(Path("config.json").read_text())
|
|
9
|
+
tb = TopicBuilder(cfg["packageName"], cfg["packageVersion"], cfg["processName"])
|
|
10
|
+
client = UnsMqttClient(
|
|
11
|
+
cfg["host"],
|
|
12
|
+
port=cfg.get("port"),
|
|
13
|
+
username=cfg.get("username") or None,
|
|
14
|
+
password=cfg.get("password") or None,
|
|
15
|
+
tls=cfg.get("tls", False),
|
|
16
|
+
client_id=cfg.get("clientId"),
|
|
17
|
+
topic_builder=tb,
|
|
18
|
+
reconnect_interval=1,
|
|
19
|
+
)
|
|
20
|
+
await client.connect()
|
|
21
|
+
await client.publish_packet("raw/data/", UnsPacket.data(value=1, uom="count"))
|
|
22
|
+
async for msg in client.resilient_messages("uns-infra/#"):
|
|
23
|
+
print(msg.topic, msg.payload.decode())
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
if __name__ == "__main__":
|
|
27
|
+
asyncio.run(main())
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: uns-kit
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.4
|
|
4
4
|
Summary: Lightweight Python UNS MQTT client (pub/sub + infra topics)
|
|
5
5
|
License: MIT
|
|
6
6
|
Author: Aljoša Vister
|
|
@@ -70,6 +70,14 @@ async for msg in client.resilient_messages("uns-infra/#"):
|
|
|
70
70
|
- `examples/publish.py` — publish 5 data packets.
|
|
71
71
|
- `examples/subscribe.py` — resilient subscription with auto-reconnect.
|
|
72
72
|
|
|
73
|
+
### Create a new project
|
|
74
|
+
```bash
|
|
75
|
+
uns-kit-py create my-uns-py-app
|
|
76
|
+
cd my-uns-py-app
|
|
77
|
+
poetry install
|
|
78
|
+
poetry run python src/main.py
|
|
79
|
+
```
|
|
80
|
+
|
|
73
81
|
## Notes
|
|
74
82
|
- Default QoS is 0; will message is retained on `<statusTopic>alive`.
|
|
75
83
|
- Uptime is published every 10 seconds on `<statusTopic>uptime`.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
uns_kit/__init__.py,sha256=-4R72u-uzg2ib2Z1SFQiSX5KSNYY6oMqVvGoVPI3eQs,290
|
|
2
|
+
uns_kit/cli.py,sha256=USq7bHl6sL75s--Y_nV2j7v1JScZWehZp92GyqYgjyw,5552
|
|
3
|
+
uns_kit/client.py,sha256=bFXAKmuR06mSlO8tsAoeB7jv9RQgw1a_AIbXQNpNFTw,5815
|
|
4
|
+
uns_kit/config.py,sha256=mRMiuxGV6CEIBDVZUJQqYIeGxKzfBhlXCcGNXnVtBj4,869
|
|
5
|
+
uns_kit/packet.py,sha256=qd6BrCv_JE8fxh-iaJBAVhUZvY28lhiDr9F1At8CXjw,1675
|
|
6
|
+
uns_kit/templates/default/README.md,sha256=IQ1zvCSzigE3foKBLkDv9UZnZEScuS6V19oCSCJPvXw,149
|
|
7
|
+
uns_kit/templates/default/pyproject.toml,sha256=dxSghe6RiljsXfz4Gt_YXB1g-P_W2jiYUJk6ug4TytE,362
|
|
8
|
+
uns_kit/templates/default/src/main.py,sha256=0mxq9Oa00UwqlEiJIBnlDiulBPECJ4YSojqjv6tonTk,850
|
|
9
|
+
uns_kit/topic_builder.py,sha256=JGYdYynRWWSwzXaCaRLjap0-du13eSc6qe1V0GrD_ak,1492
|
|
10
|
+
uns_kit-0.0.4.dist-info/METADATA,sha256=CjegZQzS1ZMvRyMEXB7p21RaejS7cidggXYvKgZ_QMs,2736
|
|
11
|
+
uns_kit-0.0.4.dist-info/WHEEL,sha256=3ny-bZhpXrU6vSQ1UPG34FoxZBp3lVcvK0LkgUz6VLk,88
|
|
12
|
+
uns_kit-0.0.4.dist-info/entry_points.txt,sha256=sLvTioiJQfGczUD-ODVx2xwwtHcGKjlIOn8t_Lt87Pg,47
|
|
13
|
+
uns_kit-0.0.4.dist-info/RECORD,,
|
uns_kit-0.0.3.dist-info/RECORD
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
uns_kit/__init__.py,sha256=-4R72u-uzg2ib2Z1SFQiSX5KSNYY6oMqVvGoVPI3eQs,290
|
|
2
|
-
uns_kit/cli.py,sha256=BVqLPNegmbEasBr_k2Qt4S_A3fQuP8tn5d5Z_bO5t5w,4800
|
|
3
|
-
uns_kit/client.py,sha256=bFXAKmuR06mSlO8tsAoeB7jv9RQgw1a_AIbXQNpNFTw,5815
|
|
4
|
-
uns_kit/config.py,sha256=mRMiuxGV6CEIBDVZUJQqYIeGxKzfBhlXCcGNXnVtBj4,869
|
|
5
|
-
uns_kit/packet.py,sha256=qd6BrCv_JE8fxh-iaJBAVhUZvY28lhiDr9F1At8CXjw,1675
|
|
6
|
-
uns_kit/topic_builder.py,sha256=JGYdYynRWWSwzXaCaRLjap0-du13eSc6qe1V0GrD_ak,1492
|
|
7
|
-
uns_kit-0.0.3.dist-info/METADATA,sha256=w6WCkwhbS7KmMuqskMiFKgblVFJsgKu4-G_Rbw6WPBk,2604
|
|
8
|
-
uns_kit-0.0.3.dist-info/WHEEL,sha256=3ny-bZhpXrU6vSQ1UPG34FoxZBp3lVcvK0LkgUz6VLk,88
|
|
9
|
-
uns_kit-0.0.3.dist-info/entry_points.txt,sha256=sLvTioiJQfGczUD-ODVx2xwwtHcGKjlIOn8t_Lt87Pg,47
|
|
10
|
-
uns_kit-0.0.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|