New platform for fan passing config from component to platform

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.

I’ve got the same issue…For me, I want to pass a config entry value from the top-level __init__.py to the sensor.py for my integration. The config dict is empty in the sensor.py setup_platform function. How can I get it to populate? Have you had any luck @barryq?

I never figured out why config was empty in setup_platform. My guess would be how the config is parsed at the component vs. platform level. I also never got a good answer as to what is the best way to get the config there, but based on lots of example code, it looks like people are just shoving things into hass.data[DOMAIN]. The other option would be to add data to the discovery_info passed into setup_platform

Thanks for your update…I’ve been looking over various integrations and see the same thing you state. I think I’ll take the discovery_info object approach as I don’t need this data to persist in global hass.data.

Hi,
i got the exact same problem. I’m trying to follow the example components on github, but none of them are really working.
the light example has a wrong configuration, and is missing the interesting parts of the implementation. the load platform example does not show how to read and forward config values. the other async examples are mostly just using init.py
I can’t find a good example that includes and explains a working component.