Skip to content

Improve and extend the _read() method availability for its users and related methods. Part 2: Response format validator#711

Merged
patkan merged 10 commits into
python-escpos:masterfrom
belono:status_validator
Jul 27, 2026
Merged

Improve and extend the _read() method availability for its users and related methods. Part 2: Response format validator#711
patkan merged 10 commits into
python-escpos:masterfrom
belono:status_validator

Conversation

@belono

@belono belono commented Oct 4, 2025

Copy link
Copy Markdown
Contributor

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.
  • Add tests for the status read functions.

Part 3: #712

Part 4: #714

Tested with

TM-U210 Parallel port printer

@codecov

codecov Bot commented Oct 4, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.65217% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 82.82%. Comparing base (f2904a8) to head (8586bd7).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/escpos/exceptions.py 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #711      +/-   ##
==========================================
+ Coverage   81.90%   82.82%   +0.91%     
==========================================
  Files          21       21              
  Lines        1708     1729      +21     
  Branches      267      270       +3     
==========================================
+ Hits         1399     1432      +33     
+ Misses        230      216      -14     
- Partials       79       81       +2     
Flag Coverage Δ
unittests 82.76% <95.65%> (+0.91%) ⬆️

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

Files with missing lines Coverage Δ
src/escpos/escpos.py 78.59% <100.00%> (+3.19%) ⬆️
src/escpos/exceptions.py 69.67% <85.71%> (+0.97%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@belono
belono force-pushed the status_validator branch from 3742883 to 0fa5b53 Compare April 21, 2026 21:48
@belono
belono force-pushed the status_validator branch from 151bbac to e37e39e Compare April 21, 2026 22:15
Comment thread src/escpos/escpos.py Outdated
@patkan
patkan merged commit 187fc37 into python-escpos:master Jul 27, 2026
15 checks passed
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.

2 participants