-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Fix pjlink issue #20510
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
Fix pjlink issue #20510
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,14 +94,29 @@ def projector(self): | |
| def update(self): | ||
| """Get the latest state from the device.""" | ||
| with self.projector() as projector: | ||
| pwstate = projector.get_power() | ||
| if pwstate == 'off': | ||
| self._pwstate = STATE_OFF | ||
| else: | ||
| self._pwstate = STATE_ON | ||
| self._muted = projector.get_mute()[1] | ||
| self._current_source = \ | ||
| format_input_source(*projector.get_input()) | ||
| try: | ||
| pwstate = projector.get_power() | ||
| if pwstate == 'on' or pwstate == 'warm-up': | ||
| self._pwstate = STATE_ON | ||
| else: | ||
| self._pwstate = STATE_OFF | ||
| self._muted = projector.get_mute()[1] | ||
| self._current_source = \ | ||
| format_input_source(*projector.get_input()) | ||
| except KeyError as err: | ||
| if str(err) == "'OK'": | ||
| self._pwstate = STATE_OFF | ||
| self._muted = False | ||
| self._current_source = None | ||
| else: | ||
| raise | ||
| except Exception as err: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the expected exception is called
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried that first, of course. But I was not able to import the ProjectorError class for some reason. I'll try again later. |
||
| if type(err).__name__ == 'ProjectorError' and str(err) == 'unavailable time': | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (93 > 79 characters) |
||
| self._pwstate = STATE_OFF | ||
| self._muted = False | ||
| self._current_source = None | ||
| else: | ||
| raise | ||
|
|
||
| @property | ||
| def name(self): | ||
|
|
||
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.
When would we get the
KeyError? Is it ifprojector.get_mute()returns a dict instead of a list?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.
No, the
KeyErroris also caused byget_power(). At least with my projector. When I turn on the projector and call the method all the time, I get the statuswarm-upfor a while. Then at some point an answer takes about one second longer. This is theKeyError, which appears only once. Immediately afterwards, I getProjectorErrorwith message "unavailable time" for about 20-30 seconds. After this time, again I get for a short time the statuswarm-upand thenon.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.
The only thing I'd change right now is to swap
if pwstate == 'on' or pwstate == 'warm-up':withif pwstate in {'on', 'warm-up'}:. Seems like my little experience in python isn't enough to solve the problem. Do you have another suggestion?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.
Yeah, that clean up is good, but use a tuple:
Uh oh!
There was an error while loading. Please reload this page.
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.
The library shouldn't let
KeyErrorslip through. That's a bug in the library. It could raise a library specific exception if needed.But it's ok to fix here for now.
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.
If you find the cause, please try to fix this in the library and make a PR to them.
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.
CC @benoitlouy
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.
Thanks for your advice.