Fix pjlink issue (#20510)

* 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
pull/20794/head
emkay82 2019-02-01 14:53:40 +01:00 committed by Paulus Schoutsen
parent 0400e29f7a
commit 557b745053
1 changed files with 24 additions and 8 deletions

View File

@ -93,15 +93,31 @@ class PjLinkDevice(MediaPlayerDevice):
def update(self):
"""Get the latest state from the device."""
from pypjlink.projector import ProjectorError
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 in ('on', '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 ProjectorError as err:
if str(err) == 'unavailable time':
self._pwstate = STATE_OFF
self._muted = False
self._current_source = None
else:
raise
@property
def name(self):