-
Notifications
You must be signed in to change notification settings - Fork 35
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
Refactor laundry.py
to use NamedTuple, add tests
#189
Conversation
Refactor laundry.py to store API output using NamedTuples rather than plain Python dicts. This makes the output more user-friendly, less error-prone, and easier to type hint. This refactoring also modifies the API behavior as follows: 1. JSON objects that don't qualify as a known laundry machine type (washer, dryer, or combo) will now be skipped, whereas previously they would be marked as "unknown". These objects should be skipped because they may represent things that aren't laundry machines, such as card readers. 2. The time_remaining field for laundry machines can now be None if the laundry machine is unavailable (either out of service or offline). Add unit tests for laundry.py to increase test coverage to 100%. The new tests use mocked data for Towers laundry machines, the vast majority of which are combo machines rather than standalone washers or dryers. Fix a heretofore unknown bug that was caught during the aforementioned unit testing: "washNdry" was misspelled as "washNDry", which was causing the API to mark all combo machines as "unknown". This typo hadn't been caught because there had been no unit tests that included data for combo machines.
d958a06
to
39a4e14
Compare
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.
The TODOs need to be addressed before merging this PR. Mark this as WIP in the meantime.
This comment has been minimized.
This comment has been minimized.
Replace mock JSON test data for Sutherland East with new mock JSON test data for Holland. Because this data was collected close to the start of the fall semester, when the laundry machines are actually being used, it contains instances of status_toggle = 1, which clears up the TODO of what that status value represented. The meaning of this value has now been documented. Rewrite the logic for parsing JSON objects for laundry machines. The logic now accurately parses combo machines and adds support for double machines, which are two washers or two dryers in a single machine. This resolves the two remaining TODOs about combo machines.
@RitwikGupta I've addressed the TODOs. I was able to figure out the TODO for |
Excellent work @tianyizheng02 and @jkruse7! |
Refactor
laundry.py
to store API output usingNamedTuple
s rather than plain Pythondict
s. This makes the output more user-friendly, less error-prone, and easier to type hint. This refactoring also modifies the API behavior as follows:time_remaining
field for laundry machines can now beNone
if the laundry machine is unavailable (either out of service or offline).name
field that stores the user-facing name of the machine (A1, B3, G10, etc).Add unit tests for
laundry.py
to increase test coverage to 95%. The new tests use mocked data for Towers laundry machines, the vast majority of which are combo machines rather than standalone washers or dryers.Fix a heretofore unknown bug that was caught during the aforementioned unit testing: "washNdry" was misspelled as "washNDry", which was causing the API to mark all combo machines as "unknown". This typo hadn't been caught because there had been no unit tests that included data for combo machines.