Skip to content

Commit 3d5552f

Browse files
committed
show area name instead of id on device list
1 parent 9922385 commit 3d5552f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

homeassistant_cli/plugins/device.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def listcmd(ctx: Configuration, devicefilter: str):
2828
"""List all devices from Home Assistant."""
2929
ctx.auto_output("table")
3030

31+
areas = api.get_areas(ctx)
32+
3133
devices = api.get_devices(ctx)
3234

3335
result = [] # type: List[Dict]
@@ -40,12 +42,19 @@ def listcmd(ctx: Configuration, devicefilter: str):
4042
if devicefilterre.search(device['name']):
4143
result.append(device)
4244

45+
for device in devices:
46+
area = next(
47+
(a for a in areas if a['area_id'] == device['area_id']), None
48+
)
49+
if area:
50+
device['area_name'] = area['name']
51+
4352
cols = [
4453
('ID', 'id'),
4554
('NAME', 'name'),
4655
('MODEL', 'model'),
4756
('MANUFACTURER', 'manufacturer'),
48-
('AREA', 'area_id'),
57+
('AREA', 'area_name'),
4958
]
5059

5160
ctx.echo(

0 commit comments

Comments
 (0)