From 6422ed2923bf6eaaa2270c02cc5c084486e95270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Maria=20Semprini?= Date: Thu, 20 Mar 2025 22:08:03 +0000 Subject: [PATCH] Fix creating component index docs with clearer examples (#2610) * clearer-examples-creating-component-index: change examples with the correct core path * clearer-examples-creating-component-index: use tip box * clearer-examples-creating-component-index: nits from code rabbit * link to manifest doc Co-authored-by: Martin Hjelmare * clearer-examples-creating-component-index: move link to "manifest file" --------- Co-authored-by: Martin Hjelmare --- docs/creating_component_index.md | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/docs/creating_component_index.md b/docs/creating_component_index.md index 37a0dfcb..3696a234 100644 --- a/docs/creating_component_index.md +++ b/docs/creating_component_index.md @@ -10,9 +10,17 @@ python3 -m script.scaffold integration This will set you up with everything that you need to build an integration that is able to be set up via the user interface. More extensive examples of integrations are available from [our example repository](https://github.com/home-assistant/example-custom-config/tree/master/custom_components/). +:::tip +This example repository shows custom integrations that live in the `/custom_components` directory. These MUST have a `version` key in their [manifest file](/docs/creating_integration_manifest/#version). Core integrations live in the `homeassistant/components` directory, and do not need a `version` key. The architecture is the same in both cases. +::: + ## The minimum -The scaffold integration contains a bit more than just the bare minimum. The minimum is that you define a `DOMAIN` constant that contains the domain of the integration. The second part is that it needs to define a setup method that returns a boolean if the set up was successful. +The scaffold integration contains a bit more than just the bare minimum. The minimum is that you define a `DOMAIN` constant that contains the domain of the integration. The second part is that it needs to define a setup method that returns a boolean if the set-up was successful. + +Create a file `homeassistant/components/hello_state/__init__.py` with one of the two following codeblocks, depending on what you need: + +- Sync component: ```python DOMAIN = "hello_state" @@ -25,7 +33,7 @@ def setup(hass, config): return True ``` -And if you prefer an async component: +- And if you prefer an async component: ```python DOMAIN = "hello_state" @@ -37,14 +45,13 @@ async def async_setup(hass, config): # Return boolean to indicate that initialization was successful. return True ``` -Create a file `/custom_components/hello_state/__init__.py` with one of the two codeblocks. -In addition a manifest file is required with below keys as the bare minimum. Create `/custom_components/hello_state/manifest.json`. + +In addition, a manifest file is required with the following keys as the bare minimum. Create `homeassistant/components/hello_state/manifest.json`. ```json { "domain": "hello_state", - "name": "Hello, state!", - "version": "0.1.0" + "name": "Hello, state!" } ```