From 118ee06ba016f88abdf767efdf4ef1eacb4e5caa Mon Sep 17 00:00:00 2001 From: escoand Date: Tue, 11 Aug 2020 15:14:25 +0200 Subject: [PATCH] handle PlatformNotReady --- homeassistant/components/samsungtv/media_player.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/samsungtv/media_player.py b/homeassistant/components/samsungtv/media_player.py index 7eb0f50efc2..96c5ff3c713 100644 --- a/homeassistant/components/samsungtv/media_player.py +++ b/homeassistant/components/samsungtv/media_player.py @@ -29,6 +29,7 @@ from homeassistant.const import ( STATE_OFF, STATE_ON, ) +from homeassistant.exceptions import PlatformNotReady import homeassistant.helpers.config_validation as cv from homeassistant.helpers.script import Script from homeassistant.util import dt as dt_util @@ -97,6 +98,7 @@ class SamsungTVDevice(MediaPlayerEntity): # Assume that the TV is in Play mode self._playing = True self._state = None + self._was_on = False # Mark the end of a shutdown command (need to wait 15 seconds before # sending the next command to avoid turning the TV back ON). self._end_of_power_off = None @@ -117,7 +119,13 @@ class SamsungTVDevice(MediaPlayerEntity): if self._power_off_in_progress(): self._state = STATE_OFF else: - self._state = STATE_ON if self._bridge.is_on() else STATE_OFF + if self._bridge.is_on(): + self._state = STATE_ON + self._was_on = True + else: + self._state = STATE_OFF + if !self._was_on: + raise PlatformNotReady def send_key(self, key): """Send a key to the tv and handles exceptions."""