1
0
mirror of https://github.com/home-assistant/core.git synced 2026-05-20 15:30:26 +01:00
Files
Abílio Costa b9105db16c Add infrared receiver entity (#169110)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: abmantis <974569+abmantis@users.noreply.github.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-05-13 18:21:46 +01:00

62 lines
2.0 KiB
Python

"""The tests for the kitchen_sink infrared platform."""
from unittest.mock import Mock, patch
from freezegun.api import FrozenDateTimeFactory
from infrared_protocols.commands.nec import NECCommand
import pytest
from homeassistant.components.infrared import (
async_send_command,
async_subscribe_receiver,
)
from homeassistant.components.kitchen_sink import DOMAIN
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from homeassistant.util import dt as dt_util
ENTITY_IR_EMITTER = "infrared.ir_blaster_infrared_emitter"
ENTITY_IR_RECEIVER = "infrared.ir_blaster_infrared_receiver"
@pytest.fixture
async def infrared_only() -> None:
"""Enable only the infrared platform."""
with patch(
"homeassistant.components.kitchen_sink.COMPONENTS_WITH_DEMO_PLATFORM",
[Platform.INFRARED],
):
yield
@pytest.fixture(autouse=True)
async def setup_comp(hass: HomeAssistant, infrared_only: None) -> None:
"""Set up demo component."""
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
await hass.async_block_till_done()
async def test_send_receive(
hass: HomeAssistant, freezer: FrozenDateTimeFactory
) -> None:
"""Test the receiver picks up commands sent by the emitter via dispatcher."""
signal_callback = Mock()
async_subscribe_receiver(hass, ENTITY_IR_RECEIVER, signal_callback)
now = dt_util.parse_datetime("2021-01-09 12:00:00+00:00")
assert now is not None
freezer.move_to(now)
command = NECCommand(address=0x04, command=0x08, modulation=38000)
await async_send_command(hass, ENTITY_IR_EMITTER, command)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_IR_RECEIVER)
assert state
assert state.state == now.isoformat(timespec="milliseconds")
assert signal_callback.call_count == 1
received_signal = signal_callback.call_args[0][0]
assert received_signal.timings == command.get_raw_timings()