mirror of
https://github.com/home-assistant/developers.home-assistant.git
synced 2025-07-15 05:16:28 +00:00
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:
parent
3133501503
commit
82d2241882
@ -22,6 +22,23 @@ Requirements is a list of strings. Each entry is a `pip` compatible string. For
|
|||||||
REQUIREMENTS = ['pychromecast==0.6.12']
|
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:
|
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`
|
* `pip install pychromecast==0.6.13 --target ~/.homeassistant/deps`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user