Skip to content

Fix AttributeError in LcdCommRevC: sub_revision/rom_version undefined until InitializeComm() - #1087

Closed
robcab75 wants to merge 1 commit into
mathoudebine:mainfrom
robcab75:fix/rev-c-sub-revision
Closed

robcab75 wants to merge 1 commit into
mathoudebine:mainfrom
robcab75:fix/rev-c-sub-revision

Conversation

@robcab75

@robcab75 robcab75 commented Sep 8, 2026

Copy link
Copy Markdown

Summary

  • LcdCommRevC.__init__ never initialized self.sub_revision or self.rom_version; both were only set inside _hello() (called from InitializeComm()). Any code path touching these attributes before InitializeComm() runs — including the test suite's mocked LcdComm, which never calls it — hits AttributeError/UnboundLocalError.
  • sub_revision detection is purely a function of display_width/display_height (the existing comment notes the device's own response is unreliable for this), so it's moved to __init__, matching the pattern already used in lcd_comm_rev_a.py.
  • rom_version genuinely requires the device handshake, so it gets the same default (87) that _hello() already falls back to when detection fails.
  • This unblocked a second, pre-existing issue: the rev_c golden test fixtures predated multi-sub-revision support (2.1"/5"/8") added later, so they expected the old single-size DISPLAY_BITMAP payload. Regenerated with the existing RECORD_GOLDEN=1 mechanism to match current, correct behavior.

Test plan

  • python -m pytest tests/ — 37/37 passing (was 29 passing / 8 failing on main)
  • python -m py_compile library/lcd/lcd_comm_rev_c.py

🤖 Generated with Claude Code

https://claude.ai/code/session_01FyR2qGEWt3ApGumu5ykE5X

…itializeComm()

LcdCommRevC.__init__ never initialized self.sub_revision or
self.rom_version; they were only set inside _hello() (called from
InitializeComm()). Any caller touching these attributes before that
point, including the test suite's mocked LcdComm which never calls
InitializeComm(), hit AttributeError/UnboundLocalError.

sub_revision detection is purely a function of display_width/height
(the code's own comment notes the device response is unreliable for
this), so move it to __init__ like lcd_comm_rev_a.py already does.
rom_version genuinely requires the device handshake, so give it the
same default (87) _hello() already falls back to on detection failure.

This also exposed that the rev_c golden test fixtures predate the
multi-sub-revision support (2.1"/5"/8") added later, so they expected
the old single-size DISPLAY_BITMAP payload. Regenerated them with
RECORD_GOLDEN=1 to match current, correct behavior.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FyR2qGEWt3ApGumu5ykE5X
@robcab75 robcab75 closed this by deleting the head repository Sep 8, 2026
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.

1 participant