Add scaffold intro (#318)

This commit is contained in:
Paulus Schoutsen 2019-09-21 22:17:22 -07:00 committed by GitHub
parent 6dd30a0929
commit 3a98667e1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 10 deletions

View File

@ -1,15 +1,18 @@
--- ---
title: "Creating a Minimal Component" title: "Creating your first integration"
sidebar_label: "Minimal Component"
--- ---
Alright, you learned about the [manifest](creating_integration_manifest.md), so it's time to write your first code for your integration. AWESOME. Don't worry, we've tried hard to keep it as easy as possible. Alright, you learned about the [manifest](creating_integration_manifest.md), so it's time to write your first code for your integration. AWESOME. Don't worry, we've tried hard to keep it as easy as possible. From a Home Assistant development environment, type the following and follow the instructions:
More extensive examples of integrations are available from [our example repository](https://github.com/home-assistant/example-custom-config/tree/master/custom_components/). ```python
python3 -m script.scaffold
```
## The code 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/).
Each component needs to have 2 basic parts: it needs to 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. So let's take a look at how this looks: ## 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.
```python ```python
DOMAIN = 'hello_state' DOMAIN = 'hello_state'
@ -33,6 +36,8 @@ async def async_setup(hass, config):
return True return True
``` ```
That's it! If you load this, you will see a new state in the state machine.
To load this, add `hello_state:` to your `configuration.yaml` file and create a file `<config_dir>/custom_components/hello_state/__init__.py` with one of the two codeblocks above to test it locally. To load this, add `hello_state:` to your `configuration.yaml` file and create a file `<config_dir>/custom_components/hello_state/__init__.py` with one of the two codeblocks above to test it locally.
## What the scaffold offers
When using the scaffold script, it will go past the bare minimum of an integration. It will include a config flow, tests for the config flow and basic translation infrastructure to provide internationalization for your config flow.

View File

@ -102,8 +102,7 @@
"sidebar_label": "Multiple platforms" "sidebar_label": "Multiple platforms"
}, },
"creating_component_index": { "creating_component_index": {
"title": "Creating a Minimal Component", "title": "Creating your first integration"
"sidebar_label": "Minimal Component"
}, },
"creating_integration_file_structure": { "creating_integration_file_structure": {
"title": "Integration File Structure", "title": "Integration File Structure",