1 """Kaleidescape Media Player."""
3 from __future__
import annotations
6 from typing
import TYPE_CHECKING
8 from kaleidescape
import const
as kaleidescape_const
12 MediaPlayerEntityFeature,
17 from .const
import DOMAIN
as KALEIDESCAPE_DOMAIN
18 from .entity
import KaleidescapeEntity
21 from datetime
import datetime
28 KALEIDESCAPE_PLAYING_STATES = [
29 kaleidescape_const.PLAY_STATUS_PLAYING,
30 kaleidescape_const.PLAY_STATUS_FORWARD,
31 kaleidescape_const.PLAY_STATUS_REVERSE,
34 KALEIDESCAPE_PAUSED_STATES = [kaleidescape_const.PLAY_STATUS_PAUSED]
37 _LOGGER = logging.getLogger(__name__)
41 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
43 """Set up the platform from a config entry."""
49 """Representation of a Kaleidescape device."""
51 _attr_supported_features = (
52 MediaPlayerEntityFeature.TURN_ON
53 | MediaPlayerEntityFeature.TURN_OFF
54 | MediaPlayerEntityFeature.PLAY
55 | MediaPlayerEntityFeature.PAUSE
56 | MediaPlayerEntityFeature.STOP
57 | MediaPlayerEntityFeature.NEXT_TRACK
58 | MediaPlayerEntityFeature.PREVIOUS_TRACK
63 """Send leave standby command."""
64 await self.
_device_device.leave_standby()
67 """Send enter standby command."""
68 await self.
_device_device.enter_standby()
71 """Send pause command."""
72 await self.
_device_device.pause()
75 """Send play command."""
76 await self.
_device_device.play()
79 """Send stop command."""
80 await self.
_device_device.stop()
83 """Send track next command."""
84 await self.
_device_device.next()
87 """Send track previous command."""
88 await self.
_device_device.previous()
91 def state(self) -> MediaPlayerState:
92 """State of device."""
93 if self.
_device_device.power.state == kaleidescape_const.DEVICE_POWER_STATE_STANDBY:
94 return MediaPlayerState.OFF
95 if self.
_device_device.movie.play_status
in KALEIDESCAPE_PLAYING_STATES:
96 return MediaPlayerState.PLAYING
97 if self.
_device_device.movie.play_status
in KALEIDESCAPE_PAUSED_STATES:
98 return MediaPlayerState.PAUSED
99 return MediaPlayerState.IDLE
103 """Return if device is available."""
104 return self.
_device_device.is_connected
108 """Content ID of current playing media."""
109 if self.
_device_device.movie.handle:
110 return self.
_device_device.movie.handle
115 """Content type of current playing media."""
116 return self.
_device_device.movie.media_type
120 """Duration of current playing media in seconds."""
121 if self.
_device_device.movie.title_length:
122 return self.
_device_device.movie.title_length
127 """Position of current playing media in seconds."""
128 if self.
_device_device.movie.title_location:
129 return self.
_device_device.movie.title_location
134 """When was the position of the current playing media valid."""
135 if self.
_device_device.movie.play_status
in KALEIDESCAPE_PLAYING_STATES:
141 """Image url of current playing media."""
142 return self.
_device_device.movie.cover
146 """Title of current playing media."""
147 return self.
_device_device.movie.title