async def async_setup_entry(hass, config_entry, async_add_entities):
    'Set up config entry.'
    discovery_info = config_entry.data
    device_ids = set()

    def supported(event):
        return (isinstance(event.device, rfxtrxmod.LightingDevice) and event.device.known_to_be_dimmable)
    entities = []
    for (packet_id, entity_info) in discovery_info[CONF_DEVICES].items():
        event = get_rfx_object(packet_id)
        if (event is None):
            _LOGGER.error('Invalid device: %s', packet_id)
            continue
        if (not supported(event)):
            continue
        device_id = get_device_id(event.device, data_bits=entity_info.get(CONF_DATA_BITS))
        if (device_id in device_ids):
            continue
        device_ids.add(device_id)
        entity = RfxtrxLight(event.device, device_id, entity_info[CONF_SIGNAL_REPETITIONS])
        entities.append(entity)
    async_add_entities(entities)

    @callback
    def light_update(event, device_id):
        'Handle light updates from the RFXtrx gateway.'
        if (not supported(event)):
            return
        if (device_id in device_ids):
            return
        device_ids.add(device_id)
        _LOGGER.info('Added light (Device ID: %s Class: %s Sub: %s, Event: %s)', event.device.id_string.lower(), event.device.__class__.__name__, event.device.subtype, ''.join((f'{x:02x}' for x in event.data)))
        entity = RfxtrxLight(event.device, device_id, DEFAULT_SIGNAL_REPETITIONS, event=event)
        async_add_entities([entity])
    if discovery_info[CONF_AUTOMATIC_ADD]:
        hass.helpers.dispatcher.async_dispatcher_connect(SIGNAL_EVENT, light_update)
Set up config entry.
async def async_setup_entry(hass, config_entry, async_add_entities):
    
    discovery_info = config_entry.data
    device_ids = set()

    def supported(event):
        return (isinstance(event.device, rfxtrxmod.LightingDevice) and event.device.known_to_be_dimmable)
    entities = []
    for (packet_id, entity_info) in discovery_info[CONF_DEVICES].items():
        event = get_rfx_object(packet_id)
        if (event is None):
            _LOGGER.error('Invalid device: %s', packet_id)
            continue
        if (not supported(event)):
            continue
        device_id = get_device_id(event.device, data_bits=entity_info.get(CONF_DATA_BITS))
        if (device_id in device_ids):
            continue
        device_ids.add(device_id)
        entity = RfxtrxLight(event.device, device_id, entity_info[CONF_SIGNAL_REPETITIONS])
        entities.append(entity)
    async_add_entities(entities)

    @callback
    def light_update(event, device_id):
        'Handle light updates from the RFXtrx gateway.'
        if (not supported(event)):
            return
        if (device_id in device_ids):
            return
        device_ids.add(device_id)
        _LOGGER.info('Added light (Device ID: %s Class: %s Sub: %s, Event: %s)', event.device.id_string.lower(), event.device.__class__.__name__, event.device.subtype, .join((f'{x:02x}' for x in event.data)))
        entity = RfxtrxLight(event.device, device_id, DEFAULT_SIGNAL_REPETITIONS, event=event)
        async_add_entities([entity])
    if discovery_info[CONF_AUTOMATIC_ADD]:
        hass.helpers.dispatcher.async_dispatcher_connect(SIGNAL_EVENT, light_update)