Skip to content

Commit f034e99

Browse files
Feat: Add helper show commands to easily print avaliable devices and plans to user
1 parent 65b7e75 commit f034e99

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/blueapi/client/client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,11 @@ def get_plan(self, name: str) -> PlanModel:
295295
"""
296296
return self._rest.get_plan(name)
297297

298+
def show_plans(self) -> None:
299+
"""Command to print all avaliable plans."""
300+
for name in self.plans:
301+
print(name)
302+
298303
@start_as_current_span(TRACER)
299304
@deprecated("devices property")
300305
def get_devices(self) -> DeviceResponse:
@@ -334,6 +339,11 @@ def get_device(self, name: str) -> DeviceModel:
334339

335340
return self._rest.get_device(name)
336341

342+
def show_devices(self) -> None:
343+
"""Command to print all avaliable devices."""
344+
for name in self.devices:
345+
print(name)
346+
337347
@property
338348
@start_as_current_span(TRACER)
339349
def state(self) -> WorkerState:

tests/unit_tests/client/test_client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@ def test_get_plan(client: BlueapiClient):
145145
assert client.plans["foo"].model == PLAN
146146

147147

148+
def test_show_plans(client: BlueapiClient, capsys: pytest.CaptureFixture):
149+
client.show_plans()
150+
captured = capsys.readouterr()
151+
for dev in PLANS.plans:
152+
assert dev.name in captured.out
153+
154+
148155
def test_get_nonexistant_plan(
149156
client: BlueapiClient,
150157
):
@@ -160,6 +167,13 @@ def test_get_device(client: BlueapiClient):
160167
assert client.devices.foo.model == DEVICE
161168

162169

170+
def test_show_devices(client: BlueapiClient, capsys: pytest.CaptureFixture):
171+
client.show_devices()
172+
captured = capsys.readouterr()
173+
for dev in DEVICES.devices:
174+
assert dev.name in captured.out
175+
176+
163177
def test_get_nonexistent_device(
164178
client: BlueapiClient,
165179
):

0 commit comments

Comments
 (0)