Skip to content

refactor(steami_screen): move constants to dedicated const.py file.#424

Open
MatteoCnda1 wants to merge 1 commit intomainfrom
refactor/steami-screen-const
Open

refactor(steami_screen): move constants to dedicated const.py file.#424
MatteoCnda1 wants to merge 1 commit intomainfrom
refactor/steami-screen-const

Conversation

@MatteoCnda1
Copy link
Copy Markdown
Contributor

Summary

Refactor steami_screen module by extracting all constants from device.py into a dedicated const.py file, aligning with the project convention of having a const.py per module (as in apds9960, hts221, bq27441, etc.).

Closes #358

Context

The project convention recommends having a const.py file in each module to group constants. In steami_screen, constants such as colors and FACES were previously defined directly in device.py, making the file more cluttered and diverging from the established structure used elsewhere in the repository.

Changes

New file

  • lib/steami_screen/steami_screen/const.py — centralizes all module constants

Constants moved from device.py to const.py

  • Colors (RGB tuples): BLACK, DARK, GRAY, LIGHT, WHITE, GREEN, RED, BLUE, YELLOW
  • Bitmaps: FACES dictionary (8x8 pixel-art expressions)

New constants extracted from inline magic numbers

  • STEAMI_CHAR_W / STEAMI_CHAR_H — framebuf font dimensions (previously inline class attributes)
  • STEAMI_DEFAULT_WIDTH / STEAMI_DEFAULT_HEIGHT — default screen size (previously hardcoded 128)
  • STEAMI_GAUGE_START_ANGLE / STEAMI_GAUGE_SWEEP — gauge widget angles
  • STEAMI_GRAPH_MARGIN, STEAMI_GRAPH_X_OFFSET, STEAMI_GRAPH_Y, STEAMI_GRAPH_HEIGHT, STEAMI_GRAPH_VALUE_Y, STEAMI_GRAPH_DASH, STEAMI_GRAPH_GAP — graph widget layout
  • GRID_DARK — graph grid color (previously inline (51, 51, 51) tuple)

Updated files

  • device.py — imports constants from const.py, no functional changes
  • __init__.py — colors and FACES are now re-exported directly from const.py (single source of truth)

Motivation

  • Improve readability and maintainability of device.py
  • Reduce file size and responsibility of device.py
  • Align with project conventions (const.py per module)
  • Make constants easier to locate and reuse across the module

API compatibility

No public API breakage.

  • Screen.CHAR_W and Screen.CHAR_H remain exposed as class attributes for backward compatibility
  • All colors and FACES remain importable from the top-level package: from steami_screen import WHITE, FACES
  • All examples in lib/steami_screen/examples/ work without modification

Validation

  • ruff check passes
  • python -m pytest tests/ -k mock -v passes
  • No public API breakage
  • Hardware test on STeaMi board: comfort_bar_demo.py runs successfully via mpremote

Notes

This is a pure refactor with no functional changes. The apds9960 module's const.py was used as the reference for naming convention (STEAMI_* prefix for module-specific constants, short names for shared color tuples).

@MatteoCnda1 MatteoCnda1 force-pushed the refactor/steami-screen-const branch from b491fe4 to 5475760 Compare April 29, 2026 07:36
@MatteoCnda1 MatteoCnda1 changed the title Move const from device.py to a new const.py file. refactor(steami_screen): move constants to dedicated const.py file. Apr 29, 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.

refactor(steami_screen): move const of device in a new const.py file

1 participant