human
I wrote the below code

    import miniupnpc
    upnp = miniupnpc.UPnP()
    hass.data[DATA_UPNP] = upnp
    upnp.discoverdelay = 200
    upnp.discover()
    try:
        upnp.selectigd()
    except Exception:
        _LOGGER.exception('Error    when    attempting    to    discover    an    UPnP    IGD')
        return False
    unit = config[DOMAIN].get(CONF_UNITS)
    discovery.load_platform(hass, 'sensor', DOMAIN, {'unit': unit}, config)
    port_mapping = config[DOMAIN].get(CONF_ENABLE_PORT_MAPPING)
    if (not port_mapping):
        return True
    base_url = urlsplit(hass.config.api.base_url)
    host = base_url.hostname
    internal_port = base_url.port
    external_port = int(config[DOMAIN].get(CONF_EXTERNAL_PORT))
    if (external_port == 0):
        external_port = internal_port
    try:
        upnp.addportmapping(external_port, 'TCP', host, internal_port, 'Home    Assistant', '')
        def deregister_port(event):
            'De-register    the    UPnP    port    mapping.'
            upnp.deleteportmapping(external_port, 'TCP')
        hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, deregister_port)
    except Exception as ex:
        _LOGGER.error('UPnP    failed    to    configure    port    mapping:    %s', str(ex))
        hass.components.persistent_notification.create('<b>ERROR:    tcp    port    {}    is    already    mapped    in    your    router.</b><br    />Please    disable    port_mapping    in    the    <i>upnp</i>    configuration    section.<br    />You    will    need    to    restart    hass    after    fixing.'.format(external_port), title=NOTIFICATION_TITLE, notification_id=NOTIFICATION_ID)
        return False
    return True

What's a good function header?

Here's a good function header?
assistant
#Here's a good function header.

def setup(hass, config):