Fix LG webOS TV turn off when device is already off (#137675)

This commit is contained in:
Shay Levy 2025-02-07 16:25:09 +02:00 committed by Franck Nijhof
parent 657e3488ba
commit e3d649d349
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
2 changed files with 12 additions and 1 deletions

View File

@ -125,7 +125,7 @@ def cmd[_R, **_P](
self: LgWebOSMediaPlayerEntity, *args: _P.args, **kwargs: _P.kwargs
) -> _R:
"""Wrap all command methods."""
if self.state is MediaPlayerState.OFF:
if self.state is MediaPlayerState.OFF and func.__name__ != "async_turn_off":
raise HomeAssistantError(
translation_domain=DOMAIN,
translation_key="device_off",

View File

@ -553,6 +553,17 @@ async def test_control_error_handling(
assert client.play.call_count == int(is_on)
async def test_turn_off_when_device_is_off(hass: HomeAssistant, client) -> None:
"""Test no error when turning off device that is already off."""
await setup_webostv(hass)
client.is_on = False
await client.mock_state_update()
data = {ATTR_ENTITY_ID: ENTITY_ID}
await hass.services.async_call(MP_DOMAIN, SERVICE_TURN_OFF, data, True)
assert client.power_off.call_count == 1
async def test_supported_features(hass: HomeAssistant, client) -> None:
"""Test test supported features."""
client.sound_output = "lineout"