Use self._attr_state in vlc_telnet media player (#78517)

This commit is contained in:
epenet 2022-09-15 14:26:09 +02:00 committed by GitHub
parent a38d998000
commit cd2abf368f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -96,7 +96,6 @@ class VlcDevice(MediaPlayerEntity):
self._name = name
self._volume: float | None = None
self._muted: bool | None = None
self._state: str | None = None
self._media_position_updated_at: datetime | None = None
self._media_position: int | None = None
self._media_duration: int | None = None
@ -134,7 +133,7 @@ class VlcDevice(MediaPlayerEntity):
)
return
self._state = MediaPlayerState.IDLE
self._attr_state = MediaPlayerState.IDLE
self._available = True
LOGGER.info("Connected to vlc host: %s", self._vlc.host)
@ -144,13 +143,13 @@ class VlcDevice(MediaPlayerEntity):
self._volume = status.audio_volume / MAX_VOLUME
state = status.state
if state == "playing":
self._state = MediaPlayerState.PLAYING
self._attr_state = MediaPlayerState.PLAYING
elif state == "paused":
self._state = MediaPlayerState.PAUSED
self._attr_state = MediaPlayerState.PAUSED
else:
self._state = MediaPlayerState.IDLE
self._attr_state = MediaPlayerState.IDLE
if self._state != MediaPlayerState.IDLE:
if self._attr_state != MediaPlayerState.IDLE:
self._media_duration = (await self._vlc.get_length()).length
time_output = await self._vlc.get_time()
vlc_position = time_output.time
@ -191,11 +190,6 @@ class VlcDevice(MediaPlayerEntity):
"""Return the name of the device."""
return self._name
@property
def state(self) -> str | None:
"""Return the state of the device."""
return self._state
@property
def available(self) -> bool:
"""Return True if entity is available."""
@ -267,7 +261,7 @@ class VlcDevice(MediaPlayerEntity):
async def async_media_play(self) -> None:
"""Send play command."""
await self._vlc.play()
self._state = MediaPlayerState.PLAYING
self._attr_state = MediaPlayerState.PLAYING
@catch_vlc_errors
async def async_media_pause(self) -> None:
@ -278,13 +272,13 @@ class VlcDevice(MediaPlayerEntity):
# pause.
await self._vlc.pause()
self._state = MediaPlayerState.PAUSED
self._attr_state = MediaPlayerState.PAUSED
@catch_vlc_errors
async def async_media_stop(self) -> None:
"""Send stop command."""
await self._vlc.stop()
self._state = MediaPlayerState.IDLE
self._attr_state = MediaPlayerState.IDLE
@catch_vlc_errors
async def async_play_media(
@ -310,7 +304,7 @@ class VlcDevice(MediaPlayerEntity):
)
await self._vlc.add(media_id)
self._state = MediaPlayerState.PLAYING
self._attr_state = MediaPlayerState.PLAYING
@catch_vlc_errors
async def async_media_previous_track(self) -> None: