-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedia_player.py
88 lines (68 loc) · 2.41 KB
/
media_player.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"""Wyoming media_player entities."""
from __future__ import annotations
from typing import TYPE_CHECKING, Any, Optional
from homeassistant.components.media_player import (
MediaPlayerDeviceClass,
MediaPlayerEntity,
MediaPlayerEntityDescription,
MediaPlayerEntityFeature,
MediaPlayerState,
MediaType,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import (
AddEntitiesCallback,
async_get_current_platform,
)
from homeassistant.helpers import config_validation as cv
import voluptuous as vol
from .const import DOMAIN
from .entity import WyomingSatelliteEntity
if TYPE_CHECKING:
from .models import DomainDataItem
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up media_player entities."""
item: DomainDataItem = hass.data[DOMAIN][config_entry.entry_id]
# Setup is only forwarded for satellites
assert item.satellite is not None
device = item.satellite.device
async_add_entities(
[
WyomingSatelliteMediaPlayer(device),
]
)
# Register service for remote trigger
platform = async_get_current_platform()
platform.async_register_entity_service(
"remote_trigger",
{
vol.Optional("question_id"): cv.string,
},
"async_handle_remote_trigger",
)
class WyomingSatelliteMediaPlayer(WyomingSatelliteEntity, MediaPlayerEntity):
"""Media Player Entity to support PLAY MEDIA for TTS."""
_attr_device_class = MediaPlayerDeviceClass.SPEAKER
_attr_supported_features = MediaPlayerEntityFeature.PLAY_MEDIA
entity_description = MediaPlayerEntityDescription(
key="speaker",
translation_key="speaker",
)
async def async_added_to_hass(self) -> None:
"""Call when entity about to be added to hass."""
await super().async_added_to_hass()
async def async_play_media(
self, media_type: MediaType | str, media_id: str, **kwargs: Any
) -> None:
self._device.play_media(media_id)
@property
def state(self) -> MediaPlayerState:
"""Return the media state."""
return MediaPlayerState.ON
async def async_handle_remote_trigger(self, question_id: Optional[str] = None) -> None:
self._device.remote_trigger(question_id)