-
Notifications
You must be signed in to change notification settings - Fork 18
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
base: master
Are you sure you want to change the base?
Dynamic api #29
Conversation
@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.
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.
@nierob might find this amusing
You are right, I think it is funny :-)
nad_receiver/__init__.py
Outdated
if attr.startswith("_"): | ||
return |
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.
Why that? Shouldn't that raise AttributeError? (https://docs.python.org/3/reference/datamodel.html#object.__getattr__)
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}") |
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.
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.
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.