Skip to content

Conversation

@belono
Copy link
Contributor

@belono belono commented Oct 4, 2025

Description

This is part 2 of the series to improve and extend the availability of the _read() method.

Part 1: #709

Part 2: Add a simple response format validator when querying for status:

As stated at the Epson ESC/POS reference guide:

Each status consists of 1 byte, and the value is 0xx1xx10b.
The real time status can be differentiated by the bits 0, 1, 4, and 7 from other transmission data, except for data in block data (Header – NUL).

So a status response consists of a byte which bits 0 and 7 are fixed to 0, and bits 1 and 4 are fixed to 1. The remaining bits contain the response to the query according to the tables given in the aforementioned reference guide.

This PR tries to reduce the possibility of false positives when interpreting data from the printer buffer as status responses by checking that the data read is at least in the right response format:

  • Add a simple validator method to validate every status format before return it as a response.
  • Log an error if validation fails.
  • Optionally raise a (new) ValidationError exception if validation fails, or return an empty response (default).
  • Treat an empty response as a negative response for the query_status() users: is_online() and paper_status() methods.

Tests will be added in a later PR.

Part 3: #712

Part 4: #714

Tested with

TM-U210 Parallel port printer

@codecov
Copy link

codecov bot commented Oct 4, 2025

Codecov Report

❌ Patch coverage is 26.08696% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.57%. Comparing base (11d46fd) to head (8d0d33e).

Files with missing lines Patch % Lines
src/escpos/escpos.py 18.75% 13 Missing ⚠️
src/escpos/exceptions.py 42.85% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #711      +/-   ##
==========================================
- Coverage   81.39%   80.57%   -0.83%     
==========================================
  Files          21       21              
  Lines        1693     1714      +21     
  Branches      267      270       +3     
==========================================
+ Hits         1378     1381       +3     
- Misses        235      251      +16     
- Partials       80       82       +2     
Flag Coverage Δ
unittests 80.51% <26.08%> (-0.71%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/escpos/exceptions.py 64.75% <42.85%> (-1.34%) ⬇️
src/escpos/escpos.py 73.73% <18.75%> (-1.67%) ⬇️

... and 2 files with indirect coverage changes

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant