1 """The lookin integration light platform."""
3 from __future__
import annotations
7 from aiolookin
import Remote
10 MediaPlayerDeviceClass,
12 MediaPlayerEntityFeature,
20 from .const
import DOMAIN, TYPE_TO_PLATFORM
21 from .coordinator
import LookinDataUpdateCoordinator
22 from .entity
import LookinPowerPushRemoteEntity
23 from .models
import LookinData
25 LOGGER = logging.getLogger(__name__)
27 _TYPE_TO_DEVICE_CLASS = {
28 "01": MediaPlayerDeviceClass.TV,
29 "02": MediaPlayerDeviceClass.RECEIVER,
32 _FUNCTION_NAME_TO_FEATURE = {
33 "power": MediaPlayerEntityFeature.TURN_OFF,
34 "poweron": MediaPlayerEntityFeature.TURN_ON,
35 "poweroff": MediaPlayerEntityFeature.TURN_OFF,
36 "mute": MediaPlayerEntityFeature.VOLUME_MUTE,
37 "volup": MediaPlayerEntityFeature.VOLUME_STEP,
38 "chup": MediaPlayerEntityFeature.NEXT_TRACK,
39 "chdown": MediaPlayerEntityFeature.PREVIOUS_TRACK,
40 "mode": MediaPlayerEntityFeature.SELECT_SOURCE,
46 config_entry: ConfigEntry,
47 async_add_entities: AddEntitiesCallback,
49 """Set up the media_player platform for lookin from a config entry."""
50 lookin_data: LookinData = hass.data[DOMAIN][config_entry.entry_id]
53 for remote
in lookin_data.devices:
54 if TYPE_TO_PLATFORM.get(remote[
"Type"]) != Platform.MEDIA_PLAYER:
57 coordinator = lookin_data.device_coordinators[uuid]
58 device: Remote = coordinator.data
61 coordinator=coordinator,
64 lookin_data=lookin_data,
65 device_class=_TYPE_TO_DEVICE_CLASS[remote[
"Type"]],
73 """A lookin media player."""
75 _attr_should_poll =
False
79 coordinator: LookinDataUpdateCoordinator,
82 lookin_data: LookinData,
83 device_class: MediaPlayerDeviceClass,
85 """Init the lookin media player."""
87 super().
__init__(coordinator, uuid, device, lookin_data)
88 for function_name, feature
in _FUNCTION_NAME_TO_FEATURE.items():
90 self._attr_supported_features |= feature
91 self.
_source_list_source_list: dict[str, str] |
None =
None
95 """List of available input sources."""
99 """Choose an available playlist and play it."""
105 """Get list of available input sources."""
107 if sources := await self.
_lookin_protocol_lookin_protocol.get_media_sources(
111 f
"INPUT_{index}": f
"{index:02x}" for index
in range(len(sources))
116 """Turn volume up for media player."""
120 """Turn volume down for media player."""
124 """Send previous track command."""
128 """Send next track command."""
132 """Mute the volume."""
138 """Turn the media player off."""
144 """Turn the media player on."""
150 """Update media property from status.
155 F - volume, 0 - muted, 1 - volume up, F - volume down
164 MediaPlayerState.ON
if state ==
"1" else MediaPlayerState.STANDBY
None _async_send_command(self, str command, str signal="FF")
None async_write_ha_state(self)