Skip to content

Commit 010a987

Browse files
committed
examples: http: json output
1 parent 2063c48 commit 010a987

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

examples/http/get_device_by_id.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import json
23
import os
34

45
import enapter
@@ -9,7 +10,7 @@ async def main():
910
device_id = os.environ["DEVICE_ID"]
1011
async with enapter.http.api.Client(config=config) as client:
1112
device = await client.devices.get(device_id)
12-
print(device)
13+
print(json.dumps(device.to_dto()))
1314

1415

1516
if __name__ == "__main__":

examples/http/list_devices.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import asyncio
2+
import json
3+
4+
import enapter
5+
6+
7+
async def main():
8+
config = enapter.http.api.Config.from_env()
9+
async with enapter.http.api.Client(config=config) as client:
10+
async with client.devices.list() as devices:
11+
async for device in devices:
12+
print(json.dumps(device.to_dto()))
13+
14+
15+
if __name__ == "__main__":
16+
asyncio.run(main())

examples/http/list_sites.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import asyncio
2+
import json
23

34
import enapter
45

56

67
async def main():
78
config = enapter.http.api.Config.from_env()
89
async with enapter.http.api.Client(config=config) as client:
9-
async for site in client.sites.list():
10-
print(site)
10+
async with client.sites.list() as sites:
11+
async for site in sites:
12+
print(json.dumps(site.to_dto()))
1113

1214

1315
if __name__ == "__main__":

0 commit comments

Comments
 (0)