Update creating_component_code_review.md

This commit is contained in:
Paulus Schoutsen 2018-08-31 09:31:37 +02:00 committed by GitHub
parent 334d29912a
commit 9b99376636
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,3 +25,18 @@ A checklist of things to do when you're adding a new component.
1. If you need to share global data with platforms, use the dictionary `hass.data`. `hass.data[DATA_XY]` while `XY` is the component is preferred over `hass.data[DOMAIN]`.
2. If the component fetches data that causes its related platform entities to update, you can notify them using the dispatcher code in `homeassistant.helpers.dispatcher`.
### 4. Communication with devices/services
1. All API specific code has to be part of a third party library hosted on PyPi. Home Assistant should only interact with objects and not make direct calls to the API.
```python
# bad
status = requests.get(url('/status'))
# good
from phue import Bridge
bridge = Bridge(…)
status = bridge.status()
```