-
Notifications
You must be signed in to change notification settings - Fork 8
Refactor Reader classes to use new Stream API #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
11f870c
Introduce Reading type to DRY-up reader internals
benthorner 2d2bd47
Separate reading single values from all values
benthorner 6343ca0
Add test to cover sensor reader temporary failure
benthorner 7cca8f9
Simplify exception handling for SensorReader
benthorner 05f2992
Change readers to be wrapper classes of streams
benthorner aa57548
Add library documentation about Stream API usage
benthorner 4db6fb4
DRY-up Reader.__call__ using custom exceptions
benthorner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
|
|
||
| PMSx003 4 samples on default format | ||
| 2021-07-29 15:57:01: PM1 1.0, PM2.5 11.0, PM10 12.0 μg/m3 | ||
| 2021-07-29 15:57:21: PM1 0.0, PM2.5 6.0, PM10 6.0 μg/m3 | ||
| 2021-07-29 15:57:41: PM1 0.0, PM2.5 1.0, PM10 2.0 μg/m3 | ||
| 2021-07-29 15:58:01: PM1 0.0, PM2.5 1.0, PM10 2.0 μg/m3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| """ | ||
| Read PMSx003 sensor on /dev/ttyUSB0. | ||
|
|
||
| Use a low-level Stream class for more granular | ||
| control of the sensor. | ||
| """ | ||
|
|
||
| from pms.core import SensorStream | ||
|
|
||
| stream = SensorStream(sensor="PMSx003", port="/dev/ttyUSB0") | ||
|
|
||
| print("\nPMSx003 4 samples on default format") | ||
|
|
||
| stream.open() | ||
| for _ in range(4): | ||
| print(stream.read()) | ||
| stream.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,9 @@ | ||
| from .sensor import Sensor, Supported # isort: skip | ||
| from .reader import MessageReader, SensorReader, UnableToRead, exit_on_fail | ||
| from .reader import ( | ||
| MessageReader, | ||
| MessageStream, | ||
| SensorReader, | ||
| SensorStream, | ||
| UnableToRead, | ||
| exit_on_fail, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe these and the "old" exceptions should be collected on a separate module
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, can do. I'll come back to this when we decide what should happen with the PR overall.