Skip to content

Commit

Permalink
Add SimpleHandler to make minimal Attributes functional
Browse files Browse the repository at this point in the history
This allows creating Attributes without a Handler for parameters that
are only used for internal controller logic and not sent directly to a
device.
  • Loading branch information
GDYendell committed Dec 10, 2024
1 parent a9936c5 commit ff2e78a
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/fastcs/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ class Handler(Sender, Updater, Protocol):
pass


class SimpleHandler(Handler):
"""Handler for internal parameters"""

async def put(self, controller: Any, attr: AttrW, value: Any):
await attr.update_display_without_process(value)

if isinstance(attr, AttrRW):
await attr.set(value)

async def update(self, controller: Any, attr: AttrR):
raise RuntimeError("SimpleHandler cannot update")


class Attribute(Generic[T]):
"""Base FastCS attribute.
Expand Down Expand Up @@ -171,7 +184,11 @@ def __init__(
)
self._process_callback: AttrCallback[T] | None = None
self._write_display_callback: AttrCallback[T] | None = None
self._sender = handler

if handler is not None:
self._sender = handler
else:
self._sender = SimpleHandler()

async def process(self, value: T) -> None:
await self.process_without_display_update(value)
Expand Down

0 comments on commit ff2e78a

Please sign in to comment.