Skip to content

Example 2 — attr getter/setter via __init__ (temperature backend) #404

Description

@coretl

Part of the tutorial examples (#388). Tutorial 2 — getter/setter: per-attribute IO as getter/setter callables supplied in __init__ (AttrRW(getter=…, setter=…)), on the temperature-controller backend.

Retargeted from a standalone Thorlabs MFF device onto the temperature sim (per Tom, 2026-07-22) so the ladder keeps to two backends.

Scope

  • Add src/fastcs/demo/temperature_attr.py: a small temperature controller (e.g. ramp_rate, power) reusing the temperature sim; no bespoke device.
  • Baseline now (current callback-IO API) — use the single callable-wrapping IO + protocol shape, NOT one IO subclass per attribute:
    • a single generic TemperatureIO(AttributeIO[...]) registered once (ios=[TemperatureIO(conn)]) whose update/send just invoke callables carried on the ref;
    • a TemperatureIORef(AttributeIORef) carrying the command-building callables (read_cmd: Callable[[], str], write_cmd: Callable[[float], str] | None);
    • a single TemperatureProtocol class with one method per command (the getters/setters), referenced by each attribute's ref — mirrors fastcs-thorlabs-mff (MFFAttributeIO/MFFAttributeIORef/ThorlabsAPTProtocol).
    • Response parsing stays inline in TemperatureIO.update (float(...)), not a separate response_handler callable.
    • This is the honest precursor to getter/setter IO rework; remove AttributeIORef and DataType #392: read_cmd/write_cmd are the getter/setter; getter/setter IO rework; remove AttributeIORef and DataType #392 promotes them onto the constructor and deletes the IO/ref wrapper, while TemperatureProtocol survives unchanged.
  • Clean form (when getter/setter IO rework; remove AttributeIORef and DataType #392 lands): AttrRW(Float(), getter=protocol.get_…, setter=protocol.set_…) (getter/setter constructor params; datatype inferred from the getter's return annotation).
  • Unit tests: read/write against the sim.

Notes

Acceptance

uv run --locked tox -e pre-commit,type-checking,tests green (full tox in real CI on the PR).

ADR: 0014 (getter/setter), 0018 (@attr)
Priority: build this baseline before the framework issues.
Parent: #388
Blocked by: none

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions