Skip to content
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

Dynamic api #29

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Dynamic api #29

wants to merge 4 commits into from

Conversation

gladhorn
Copy link
Collaborator

This is a bit of an exercise to play with Python attributes. See description in the commit message of 4c73c46

Basically new API can be added by just editing CMDS in nad_commands.py.
receiver.main.volume.increase() works then by inspecting the commands dictionary.

@gladhorn
Copy link
Collaborator Author

@nierob might find this amusing

Just the very basic infrastructure to make debugging easier.
Since most people have only one receiver, we need to be able to capture logs.

One option for users is to simply uncomment one line to enable logging
of all communication through serial or telnet.
Copy link

@nierob nierob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nierob might find this amusing

You are right, I think it is funny :-)

Comment on lines 185 to 186
if attr.startswith("_"):
return
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why that? Shouldn't that raise AttributeError? (https://docs.python.org/3/reference/datamodel.html#object.__getattr__)

return _CallHandler(self._transport, self._domain, attr)
raise TypeError(f"{attr}")
if self._op:
raise TypeError(f"{self} has no attribute {attr}")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AttributeError?

This implements the complete RS232 API of the receiver in a mock class.
With this the receiver can be tested locally without having any serial port.

Add a test that checks that communication with that particular amplifier
doesn't break again. Similar tests are needed for other models, but
since this is the only amp I have, I'm not easily able to write them.

The sources are for now left out because the current implementation
assumes sources to be integers, while the V2 protocol is purely string
based.
We have a complete description of the protocol in nad_commands. Let's
use it. This dynamically generates objects from the command dictionary,
so that new functions do not need any code any more. Instead one can
simply call:
receiver.main.volume.increase()

This works by inspecting nad_commands when asking for attributes of the
receiver class or it's dynamically created subclasses.

The old API is around unchanged to stay compatible.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants