-
-
Notifications
You must be signed in to change notification settings - Fork 33.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
Conversation
Some projectors do not respond to pjlink requests during a short period after the status changes or when it 8000 s in standby, resulting in pypjlink2 throwing an error. This fix catches these errors. Furthermore, only the status 'on' and 'warm-up' is interpreted as switched on, because 'cooling' is actually a switched off status.
self._muted = projector.get_mute()[1] | ||
self._current_source = \ | ||
format_input_source(*projector.get_input()) | ||
except: |
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.
do not use bare except'
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.
ok to merge when CI passes
self._muted = projector.get_mute()[1] | ||
self._current_source = \ | ||
format_input_source(*projector.get_input()) | ||
except: |
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.
Make sure to only catch exceptions we expect.
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.
I could make the changes you mentioned, but I'm new to Github and don't know the processes yet. Do I have to open a new pull request or is it possible to modify the existing pull request?
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.
Just commit and push to the same branch and this PR will be updated.
Improved error handling
else: | ||
raise | ||
except Exception as err: | ||
if type(err).__name__ == 'ProjectorError' and str(err) == 'unavailable time': |
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.
line too long (93 > 79 characters)
self._current_source = None | ||
else: | ||
raise | ||
except Exception as err: |
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 the expected exception is called ProjectorError
we should catch that here, instead of Exception
.
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.
I tried that first, of course. But I was not able to import the ProjectorError class for some reason. I'll try again later.
Improved error handling
I'm afraid that my changes only fix my own problem. I've noticed that the error is also triggered, when the methods 'turn_on' and 'turn_off' are called, while my projector is in this 'unknown mode'. But unlike ChronicledMonocle's projector, this 'unknown mode' does not occur permanently in standby mode, but only for a short time after switching on or off. In my opinion, issue #16606 probably can't be solved by modifying homeassistants PJLink component. To really fix this, the error handling of "pypjlink2" needs to be improved. If that happens, my changes will also become obsolete. |
self._muted = projector.get_mute()[1] | ||
self._current_source = \ | ||
format_input_source(*projector.get_input()) | ||
except KeyError as err: |
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 if projector.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 KeyError
is also caused by get_power()
. At least with my projector. When I turn on the projector and call the method all the time, I get the status warm-up
for a while. Then at some point an answer takes about one second longer. This is the KeyError
, which appears only once. Immediately afterwards, I get ProjectorError
with message "unavailable time" for about 20-30 seconds. After this time, again I get for a short time the status warm-up
and then on
.
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':
with if 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:
if pwstate in ('on', 'warm-up'):
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 KeyError
slip 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.
Clean up
Can be merged when build passes. |
* Fix issue #16606 Some projectors do not respond to pjlink requests during a short period after the status changes or when its in standby, resulting in pypjlink2 throwing an error. This fix catches these errors. Furthermore, only the status 'on' and 'warm-up' is interpreted as switched on, because 'cooling' is actually a switched off status. * Update pjlink.py Improved error handling * Update pjlink.py Improved error handling * Update pjlink.py Clean up
Description:
Some projectors do not respond to pjlink requests during a short period after the status changes or when its in standby, resulting in pypjlink2 throwing an error. This fix catches these errors. Furthermore, only the status 'on' and 'warm-up' is interpreted as switched on, because 'cooling' is actually a switched off status.
Related issue (if applicable): fixes #16606
Checklist:
tox
. Your PR cannot be merged unless tests pass