mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Add home theater support to LG Infrared (#190115)
This commit is contained in:
@@ -4,6 +4,7 @@ from dataclasses import dataclass
|
||||
from typing import override
|
||||
|
||||
from infrared_protocols.codes.lg.ac import LGACCode
|
||||
from infrared_protocols.codes.lg.home_theater import LGHomeTheaterCode
|
||||
from infrared_protocols.codes.lg.tv import LGTVCode
|
||||
|
||||
from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
|
||||
@@ -23,7 +24,7 @@ PARALLEL_UPDATES = 1
|
||||
class LgIrButtonEntityDescription(ButtonEntityDescription):
|
||||
"""Describes LG IR button entity."""
|
||||
|
||||
command_code: LGTVCode | LGACCode
|
||||
command_code: LGTVCode | LGACCode | LGHomeTheaterCode
|
||||
|
||||
|
||||
TV_BUTTON_DESCRIPTIONS: tuple[LgIrButtonEntityDescription, ...] = (
|
||||
@@ -171,13 +172,161 @@ AC_BUTTON_DESCRIPTIONS: tuple[LgIrButtonEntityDescription, ...] = (
|
||||
),
|
||||
)
|
||||
|
||||
HOME_THEATER_BUTTON_DESCRIPTIONS: tuple[LgIrButtonEntityDescription, ...] = (
|
||||
LgIrButtonEntityDescription(
|
||||
key="power", translation_key="power", command_code=LGHomeTheaterCode.POWER
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="home", translation_key="home", command_code=LGHomeTheaterCode.HOME
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="input",
|
||||
translation_key="input",
|
||||
command_code=LGHomeTheaterCode.FUNCTION,
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="info",
|
||||
translation_key="info",
|
||||
command_code=LGHomeTheaterCode.INFO_MENU,
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="disc_menu",
|
||||
translation_key="disc_menu",
|
||||
command_code=LGHomeTheaterCode.DISC_MENU,
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="title_popup",
|
||||
translation_key="title_popup",
|
||||
command_code=LGHomeTheaterCode.TITLE_POPUP,
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="up", translation_key="up", command_code=LGHomeTheaterCode.NAV_UP
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="down", translation_key="down", command_code=LGHomeTheaterCode.NAV_DOWN
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="left", translation_key="left", command_code=LGHomeTheaterCode.NAV_LEFT
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="right", translation_key="right", command_code=LGHomeTheaterCode.NAV_RIGHT
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="ok", translation_key="ok", command_code=LGHomeTheaterCode.OK
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="back", translation_key="back", command_code=LGHomeTheaterCode.BACK
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="clear", translation_key="clear", command_code=LGHomeTheaterCode.CLEAR
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="num_0", translation_key="num_0", command_code=LGHomeTheaterCode.NUM_0
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="num_1", translation_key="num_1", command_code=LGHomeTheaterCode.NUM_1
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="num_2", translation_key="num_2", command_code=LGHomeTheaterCode.NUM_2
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="num_3", translation_key="num_3", command_code=LGHomeTheaterCode.NUM_3
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="num_4", translation_key="num_4", command_code=LGHomeTheaterCode.NUM_4
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="num_5", translation_key="num_5", command_code=LGHomeTheaterCode.NUM_5
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="num_6", translation_key="num_6", command_code=LGHomeTheaterCode.NUM_6
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="num_7", translation_key="num_7", command_code=LGHomeTheaterCode.NUM_7
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="num_8", translation_key="num_8", command_code=LGHomeTheaterCode.NUM_8
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="num_9", translation_key="num_9", command_code=LGHomeTheaterCode.NUM_9
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="asterisk",
|
||||
translation_key="asterisk",
|
||||
command_code=LGHomeTheaterCode.ASTERISK,
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="open_close",
|
||||
translation_key="open_close",
|
||||
command_code=LGHomeTheaterCode.OPEN_CLOSE,
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="optical_tv_sound",
|
||||
translation_key="optical_tv_sound",
|
||||
command_code=LGHomeTheaterCode.OPTICAL_TV_SOUND,
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="sound_effect",
|
||||
translation_key="sound_effect",
|
||||
command_code=LGHomeTheaterCode.SOUND_EFFECT,
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="speaker_level",
|
||||
translation_key="speaker_level",
|
||||
command_code=LGHomeTheaterCode.SPEAKER_LEVEL,
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="audio_track",
|
||||
translation_key="audio_track",
|
||||
command_code=LGHomeTheaterCode.AUDIO,
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="subtitle",
|
||||
translation_key="subtitle",
|
||||
command_code=LGHomeTheaterCode.SUBTITLE,
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="sleep", translation_key="sleep", command_code=LGHomeTheaterCode.SLEEP
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="record", translation_key="record", command_code=LGHomeTheaterCode.RECORD
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="repeat", translation_key="repeat", command_code=LGHomeTheaterCode.REPEAT
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="rewind",
|
||||
translation_key="rewind",
|
||||
command_code=LGHomeTheaterCode.SCAN_BACKWARD,
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="fast_forward",
|
||||
translation_key="fast_forward",
|
||||
command_code=LGHomeTheaterCode.SCAN_FORWARD,
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="red", translation_key="red", command_code=LGHomeTheaterCode.RED
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="green", translation_key="green", command_code=LGHomeTheaterCode.GREEN
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="yellow", translation_key="yellow", command_code=LGHomeTheaterCode.YELLOW
|
||||
),
|
||||
LgIrButtonEntityDescription(
|
||||
key="blue", translation_key="blue", command_code=LGHomeTheaterCode.BLUE
|
||||
),
|
||||
)
|
||||
|
||||
_DEVICE_BUTTONS: dict[LGDeviceType, tuple[LgIrButtonEntityDescription, ...]] = {
|
||||
LGDeviceType.TV: TV_BUTTON_DESCRIPTIONS,
|
||||
LGDeviceType.AC: AC_BUTTON_DESCRIPTIONS,
|
||||
LGDeviceType.HOME_THEATER: HOME_THEATER_BUTTON_DESCRIPTIONS,
|
||||
}
|
||||
_DEVICE_NAMES: dict[LGDeviceType, str] = {
|
||||
LGDeviceType.TV: "LG TV",
|
||||
LGDeviceType.AC: "LG AC",
|
||||
LGDeviceType.HOME_THEATER: "LG Home Theater",
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ from .const import (
|
||||
DEVICE_TYPE_NAMES: dict[LGDeviceType, str] = {
|
||||
LGDeviceType.TV: "TV",
|
||||
LGDeviceType.AC: "AC",
|
||||
LGDeviceType.HOME_THEATER: "Home Theater",
|
||||
}
|
||||
|
||||
_HVAC_MODE_OPTIONS = [
|
||||
@@ -90,6 +91,21 @@ def _ac_schema(hass: HomeAssistant) -> probatio.Schema:
|
||||
)
|
||||
|
||||
|
||||
@callback
|
||||
def _home_theater_schema(hass: HomeAssistant) -> probatio.Schema:
|
||||
"""Return the Home Theater schema: emitter only."""
|
||||
return probatio.Schema(
|
||||
{
|
||||
probatio.Required(CONF_INFRARED_ENTITY_ID): EntitySelector(
|
||||
EntitySelectorConfig(
|
||||
domain=INFRARED_DOMAIN,
|
||||
include_entities=async_get_emitters(hass),
|
||||
)
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class LgIrConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
"""Handle config flow for LG IR."""
|
||||
|
||||
@@ -144,9 +160,10 @@ class LgIrConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
return self.async_abort(reason="no_infrared_entities")
|
||||
|
||||
menu_options = [LGDeviceType.TV.value]
|
||||
# The AC step requires an emitter, so offering it without one dead-ends.
|
||||
# The AC and Home Theater steps require an emitter, so offering them without one dead-ends.
|
||||
if emitter_entity_ids:
|
||||
menu_options.append(LGDeviceType.AC.value)
|
||||
menu_options.append(LGDeviceType.HOME_THEATER.value)
|
||||
|
||||
return self.async_show_menu(step_id="user", menu_options=menu_options)
|
||||
|
||||
@@ -180,6 +197,20 @@ class LgIrConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
return self.async_show_form(step_id="ac", data_schema=_ac_schema(self.hass))
|
||||
|
||||
async def async_step_home_theater(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> ConfigFlowResult:
|
||||
"""Handle Home Theater entity selection."""
|
||||
if user_input is not None:
|
||||
return await self._async_create_device_entry(
|
||||
LGDeviceType.HOME_THEATER, user_input
|
||||
)
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="home_theater",
|
||||
data_schema=_home_theater_schema(self.hass),
|
||||
)
|
||||
|
||||
async def async_step_reconfigure(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> ConfigFlowResult:
|
||||
@@ -192,6 +223,10 @@ class LgIrConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
if not async_get_emitters(self.hass):
|
||||
return self.async_abort(reason="no_infrared_emitters")
|
||||
data_schema = _ac_schema(self.hass)
|
||||
elif device_type is LGDeviceType.HOME_THEATER:
|
||||
if not async_get_emitters(self.hass):
|
||||
return self.async_abort(reason="no_infrared_emitters")
|
||||
data_schema = _home_theater_schema(self.hass)
|
||||
else:
|
||||
if not async_get_emitters(self.hass) and not async_get_receivers(self.hass):
|
||||
return self.async_abort(reason="no_infrared_entities")
|
||||
|
||||
@@ -14,3 +14,4 @@ class LGDeviceType(StrEnum):
|
||||
|
||||
TV = "tv"
|
||||
AC = "ac"
|
||||
HOME_THEATER = "home_theater"
|
||||
|
||||
@@ -4,15 +4,30 @@
|
||||
"ai_convertible": {
|
||||
"default": "mdi:brain"
|
||||
},
|
||||
"asterisk": {
|
||||
"default": "mdi:asterisk"
|
||||
},
|
||||
"audio": {
|
||||
"default": "mdi:volume-high"
|
||||
},
|
||||
"audio_track": {
|
||||
"default": "mdi:volume-source"
|
||||
},
|
||||
"back": {
|
||||
"default": "mdi:keyboard-backspace"
|
||||
},
|
||||
"blue": {
|
||||
"default": "mdi:circle"
|
||||
},
|
||||
"clear": {
|
||||
"default": "mdi:close-circle-outline"
|
||||
},
|
||||
"diagnose": {
|
||||
"default": "mdi:stethoscope"
|
||||
},
|
||||
"disc_menu": {
|
||||
"default": "mdi:disc"
|
||||
},
|
||||
"down": {
|
||||
"default": "mdi:arrow-down"
|
||||
},
|
||||
@@ -22,6 +37,12 @@
|
||||
"exit": {
|
||||
"default": "mdi:exit-to-app"
|
||||
},
|
||||
"fast_forward": {
|
||||
"default": "mdi:fast-forward"
|
||||
},
|
||||
"green": {
|
||||
"default": "mdi:circle"
|
||||
},
|
||||
"guide": {
|
||||
"default": "mdi:television-guide"
|
||||
},
|
||||
@@ -91,6 +112,12 @@
|
||||
"ok": {
|
||||
"default": "mdi:check"
|
||||
},
|
||||
"open_close": {
|
||||
"default": "mdi:eject"
|
||||
},
|
||||
"optical_tv_sound": {
|
||||
"default": "mdi:television-speaker"
|
||||
},
|
||||
"power": {
|
||||
"default": "mdi:power"
|
||||
},
|
||||
@@ -100,12 +127,39 @@
|
||||
"power_on": {
|
||||
"default": "mdi:power-on"
|
||||
},
|
||||
"record": {
|
||||
"default": "mdi:record-rec"
|
||||
},
|
||||
"red": {
|
||||
"default": "mdi:circle"
|
||||
},
|
||||
"repeat": {
|
||||
"default": "mdi:repeat"
|
||||
},
|
||||
"rewind": {
|
||||
"default": "mdi:rewind"
|
||||
},
|
||||
"right": {
|
||||
"default": "mdi:arrow-right"
|
||||
},
|
||||
"sleep": {
|
||||
"default": "mdi:sleep"
|
||||
},
|
||||
"sound_effect": {
|
||||
"default": "mdi:equalizer"
|
||||
},
|
||||
"speaker_level": {
|
||||
"default": "mdi:surround-sound"
|
||||
},
|
||||
"subtitle": {
|
||||
"default": "mdi:subtitles"
|
||||
},
|
||||
"swing_v_toggle": {
|
||||
"default": "mdi:arrow-up-down"
|
||||
},
|
||||
"title_popup": {
|
||||
"default": "mdi:menu-open"
|
||||
},
|
||||
"up": {
|
||||
"default": "mdi:arrow-up"
|
||||
},
|
||||
@@ -114,6 +168,9 @@
|
||||
},
|
||||
"wifi": {
|
||||
"default": "mdi:wifi"
|
||||
},
|
||||
"yellow": {
|
||||
"default": "mdi:circle"
|
||||
}
|
||||
},
|
||||
"climate": {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
from typing import override
|
||||
|
||||
from infrared_protocols.codes.lg.home_theater import LGHomeTheaterCode
|
||||
from infrared_protocols.codes.lg.tv import LGTVCode
|
||||
|
||||
from homeassistant.components.infrared import InfraredEmitterConsumerEntity
|
||||
@@ -33,6 +34,8 @@ async def async_setup_entry(
|
||||
device_type = entry.data[CONF_DEVICE_TYPE]
|
||||
if device_type == LGDeviceType.TV:
|
||||
async_add_entities([LgIrTvMediaPlayer(entry, infrared_entity_id)])
|
||||
elif device_type == LGDeviceType.HOME_THEATER:
|
||||
async_add_entities([LgIrHomeTheaterMediaPlayer(entry, infrared_entity_id)])
|
||||
|
||||
|
||||
class LgIrTvMediaPlayer(LgIrEntity, InfraredEmitterConsumerEntity, MediaPlayerEntity):
|
||||
@@ -108,3 +111,82 @@ class LgIrTvMediaPlayer(LgIrEntity, InfraredEmitterConsumerEntity, MediaPlayerEn
|
||||
async def async_media_stop(self) -> None:
|
||||
"""Send stop command."""
|
||||
await self._send_command(LGTVCode.STOP.to_command())
|
||||
|
||||
|
||||
class LgIrHomeTheaterMediaPlayer(
|
||||
LgIrEntity, InfraredEmitterConsumerEntity, MediaPlayerEntity
|
||||
):
|
||||
"""LG IR home theater media player entity."""
|
||||
|
||||
_attr_name = None
|
||||
_attr_assumed_state = True
|
||||
_attr_device_class = MediaPlayerDeviceClass.RECEIVER
|
||||
_attr_supported_features = (
|
||||
MediaPlayerEntityFeature.TURN_ON
|
||||
| MediaPlayerEntityFeature.TURN_OFF
|
||||
| MediaPlayerEntityFeature.VOLUME_STEP
|
||||
| MediaPlayerEntityFeature.VOLUME_MUTE
|
||||
| MediaPlayerEntityFeature.NEXT_TRACK
|
||||
| MediaPlayerEntityFeature.PREVIOUS_TRACK
|
||||
| MediaPlayerEntityFeature.PLAY
|
||||
| MediaPlayerEntityFeature.PAUSE
|
||||
| MediaPlayerEntityFeature.STOP
|
||||
)
|
||||
|
||||
def __init__(self, entry: ConfigEntry, infrared_entity_id: str) -> None:
|
||||
"""Initialize LG IR home theater media player."""
|
||||
super().__init__(
|
||||
entry, unique_id_suffix="media_player", device_name="LG Home Theater"
|
||||
)
|
||||
self._infrared_emitter_entity_id = infrared_entity_id
|
||||
self._attr_state = MediaPlayerState.ON
|
||||
|
||||
@override
|
||||
async def async_turn_on(self) -> None:
|
||||
"""Turn on the home theater."""
|
||||
await self._send_command(LGHomeTheaterCode.POWER.to_command())
|
||||
|
||||
@override
|
||||
async def async_turn_off(self) -> None:
|
||||
"""Turn off the home theater."""
|
||||
await self._send_command(LGHomeTheaterCode.POWER.to_command())
|
||||
|
||||
@override
|
||||
async def async_volume_up(self) -> None:
|
||||
"""Send volume up command."""
|
||||
await self._send_command(LGHomeTheaterCode.VOLUME_UP.to_command())
|
||||
|
||||
@override
|
||||
async def async_volume_down(self) -> None:
|
||||
"""Send volume down command."""
|
||||
await self._send_command(LGHomeTheaterCode.VOLUME_DOWN.to_command())
|
||||
|
||||
@override
|
||||
async def async_mute_volume(self, mute: bool) -> None:
|
||||
"""Send mute command."""
|
||||
await self._send_command(LGHomeTheaterCode.MUTE.to_command())
|
||||
|
||||
@override
|
||||
async def async_media_next_track(self) -> None:
|
||||
"""Send skip next command."""
|
||||
await self._send_command(LGHomeTheaterCode.SKIP_FORWARD.to_command())
|
||||
|
||||
@override
|
||||
async def async_media_previous_track(self) -> None:
|
||||
"""Send skip previous command."""
|
||||
await self._send_command(LGHomeTheaterCode.SKIP_BACKWARD.to_command())
|
||||
|
||||
@override
|
||||
async def async_media_play(self) -> None:
|
||||
"""Send play command."""
|
||||
await self._send_command(LGHomeTheaterCode.PLAY.to_command())
|
||||
|
||||
@override
|
||||
async def async_media_pause(self) -> None:
|
||||
"""Send pause command."""
|
||||
await self._send_command(LGHomeTheaterCode.PAUSE.to_command())
|
||||
|
||||
@override
|
||||
async def async_media_stop(self) -> None:
|
||||
"""Send stop command."""
|
||||
await self._send_command(LGHomeTheaterCode.STOP.to_command())
|
||||
|
||||
@@ -24,6 +24,16 @@
|
||||
"description": "Select an infrared emitter and the modes your LG AC supports.",
|
||||
"title": "Set up LG AC"
|
||||
},
|
||||
"home_theater": {
|
||||
"data": {
|
||||
"infrared_entity_id": "[%key:common::config_flow::data::infrared_entity_id%]"
|
||||
},
|
||||
"data_description": {
|
||||
"infrared_entity_id": "[%key:common::config_flow::data_description::infrared_entity_id%]"
|
||||
},
|
||||
"description": "Select an infrared emitter to use with your LG Home Theater.",
|
||||
"title": "Set up LG Home Theater"
|
||||
},
|
||||
"reconfigure": {
|
||||
"data": {
|
||||
"hvac_modes": "[%key:component::lg_infrared::config::step::ac::data::hvac_modes%]",
|
||||
@@ -54,6 +64,7 @@
|
||||
"description": "Select the type of LG device to set up.",
|
||||
"menu_options": {
|
||||
"ac": "Air conditioner",
|
||||
"home_theater": "Home theater",
|
||||
"tv": "[%key:common::generic::tv%]"
|
||||
},
|
||||
"title": "Set up LG IR Remote"
|
||||
@@ -65,15 +76,30 @@
|
||||
"ai_convertible": {
|
||||
"name": "AI mode"
|
||||
},
|
||||
"asterisk": {
|
||||
"name": "Asterisk"
|
||||
},
|
||||
"audio": {
|
||||
"name": "Toggle beep"
|
||||
},
|
||||
"audio_track": {
|
||||
"name": "Audio track"
|
||||
},
|
||||
"back": {
|
||||
"name": "[%key:common::entity::button::back::name%]"
|
||||
},
|
||||
"blue": {
|
||||
"name": "Blue"
|
||||
},
|
||||
"clear": {
|
||||
"name": "Clear"
|
||||
},
|
||||
"diagnose": {
|
||||
"name": "Diagnose"
|
||||
},
|
||||
"disc_menu": {
|
||||
"name": "Disc menu"
|
||||
},
|
||||
"down": {
|
||||
"name": "[%key:common::entity::button::down::name%]"
|
||||
},
|
||||
@@ -83,6 +109,12 @@
|
||||
"exit": {
|
||||
"name": "[%key:common::entity::button::exit::name%]"
|
||||
},
|
||||
"fast_forward": {
|
||||
"name": "Fast forward"
|
||||
},
|
||||
"green": {
|
||||
"name": "Green"
|
||||
},
|
||||
"guide": {
|
||||
"name": "[%key:common::entity::button::guide::name%]"
|
||||
},
|
||||
@@ -152,6 +184,12 @@
|
||||
"ok": {
|
||||
"name": "[%key:common::entity::button::ok::name%]"
|
||||
},
|
||||
"open_close": {
|
||||
"name": "Open/close"
|
||||
},
|
||||
"optical_tv_sound": {
|
||||
"name": "Optical/TV sound"
|
||||
},
|
||||
"power": {
|
||||
"name": "[%key:common::entity::button::power::name%]"
|
||||
},
|
||||
@@ -161,12 +199,39 @@
|
||||
"power_on": {
|
||||
"name": "[%key:common::entity::button::power_on::name%]"
|
||||
},
|
||||
"record": {
|
||||
"name": "Record"
|
||||
},
|
||||
"red": {
|
||||
"name": "Red"
|
||||
},
|
||||
"repeat": {
|
||||
"name": "Repeat"
|
||||
},
|
||||
"rewind": {
|
||||
"name": "Rewind"
|
||||
},
|
||||
"right": {
|
||||
"name": "[%key:common::entity::button::right::name%]"
|
||||
},
|
||||
"sleep": {
|
||||
"name": "Sleep"
|
||||
},
|
||||
"sound_effect": {
|
||||
"name": "Sound effect"
|
||||
},
|
||||
"speaker_level": {
|
||||
"name": "Speaker level"
|
||||
},
|
||||
"subtitle": {
|
||||
"name": "Subtitle"
|
||||
},
|
||||
"swing_v_toggle": {
|
||||
"name": "Toggle vertical swing"
|
||||
},
|
||||
"title_popup": {
|
||||
"name": "Title/popup"
|
||||
},
|
||||
"up": {
|
||||
"name": "[%key:common::entity::button::up::name%]"
|
||||
},
|
||||
@@ -175,6 +240,9 @@
|
||||
},
|
||||
"wifi": {
|
||||
"name": "Start Wi-Fi pairing"
|
||||
},
|
||||
"yellow": {
|
||||
"name": "Yellow"
|
||||
}
|
||||
},
|
||||
"climate": {
|
||||
|
||||
@@ -45,9 +45,9 @@ def hvac_modes() -> list[HVACMode]:
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def has_receiver() -> bool:
|
||||
def has_receiver(device_type: LGDeviceType) -> bool:
|
||||
"""Return whether the config entry has an infrared receiver configured."""
|
||||
return True
|
||||
return device_type != LGDeviceType.HOME_THEATER
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -58,6 +58,7 @@ def extra_entry_data(
|
||||
return {
|
||||
LGDeviceType.TV: {},
|
||||
LGDeviceType.AC: {CONF_HVAC_MODES: hvac_modes},
|
||||
LGDeviceType.HOME_THEATER: {},
|
||||
}[device_type]
|
||||
|
||||
|
||||
@@ -106,6 +107,21 @@ def mock_lg_tv_code_to_command() -> Generator[None]:
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_lg_home_theater_code_to_command() -> Generator[None]:
|
||||
"""Patch LGHomeTheaterCode.to_command to return the LGHomeTheaterCode directly.
|
||||
|
||||
This allows tests to assert on the high-level code enum value
|
||||
rather than the raw timings.
|
||||
"""
|
||||
with patch(
|
||||
"infrared_protocols.codes.lg.home_theater.LGHomeTheaterCode.to_command",
|
||||
autospec=True,
|
||||
side_effect=lambda self, **kwargs: self,
|
||||
):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def init_integration(
|
||||
hass: HomeAssistant,
|
||||
@@ -113,6 +129,7 @@ async def init_integration(
|
||||
mock_infrared_emitter_entity: MockInfraredEmitterEntity,
|
||||
mock_infrared_receiver_entity: MockInfraredReceiverEntity,
|
||||
mock_lg_tv_code_to_command: None,
|
||||
mock_lg_home_theater_code_to_command: None,
|
||||
platforms: list[Platform],
|
||||
) -> MockConfigEntry:
|
||||
"""Set up the LG Infrared integration for testing."""
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,59 @@
|
||||
# serializer version: 1
|
||||
# name: test_entities[media_player.lg_tv-entry]
|
||||
# name: test_entities[home_theater][media_player.lg_home_theater-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': list([
|
||||
None,
|
||||
]),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': None,
|
||||
'device_class': None,
|
||||
'device_id': <DeviceEntry identifiers=[('lg_infrared', '01JTEST0000000000000000000')]>,
|
||||
'disabled_by': None,
|
||||
'domain': 'media_player',
|
||||
'entity_category': None,
|
||||
'entity_id': 'media_player.lg_home_theater',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'object_id_base': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <MediaPlayerDeviceClass.RECEIVER: 'receiver'>,
|
||||
'original_icon': None,
|
||||
'original_name': None,
|
||||
'platform': 'lg_infrared',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': <MediaPlayerEntityFeature: 21945>,
|
||||
'translation_key': None,
|
||||
'unique_id': '01JTEST0000000000000000000_media_player',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_entities[home_theater][media_player.lg_home_theater-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
<EntityStateAttribute.ASSUMED_STATE: 'assumed_state'>: True,
|
||||
<EntityStateAttribute.DEVICE_CLASS: 'device_class'>: 'receiver',
|
||||
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'LG Home Theater',
|
||||
<EntityStateAttribute.SUPPORTED_FEATURES: 'supported_features'>: <MediaPlayerEntityFeature: 21945>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'media_player.lg_home_theater',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_entities[tv][media_player.lg_tv-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': list([
|
||||
None,
|
||||
@@ -37,7 +91,7 @@
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_entities[media_player.lg_tv-state]
|
||||
# name: test_entities[tv][media_player.lg_tv-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
<EntityStateAttribute.ASSUMED_STATE: 'assumed_state'>: True,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""Tests for the LG Infrared button platform."""
|
||||
|
||||
from infrared_protocols.codes.lg.ac import LGACCode
|
||||
from infrared_protocols.codes.lg.home_theater import LGHomeTheaterCode
|
||||
from infrared_protocols.codes.lg.tv import LGTVCode
|
||||
import pytest
|
||||
from pytest_homeassistant.common import MockConfigEntry, snapshot_platform
|
||||
@@ -24,7 +25,9 @@ def platforms() -> list[Platform]:
|
||||
return [Platform.BUTTON]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("device_type", [LGDeviceType.TV, LGDeviceType.AC])
|
||||
@pytest.mark.parametrize(
|
||||
"device_type", [LGDeviceType.TV, LGDeviceType.AC, LGDeviceType.HOME_THEATER]
|
||||
)
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default", "init_integration")
|
||||
async def test_entities(
|
||||
hass: HomeAssistant,
|
||||
@@ -161,3 +164,82 @@ async def test_ac_buttons_disabled_by_default(
|
||||
entry = entity_registry.async_get(entity_id)
|
||||
assert entry is not None
|
||||
assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
|
||||
|
||||
|
||||
@pytest.mark.parametrize("device_type", [LGDeviceType.HOME_THEATER])
|
||||
@pytest.mark.parametrize(
|
||||
("entity_id", "expected_code"),
|
||||
[
|
||||
("button.lg_home_theater_power", LGHomeTheaterCode.POWER),
|
||||
("button.lg_home_theater_home", LGHomeTheaterCode.HOME),
|
||||
("button.lg_home_theater_input", LGHomeTheaterCode.FUNCTION),
|
||||
("button.lg_home_theater_info", LGHomeTheaterCode.INFO_MENU),
|
||||
("button.lg_home_theater_disc_menu", LGHomeTheaterCode.DISC_MENU),
|
||||
("button.lg_home_theater_title_popup", LGHomeTheaterCode.TITLE_POPUP),
|
||||
("button.lg_home_theater_up", LGHomeTheaterCode.NAV_UP),
|
||||
("button.lg_home_theater_down", LGHomeTheaterCode.NAV_DOWN),
|
||||
("button.lg_home_theater_left", LGHomeTheaterCode.NAV_LEFT),
|
||||
("button.lg_home_theater_right", LGHomeTheaterCode.NAV_RIGHT),
|
||||
("button.lg_home_theater_ok", LGHomeTheaterCode.OK),
|
||||
("button.lg_home_theater_back", LGHomeTheaterCode.BACK),
|
||||
("button.lg_home_theater_clear", LGHomeTheaterCode.CLEAR),
|
||||
("button.lg_home_theater_number_0", LGHomeTheaterCode.NUM_0),
|
||||
("button.lg_home_theater_number_1", LGHomeTheaterCode.NUM_1),
|
||||
("button.lg_home_theater_number_2", LGHomeTheaterCode.NUM_2),
|
||||
("button.lg_home_theater_number_3", LGHomeTheaterCode.NUM_3),
|
||||
("button.lg_home_theater_number_4", LGHomeTheaterCode.NUM_4),
|
||||
("button.lg_home_theater_number_5", LGHomeTheaterCode.NUM_5),
|
||||
("button.lg_home_theater_number_6", LGHomeTheaterCode.NUM_6),
|
||||
("button.lg_home_theater_number_7", LGHomeTheaterCode.NUM_7),
|
||||
("button.lg_home_theater_number_8", LGHomeTheaterCode.NUM_8),
|
||||
("button.lg_home_theater_number_9", LGHomeTheaterCode.NUM_9),
|
||||
("button.lg_home_theater_asterisk", LGHomeTheaterCode.ASTERISK),
|
||||
("button.lg_home_theater_open_close", LGHomeTheaterCode.OPEN_CLOSE),
|
||||
(
|
||||
"button.lg_home_theater_optical_tv_sound",
|
||||
LGHomeTheaterCode.OPTICAL_TV_SOUND,
|
||||
),
|
||||
("button.lg_home_theater_sound_effect", LGHomeTheaterCode.SOUND_EFFECT),
|
||||
("button.lg_home_theater_speaker_level", LGHomeTheaterCode.SPEAKER_LEVEL),
|
||||
("button.lg_home_theater_audio_track", LGHomeTheaterCode.AUDIO),
|
||||
("button.lg_home_theater_subtitle", LGHomeTheaterCode.SUBTITLE),
|
||||
("button.lg_home_theater_sleep", LGHomeTheaterCode.SLEEP),
|
||||
("button.lg_home_theater_record", LGHomeTheaterCode.RECORD),
|
||||
("button.lg_home_theater_repeat", LGHomeTheaterCode.REPEAT),
|
||||
("button.lg_home_theater_rewind", LGHomeTheaterCode.SCAN_BACKWARD),
|
||||
("button.lg_home_theater_fast_forward", LGHomeTheaterCode.SCAN_FORWARD),
|
||||
("button.lg_home_theater_red", LGHomeTheaterCode.RED),
|
||||
("button.lg_home_theater_green", LGHomeTheaterCode.GREEN),
|
||||
("button.lg_home_theater_yellow", LGHomeTheaterCode.YELLOW),
|
||||
("button.lg_home_theater_blue", LGHomeTheaterCode.BLUE),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("init_integration")
|
||||
async def test_home_theater_button_press_sends_correct_code(
|
||||
hass: HomeAssistant,
|
||||
mock_infrared_emitter_entity: MockInfraredEmitterEntity,
|
||||
entity_id: str,
|
||||
expected_code: LGHomeTheaterCode,
|
||||
) -> None:
|
||||
"""Test pressing a Home Theater button sends the correct IR code."""
|
||||
await hass.services.async_call(
|
||||
BUTTON_DOMAIN,
|
||||
SERVICE_PRESS,
|
||||
{ATTR_ENTITY_ID: entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert len(mock_infrared_emitter_entity.send_command_calls) == 1
|
||||
assert mock_infrared_emitter_entity.send_command_calls[0] == expected_code
|
||||
|
||||
|
||||
@pytest.mark.parametrize("device_type", [LGDeviceType.HOME_THEATER])
|
||||
@pytest.mark.usefixtures("init_integration")
|
||||
async def test_home_theater_button_availability_follows_ir_entity(
|
||||
hass: HomeAssistant,
|
||||
) -> None:
|
||||
"""Test Home Theater button becomes unavailable when IR entity is unavailable."""
|
||||
entity_id = "button.lg_home_theater_power"
|
||||
await assert_availability_follows_source_entity(
|
||||
hass, entity_id, [EMITTER_ENTITY_ID]
|
||||
)
|
||||
|
||||
@@ -170,8 +170,10 @@ async def test_user_flow_no_emitters_receivers(hass: HomeAssistant) -> None:
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_infrared_receiver_entity")
|
||||
async def test_user_flow_menu_hides_ac_without_emitter(hass: HomeAssistant) -> None:
|
||||
"""Test the AC option is hidden when only a receiver is available."""
|
||||
async def test_user_flow_menu_hides_ac_and_home_theater_without_emitter(
|
||||
hass: HomeAssistant,
|
||||
) -> None:
|
||||
"""Test the AC and Home Theater options are hidden when only a receiver is available."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
@@ -299,6 +301,78 @@ async def test_user_flow_ac_already_configured(
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_infrared_emitter_entity")
|
||||
async def test_user_flow_home_theater_success(hass: HomeAssistant) -> None:
|
||||
"""Test successful Home Theater config flow."""
|
||||
result = await _async_start_flow(hass, LGDeviceType.HOME_THEATER)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "home_theater"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={CONF_INFRARED_ENTITY_ID: mock_infrared_emitter_entity_id},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == "LG Home Theater via Test IR emitter"
|
||||
assert result["data"] == {
|
||||
CONF_DEVICE_TYPE: LGDeviceType.HOME_THEATER,
|
||||
CONF_INFRARED_ENTITY_ID: mock_infrared_emitter_entity_id,
|
||||
}
|
||||
assert result["result"].unique_id is None
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_infrared_emitter_entity")
|
||||
@pytest.mark.parametrize(
|
||||
("entity_name", "expected_title"),
|
||||
[
|
||||
pytest.param(None, "LG Home Theater via Test IR emitter", id="original_name"),
|
||||
pytest.param(
|
||||
"HT IR emitter",
|
||||
"LG Home Theater via HT IR emitter",
|
||||
id="custom_name",
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_user_flow_home_theater_title_from_entity_name(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
entity_name: str | None,
|
||||
expected_title: str,
|
||||
) -> None:
|
||||
"""Test Home Theater config entry title uses the entity name."""
|
||||
entity_registry.async_update_entity(
|
||||
mock_infrared_emitter_entity_id, name=entity_name
|
||||
)
|
||||
|
||||
result = await _async_start_flow(hass, LGDeviceType.HOME_THEATER)
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={CONF_INFRARED_ENTITY_ID: mock_infrared_emitter_entity_id},
|
||||
)
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == expected_title
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_infrared_emitter_entity")
|
||||
@pytest.mark.parametrize("device_type", [LGDeviceType.HOME_THEATER])
|
||||
async def test_user_flow_home_theater_already_configured(
|
||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test Home Theater flow aborts when emitter is already configured."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
result = await _async_start_flow(hass, LGDeviceType.HOME_THEATER)
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={CONF_INFRARED_ENTITY_ID: mock_infrared_emitter_entity_id},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def mock_second_infrared_entities(
|
||||
hass: HomeAssistant, init_infrared: None
|
||||
@@ -320,6 +394,7 @@ async def mock_second_infrared_entities(
|
||||
[
|
||||
pytest.param(LGDeviceType.TV, None, id="tv"),
|
||||
pytest.param(LGDeviceType.AC, [HVACMode.COOL, HVACMode.DRY], id="ac"),
|
||||
pytest.param(LGDeviceType.HOME_THEATER, None, id="home_theater"),
|
||||
],
|
||||
)
|
||||
async def test_reconfigure_flow_suggests_current_values(
|
||||
@@ -339,10 +414,11 @@ async def test_reconfigure_flow_suggests_current_values(
|
||||
get_schema_suggested_value(schema, CONF_INFRARED_ENTITY_ID)
|
||||
== mock_infrared_emitter_entity_id
|
||||
)
|
||||
assert (
|
||||
get_schema_suggested_value(schema, CONF_INFRARED_RECEIVER_ENTITY_ID)
|
||||
== mock_infrared_receiver_entity_id
|
||||
)
|
||||
if mock_config_entry.data.get(CONF_INFRARED_RECEIVER_ENTITY_ID):
|
||||
assert (
|
||||
get_schema_suggested_value(schema, CONF_INFRARED_RECEIVER_ENTITY_ID)
|
||||
== mock_infrared_receiver_entity_id
|
||||
)
|
||||
assert get_schema_suggested_value(schema, CONF_HVAC_MODES) == expected_hvac_modes
|
||||
|
||||
|
||||
@@ -384,6 +460,12 @@ async def test_reconfigure_flow_suggests_current_values(
|
||||
},
|
||||
id="ac_change_emitter_remove_receiver",
|
||||
),
|
||||
pytest.param(
|
||||
LGDeviceType.HOME_THEATER,
|
||||
False,
|
||||
{CONF_INFRARED_ENTITY_ID: SECOND_EMITTER_ENTITY_ID},
|
||||
id="home_theater_change_emitter",
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_reconfigure_flow(
|
||||
@@ -500,11 +582,11 @@ async def test_reconfigure_flow_tv_no_infrared_entities(
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_infrared_receiver_entity")
|
||||
@pytest.mark.parametrize("device_type", [LGDeviceType.AC])
|
||||
async def test_reconfigure_flow_ac_no_infrared_emitters(
|
||||
@pytest.mark.parametrize("device_type", [LGDeviceType.AC, LGDeviceType.HOME_THEATER])
|
||||
async def test_reconfigure_flow_no_infrared_emitters(
|
||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test reconfiguring an AC aborts when only a receiver exists."""
|
||||
"""Test reconfiguring an AC or Home Theater aborts when only a receiver exists."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
result = await mock_config_entry.start_reconfigure_flow(hass)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"""Tests for the LG Infrared media player platform."""
|
||||
|
||||
from infrared_protocols.codes.lg.home_theater import LGHomeTheaterCode
|
||||
from infrared_protocols.codes.lg.tv import LGTVCode
|
||||
import pytest
|
||||
from pytest_homeassistant.common import MockConfigEntry, snapshot_platform
|
||||
@@ -10,6 +11,7 @@ from pytest_homeassistant.components.infrared import EMITTER_ENTITY_ID
|
||||
from pytest_homeassistant.components.infrared.common import MockInfraredEmitterEntity
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.lg_infrared.const import LGDeviceType
|
||||
from homeassistant.components.media_player import (
|
||||
DOMAIN as MEDIA_PLAYER_DOMAIN,
|
||||
SERVICE_MEDIA_NEXT_TRACK,
|
||||
@@ -28,6 +30,7 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
MEDIA_PLAYER_ENTITY_ID = "media_player.lg_tv"
|
||||
HOME_THEATER_MEDIA_PLAYER_ENTITY_ID = "media_player.lg_home_theater"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -36,6 +39,7 @@ def platforms() -> list[Platform]:
|
||||
return [Platform.MEDIA_PLAYER]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("device_type", [LGDeviceType.TV, LGDeviceType.HOME_THEATER])
|
||||
@pytest.mark.usefixtures("init_integration")
|
||||
async def test_entities(
|
||||
hass: HomeAssistant,
|
||||
@@ -102,3 +106,50 @@ async def test_media_player_availability_follows_ir_entity(
|
||||
await assert_availability_follows_source_entity(
|
||||
hass, MEDIA_PLAYER_ENTITY_ID, [EMITTER_ENTITY_ID]
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("device_type", [LGDeviceType.HOME_THEATER])
|
||||
@pytest.mark.parametrize(
|
||||
("service", "service_data", "expected_code"),
|
||||
[
|
||||
(SERVICE_TURN_ON, {}, LGHomeTheaterCode.POWER),
|
||||
(SERVICE_TURN_OFF, {}, LGHomeTheaterCode.POWER),
|
||||
(SERVICE_VOLUME_UP, {}, LGHomeTheaterCode.VOLUME_UP),
|
||||
(SERVICE_VOLUME_DOWN, {}, LGHomeTheaterCode.VOLUME_DOWN),
|
||||
(SERVICE_VOLUME_MUTE, {"is_volume_muted": True}, LGHomeTheaterCode.MUTE),
|
||||
(SERVICE_MEDIA_NEXT_TRACK, {}, LGHomeTheaterCode.SKIP_FORWARD),
|
||||
(SERVICE_MEDIA_PREVIOUS_TRACK, {}, LGHomeTheaterCode.SKIP_BACKWARD),
|
||||
(SERVICE_MEDIA_PLAY, {}, LGHomeTheaterCode.PLAY),
|
||||
(SERVICE_MEDIA_PAUSE, {}, LGHomeTheaterCode.PAUSE),
|
||||
(SERVICE_MEDIA_STOP, {}, LGHomeTheaterCode.STOP),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("init_integration")
|
||||
async def test_home_theater_media_player_action_sends_correct_code(
|
||||
hass: HomeAssistant,
|
||||
mock_infrared_emitter_entity: MockInfraredEmitterEntity,
|
||||
service: str,
|
||||
service_data: dict[str, bool],
|
||||
expected_code: LGHomeTheaterCode,
|
||||
) -> None:
|
||||
"""Test each home theater media player action sends the correct IR code."""
|
||||
await hass.services.async_call(
|
||||
MEDIA_PLAYER_DOMAIN,
|
||||
service,
|
||||
{ATTR_ENTITY_ID: HOME_THEATER_MEDIA_PLAYER_ENTITY_ID, **service_data},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert len(mock_infrared_emitter_entity.send_command_calls) == 1
|
||||
assert mock_infrared_emitter_entity.send_command_calls[0] == expected_code
|
||||
|
||||
|
||||
@pytest.mark.parametrize("device_type", [LGDeviceType.HOME_THEATER])
|
||||
@pytest.mark.usefixtures("init_integration")
|
||||
async def test_home_theater_media_player_availability_follows_ir_entity(
|
||||
hass: HomeAssistant,
|
||||
) -> None:
|
||||
"""Test home theater media player becomes unavailable when IR entity is unavailable."""
|
||||
await assert_availability_follows_source_entity(
|
||||
hass, HOME_THEATER_MEDIA_PLAYER_ENTITY_ID, [EMITTER_ENTITY_ID]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user