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).
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.