mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-21 08:16:53 +00:00
Update component_generic_discovery.markdown (#2000)
This commit is contained in:
parent
daa11ee550
commit
ba3bfb63f8
@ -10,13 +10,13 @@ footer: true
|
|||||||
---
|
---
|
||||||
|
|
||||||
New controller or hub components often need to add platforms in sub-components (i.e. Lights & Switches) without additional configuration.
|
New controller or hub components often need to add platforms in sub-components (i.e. Lights & Switches) without additional configuration.
|
||||||
This can be achieved using the `homeassistant.components.discovery.load_platform` method:
|
This can be achieved using the `load_platform` or `async_load_platform` methods from `homeassistant.helpers.discovery`:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def load_platform(hass, component, platform, info=None, hass_config=None)
|
def load_platform(hass, component, platform, discovered=None, hass_config=None)
|
||||||
```
|
```
|
||||||
|
|
||||||
From more info on how this works, refer to the [load_platform](https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/discovery.py#L78) method.
|
From more info on how this works, refer to the [load_platform](https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/helpers/discovery.py#L136) method.
|
||||||
|
|
||||||
### {% linkable_title Example %}
|
### {% linkable_title Example %}
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ The source for your component can be located in your configuration directory for
|
|||||||
In the hub component `myflashyhub.py` you can call your light and switch components. To pass any non-serializable information to the platforms in the sub-component, you can use a global variable.
|
In the hub component `myflashyhub.py` you can call your light and switch components. To pass any non-serializable information to the platforms in the sub-component, you can use a global variable.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from homeassistant.components.discovery import load_platform
|
from homeassistant.helpers.discovery import load_platform
|
||||||
DOMAIN = 'myflashyhub'
|
DOMAIN = 'myflashyhub'
|
||||||
|
|
||||||
MFH_GLOBAL = None
|
MFH_GLOBAL = None
|
||||||
@ -77,7 +77,3 @@ The `load_platform` method allows the platforms to be loaded with the need for a
|
|||||||
#switch:
|
#switch:
|
||||||
# platform: myflashyhub
|
# platform: myflashyhub
|
||||||
```
|
```
|
||||||
|
|
||||||
<p class='note '>
|
|
||||||
In the past, this was achieved by adding your component to the `DISCOVERY_PLATFORMS` in the target sub-component. Generic discovery through `load_platform()` allows you to load any sub-component, including custom components, without changing the sub-component.
|
|
||||||
</p>
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user