diff --git a/python/lvmecp/plc.py b/python/lvmecp/plc.py index 9087958..412949b 100644 --- a/python/lvmecp/plc.py +++ b/python/lvmecp/plc.py @@ -44,12 +44,12 @@ async def notifier(value: int, labels: str, command: Command | None = None): # Allow for 3 seconds for broadcast. This is needed because the PLC # starts before the actor and for the first message the exchange is # not yet available. - n_tries = 0 + elapsed: float = 0 while actor.connection.connection is None: - n_tries += 1 - if n_tries >= 3: - return None - await asyncio.sleep(1) + elapsed += 0.01 + if elapsed > 3: + return + await asyncio.sleep(0.01) actor.write(level, message) elif command is not None: command.write(level, message) diff --git a/tests/conftest.py b/tests/conftest.py index ddab5f8..eb240d8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -51,6 +51,7 @@ async def actor(simulator: Simulator, mocker): mocker.patch.object(_actor.plc.hvac.modbus, "get_all", return_value={}) _actor = await setup_test_actor(_actor) # type: ignore + _actor.connection.connection = mocker.MagicMock(spec={"is_closed": False}) yield _actor