Skip to content

demo: getter/setter-in-init temperature attr example#411

Open
coretl wants to merge 4 commits into
refactorfrom
refactor-issue-404
Open

demo: getter/setter-in-init temperature attr example#411
coretl wants to merge 4 commits into
refactorfrom
refactor-issue-404

Conversation

@coretl

@coretl coretl commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Closes #404

Adds Tutorial 2 (getter/setter) from the demo README ladder: src/fastcs/demo/temperature_attr.py, a small temperature controller (ramp_rate, power) wired attribute-by-attribute in __init__ rather than via shared class-body declarations.

Retargeted onto the temperature sim (per the issue, 2026-07-22 update) rather than a standalone Thorlabs MFF device, so the tutorial ladder keeps to two backends.

Current-API baseline in the intended shape: a single generic TemperatureIO drives every attribute, and each TemperatureIORef carries the command-building callables (read_cmd/write_cmd) sourced from a single TemperatureProtocol class — mirroring fastcs-thorlabs-mff (MFFAttributeIO/MFFAttributeIORef/ThorlabsAPTProtocol). read_cmd/write_cmd are the getter/setter this foreshadows: #392 promotes them onto AttrRW(getter=..., setter=...) and deletes the IO/ref wrapper, while TemperatureProtocol survives unchanged. Response parsing (float()) is inline in TemperatureIO.update, not a response_handler callable. (Contrast the composition example controllers.py, #390, whose shared IO dispatches on a name string.)

Instructions to reviewer on how to test:

  1. uv run pytest tests/demo/test_temperature_attr.py -v

Checks for reviewer

  • Would the PR title make sense to a user on a set of release notes

Notes


Generated by Claude Code

Summary by CodeRabbit

  • New Features

    • Added a temperature controller demo with readable ramp-rate and power attributes.
    • Added support for updating values from a connected device.
    • Added the ability to set the ramp rate.
  • Tests

    • Added coverage for reading ramp rate and power values.
    • Added coverage confirming ramp-rate updates are sent correctly.

Add temperature_attr.py: a small temperature controller with
per-attribute IO (a fresh AttributeIO/AttributeIORef pair per
attribute) wired directly in __init__ rather than shared class-body
declarations, foreshadowing the AttrRW(getter=, setter=) constructor
params landing in #392. Baseline against the current callback-IO API.

Closes #404
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: bf6aa40f-3d92-4702-b184-9c1c78e7ae4b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR adds the temperature-simulator example and tests, and it uses the current callback-IO baseline called for in #404.
Out of Scope Changes check ✅ Passed The changes stay focused on the temperature demo example and its tests, with no unrelated scope evident.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the new temperature attribute demo using getter/setter wiring in init.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor-issue-404

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.25%. Comparing base (3da025f) to head (3e774b3).
⚠️ Report is 2 commits behind head on refactor.

Additional details and impacted files
@@            Coverage Diff            @@
##           refactor     #411   +/-   ##
=========================================
  Coverage     91.25%   91.25%           
=========================================
  Files            72       72           
  Lines          2892     2892           
=========================================
  Hits           2639     2639           
  Misses          253      253           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/fastcs/demo/temperature_attr.py`:
- Around line 76-77: Update the async close method to reset the controller’s
_connected state to False after awaiting self.connection.close(), so subsequent
connection status checks correctly report the closed state.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a64717b0-dfc5-439f-a5e0-0a883dacae7c

📥 Commits

Reviewing files that changed from the base of the PR and between 3da025f and 4dbaf83.

📒 Files selected for processing (2)
  • src/fastcs/demo/temperature_attr.py
  • tests/demo/test_temperature_attr.py

Comment on lines +76 to +77
async def close(self) -> None:
await self.connection.close()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Reset the controller connection state after closing.

Line 74 sets _connected to True, but close() never clears it. After the socket closes, the controller can still report itself as connected.

Proposed fix
 async def close(self) -> None:
     await self.connection.close()
+    self._connected = False
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async def close(self) -> None:
await self.connection.close()
async def close(self) -> None:
await self.connection.close()
self._connected = False
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/fastcs/demo/temperature_attr.py` around lines 76 - 77, Update the async
close method to reset the controller’s _connected state to False after awaiting
self.connection.close(), so subsequent connection status checks correctly report
the closed state.

claude and others added 2 commits July 23, 2026 12:16
Address CodeRabbit review comment: close() closed the socket but left
_connected True, so a subsequent status check would still report
connected.
…ape)

Rewrites the getter/setter baseline to the intended shape: one generic
TemperatureIO drives every attribute, and each TemperatureIORef carries the
command-building callables (read_cmd/write_cmd) sourced from a single
TemperatureProtocol class - mirroring fastcs-thorlabs-mff's
MFFAttributeIO/MFFAttributeIORef/ThorlabsAPTProtocol.

This is the honest precursor to #392's AttrRW(getter=, setter=): read_cmd/
write_cmd ARE the getter/setter, promoted onto the constructor when the IO/ref
wrapper is deleted, while TemperatureProtocol survives unchanged.

Replaces the previous per-attribute AttributeIO subclasses (RampRateIO/PowerIO),
which hardcoded commands and foreshadowed nothing. Response parsing (float())
is inline in TemperatureIO.update rather than a response_handler callable.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LgnovZ7FWY8YptwqiufTbX
Comment thread src/fastcs/demo/temperature_attr.py
Comment thread tests/demo/test_temperature_attr.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants