Skip to content

Commit

Permalink
Force output periodic status
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Jan 15, 2024
1 parent a1cfae9 commit 1e5ae82
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion python/lvmecp/actor/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async def update_status(self, delay: float = 30.0):
"""Emits the status on a timer."""

while True:
await self.plc.update_all()
await self.plc.update_all(force_output=True, internal=True)
await asyncio.sleep(delay)

async def emit_heartbeat(self, delay: float = 5.0):
Expand Down
15 changes: 10 additions & 5 deletions python/lvmecp/plc.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ def create_actor_notifier(
):
"""Generate a notifier function for a keyword."""

async def notifier(value: int, labels: str, command: Command | None = None):
async def notifier(
value: int,
labels: str,
command: Command | None = None,
internal: bool = False,
):
message = {
keyword: value if use_hex is False else hex(value),
f"{keyword}{labels_suffix}": labels,
Expand All @@ -51,9 +56,9 @@ async def notifier(value: int, labels: str, command: Command | None = None):
if n_tries >= 3:
return None
await asyncio.sleep(1)
actor.write(level, message)
actor.write(level, message, internal=internal)
elif command is not None:
command.write(level, message)
command.write(level, message, internal=internal)

return notifier if actor else None

Expand Down Expand Up @@ -91,7 +96,7 @@ def __init__(self, config: dict, actor: ECPActor | None = None):
notifier=None,
)

async def update_all(self, use_cache: bool = True):
async def update_all(self, use_cache: bool = True, **kwargs):
"""Updates all the modules."""

# Force an update of the caches if needed.
Expand All @@ -100,7 +105,7 @@ async def update_all(self, use_cache: bool = True):
# Update modules. This will output values that have changed.
await asyncio.gather(
*[
module.update(use_cache=use_cache)
module.update(use_cache=use_cache, **kwargs)
for module in self.__dict__.values()
if isinstance(module, PLCModule)
]
Expand Down

0 comments on commit 1e5ae82

Please sign in to comment.