1 """Support for Frontier Silicon Devices (Medion, Hama, Auna,...)."""
3 from __future__
import annotations
10 ConnectionError
as FSConnectionError,
11 NotImplementedException
as FSNotImplementedException,
19 MediaPlayerEntityFeature,
28 from .browse_media
import browse_node, browse_top_level
29 from .const
import DOMAIN, MEDIA_CONTENT_ID_PRESET
31 _LOGGER = logging.getLogger(__name__)
36 config_entry: ConfigEntry,
37 async_add_entities: AddEntitiesCallback,
39 """Set up the Frontier Silicon entity."""
41 afsapi: AFSAPI = hass.data[DOMAIN][config_entry.entry_id]
46 config_entry.entry_id,
56 """Representation of a Frontier Silicon device on the network."""
58 _attr_media_content_type: str = MediaType.CHANNEL
59 _attr_has_entity_name =
True
62 _attr_supported_features = (
63 MediaPlayerEntityFeature.PAUSE
64 | MediaPlayerEntityFeature.VOLUME_SET
65 | MediaPlayerEntityFeature.VOLUME_MUTE
66 | MediaPlayerEntityFeature.VOLUME_STEP
67 | MediaPlayerEntityFeature.PREVIOUS_TRACK
68 | MediaPlayerEntityFeature.NEXT_TRACK
69 | MediaPlayerEntityFeature.SEEK
70 | MediaPlayerEntityFeature.PLAY_MEDIA
71 | MediaPlayerEntityFeature.PLAY
72 | MediaPlayerEntityFeature.STOP
73 | MediaPlayerEntityFeature.TURN_ON
74 | MediaPlayerEntityFeature.TURN_OFF
75 | MediaPlayerEntityFeature.SELECT_SOURCE
76 | MediaPlayerEntityFeature.SELECT_SOUND_MODE
77 | MediaPlayerEntityFeature.BROWSE_MEDIA
80 def __init__(self, unique_id: str, name: str |
None, afsapi: AFSAPI) ->
None:
81 """Initialize the Frontier Silicon API device."""
85 identifiers={(DOMAIN, unique_id)},
97 """Get the latest date and update device state."""
100 if await afsapi.get_power():
101 status = await afsapi.get_play_status()
103 PlayState.PLAYING: MediaPlayerState.PLAYING,
104 PlayState.PAUSED: MediaPlayerState.PAUSED,
105 PlayState.STOPPED: MediaPlayerState.IDLE,
106 PlayState.LOADING: MediaPlayerState.BUFFERING,
107 None: MediaPlayerState.IDLE,
111 except FSConnectionError:
114 "Could not connect to %s. Did it go offline?",
115 self.
namename
or afsapi.webfsapi_endpoint,
123 self.
namename
or afsapi.webfsapi_endpoint,
130 (mode.label
if mode.label
else mode.id): mode.key
131 for mode
in await afsapi.get_modes()
137 equalisers = await afsapi.get_equalisers()
138 except FSNotImplementedException:
142 MediaPlayerEntityFeature.SELECT_SOUND_MODE
146 sound_mode.label: sound_mode.key
for sound_mode
in equalisers
156 if self.
_attr_state_attr_state != MediaPlayerState.OFF:
157 info_name = await afsapi.get_play_name()
158 info_text = await afsapi.get_play_text()
164 radio_mode = await afsapi.get_mode()
165 self.
_attr_source_attr_source = radio_mode.label
if radio_mode
is not None else None
172 eq_preset = await afsapi.get_eq_preset()
173 except FSNotImplementedException:
177 MediaPlayerEntityFeature.SELECT_SOUND_MODE
181 eq_preset.label
if eq_preset
is not None else None
184 volume = await self.
fs_devicefs_device.get_volume()
204 """Turn on the device."""
205 await self.
fs_devicefs_device.set_power(
True)
208 """Turn off the device."""
209 await self.
fs_devicefs_device.set_power(
False)
212 """Send play command."""
216 """Send pause command."""
220 """Send play/pause command."""
221 if self.
_attr_state_attr_state == MediaPlayerState.PLAYING:
227 """Send play/pause command."""
231 """Send previous track command (results in rewind)."""
235 """Send next track command (results in fast-forward)."""
239 """Send mute command."""
240 await self.
fs_devicefs_device.set_mute(mute)
244 """Send volume up command."""
245 volume = await self.
fs_devicefs_device.get_volume()
246 volume =
int(volume
or 0) + 1
250 """Send volume down command."""
251 volume = await self.
fs_devicefs_device.get_volume()
252 volume =
int(volume
or 0) - 1
253 await self.
fs_devicefs_device.set_volume(
max(volume, 0))
256 """Set volume command."""
259 await self.
fs_devicefs_device.set_volume(volume)
262 """Select input source."""
263 await self.
fs_devicefs_device.set_power(
True)
268 await self.
fs_devicefs_device.set_mode(mode)
271 """Select EQ Preset."""
276 await self.
fs_devicefs_device.set_eq_preset(mode)
280 media_content_type: MediaType | str |
None =
None,
281 media_content_id: str |
None =
None,
283 """Browse media library and preset stations."""
284 if not media_content_id:
290 self, media_type: MediaType | str, media_id: str, **kwargs: Any
292 """Play selected media or channel."""
293 if media_type != MediaType.CHANNEL:
295 "Got %s, but frontier_silicon only supports playing channels",
300 player_mode, media_type, *keys = media_id.split(
"/")
304 if media_type == MEDIA_CONTENT_ID_PRESET:
306 raise BrowseError(
"Presets can only have 1 level")
309 preset =
int(keys[0]) - 1
311 await self.
fs_devicefs_device.select_preset(preset)
313 await self.
fs_devicefs_device.nav_select_item_via_path(keys)
str|UndefinedType|None name(self)
web.Response get(self, web.Request request, str config_key)