If there's a single PD Buddy Sink attached, it's pretty clear which one
we want to be testing. As such, the testing script shouldn't require
the device to be specified if it can find exactly one Sink. This commit
does just that, and like so, I will almost never have to figure out
which device file I need when testing a Sink again.
This commit adds the SourcePPSAPDO class for holding information from a
Source Programmable Power Supply APDO. It can be read and written and
printed and all that fun stuff.
The i member in SinkConfig now has its dimension, and thus its unit,
set by the new idim member. It's a bit clunky, but the other
alternative I thought of is even clunkier.
To replace my old Sink testing system (GNU Screen and a text file with
the commands to send to the Sink), I wrote a Python script that tests
the Sink automatically. The only thing I have to do (assuming the test
is successful) is press Enter a few times while watching a voltmeter's
display. A basic testing script could be useful to other people, so I'm
including it in this Python package.
I have a vague plan to integrate this with Kaylee at some point so I
don't even have to press Enter, but that will have to wait until Kaylee
has menu support.
This commit adds support for the new, yet-to-be-released typec_virtual
PDO reported from the firmware. This was done by adding a
TypeCVirtualPDO class, code to load them from text, and support for them
in the calculation functions. New tests have been written for all the
new code as well.
Now there are two functions to perform calculations on PDO lists:
calculate_pdp and follows_power_rules. calculate_pdp calculates an
estimate of the power supply's PDP, and follows_power_rules tries to
determine if the power supply follows the USB PD Power Rules. Either
one could run into problems that cannot be detected, but for the
problems that can be detected there's a whole mound of new test code.
The intended behavior for Sink.get_source_cap() when no
Source_Capabilities are read was to return an empty list. This wasn't
done before, instead raising a ValueError when read_pdo() tried to parse
"No Source_Capabilities" as an UnknownPDO. Now we're a bit more
cautious, and the bug is fixed.
Now there are namedtuples for PDO types, and two functions to help with
reading PDOs from the Sink. They're all tested, and our test coverage
is now at 98%(!).
Since SinkConfig is a namedtuple now, several of the methods we had been
testing are now inherited from tuple. There's no need for me to test
those here, so I've removed the unneeded test cases.
Rather than having one method doing double-duty as getter and setter,
with ugly syntax, why not use a property? Now the Sink's output can
simply be read and written as a boolean.
The README has been updated to show how to manipulate the new SinkConfig
objects, as well as what the output really looks like now.
Since it's a class used for little more than storage, with no
interesting non-magic instance methods, it makes sense for SinkConfig to
be a namedtuple. The rest of its code was mostly just boilerplate,
after all. What remains makes it do everything we need with only slight
changes to its behavior (most notably, SinkConfig must be instantiated
with all its arguments now).
Any command sent with send_command could be invalid. It makes sense for
that method to throw an exception if the command isn't recognized so I
don't have to duplicate that effort in the methods for all commands
introduced after firmware version 1.0. This commit moves the command
validity checking to Sink.send_command.
Now when the `output` command is unsupported by the Sink, the library
raises a different exception than if unknown text is printed. This
allows feature testing, which is great.
Added code to set_v and set_i to check if the Sink gave any error
message when running those commands, raising exceptions if it did.
This makes two of the three new tests pass. The other one will need
support from the Sink itself, which currently doesn't care if the
voltage is over 20 V or the current is over 5 A. That is to say that
the third test will automatically start passing if the Sink is running
firmware 1.0.1, which is yet to be released.
Added three new tests: test_set_tmpcfg_huge, test_set_tmpcfg_big, and
test_set_tmpcfg_neg. They set temporary configurations with huge
(> UINT16_MAX), big (> 20 V, > 5 A), and negative voltages and currents,
respectively. These tests all fail currently, so I'll work on making
them pass.
Testing info in README, wider Python compatibility
The library has now been tested with Python 2.7, 3.3, 3.4, 3.5, and 3.6.
The README and setup.py now indicate this. The README also says how to
run the tests, and that you need a PD Buddy Sink plugged in for them to
be completely thorough.
Before, we sent ^D, but didn't read past the prompt that appeared. This
put us one command behind the most recent, causing all manner of mayhem.
It's all fixed now I believe, but this really shows the need for unit
testing. I'm working on that.
This removes any garbage that the Sink may have in its buffer, e.g.
partially entered commands or nonsense that appeared when moving the
device to/from a VM.
One extra dependency is pulled in for Python versions older than 3.6,
but other than that it's pretty easy to support them. It definitely
works on 2.7 now, and should work on older 3.x versions (but that's
untested).