Home Assistant Core
repository·dev·Indexed 13 days ago
https://github.com/home-assistant/coreAn open-source home automation platform running on Python 3. This documentation covers core development, including the Prometheus integration for metrics, TPLink and Z-Wave JS integration guides, and the internal Pylint plugin used to enforce domain-specific coding standards and quality scale compliance for version 2026.9.0.dev0.
What's inside Home Assistant
- The Prometheus integration allows Home Assistant to expose metrics in a format compatible with Prometheus. This enables external monitoring systems to scrape Home Assistant data for observability and alerting.
Understand the Z-Wave JS architecture
devThe Z-Wave integration follows a layered architecture to connect Home Assistant to the physical Z-Wave hardware:
- Z-Wave USB stick: Communicates via radio and handles device pairing.
- Z-Wave JS: Translates the USB stick's serial protocol into device representations.
- Z-Wave JS Server: Forwards the state of Z-Wave JS over a WebSocket connection.
- Z-Wave JS Server Python: Consumes the WebSocket connection to make the state available to Python.
- Z-Wave integration: Represents the devices within Home Assistant for user control.
- Home Assistant: The top-level automation platform.
Avoid redundant information in Entity Unique IDs
devTo prevent duplication in the entity registry, unique IDs should not include the integration's domain or the entity's platform name.
W7425: home-assistant-entity-unique-id-redundant-domain: Do not include the integration's name (frommanifest.json) as a delimited segment in theunique_id. For example, if the domain ismyhub, avoidf"myhub-{device_id}". This applies to_attr_unique_idassignments andunique_idproperty returns.W7427: home-assistant-entity-unique-id-redundant-platform: Do not include the platform name (e.g.,sensor,light) as a delimited segment in theunique_id. This check is scoped to platform modules likesensor.pyorlight/__init__.py.
Avoid non-deterministic execution paths in tests
devUsing
iformatchstatements inside test functions can create non-deterministic execution paths where some branches may never run, hiding failures.To fix
W7409:home-assistant-test-non-deterministic:- Use
@pytest.mark.parametrizeto cover different cases explicitly. - Split the logic into separate test functions.
Exemptions for
ifstatements:- Guard clauses (
return,raise,pytest.skip,pytest.xfail,pytest.fail). - Conditions referencing a function parameter.
- Branches that contain no
assertstatements.
Note:
matchstatements have no exemptions.- Use
Use Home Assistant helpers for current time
devTo maintain consistency and ensure correct time zone handling, use Home Assistant's
dtutility instead of standarddatetimemethods.- For aware local time: Use
homeassistant.util.dt.now()instead ofdatetime.datetime.now(<tz>)when a non-UTC time zone is provided. This returns an awaredatetimein the given time zone (defaulting toDEFAULT_TIME_ZONE). - For naive local time: Use
homeassistant.util.dt.naive_now()instead ofdatetime.datetime.now()(called without a time zone argument). This returns a naivedatetimein system local time. - For UTC: Use the
home-assistant-enforce-utcnowchecker (C7414) fordatetime.now(UTC)cases.
# Instead of: import datetime now = datetime.datetime.now(timezone.utc) # Use: from homeassistant.util import dt now = dt.now()- For aware local time: Use
Prohibition of autonomous agents
devAutonomous agents are not allowed to contribute to OHF projects.
Any pull requests or issues believed to be created autonomously will be closed. Automated comments may be marked as spam. This includes any contribution that bypasses the provided issue or pull request templates.
Use the translation system for HomeAssistantError
devTo support multi-language support,
HomeAssistantErrorand its subclasses must use the translation system instead of hardcoded English strings.Requirements
- Use
translation_domainandtranslation_keyinstead of a positional message argument (W7417). - Do not provide both a positional message and a
translation_key(W7419). - Ensure
translation_keyandtranslation_domainare both provided (E7408). - The referenced key must exist in the integration's
strings.jsonunder theexceptionssection (E7406). - Placeholders passed in code (via
translation_placeholders) must match the{placeholder}slots in thestrings.jsonmessage (E7418).
- Use
Understand Home Assistant Pylint check codes
devThe Home Assistant Pylint plugin uses a specific numbering convention for its automated checks. Every check follows the standard Pylint format
{C,W,E,R}74{00-99}, where74is the base ID for Home Assistant. The prefix indicates the type of issue:C: ConventionW: WarningE: ErrorR: Refactor
Validate MDI icon references
devThe
home_assistant_mdi_iconschecker ensures that Material Design Icon (MDI) references are valid.E7409: home-assistant-mdi-icon-not-found: Triggered when anmdi:icon reference in Python code does not exist in the MDI set.E7410: home-assistant-mdi-icon-json-not-found: Triggered when anmdi:icon reference inicons.jsondoes not exist in the MDI set.
Follow metric naming guidelines for Prometheus
devWhen defining custom metrics for the Prometheus integration, adhere to the following rules to ensure compatibility and consistency:
- Standard Compliance: Metric and label names must follow the official Prometheus naming guidelines.
- Domain Prefixing: For domain-specific metrics, use the domain name (e.g.,
sensor,switch,climate) as a prefix in the metric name. - Handling Enum-like Values: Do not export state strings directly as metric values. Instead, use a "boolean" metric approach where the value is either
0or1, and use the specific state or mode as a metric label.
Enforce logger message conventions with `home_assistant_logger` checker
devThe
home_assistant_loggerchecker ensures consistent formatting for logger messages across the codebase. It enforces two main rules:C7401:home-assistant-logger-periodUser-visible logger messages must not end with a period. Home Assistant follows a convention of avoiding trailing punctuation in log messages.
C7402:home-assistant-logger-capitalLogger messages must start with a capital letter. If a message does not warrant capitalization, it should be downgraded to the
debuglevel.Register services in `async_setup`
devW7414: home-assistant-service-registered-in-setup-entryServices should be registered inasync_setuprather thanasync_setup_entry. This ensures services are available for automation validation even when no specific configuration entry is loaded. This rule also catches registrations inside helper functions called fromasync_setup_entry.