1 """Support for Enigma2 media players."""
3 from __future__
import annotations
6 from logging
import getLogger
7 from typing
import cast
9 from aiohttp.client_exceptions
import ServerDisconnectedError
10 from openwebif.enums
import PowerState, RemoteControlCodes, SetVolumeOption
14 MediaPlayerEntityFeature,
23 from .
import Enigma2ConfigEntry
24 from .coordinator
import Enigma2UpdateCoordinator
26 ATTR_MEDIA_CURRENTLY_RECORDING =
"media_currently_recording"
27 ATTR_MEDIA_DESCRIPTION =
"media_description"
28 ATTR_MEDIA_END_TIME =
"media_end_time"
29 ATTR_MEDIA_START_TIME =
"media_start_time"
31 _LOGGER = getLogger(__name__)
36 entry: Enigma2ConfigEntry,
37 async_add_entities: AddEntitiesCallback,
39 """Set up the Enigma2 media player platform."""
44 """Representation of an Enigma2 box."""
46 _attr_has_entity_name =
True
49 _attr_media_content_type = MediaType.TVSHOW
50 _attr_supported_features = (
51 MediaPlayerEntityFeature.VOLUME_SET
52 | MediaPlayerEntityFeature.VOLUME_MUTE
53 | MediaPlayerEntityFeature.TURN_OFF
54 | MediaPlayerEntityFeature.NEXT_TRACK
55 | MediaPlayerEntityFeature.STOP
56 | MediaPlayerEntityFeature.PREVIOUS_TRACK
57 | MediaPlayerEntityFeature.VOLUME_STEP
58 | MediaPlayerEntityFeature.TURN_ON
59 | MediaPlayerEntityFeature.PAUSE
60 | MediaPlayerEntityFeature.SELECT_SOURCE
63 def __init__(self, coordinator: Enigma2UpdateCoordinator) ->
None:
64 """Initialize the Enigma2 device."""
69 coordinator.device.mac_address
70 or cast(ConfigEntry, coordinator.config_entry).entry_id
76 """Turn off media player."""
77 if self.coordinator.device.turn_off_to_deep:
78 with contextlib.suppress(ServerDisconnectedError):
79 await self.coordinator.device.set_powerstate(PowerState.DEEP_STANDBY)
82 await self.coordinator.device.set_powerstate(PowerState.STANDBY)
86 """Turn the media player on."""
87 await self.coordinator.device.turn_on()
91 """Set volume level, range 0..1."""
92 await self.coordinator.device.set_volume(
int(volume * 100))
96 """Volume up the media player."""
97 await self.coordinator.device.set_volume(SetVolumeOption.UP)
101 """Volume down media player."""
102 await self.coordinator.device.set_volume(SetVolumeOption.DOWN)
106 """Send stop command."""
107 await self.coordinator.device.send_remote_control_action(
108 RemoteControlCodes.STOP
114 await self.coordinator.device.send_remote_control_action(
115 RemoteControlCodes.PLAY
120 """Pause the media player."""
121 await self.coordinator.device.send_remote_control_action(
122 RemoteControlCodes.PAUSE
127 """Send next track command."""
128 await self.coordinator.device.send_remote_control_action(
129 RemoteControlCodes.CHANNEL_UP
134 """Send previous track command."""
135 await self.coordinator.device.send_remote_control_action(
136 RemoteControlCodes.CHANNEL_DOWN
141 """Mute or unmute."""
142 if mute != self.coordinator.data.muted:
143 await self.coordinator.device.toggle_mute()
147 """Select input source."""
148 await self.coordinator.device.zap(self.coordinator.device.sources[source])
153 """Update state of the media_player."""
155 if not self.coordinator.data.in_standby:
157 ATTR_MEDIA_CURRENTLY_RECORDING: self.coordinator.data.is_recording,
158 ATTR_MEDIA_DESCRIPTION: self.coordinator.data.currservice.fulldescription,
159 ATTR_MEDIA_START_TIME: self.coordinator.data.currservice.begin,
160 ATTR_MEDIA_END_TIME: self.coordinator.data.currservice.end,
171 self.
_attr_source_attr_source = self.coordinator.data.currservice.station
174 if self.coordinator.data.in_standby:
179 if (volume_level := self.coordinator.data.volume)
is not None:
None async_write_ha_state(self)