home-assistant.io/source/developers/add_new_platform.markdown
2016-04-16 23:00:45 -07:00

2.2 KiB

layout, title, description, date, sidebar, comments, sharing, footer
layout title description date sidebar comments sharing footer
page Adding support for a new platform Hints and tips for when you're adding a new platform to Home Assistant. 2014-12-21 13:27 true false true true

Components that interact with devices are called Entity Components. They are structured in core- and platform logic. This allows the same logic to handle a light to be used by different brands.

For example, the built-in switch component consists of various platform in homeassistant/components/switch/. The file __init__.py contains the core logic of all platform and the vendor_name.py files only the relevant platform code.

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:

{% 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.

To integrate the third-party library you create an Entity class for your device. Entities are Home Assistant's representation of lights, switches, sensors, etc. and are derived from the Entity Abstract Class. This abstract class contains logic for integrating most standard features into your entities, such as visibility, entity IDs, updates, and much more.

{% linkable_title Requirements and dependencies %}

Platforms can specify dependencies and requirements the same way as a component does.

REQUIREMENTS = ['some-package==2.0.0', 'some-other-package==2.5.0']
DEPENDENCIES = ['mqtt']