From 557b745053a086f73643801708be6f6b0735be00 Mon Sep 17 00:00:00 2001 From: emkay82 <37954256+emkay82@users.noreply.github.com> Date: Fri, 1 Feb 2019 14:53:40 +0100 Subject: [PATCH] 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 --- .../components/media_player/pjlink.py | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/media_player/pjlink.py b/homeassistant/components/media_player/pjlink.py index 168cde4a792..0609b75f98d 100644 --- a/homeassistant/components/media_player/pjlink.py +++ b/homeassistant/components/media_player/pjlink.py @@ -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):