From 82d2241882b514333ee6e496b4b69585590dd4b4 Mon Sep 17 00:00:00 2001 From: Max Rydahl Andersen Date: Thu, 1 Nov 2018 09:41:55 +0100 Subject: [PATCH] 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 --- docs/creating_component_deps_and_reqs.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/creating_component_deps_and_reqs.md b/docs/creating_component_deps_and_reqs.md index f7a8c0e3..821e360b 100644 --- a/docs/creating_component_deps_and_reqs.md +++ b/docs/creating_component_deps_and_reqs.md @@ -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 + + +``` + +### 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`