Skip to content

Commit a341b72

Browse files
committed
Add initial code review check lists
1 parent f0ebc4a commit a341b72

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed

source/_includes/asides/developers_navigation.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ <h1 class="title delta">Development Guide</h1>
2525
<li>
2626
{% active_link /developers/add_new_platform/ Support a new device (as a platform) %}
2727
<ul>
28+
<li>{% active_link /developers/code_review_platform/ Checklist creating a platform %}</li>
2829
<li>{% active_link /developers/platform_example_sensor/ Example sensor platform %}</li>
2930
<li>{% active_link /developers/platform_example_light/ Example light platform %}</li>
3031
</ul>
3132
</li>
3233
<li>
3334
{% active_link /developers/creating_components/ Adding a new component %}
3435
<ul>
36+
<li>{% active_link /developers/code_review_component/ Checklist creating a component %}</li>
3537
<li>{% active_link /developers/component_loading/ Loading components %}</li>
3638
<li>{% active_link /developers/component_deps_and_reqs/ Requirements & Dependencies %}</li>
3739
<li>{% active_link /developers/component_initialization/ Initialization %}</li>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
layout: page
3+
title: "Checklist for creating a component"
4+
description: "A list of things to pay attention to when code reviewing a component."
5+
date: 2017-01-15 14:09 -0800
6+
sidebar: true
7+
comments: false
8+
sharing: true
9+
footer: true
10+
---
11+
12+
A checklist of things to do when you're adding a new component.
13+
14+
### {% linkable_title Requirements %}
15+
16+
1. Requirement version pinned: `REQUIREMENTS = ['phue==0.8.1']`
17+
2. If requirement hosted on GitHub:
18+
- Point at a zip archive of a release tag or commit SHA.
19+
- Add version found in zip-archive as hash to url.
20+
21+
```python
22+
REQUIREMENTS = [
23+
'http://github.com/technicalpickles/python-nest'
24+
'/archive/e6c9d56a8df455d4d7746389811f2c1387e8cb33.zip'
25+
'#python-nest==3.0.3']
26+
```
27+
28+
### {% linkable_title Configuration %}
29+
30+
1. Volutpuous schema present for config validation
31+
2. Default parameters specified in voluptuous schema, not in `setup_platform(…)`
32+
3. Schema using as many generic config keys as possible from `homeassistant.const`
33+
4. If having platforms, have a `PLATFORM_SCHEMA`, otherwise `CONFIG_SCHEMA`.
34+
5. If `PLATFORM_SCHEMA`, import base from `homeassistant.helpers.config_validation`
35+
36+
37+
### {% linkable_title Component/platform communication %}
38+
39+
1. If you need to share global data with platforms, use the dictionary `hass.data`.
40+
2. If the component fetches data that causes related platform entities to update,
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
layout: page
3+
title: "Checklist for creating a platform"
4+
description: "A list of things to pay attention to when code reviewing a platform."
5+
date: 2017-01-15 14:09 -0800
6+
sidebar: true
7+
comments: false
8+
sharing: true
9+
footer: true
10+
---
11+
12+
A checklist of things to do when you're adding a new platform.
13+
14+
### {% linkable_title 1. Requirements %}
15+
16+
1. Requirement version pinned: `REQUIREMENTS = ['phue==0.8.1']`
17+
2. If requirement hosted on GitHub:
18+
- Point at a zip archive of a release tag or commit SHA.
19+
- Add version found in zip-archive as hash to url.
20+
21+
```python
22+
REQUIREMENTS = [
23+
'http://github.com/technicalpickles/python-nest'
24+
'/archive/e6c9d56a8df455d4d7746389811f2c1387e8cb33.zip'
25+
'#python-nest==3.0.3']
26+
```
27+
28+
### {% linkable_title 2. Dependencies %}
29+
30+
1. If you depend on a component for the connection, add it to your dependencies: `DEPENDENCIES = ['nest']`
31+
32+
### {% linkable_title 3. Configuration %}
33+
34+
1. Volutpuous schema present for config validation
35+
2. Voluptuous schema extends schema from component<br>(e.g. `light.hue.PLATFORM_SCHEMA` extends `light.PLATFORM_SCHEMA`)
36+
3. Default parameters specified in voluptuous schema, not in `setup_platform(…)`
37+
4. Schema using as many generic config keys as possible from `homeassistant.const`
38+
39+
```python
40+
import voluptuous as vol
41+
42+
from homeassistant.const import CONF_FILENAME, CONF_HOST
43+
from homeassistant.components.light import PLATFORM_SCHEMA
44+
import homeassistant.helpers.config_validation as cv
45+
46+
CONF_ALLOW_UNREACHABLE = 'allow_unreachable'
47+
DEFAULT_UNREACHABLE = False
48+
49+
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
50+
vol.Required(CONF_HOST): cv.string,
51+
vol.Optional(CONF_ALLOW_UNREACHABLE,
52+
default=DEFAULT_UNREACHABLE): cv.boolean,
53+
vol.Optional(CONF_FILENAME): cv.string,
54+
})
55+
```
56+
57+
### {% linkable_title 4. Setup Platform %}
58+
59+
1. Test if passed in info (user/pass/host etc.) works.
60+
2. Group your calls to `add_devices` if possible.
61+
3. If platform adds extra services, format should be `<component>.<platform>_<service name>`.
62+
63+
### {% linkable_title 5. Entity %}
64+
65+
1. Extend entity from component, e.g. `class HueLight(Light)`
66+
2. Do not call `update()` in constructor, use `add_devices(devices, True)` instead.
67+
3. Do not do any I/O inside properties. Cache values inside `update()` instead.

0 commit comments

Comments
 (0)