Skip to content

Commit c0dbb04

Browse files
committed
http: api: implement expand device properties
1 parent b7a3bc5 commit c0dbb04

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,19 @@ def register(parent: cli.Subparsers) -> None:
2020
action="store_true",
2121
help="Expand device manifest information",
2222
)
23+
parser.add_argument(
24+
"-p",
25+
"--properties",
26+
action="store_true",
27+
help="Expand device properties information",
28+
)
2329

2430
@staticmethod
2531
async def run(args: argparse.Namespace) -> None:
2632
async with http.api.Client(http.api.Config.from_env()) as client:
27-
device = await client.devices.get(args.id, expand_manifest=args.manifest)
33+
device = await client.devices.get(
34+
args.id,
35+
expand_manifest=args.manifest,
36+
expand_properties=args.properties,
37+
)
2838
print(json.dumps(device.to_dto()))

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ async def create_standalone(self, name: str, site_id: str | None = None) -> Devi
2121
api.check_error(response)
2222
return await self.get(device_id=response.json()["device_id"])
2323

24-
async def get(self, device_id: str, expand_manifest: bool = False) -> Device:
24+
async def get(
25+
self,
26+
device_id: str,
27+
expand_manifest: bool = False,
28+
expand_properties: bool = False,
29+
) -> Device:
2530
url = f"v3/devices/{device_id}"
26-
expand = {"manifest": expand_manifest}
31+
expand = {"manifest": expand_manifest, "properties": expand_properties}
2732
params = {"expand": ",".join(k for k, v in expand.items() if v)}
2833
response = await self._client.get(url, params=params)
2934
api.check_error(response)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Device:
1818
type: DeviceType
1919
authorized_role: AuthorizedRole
2020
manifest: dict[str, Any] | None = None
21+
properties: dict[str, Any] | None = None
2122

2223
@classmethod
2324
def from_dto(cls, dto: dict[str, Any]) -> Self:
@@ -31,6 +32,7 @@ def from_dto(cls, dto: dict[str, Any]) -> Self:
3132
type=DeviceType(dto["type"]),
3233
authorized_role=AuthorizedRole(dto["authorized_role"]),
3334
manifest=dto.get("manifest"),
35+
properties=dto.get("properties"),
3436
)
3537

3638
def to_dto(self) -> dict[str, Any]:
@@ -44,4 +46,5 @@ def to_dto(self) -> dict[str, Any]:
4446
"type": self.type.value,
4547
"authorized_role": self.authorized_role.value,
4648
"manifest": self.manifest,
49+
"properties": self.properties,
4750
}

0 commit comments

Comments
 (0)