Assumed state in Bravia TV media player (#84885)

This commit is contained in:
Artem Draft 2023-01-01 20:07:14 +03:00 committed by GitHub
parent e5b6f05e5b
commit ed0e583556
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 9 deletions

View File

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

View File

@ -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()