-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove automatic setting of heartbeat and add heartbeat command * Update changelog * Update CHANGELOG with PR link * Remove unused imports * Add _check_internal back * Add asyncio_default_fixture_loop_scope = "function" * Improve actor test fixture * Add test for heartbeat command * Add fail test
- Loading branch information
Showing
7 changed files
with
77 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# @Author: José Sánchez-Gallego ([email protected]) | ||
# @Date: 2024-12-20 | ||
# @Filename: heartbeat.py | ||
# @License: BSD 3-clause (http://www.opensource.org/licenses/BSD-3-Clause) | ||
|
||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from . import parser | ||
|
||
|
||
if TYPE_CHECKING: | ||
from lvmecp.actor import ECPCommand | ||
|
||
|
||
@parser.command() | ||
async def heartbeat(command: ECPCommand): | ||
"""Sets the heartbeat variable on the PLC.""" | ||
|
||
try: | ||
await command.actor.plc.modbus["hb_set"].set(True) | ||
except Exception: | ||
return command.fail("Failed to set heartbeat.") | ||
finally: | ||
return command.finish() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# @Author: José Sánchez-Gallego ([email protected]) | ||
# @Date: 2024-12-24 | ||
# @Filename: test_command_heartbeat.py | ||
# @License: BSD 3-clause (http://www.opensource.org/licenses/BSD-3-Clause) | ||
|
||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
|
||
if TYPE_CHECKING: | ||
from pytest_mock import MockerFixture | ||
|
||
from lvmecp.actor import ECPActor | ||
|
||
|
||
async def test_command_heartbeat(actor: ECPActor, mocker: MockerFixture): | ||
hb_set_mock = mocker.patch.object(actor.plc.modbus["hb_set"], "set") | ||
|
||
cmd = await actor.invoke_mock_command("heartbeat") | ||
await cmd | ||
|
||
assert cmd.status.did_succeed | ||
|
||
hb_set_mock.assert_called_once_with(True) | ||
|
||
|
||
async def test_command_heartbeat_fails(actor: ECPActor, mocker: MockerFixture): | ||
mocker.patch.object(actor.plc.modbus["hb_set"], "set", side_effect=Exception) | ||
|
||
cmd = await actor.invoke_mock_command("heartbeat") | ||
await cmd | ||
|
||
assert cmd.status.did_fail |