Skip to content

Commit 495ae22

Browse files
committed
http: api: devices: add get manifest
1 parent 2e84232 commit 495ae22

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/enapter/cli/http/api/device_command.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
DeviceGenerateCommunicationConfigCommand,
1010
)
1111
from .device_get_command import DeviceGetCommand
12+
from .device_get_manifest_command import DeviceGetManifestCommand
1213
from .device_list_command import DeviceListCommand
1314
from .device_update_command import DeviceUpdateCommand
1415

@@ -29,6 +30,7 @@ def register(parent: cli.Subparsers) -> None:
2930
DeviceDeleteCommand,
3031
DeviceGenerateCommunicationConfigCommand,
3132
DeviceGetCommand,
33+
DeviceGetManifestCommand,
3234
DeviceListCommand,
3335
DeviceUpdateCommand,
3436
]:
@@ -47,6 +49,8 @@ async def run(args: argparse.Namespace) -> None:
4749
await DeviceGenerateCommunicationConfigCommand.run(args)
4850
case "get":
4951
await DeviceGetCommand.run(args)
52+
case "get-manifest":
53+
await DeviceGetManifestCommand.run(args)
5054
case "list":
5155
await DeviceListCommand.run(args)
5256
case "update":
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import argparse
2+
import json
3+
4+
from enapter import cli, http
5+
6+
7+
class DeviceGetManifestCommand(cli.Command):
8+
9+
@staticmethod
10+
def register(parent: cli.Subparsers) -> None:
11+
parser = parent.add_parser(
12+
"get-manifest", formatter_class=argparse.ArgumentDefaultsHelpFormatter
13+
)
14+
parser.add_argument("id", help="ID or slug of the device")
15+
16+
@staticmethod
17+
async def run(args: argparse.Namespace) -> None:
18+
async with http.api.Client(http.api.Config.from_env()) as client:
19+
manifest = await client.devices.get_manifest(args.id)
20+
print(json.dumps(manifest))

src/enapter/http/api/devices/client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import AsyncGenerator
1+
from typing import Any, AsyncGenerator
22

33
import httpx
44

@@ -27,6 +27,12 @@ async def get(self, device_id: str) -> Device:
2727
api.check_error(response)
2828
return Device.from_dto(response.json()["device"])
2929

30+
async def get_manifest(self, device_id: str) -> dict[str, Any]:
31+
url = f"v3/devices/{device_id}/manifest"
32+
response = await self._client.get(url)
33+
api.check_error(response)
34+
return response.json()["manifest"]
35+
3036
@async_.generator
3137
async def list(self) -> AsyncGenerator[Device, None]:
3238
url = "v3/devices"

0 commit comments

Comments
 (0)