Skip to content

Commit

Permalink
Add is_engineering_mode_enabled() to retrieve status
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Dec 25, 2024
1 parent 2b4f23f commit d875ea2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
12 changes: 6 additions & 6 deletions python/lvmecp/actor/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,11 @@ async def emit_status(self, delay: float = 30.0):

async def engineering_mode(
self,
enable: bool | None = None,
enable: bool,
timeout: float | None = None,
):
"""Sets or returns the engineering mode."""

is_enabled = self._engineering_mode

if enable is None:
return is_enabled

# Kill current task if it exists.
self._engineering_mode_task = await cancel_task(self._engineering_mode_task)

Expand All @@ -124,6 +119,11 @@ async def engineering_mode(

self._engineering_mode = enable

def is_engineering_mode_enabled(self):
"""Returns whether engineering mode is enabled."""

return self._engineering_mode

async def _run_eng_mode(self, timeout: float | None = None):
"""Runs the engineering mode.
Expand Down
4 changes: 1 addition & 3 deletions python/lvmecp/actor/commands/engineering.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,4 @@ async def disable(command: ECPCommand):
async def status(command: ECPCommand):
"""Returns the status of the engineering mode."""

status = await command.actor.engineering_mode()

return command.finish(engineering_mode=status)
return command.finish(engineering_mode=command.actor.is_engineering_mode_enabled())
8 changes: 4 additions & 4 deletions tests/test_command_engineering_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ async def test_command_engineering_mode_no_mock(actor: ECPActor):
cmd = await actor.invoke_mock_command("engineering-mode enable --timeout 10")
await cmd

assert await actor.engineering_mode() is True
assert actor.is_engineering_mode_enabled() is True

cmd = await actor.invoke_mock_command("engineering-mode disable")
await cmd

assert await actor.engineering_mode() is False
assert actor.is_engineering_mode_enabled() is False


async def test_command_engineering_mode_timeouts(actor: ECPActor):
Expand All @@ -55,8 +55,8 @@ async def test_command_engineering_mode_timeouts(actor: ECPActor):
cmd = await actor.invoke_mock_command("engineering-mode enable --timeout 0.2")
await cmd

assert await actor.engineering_mode() is True
assert actor.is_engineering_mode_enabled() is True

await asyncio.sleep(0.3)

assert await actor.engineering_mode() is False
assert actor.is_engineering_mode_enabled() is False

0 comments on commit d875ea2

Please sign in to comment.