Skip to content

Dynamic api#29

Open
gladhorn wants to merge 4 commits intojoopert:masterfrom
gladhorn:dynamic_api
Open

Dynamic api#29
gladhorn wants to merge 4 commits intojoopert:masterfrom
gladhorn:dynamic_api

Conversation

@gladhorn
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown

@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 thread nad_receiver/__init__.py Outdated
Comment on lines +185 to +186
if attr.startswith("_"):
return
Copy link
Copy Markdown

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

Comment thread nad_receiver/__init__.py Outdated
return _CallHandler(self._transport, self._domain, attr)
raise TypeError(f"{attr}")
if self._op:
raise TypeError(f"{self} has no attribute {attr}")
Copy link
Copy Markdown

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