Conversation
5f4c9cc to
877df77
Compare
There was a problem hiding this comment.
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
infraredentity 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 |
| @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") |
There was a problem hiding this comment.
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).
| _attr_has_entity_name = True | ||
| _attr_name = "Test IR transmitter" |
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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):.
|
|
||
| async def async_send_command( | ||
| hass: HomeAssistant, | ||
| entity_uuid: str, |
There was a problem hiding this comment.
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.
Proposed change
Adds the new
infraredentity integration, as approved in home-assistant/architecture#1316PR with the implementation of the
infraredplatform in ESPHome: #162346PR with using the
infraredintegration in a newlg_infraredintegration: #162359Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: