Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion homeassistant/components/hdmi_cec/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from pycec.commands import CecCommand, KeyPressCommand, KeyReleaseCommand
from pycec.const import (
CMD_STANDBY,
KEY_BACKWARD,
KEY_FORWARD,
KEY_MUTE_TOGGLE,
Expand Down Expand Up @@ -93,7 +94,7 @@ async def async_turn_on(self) -> None:

async def async_turn_off(self) -> None:
"""Turn device off."""
self._device.turn_off()
self._device.send_command(CecCommand(CMD_STANDBY, dst=self._logical_address))
self._attr_state = MediaPlayerState.OFF
Comment thread
pattyland marked this conversation as resolved.
self.async_write_ha_state()

Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/hdmi_cec/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import logging
from typing import Any

from pycec.const import POWER_OFF, POWER_ON
from pycec.commands import CecCommand
from pycec.const import CMD_STANDBY, POWER_OFF, POWER_ON

from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN, SwitchEntity
from homeassistant.core import HomeAssistant
Expand Down Expand Up @@ -50,7 +51,7 @@ async def async_turn_on(self, **kwargs: Any) -> None:

async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn device off."""
self._device.turn_off()
self._device.send_command(CecCommand(CMD_STANDBY, dst=self._logical_address))
self._attr_is_on = False
Comment thread
pattyland marked this conversation as resolved.
self.async_write_ha_state()

Expand Down
15 changes: 14 additions & 1 deletion tests/components/hdmi_cec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

from unittest.mock import AsyncMock, Mock

from homeassistant.components.hdmi_cec import KeyPressCommand, KeyReleaseCommand
from homeassistant.components.hdmi_cec import (
CecCommand,
KeyPressCommand,
KeyReleaseCommand,
)


class MockHDMIDevice:
Expand Down Expand Up @@ -49,3 +53,12 @@ def assert_key_press_release(fnc, count=0, *, dst, key):
assert press_arg.dst == dst
assert isinstance(release_arg, KeyReleaseCommand)
assert release_arg.dst == dst


def assert_cec_command(fnc, *, cmd, dst):
"""Assert that correct CecCommand was sent."""
fnc.assert_called_once()
command = fnc.call_args.args[0]
assert isinstance(command, CecCommand)
assert command.cmd == cmd
assert command.dst == dst
10 changes: 8 additions & 2 deletions tests/components/hdmi_cec/test_media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Any

from pycec.const import (
CMD_STANDBY,
DEVICE_TYPE_NAMES,
KEY_BACKWARD,
KEY_FORWARD,
Expand Down Expand Up @@ -54,7 +55,7 @@
)
from homeassistant.core import HomeAssistant

from . import MockHDMIDevice, assert_key_press_release
from . import MockHDMIDevice, assert_cec_command, assert_key_press_release
from .conftest import CecEntityCreator, HDMINetworkCreator


Expand Down Expand Up @@ -148,7 +149,12 @@ async def test_service_off(
blocking=True,
)

mock_hdmi_device.turn_off.assert_called_once_with()
mock_hdmi_device.turn_off.assert_not_called()
assert_cec_command(
mock_hdmi_device.send_command,
cmd=CMD_STANDBY,
dst=mock_hdmi_device.logical_address,
)

state = hass.states.get("media_player.hdmi_3")
assert state.state == STATE_OFF
Expand Down
18 changes: 15 additions & 3 deletions tests/components/hdmi_cec/test_switch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
"""Tests for the HDMI-CEC switch platform."""

from pycec.const import POWER_OFF, POWER_ON, STATUS_PLAY, STATUS_STILL, STATUS_STOP
from pycec.const import (
CMD_STANDBY,
POWER_OFF,
POWER_ON,
STATUS_PLAY,
STATUS_STILL,
STATUS_STOP,
)
from pycec.network import PhysicalAddress
import pytest

Expand All @@ -16,7 +23,7 @@
)
from homeassistant.core import HomeAssistant

from . import MockHDMIDevice
from . import MockHDMIDevice, assert_cec_command
from .conftest import CecEntityCreator, HDMINetworkCreator


Expand Down Expand Up @@ -107,7 +114,12 @@ async def test_service_off(
blocking=True,
)

mock_hdmi_device.turn_off.assert_called_once_with()
mock_hdmi_device.turn_off.assert_not_called()
assert_cec_command(
mock_hdmi_device.send_command,
cmd=CMD_STANDBY,
dst=mock_hdmi_device.logical_address,
)

state = hass.states.get("switch.hdmi_3")
assert state.state == STATE_OFF
Expand Down
Loading