Site updated at 2018-01-05 04:58:25 UTC
This commit is contained in:
parent
93c7f7ae56
commit
fd28feb4f9
27 changed files with 78 additions and 75 deletions
|
@ -78,21 +78,22 @@
|
|||
<p class="note">
|
||||
Not all existing platforms follow the requirements in this checklist. This cannot be used as a reason to not follow them!
|
||||
</p>
|
||||
<h3><a class="title-link" name="requirements" href="#requirements"></a> Requirements</h3>
|
||||
<h3><a class="title-link" name="1-requirements" href="#1-requirements"></a> 1. Requirements</h3>
|
||||
<ol>
|
||||
<li>Requirement version pinned: <code class="highlighter-rouge">REQUIREMENTS = ['phue==0.8.1']</code></li>
|
||||
<li>We no longer want requirements hosted on GitHub. Please upload to PyPi.</li>
|
||||
<li>Requirements should only be imported inside functions. This is necessary because requirements are installed on the fly.</li>
|
||||
</ol>
|
||||
<h3><a class="title-link" name="configuration" href="#configuration"></a> Configuration</h3>
|
||||
<h3><a class="title-link" name="2-configuration" href="#2-configuration"></a> 2. Configuration</h3>
|
||||
<ol>
|
||||
<li>Voluptuous schema present for config validation</li>
|
||||
<li>Default parameters specified in voluptuous schema, not in <code class="highlighter-rouge">setup(…)</code></li>
|
||||
<li>Schema using as many generic config keys as possible from <code class="highlighter-rouge">homeassistant.const</code></li>
|
||||
<li>If having platforms, have a <code class="highlighter-rouge">PLATFORM_SCHEMA</code>, otherwise <code class="highlighter-rouge">CONFIG_SCHEMA</code>.</li>
|
||||
<li>If <code class="highlighter-rouge">PLATFORM_SCHEMA</code>, import base from <code class="highlighter-rouge">homeassistant.helpers.config_validation</code></li>
|
||||
<li>If your component has platforms, define a <code class="highlighter-rouge">PLATFORM_SCHEMA</code> instead of a <code class="highlighter-rouge">CONFIG_SCHEMA</code>.</li>
|
||||
<li>If using a <code class="highlighter-rouge">PLATFORM_SCHEMA</code> to be used with <code class="highlighter-rouge">EntityComponent</code>, import base from <code class="highlighter-rouge">homeassistant.helpers.config_validation</code></li>
|
||||
<li>Never depend on users adding things to <code class="highlighter-rouge">customize</code> to configure behavior inside your component.</li>
|
||||
</ol>
|
||||
<h3><a class="title-link" name="componentplatform-communication" href="#componentplatform-communication"></a> Component/platform communication</h3>
|
||||
<h3><a class="title-link" name="3-componentplatform-communication" href="#3-componentplatform-communication"></a> 3. Component/platform communication</h3>
|
||||
<ol>
|
||||
<li>If you need to share global data with platforms, use the dictionary <code class="highlighter-rouge">hass.data</code>. <code class="highlighter-rouge">hass.data[DATA_XY]</code> while <code class="highlighter-rouge">XY</code> is the component is preferred over <code class="highlighter-rouge">hass.data[DOMAIN]</code>.</li>
|
||||
<li>If the component fetches data that causes it’s related platform entities to update, you can notify them using the dispatcher code in <code class="highlighter-rouge">homeassistant.helpers.dispatcher</code>.</li>
|
||||
|
|
|
@ -90,12 +90,11 @@ Not all existing platforms follow the requirements in this checklist. This canno
|
|||
</ol>
|
||||
<h3><a class="title-link" name="3-configuration" href="#3-configuration"></a> 3. Configuration</h3>
|
||||
<ol>
|
||||
<li>Volutpuous schema present for config validation</li>
|
||||
<li>Voluptuous schema present for config validation</li>
|
||||
<li>Voluptuous schema extends schema from component<br />(e.g. <code class="highlighter-rouge">light.hue.PLATFORM_SCHEMA</code> extends <code class="highlighter-rouge">light.PLATFORM_SCHEMA</code>)</li>
|
||||
<li>Default parameters specified in voluptuous schema, not in <code class="highlighter-rouge">setup_platform(…)</code></li>
|
||||
<li>Schema using as many generic config keys as possible from <code class="highlighter-rouge">homeassistant.const</code></li>
|
||||
</ol>
|
||||
<div class="language-python highlighter-rouge"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">voluptuous</span> <span class="kn">as</span> <span class="nn">vol</span>
|
||||
<li>Your <code class="highlighter-rouge">PLATFORM_SCHEMA</code> should use as many generic config keys as possible from <code class="highlighter-rouge">homeassistant.const</code>
|
||||
<div class="language-python highlighter-rouge"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">voluptuous</span> <span class="kn">as</span> <span class="nn">vol</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">homeassistant.const</span> <span class="kn">import</span> <span class="n">CONF_FILENAME</span><span class="p">,</span> <span class="n">CONF_HOST</span>
|
||||
<span class="kn">from</span> <span class="nn">homeassistant.components.light</span> <span class="kn">import</span> <span class="n">PLATFORM_SCHEMA</span>
|
||||
|
@ -107,11 +106,14 @@ Not all existing platforms follow the requirements in this checklist. This canno
|
|||
<span class="n">PLATFORM_SCHEMA</span> <span class="o">=</span> <span class="n">PLATFORM_SCHEMA</span><span class="o">.</span><span class="n">extend</span><span class="p">({</span>
|
||||
<span class="n">vol</span><span class="o">.</span><span class="n">Required</span><span class="p">(</span><span class="n">CONF_HOST</span><span class="p">):</span> <span class="n">cv</span><span class="o">.</span><span class="n">string</span><span class="p">,</span>
|
||||
<span class="n">vol</span><span class="o">.</span><span class="n">Optional</span><span class="p">(</span><span class="n">CONF_ALLOW_UNREACHABLE</span><span class="p">,</span>
|
||||
<span class="n">default</span><span class="o">=</span><span class="n">DEFAULT_UNREACHABLE</span><span class="p">):</span> <span class="n">cv</span><span class="o">.</span><span class="n">boolean</span><span class="p">,</span>
|
||||
<span class="n">default</span><span class="o">=</span><span class="n">DEFAULT_UNREACHABLE</span><span class="p">):</span> <span class="n">cv</span><span class="o">.</span><span class="n">boolean</span><span class="p">,</span>
|
||||
<span class="n">vol</span><span class="o">.</span><span class="n">Optional</span><span class="p">(</span><span class="n">CONF_FILENAME</span><span class="p">):</span> <span class="n">cv</span><span class="o">.</span><span class="n">string</span><span class="p">,</span>
|
||||
<span class="p">})</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li>Never depend on users adding things to <code class="highlighter-rouge">customize</code> to configure behavior inside your platform.</li>
|
||||
</ol>
|
||||
<h3><a class="title-link" name="4-setup-platform" href="#4-setup-platform"></a> 4. Setup Platform</h3>
|
||||
<ol>
|
||||
<li>Test if passed in info (user/pass/host etc.) works.</li>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue