mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +00:00
Use _attr_state in gstreamer media player (#82846)
This commit is contained in:
parent
b7f1ebe13c
commit
6e37aa425b
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from gsp import GstreamerPlayer
|
from gsp import STATE_IDLE, STATE_PAUSED, STATE_PLAYING, GstreamerPlayer
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components import media_source
|
from homeassistant.components import media_source
|
||||||
@ -33,6 +33,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
{vol.Optional(CONF_NAME): cv.string, vol.Optional(CONF_PIPELINE): cv.string}
|
{vol.Optional(CONF_NAME): cv.string, vol.Optional(CONF_PIPELINE): cv.string}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
GSP_STATE_MAPPING = {
|
||||||
|
STATE_IDLE: MediaPlayerState.IDLE,
|
||||||
|
STATE_PAUSED: MediaPlayerState.PAUSED,
|
||||||
|
STATE_PLAYING: MediaPlayerState.PLAYING,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(
|
def setup_platform(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
@ -67,11 +73,11 @@ class GstreamerDevice(MediaPlayerEntity):
|
|||||||
| MediaPlayerEntityFeature.BROWSE_MEDIA
|
| MediaPlayerEntityFeature.BROWSE_MEDIA
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, player, name):
|
def __init__(self, player: GstreamerPlayer, name: str | None) -> None:
|
||||||
"""Initialize the Gstreamer device."""
|
"""Initialize the Gstreamer device."""
|
||||||
self._player = player
|
self._player = player
|
||||||
self._name = name or DOMAIN
|
self._name = name or DOMAIN
|
||||||
self._state = MediaPlayerState.IDLE
|
self._attr_state = MediaPlayerState.IDLE
|
||||||
self._volume = None
|
self._volume = None
|
||||||
self._duration = None
|
self._duration = None
|
||||||
self._uri = None
|
self._uri = None
|
||||||
@ -81,7 +87,7 @@ class GstreamerDevice(MediaPlayerEntity):
|
|||||||
|
|
||||||
def update(self) -> None:
|
def update(self) -> None:
|
||||||
"""Update properties."""
|
"""Update properties."""
|
||||||
self._state = self._player.state
|
self._attr_state = GSP_STATE_MAPPING.get(self._player.state)
|
||||||
self._volume = self._player.volume
|
self._volume = self._player.volume
|
||||||
self._duration = self._player.duration
|
self._duration = self._player.duration
|
||||||
self._uri = self._player.uri
|
self._uri = self._player.uri
|
||||||
@ -139,11 +145,6 @@ class GstreamerDevice(MediaPlayerEntity):
|
|||||||
"""Return the volume level."""
|
"""Return the volume level."""
|
||||||
return self._volume
|
return self._volume
|
||||||
|
|
||||||
@property
|
|
||||||
def state(self):
|
|
||||||
"""Return the state of the player."""
|
|
||||||
return self._state
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def media_duration(self):
|
def media_duration(self):
|
||||||
"""Duration of current playing media in seconds."""
|
"""Duration of current playing media in seconds."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user