From 04390b9357d5a7b6ca88f57c81ea3c036dc73f8d Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Sat, 20 Feb 2016 09:45:42 +0100 Subject: [PATCH 1/6] Add first section of devel tutorial --- source/developers/tutorial.markdown | 117 ++++++++++++++++++ .../images/screenshots/create-component01.png | Bin 0 -> 11155 bytes 2 files changed, 117 insertions(+) create mode 100644 source/developers/tutorial.markdown create mode 100644 source/images/screenshots/create-component01.png diff --git a/source/developers/tutorial.markdown b/source/developers/tutorial.markdown new file mode 100644 index 00000000000..fb149a8b8a3 --- /dev/null +++ b/source/developers/tutorial.markdown @@ -0,0 +1,117 @@ +--- +layout: page +title: "Development tuorial" +description: "Tutorial about the first steps on Home Assistant development" +date: 2016-02-20 07:00 +sidebar: false +comments: false +sharing: true +footer: true +--- + +This is a simple tutorial on how to write a component for [Home Assistant](https://home-assistant.io/). We will work on a component called "information". The purpose of this component is to display a given text in the frontend. + +The setup of a development environment is described in the [Developers section](/developers/#starting-development) of the documentation. + +As a start, create a file `information.py` in your Git checkout of Home Assistant in the folder `homeassistant/component/`. + +```python +""" +homeassistant.components.information +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +The information component allows to show text in the frontend. + +For more details about this component, please refer to the documentation at +https://home-assistant.io/components/information/ +""" +import logging + +_LOGGER = logging.getLogger(__name__) + +DOMAIN = 'information' +DEPENDENCIES = [] + +def setup(hass, config=None): + """ Setup the Information component. """ + + _LOGGER.info("The 'information' component is ready!") + + return True +``` + +1. In the file header we decided to add some details. Like the path, a short description, and the link to the documentation. +2. We want to do some logging. This means that we import the Python logging module and create an alias. +3. The component name is equal to the domain name. +4. At the moment this component has no dependencies. For detail check [dependencies](/developers/creating_components/#dependencies) section. +5. The `setup` function will take care of the initialization of our component. + The component will only write a log message. Keep in mind for later that you have several options for the severity: + + - _LOGGER.info(msg) + - _LOGGER.warning(msg) + - _LOGGER.error(msg) + - _LOGGER.critical(msg) + - _LOGGER.exception(msg) + +7. We return `True` if everything is ok. + +Add the component to your `configuration.yaml` file. + +```yaml +information: +``` + +If you replace `_LOGGER.info("The 'information' component is ready!")` with or add + +```python +hass.states.set('information.Text', 'Info component') +``` + +Then the component will not be different to the sample included in the `config/custom_components` folder or shown as an [example](/cookbook/python_component_basic_state/). After a start or a restart of Home Assistant the component will be visible in the frontend. + +

+ +

+ +The next step is the introduction of configuration options. Most configuration details are coming out of the `configuration.yaml` file. To do that we need to update the `def setup()` method to accept configuration information and access the configuration variable in the `setup` method. + +```python +import logging + +_LOGGER = logging.getLogger(__name__) + +DOMAIN = 'information' +DEPENDENCIES = [] +CONF_NAME = 'text' + +def setup(hass, config): + """ Setup the Information component. """ + + test = config[DOMAIN].get(CONF_NAME, DEFAULT_NAME) + hass.states.set('information.Text', test) + + return True +``` + +To add the latest feature of our component, update the entry in your `configuration.yaml` file. + +```yaml +information: + text: 'Sample text' +``` + +It's important to check if all mandatory configuration variables are provided. If not, the setup should fail. We will use the `validate_config` as a helper to archive this. The next listing shows the essential parts. + +```python +from homeassistant.helpers import validate_config +[...] + if not validate_config(config, {DOMAIN: ['text']}, _LOGGER): + return False +``` + +So far our new component is rendered as a default compoment in the frontend. But we want our own view of the component in the frontend. We assume that you have setup the (frontend development)[/developers/frontend/] already + +We need two new files in the folder `src/cards/`: + +- ha-information-card.html +- ha-information-card.js + diff --git a/source/images/screenshots/create-component01.png b/source/images/screenshots/create-component01.png new file mode 100644 index 0000000000000000000000000000000000000000..74a4fd0cde65d872fb95a24a664f9fb6182ab8a8 GIT binary patch literal 11155 zcmcI~bySpVwD(I0Lyrdq4@is!f`n3ngo1#mfJifxN=Zm}dI%Ln5KuY}NOzZXC?E*Z z-2y{*!?(w~zI*?;|J=3iy6;)%oM9N=dEWi(y??QvcTW^#smK|~5d@)G^iEtZ(Cp9f>#0b(UBk7gMUNEWV(bH&F zoT6x8%dN-C=&{c>c+_U~Y-pzYhzRLSN%T67|My3A?W@c@5h382{NO4 zJfr8ycxebyglmh`@9Ic8L?w3ig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Swd@+4**vWMyPL{1aN!#E8Bun!86%n7f;BoFWk*2n;I#U6{_ojQ1}H ztVuLKLm;>eP+$tFwqQHj*_mG>{!ZYP(tz}$6M9V{@8Q?6v9WdfumrH&V7(XNL834H zoH0b@6&BiBS#`o0vh2QJaY!-aT|XpS&5WM`PFb376l+0>XCH+9`TRrV7V*HqfJw0y zDJdyD0i6$0%y;)U0*q%nJuom3zCt%Q6;7LamBf&kdw{!bY-Tp>hT^q20iSniA3C&F zwptZ8>mdSXItMwvLy$!WsF6=!Ykq=A(xnepiE{_!*R}=7btJhrS+e|3GL(6 z_|OB?liY>O{#`C|f|OW-Tcl~(mF6dlsbo=}@Js!3=xc>18bh@D4&GivnXD{)%y2d^ z6GfbIs>MKvn?tr&?sc3HAbAzK1dn(~BdTh%9^I8kjwtW#3@a*e6Js%LNDSBRXn!u=dc{eS)+eHcGO literal 0 HcmV?d00001 From 3fe9bf754b8e359a626e47d6ada27f4aed672b56 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Sat, 20 Feb 2016 10:50:24 +0100 Subject: [PATCH 2/6] Add more content --- source/developers/tutorial.markdown | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/source/developers/tutorial.markdown b/source/developers/tutorial.markdown index fb149a8b8a3..8dbde843ce5 100644 --- a/source/developers/tutorial.markdown +++ b/source/developers/tutorial.markdown @@ -1,6 +1,6 @@ --- layout: page -title: "Development tuorial" +title: "Development tutorial" description: "Tutorial about the first steps on Home Assistant development" date: 2016-02-20 07:00 sidebar: false @@ -13,6 +13,9 @@ This is a simple tutorial on how to write a component for [Home Assistant](https The setup of a development environment is described in the [Developers section](/developers/#starting-development) of the documentation. +## {% linkable_title Component %} + + As a start, create a file `information.py` in your Git checkout of Home Assistant in the folder `homeassistant/component/`. ```python @@ -66,7 +69,7 @@ If you replace `_LOGGER.info("The 'information' component is ready!")` with or a hass.states.set('information.Text', 'Info component') ``` -Then the component will not be different to the sample included in the `config/custom_components` folder or shown as an [example](/cookbook/python_component_basic_state/). After a start or a restart of Home Assistant the component will be visible in the frontend. +then the component will not be different to the sample included in the `config/custom_components` folder or shown as an [example](/cookbook/python_component_basic_state/). After a start or a restart of Home Assistant the component will be visible in the frontend.

@@ -74,6 +77,8 @@ Then the component will not be different to the sample included in the `config/c The next step is the introduction of configuration options. Most configuration details are coming out of the `configuration.yaml` file. To do that we need to update the `def setup()` method to accept configuration information and access the configuration variable in the `setup` method. +More details about this topic can be found in the [User given configuration](/developers/creating_components/#config-user-given-configuration) section. + ```python import logging @@ -108,10 +113,28 @@ from homeassistant.helpers import validate_config return False ``` -So far our new component is rendered as a default compoment in the frontend. But we want our own view of the component in the frontend. We assume that you have setup the (frontend development)[/developers/frontend/] already +## {% linkable_title Frontend %} + +So far our new component is rendered as a default compoment in the frontend. But we want our own view of the component in the frontend. We assume that you have setup the (frontend development)[/developers/frontend/] already. We need two new files in the folder `src/cards/`: - ha-information-card.html - ha-information-card.js + +TBD + +Rebuild the frontend. + +```bash +$ script/build_frontend +``` + +Change the [http](/components/http/) component to load the `development` version of the frontend as also mentioned in the [ Setting up the environment](/developers/frontend/#setting-up-the-environment) section of the (frontend development)[/developers/frontend/] page. + +```yaml +http: + development: 1 +``` + From 3b0e7e67b9b73ec07479e9b0ef96ef3e0a089d28 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Sat, 20 Feb 2016 09:45:42 +0100 Subject: [PATCH 3/6] Add first section of devel tutorial --- source/developers/tutorial.markdown | 117 ++++++++++++++++++ .../images/screenshots/create-component01.png | Bin 0 -> 11155 bytes 2 files changed, 117 insertions(+) create mode 100644 source/developers/tutorial.markdown create mode 100644 source/images/screenshots/create-component01.png diff --git a/source/developers/tutorial.markdown b/source/developers/tutorial.markdown new file mode 100644 index 00000000000..fb149a8b8a3 --- /dev/null +++ b/source/developers/tutorial.markdown @@ -0,0 +1,117 @@ +--- +layout: page +title: "Development tuorial" +description: "Tutorial about the first steps on Home Assistant development" +date: 2016-02-20 07:00 +sidebar: false +comments: false +sharing: true +footer: true +--- + +This is a simple tutorial on how to write a component for [Home Assistant](https://home-assistant.io/). We will work on a component called "information". The purpose of this component is to display a given text in the frontend. + +The setup of a development environment is described in the [Developers section](/developers/#starting-development) of the documentation. + +As a start, create a file `information.py` in your Git checkout of Home Assistant in the folder `homeassistant/component/`. + +```python +""" +homeassistant.components.information +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +The information component allows to show text in the frontend. + +For more details about this component, please refer to the documentation at +https://home-assistant.io/components/information/ +""" +import logging + +_LOGGER = logging.getLogger(__name__) + +DOMAIN = 'information' +DEPENDENCIES = [] + +def setup(hass, config=None): + """ Setup the Information component. """ + + _LOGGER.info("The 'information' component is ready!") + + return True +``` + +1. In the file header we decided to add some details. Like the path, a short description, and the link to the documentation. +2. We want to do some logging. This means that we import the Python logging module and create an alias. +3. The component name is equal to the domain name. +4. At the moment this component has no dependencies. For detail check [dependencies](/developers/creating_components/#dependencies) section. +5. The `setup` function will take care of the initialization of our component. + The component will only write a log message. Keep in mind for later that you have several options for the severity: + + - _LOGGER.info(msg) + - _LOGGER.warning(msg) + - _LOGGER.error(msg) + - _LOGGER.critical(msg) + - _LOGGER.exception(msg) + +7. We return `True` if everything is ok. + +Add the component to your `configuration.yaml` file. + +```yaml +information: +``` + +If you replace `_LOGGER.info("The 'information' component is ready!")` with or add + +```python +hass.states.set('information.Text', 'Info component') +``` + +Then the component will not be different to the sample included in the `config/custom_components` folder or shown as an [example](/cookbook/python_component_basic_state/). After a start or a restart of Home Assistant the component will be visible in the frontend. + +

+ +

+ +The next step is the introduction of configuration options. Most configuration details are coming out of the `configuration.yaml` file. To do that we need to update the `def setup()` method to accept configuration information and access the configuration variable in the `setup` method. + +```python +import logging + +_LOGGER = logging.getLogger(__name__) + +DOMAIN = 'information' +DEPENDENCIES = [] +CONF_NAME = 'text' + +def setup(hass, config): + """ Setup the Information component. """ + + test = config[DOMAIN].get(CONF_NAME, DEFAULT_NAME) + hass.states.set('information.Text', test) + + return True +``` + +To add the latest feature of our component, update the entry in your `configuration.yaml` file. + +```yaml +information: + text: 'Sample text' +``` + +It's important to check if all mandatory configuration variables are provided. If not, the setup should fail. We will use the `validate_config` as a helper to archive this. The next listing shows the essential parts. + +```python +from homeassistant.helpers import validate_config +[...] + if not validate_config(config, {DOMAIN: ['text']}, _LOGGER): + return False +``` + +So far our new component is rendered as a default compoment in the frontend. But we want our own view of the component in the frontend. We assume that you have setup the (frontend development)[/developers/frontend/] already + +We need two new files in the folder `src/cards/`: + +- ha-information-card.html +- ha-information-card.js + diff --git a/source/images/screenshots/create-component01.png b/source/images/screenshots/create-component01.png new file mode 100644 index 0000000000000000000000000000000000000000..74a4fd0cde65d872fb95a24a664f9fb6182ab8a8 GIT binary patch literal 11155 zcmcI~bySpVwD(I0Lyrdq4@is!f`n3ngo1#mfJifxN=Zm}dI%Ln5KuY}NOzZXC?E*Z z-2y{*!?(w~zI*?;|J=3iy6;)%oM9N=dEWi(y??QvcTW^#smK|~5d@)G^iEtZ(Cp9f>#0b(UBk7gMUNEWV(bH&F zoT6x8%dN-C=&{c>c+_U~Y-pzYhzRLSN%T67|My3A?W@c@5h382{NO4 zJfr8ycxebyglmh`@9Ic8L?w3ig#Zu zSFOwX!0rs$uy`%F6SVK3O%@%AA_RAE#P_ys5eo?fvEZPJxa#$J^pc5#bge$`1xgY& zHZ~d>nmczYjlR*t4NGcG`1^W#&YeH6s-nWL^jP`SFomoZ;$%D5v9q&t1#X{}_M&!d ztQy{+Ii_5{G1vAznNEM{T502Yke7 zwnVT{4hncHqf77X6$03lvr>pHAtBOf?Mm2_3Gqyj@=WY z2Nb;ULjPa9z`#w>_iB)7I!V6pa%3`EU33bzY z>i%D~-XT#@94s-ywthnhB3bKhv$r-`Q6Yk9Ec_|n_RX{3Vzfe4>72BZ!^+6u{d`{v zdWYqq-v0jGUUj|XU&zG01*`BEo_mv|`}*I5F>XgRt=~Uh&eg4YD25cz&AnMS)o1=$-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Kvn?tr&?sc3HAbAzK1dn(~BdTh%9^I8kjwtW#3@a*e6Js%LNDSBRXn!u=dc{eS)+eHcGO literal 0 HcmV?d00001 From 76a3a0ce16ac806b74cf8e9663fc2e515ab1c7a4 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Sat, 20 Feb 2016 10:50:24 +0100 Subject: [PATCH 4/6] Add more content --- source/developers/tutorial.markdown | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/source/developers/tutorial.markdown b/source/developers/tutorial.markdown index fb149a8b8a3..8dbde843ce5 100644 --- a/source/developers/tutorial.markdown +++ b/source/developers/tutorial.markdown @@ -1,6 +1,6 @@ --- layout: page -title: "Development tuorial" +title: "Development tutorial" description: "Tutorial about the first steps on Home Assistant development" date: 2016-02-20 07:00 sidebar: false @@ -13,6 +13,9 @@ This is a simple tutorial on how to write a component for [Home Assistant](https The setup of a development environment is described in the [Developers section](/developers/#starting-development) of the documentation. +## {% linkable_title Component %} + + As a start, create a file `information.py` in your Git checkout of Home Assistant in the folder `homeassistant/component/`. ```python @@ -66,7 +69,7 @@ If you replace `_LOGGER.info("The 'information' component is ready!")` with or a hass.states.set('information.Text', 'Info component') ``` -Then the component will not be different to the sample included in the `config/custom_components` folder or shown as an [example](/cookbook/python_component_basic_state/). After a start or a restart of Home Assistant the component will be visible in the frontend. +then the component will not be different to the sample included in the `config/custom_components` folder or shown as an [example](/cookbook/python_component_basic_state/). After a start or a restart of Home Assistant the component will be visible in the frontend.

@@ -74,6 +77,8 @@ Then the component will not be different to the sample included in the `config/c The next step is the introduction of configuration options. Most configuration details are coming out of the `configuration.yaml` file. To do that we need to update the `def setup()` method to accept configuration information and access the configuration variable in the `setup` method. +More details about this topic can be found in the [User given configuration](/developers/creating_components/#config-user-given-configuration) section. + ```python import logging @@ -108,10 +113,28 @@ from homeassistant.helpers import validate_config return False ``` -So far our new component is rendered as a default compoment in the frontend. But we want our own view of the component in the frontend. We assume that you have setup the (frontend development)[/developers/frontend/] already +## {% linkable_title Frontend %} + +So far our new component is rendered as a default compoment in the frontend. But we want our own view of the component in the frontend. We assume that you have setup the (frontend development)[/developers/frontend/] already. We need two new files in the folder `src/cards/`: - ha-information-card.html - ha-information-card.js + +TBD + +Rebuild the frontend. + +```bash +$ script/build_frontend +``` + +Change the [http](/components/http/) component to load the `development` version of the frontend as also mentioned in the [ Setting up the environment](/developers/frontend/#setting-up-the-environment) section of the (frontend development)[/developers/frontend/] page. + +```yaml +http: + development: 1 +``` + From 662821a2685709fd86a980b9cc15e772a45eed65 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Sat, 12 Mar 2016 14:52:22 +0100 Subject: [PATCH 5/6] Update --- .../images/screenshots/create-component01.png | Bin 11155 -> 12625 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/source/images/screenshots/create-component01.png b/source/images/screenshots/create-component01.png index 74a4fd0cde65d872fb95a24a664f9fb6182ab8a8..3bc3b34984aa8b355d5803d26246a53127ba9d42 100644 GIT binary patch literal 12625 zcmdUWXH-<#)@`Y+whPG*Qv8y=Y}&VPI*Cmn70fYlG{y2Ks;4o7fuvAw`x|(C0PSOd|b3B40YM;?O?U z<*2RF_pNGj;?R{l`!4-f$#}l6I4UMNDXB|Px{2H3R8aOzeu!Po@SU;z2_GIq(`_au z>a=Q=Mr}&<#=1*_`+{mW{ucC(ow0 zQT=vvp@4)m13XgDVV_E+=z+8Zlj@U?lrBEIevn`G+5V0App0rQPhLl%rp+;r9`?^Y z#ezN2=3q&QQ?Q$x_T6PbM>bl!ruEm~oFvjM5zmBb{UfO+A@QDxjS(kg){*Yku!sfR z`IeO1S9yWf#?^M8{@3s8SyFNbcD%VIM%kfg6BL95)ub2P6=KsxG&^&~!y2TE8vb;ID@9<&g`Vl1?&!ES z)}Gh&-tQPaJ$-y_tqj99(k*g!<8MiFW-V!-;>gctI;<)J3dO|5b%ut9C|9q34AOH; z-puTxu=j)(F&~er0$xwWydo)4YIf{PgX6? z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fJw0y zDJdyD0i6$0%y;)U0*q%nJuom3zCt%Q6;7LamBf&kdw{!bY-Tp>hT^q20iSniA3C&F zwptZ8>mdSXItMwvLy$!WsF6=!Ykq=A(xnepiE{_!*R}=7btJhrS+e|3GL(6 z_|OB?liY>O{#`C|f|OW-Tcl~(mF6dlsbo=}@Js!3=xc>18bh@D4&GivnXD{)%y2d^ z6GfbIs>MKvn?tr&?sc3HAbAzK1dn(~BdTh%9^I8kjwtW#3@a*e6Js%LNDSBRXn!u=dc{eS)+eHcGO From 82fde628ce6d715a8c7087943a8aa8dfa684d5e1 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Sat, 12 Mar 2016 14:52:33 +0100 Subject: [PATCH 6/6] Move content --- .../python_component_basic_state.markdown | 120 +++++++++++++++--- 1 file changed, 101 insertions(+), 19 deletions(-) diff --git a/source/_cookbook/python_component_basic_state.markdown b/source/_cookbook/python_component_basic_state.markdown index 3eca0d8bbab..7a95cec30ad 100644 --- a/source/_cookbook/python_component_basic_state.markdown +++ b/source/_cookbook/python_component_basic_state.markdown @@ -10,34 +10,116 @@ footer: true ha_category: Custom Python Component Examples --- -This is a simple hello world example to show the basics for setting a state. To use this example, create the file `/custom_components/hello_state.py` and copy the below example code. +This is a simple tutorial/example on how to write a component for [Home Assistant](https://home-assistant.io/). We will work on a component called "hello_state" to beginn with. The purpose of this component is to display a given text in the frontend. + +The setup of a development environment is described in the [Developers section](/developers/#starting-development) of the documentation. + +## {% linkable_title Component %} + +To get started, create the file `/custom_components/hello_state.py` and copy the below example code. ```python -# The domain of your component. Should be equal to the name of your component. +""" +Support for showing text in the frontend. + +For more details about this component, please refer to the documentation at +https://home-assistant.io/components/hello_state/ +""" +import logging + +_LOGGER = logging.getLogger(__name__) + DOMAIN = 'hello_state' +DEPENDENCIES = [] -CONF_NAME = 'name' -DEFAULT_NAME = 'World' +def setup(hass, config=None): + """Setup the Hello State component. """ + _LOGGER.info("The 'hello state' component is ready!") - -def setup(hass, config): - """Setup is called when Home Assistant is loading our component.""" - - # Get the name from the configuration. Use DEFAULT_NAME if no name provided. - name = config[DOMAIN].get(CONF_NAME, DEFAULT_NAME) - - # States are in the format DOMAIN.OBJECT_ID - hass.states.set('hello_state.hello', name) - - # Return boolean to indicate that initialization was successfully. return True ``` -Load the component by adding the following to your `configuration.yaml`: +1. In the file header we decided to add some details: A short description and the link to the documentation. +2. We want to do some logging. This means that we import the Python logging module and create an alias. +3. The component name is equal to the domain name. +4. At the moment this component has no dependencies. For detail check [dependencies](/developers/creating_components/#dependencies) section. +5. The `setup` function will take care of the initialization of our component. + The component will only write a log message. Keep in mind for later that you have several options for the severity: + + - `_LOGGER.info(msg)` + - `_LOGGER.warning(msg)` + - `_LOGGER.error(msg)` + - `_LOGGER.critical(msg)` + - `_LOGGER.exception(msg)` + +7. We return `True` if everything is ok. + +Add the component to your `configuration.yaml` file. ```yaml -# configuration.yaml entry hello_state: - # optional - name: Paulus ``` + +After a start or a restart of Home Assistant the component will create an entry in the log. + +```bash +16-03-12 14:16:42 INFO (MainThread) [custom_components.hello_state] The 'hello state' component is ready! +``` + +The next step is the introduction of configuration options. Most configuration details are coming out of the `configuration.yaml` file. To do that we need to update the `def setup()` method to accept configuration information and access the configuration variable in the `setup` method. + +More details about this topic can be found in the [User given configuration](/developers/creating_components/#config-user-given-configuration) section. + +```python +import logging + +_LOGGER = logging.getLogger(__name__) + +DOMAIN = 'hello_state' +DEPENDENCIES = [] + +CONF_TEXT = 'text' +DEFAULT_TEXT = 'No text!' + +def setup(hass, config): + """Setup the Hello State component. """ + # Get the text from the configuration. Use DEFAULT_TEXT if no name is provided. + text = config[DOMAIN].get(CONF_TEXT, DEFAULT_TEXT) + + # States are in the format DOMAIN.OBJECT_ID + hass.states.set('hello_state.Hello_State', text) + + return True +``` + +To add the latest feature of our component, update the entry in your `configuration.yaml` file. + +```yaml +information: + text: 'Hello, World!' +``` + +Thanks to `DEFAULT_TEXT` variable the component will launch even if no `text:` field is used in the `configuration.yaml` file. Quite often there are variables which are required. It's important to check if all mandatory configuration variables are provided. If not, the setup should fail. We will use the `validate_config` function as a helper to achive this. The next listing shows the essential parts. + +```python +from homeassistant.helpers import validate_config +[...] + if not validate_config(config, {DOMAIN: [CONF_TEXT]}, _LOGGER): + return False +``` + +If `text:` is missing, there will be a warning in the log file. + +```bash +16-03-12 14:37:37 ERROR (MainThread) [custom_components.hello_state] Missing required configuration items in hello_state: text +16-03-12 14:37:37 ERROR (MainThread) [homeassistant.bootstrap] component hello_state failed to initialize +``` + +After a start or a restart of Home Assistant the component will be visible in the frontend if the `configuration.yaml` file is up-to-date. + +

+ +

+ +To get your component included in the Home Assistant releases, follow the steps described in the [Submitting improvements](https://home-assistant.io/developers/#submitting-improvements) section. Basically you only need to move your component in the `homeassistant/component/` directory of your fork and create a Pull Request. +