add notice about putting imports inside functions (#137)

* add notice about putting imports inside functions

* Fix based on feedback

* notice on custom_components handling of deps

* Update creating_component_deps_and_reqs.md
This commit is contained in:
Max Rydahl Andersen 2018-11-01 09:41:55 +01:00 committed by Paulus Schoutsen
parent 3133501503
commit 82d2241882

View File

@ -22,6 +22,23 @@ Requirements is a list of strings. Each entry is a `pip` compatible string. For
REQUIREMENTS = ['pychromecast==0.6.12']
```
### Note
Be aware that actual python imports of these dependencies should be done inside functions that use them. This is because Home Assistant installs requirements on demand and so the requirement won't be loaded the first time your component is loaded.
Example:
```python
REQUIREMENTS = ['pychromecast==0.6.12']
def setup(hass, config):
import pychromecast
<your code goes here>
```
### Custom requirements during development & testing
During development of a component, it can be useful to test against different versions of a requirement. This can be done in two steps, using pychromecast as an example:
* `pip install pychromecast==0.6.13 --target ~/.homeassistant/deps`