Update developer documentation

This commit is contained in:
Paulus Schoutsen 2015-08-30 22:28:10 -07:00
parent fe2b626446
commit 81f2e68af4
3 changed files with 89 additions and 31 deletions

View file

@ -21,11 +21,38 @@ For example, the built-in `switch` component consists of the following files in
If you are planning to add support for a new type of device to an existing component, you can get away with only writing platform logic. Have a look at how the component works with other platforms and create a similar file for the platform that you would like to add.
<p class='note'>
Platform logic should not interface directly with the devices but use a third-party Python 3 library that speaks the actual API.
</p>
### {% linkable_title Interfacing with devices %}
One of the rules for Home Assistant is that platform logic should never interface directly with
devices but use a third-party Python 3 library to do so. This way Home Assistant is able to share
code with the Python community and we can keep the project maintainable.
Platforms can specify dependencies and requirements the same way as a component does. Please see
[the component page](/developers/creating_components.html#dependencies) for more information.
### {% linkable_title Creating Entities %}
Home Assistant will call a function with the following signature to initialize
your new platform. This function must exist in the platform module you create.
```python
def setup_platform(hass, config, add_devices, discovery_info=None)
```
In this function, your platform should create the appropriate entities and
register them with the Home Assistant core. Entities are Home Assistant's
representation of lights, switches, sensors, etc. and are derived from the
[Entity Abstract Class](https://github.com/balloob/home-assistant/blob/master/homeassistant/helpers/entity.py).
This abstract class contains logic for integrating most standard features into
your entities, such as visibility, entity IDs, updates, and many more.
A list of entities can be registered with Home Assistant using the *add_devices*
function that is provided as an input to *setup_platform*. Once entities are
registered with with Home Assistant their updates will be provided to the core
and the core will have control over them. For more information on how Entities
can be customized, take a look at the [Entity Abstract
Class](https://github.com/balloob/home-assistant/blob/master/homeassistant/helpers/entity.py#L18).
<a name='discovery'></a>
## {% linkable_title Allowing your platform to be discovered %}
Home Assistant has a discovery service running in the background to discover new devices. Whenever a new device is discovered, an `SERVICE_DISCOVERED` event will be fired with the found service and the information. The `discovery` component has some knowledge about which components handle which type of services and will ensure those are loaded and listening before firing the `SERVICE_DISCOVERED` event.
@ -61,28 +88,3 @@ The Discovery component is capable of setting up your components before firing t
<p class='note warning'>
This option is currently limited to built-in components.
</p>
### {% linkable_title Creating Entities %}
Home Assistant will call a function with the following signature to initialize
your new platform. This function must exist in the platform module you create.
```python
def setup_platform(hass, config, add_devices, discovery_info=None)
```
In this function, your platform should create the appropriate entities and
register them with the Home Assistant core. Entities are Home Assistant's
representation of lights, switches, sensors, etc. It is best practice for all
new entities to inherit the
[Entity Abstract Class](https://github.com/balloob/home-assistant/blob/master/homeassistant/helpers/entity.py#L18).
This abstract class contains logic for integrating most standard features into
your entities, such as visibility, entity IDs, updates, and many more. That is
why it is best practice to reference the existing class.
A list of entities can be registered with Home Assistant using the *add_devices*
function that is provided as an input to *setup_platform*. Once entities are
registered with with Home Assistant their updates will be provided to the core
and the core will have control over them. For more information on how Entities
can be customized, take a look at the [Entity Abstract
Class](https://github.com/balloob/home-assistant/blob/master/homeassistant/helpers/entity.py#L18).