I need a bit of help on figuring out how to pass config around between the component __init__.py
and the platform.
Originally I started with just he platform of my device for the fan component and that worked fine.
Creating components/airscape/fan.py, defined PLATFORM_SCHEMA etc I was able to control the fan as expected. I decided that I wanted to create a custom service to speed_up and slow_down the fan. It’s a whole house fan and I want to incrementally adjust the speed based on the inside and outside temperature delta.
The only thing I need for the component is the two custom services I’m trying to add. Otherwise I would just leave it as a platform entity.
I started building out the __init__.py
for the component and got stuck with how to get the config to the platform setup_platform
from the component setup
. In setup
I make a call to hass.helpers.discover.load_platform
using it’s required parameters. And I can see the config I want in config that was passed into setup
. I pass that same config in load_platform
But when setup_platform
executes the config attribute is empty.
I’m not trying to define the config as a platform… declaring it directly in the configuration.yaml like:
airscape:
name: Whole House Fan
host: '192.168.10.10'
I would just like to declare the config as a fan entity using the airscape platform:
fan:
- platform: airscape
name: Whole House Fan
host: '192.168.10.10'
The component __init__.py
is still simple at this point. I haven’t add any of the service stuff. I am still trying to get the platform working by declaring it through load_platform
"""The Airscape component."""
import logging
_LOGGER = logging.getLogger(__name__)
DOMAIN = "airscape"
def setup(hass, config):
"""Set up is called when Home Assistant is loading our component."""
hass.helpers.discovery.load_platform("fan", DOMAIN, {}, config)
# Return boolean to indicate that initialization was successfully.
return True
In setup
I could stuff all the config in hass.data[DOMAIN]
and then pull it back out in setup_platform
, but that doesn’t seem like the right way to do that. It seems like since I can pass config into load_platform
I should be able to get get it from config
in setup_platform
.