From ed0e5835563709b1b88021f391a81ce00eadde05 Mon Sep 17 00:00:00 2001 From: Artem Draft Date: Sun, 1 Jan 2023 20:07:14 +0300 Subject: [PATCH] Assumed state in Bravia TV media player (#84885) --- homeassistant/components/braviatv/coordinator.py | 4 ---- homeassistant/components/braviatv/media_player.py | 11 ++++++----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/braviatv/coordinator.py b/homeassistant/components/braviatv/coordinator.py index 3d57850a648..317f675a906 100644 --- a/homeassistant/components/braviatv/coordinator.py +++ b/homeassistant/components/braviatv/coordinator.py @@ -95,8 +95,6 @@ class BraviaTVCoordinator(DataUpdateCoordinator[None]): self.is_on = False self.is_channel = False self.connected = False - # Assume that the TV is in Play mode - self.playing = True self.skipped_updates = 0 super().__init__( @@ -249,13 +247,11 @@ class BraviaTVCoordinator(DataUpdateCoordinator[None]): async def async_media_play(self) -> None: """Send play command to device.""" await self.client.play() - self.playing = True @catch_braviatv_errors async def async_media_pause(self) -> None: """Send pause command to device.""" await self.client.pause() - self.playing = False @catch_braviatv_errors async def async_media_stop(self) -> None: diff --git a/homeassistant/components/braviatv/media_player.py b/homeassistant/components/braviatv/media_player.py index 65a8e46946e..5de2c3d38cd 100644 --- a/homeassistant/components/braviatv/media_player.py +++ b/homeassistant/components/braviatv/media_player.py @@ -35,6 +35,7 @@ async def async_setup_entry( class BraviaTVMediaPlayer(BraviaTVEntity, MediaPlayerEntity): """Representation of a Bravia TV Media Player.""" + _attr_assumed_state = True _attr_device_class = MediaPlayerDeviceClass.TV _attr_supported_features = ( MediaPlayerEntityFeature.PAUSE @@ -54,11 +55,7 @@ class BraviaTVMediaPlayer(BraviaTVEntity, MediaPlayerEntity): def state(self) -> MediaPlayerState: """Return the state of the device.""" if self.coordinator.is_on: - return ( - MediaPlayerState.PLAYING - if self.coordinator.playing - else MediaPlayerState.PAUSED - ) + return MediaPlayerState.ON return MediaPlayerState.OFF @property @@ -137,6 +134,10 @@ class BraviaTVMediaPlayer(BraviaTVEntity, MediaPlayerEntity): """Send pause command.""" await self.coordinator.async_media_pause() + async def async_media_play_pause(self) -> None: + """Send pause command that toggle play/pause.""" + await self.coordinator.async_media_pause() + async def async_media_stop(self) -> None: """Send media stop command to media player.""" await self.coordinator.async_media_stop()