Skip to content

Add infrared entity integration#162251

Open
abmantis wants to merge 1 commit intodevfrom
infrared
Open

Add infrared entity integration#162251
abmantis wants to merge 1 commit intodevfrom
infrared

Conversation

@abmantis
Copy link
Member

@abmantis abmantis commented Feb 4, 2026

Proposed change

Adds the new infrared entity integration, as approved in home-assistant/architecture#1316

PR with the implementation of the infrared platform in ESPHome: #162346
PR with using the infrared integration in a new lg_infrared integration: #162359

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

@abmantis abmantis marked this pull request as ready for review February 5, 2026 22:41
Copilot AI review requested due to automatic review settings February 5, 2026 22:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request introduces a new infrared entity integration to Home Assistant, providing a foundation for integrations that control infrared transmitters. The integration follows Home Assistant's entity platform pattern and is designed to be used by other integrations (like ESPHome and LG Infrared) that need to send IR commands.

Changes:

  • Added new infrared entity platform with base classes and helper functions for IR command transmission
  • Implemented NEC IR protocol support with standard and extended address formats
  • Added comprehensive test coverage including protocol tests and entity state management tests

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
homeassistant/components/infrared/__init__.py Core integration module with InfraredEntity base class, async_send_command helper, and component setup functions
homeassistant/components/infrared/protocols.py IR protocol definitions including base InfraredCommand class and NECInfraredCommand implementation
homeassistant/components/infrared/const.py Domain constant definition
homeassistant/components/infrared/manifest.json Integration metadata with entity type and internal quality scale
homeassistant/components/infrared/icons.json Default icon configuration for infrared entities
homeassistant/components/infrared/strings.json Translatable error messages
tests/components/infrared/test_init.py Comprehensive tests for entity setup, command sending, error handling, and state restoration
tests/components/infrared/test_protocols.py Tests for NEC protocol implementation with standard and extended addressing
tests/components/infrared/conftest.py Test fixtures including MockInfraredEntity and integration setup
homeassistant/generated/entity_platforms.py Added INFRARED to entity platform enum
mypy.ini Added strict type checking configuration for infrared component
.strict-typing Added infrared component to strict typing list
CODEOWNERS Added code ownership entries for infrared component

Comment on lines +121 to +127
@property
@final
def state(self) -> str | None:
"""Return the entity state."""
if (last_command := self.__last_command_sent) is None:
return None
return last_command.isoformat(timespec="milliseconds")
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The state property should use @cached_property decorator and a helper method to invalidate the cache when updating state, similar to button and notify entities. Without @cached_property, the state is computed on every access, which is unnecessary. Add from propcache.api import cached_property and update the implementation to match the pattern used in button/init.py (lines 112-122) and notify/init.py (lines 139-149).

Copilot uses AI. Check for mistakes.
Comment on lines +21 to +22
_attr_has_entity_name = True
_attr_name = "Test IR transmitter"
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MockInfraredEntity sets _attr_name which should not be used according to Home Assistant guidelines when _attr_has_entity_name is True. When has_entity_name is True, the name should come from the device name, and _attr_name should represent a specific field (like "temperature"). For a mock entity without a device, set _attr_name = None to represent the device itself, or remove _attr_has_entity_name = True.

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +143 to +145
state = await self.async_get_last_state()
if state is not None and state.state is not None:
self.__last_command_sent = dt_util.parse_datetime(state.state)
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The async_internal_added_to_hass method should check for STATE_UNAVAILABLE when restoring state, similar to button (line 138) and notify (line 155) entities. Currently it only checks if state.state is not None, but it should also exclude STATE_UNAVAILABLE. Import STATE_UNAVAILABLE from homeassistant.const and add the check: if state is not None and state.state not in (STATE_UNAVAILABLE, None):.

Copilot uses AI. Check for mistakes.

async def async_send_command(
hass: HomeAssistant,
entity_uuid: str,
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter name entity_uuid is misleading because the function accepts either an entity_id (like "infrared.my_device") or a UUID. The helper function async_validate_entity_id uses the parameter name entity_id_or_uuid to clarify this. Consider renaming to entity_id_or_uuid to match the convention used by the helper function and make it clear that both formats are accepted.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant