8000 Fix pjlink issue by emkay82 · Pull Request #20510 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged
merged 4 commits into from
Feb 1, 2019
Merged

Fix pjlink issue #20510

merged 4 commits into from
Feb 1, 2019

Conversation

emkay82
Copy link
Contributor
@emkay82 emkay82 commented Jan 27, 2019

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:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.

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.
@homeassistant
Copy link
Contributor

Hi @emkay82,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

self._muted = projector.get_mute()[1]
self._current_source = \
format_input_source(*projector.get_input())
except:

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'

@MartinHjelmare MartinHjelmare changed the title Fix issue #16606 Fix pjlink issue Jan 27, 2019
Copy link
Member
@balloob balloob left a 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:
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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':

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:
Copy link
Member

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.

Copy link
Contributor Author

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
@emkay82
Copy link
Contributor Author
emkay82 commented Jan 31, 2019

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:
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

Copy link
Member

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'):
8000

Copy link
Member
@MartinHjelmare MartinHjelmare Feb 1, 2019

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.

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your advice.

@MartinHjelmare
Copy link
Member

Can be merged when build passes.

@MartinHjelmare MartinHjelmare added this to the 0.87.0 milestone Feb 1, 2019
@MartinHjelmare MartinHjelmare merged commit 47d2475 into home-assistant:dev Feb 1, 2019
@ghost ghost removed the in progress label Feb 1, 2019
balloob pushed a commit that referenced this pull request Feb 1, 2019
* 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
@emkay82 emkay82 deleted the patch-1 branch February 2, 2019 16:28
@balloob balloob mentioned this pull request Feb 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PJLink Media Player Component Doesn't Work with Standby Devices
5 participants
0