async def _async_add_entity(self, entity, update_before_add, entity_registry, device_registry):
    'Add an entity to the platform.'
    if (entity is None):
        raise ValueError('Entity cannot be None')
    entity.hass = self.hass
    entity.platform = self
    if (hasattr(entity, 'async_update') and (not self.parallel_updates)):
        entity.parallel_updates = None
    elif ((not hasattr(entity, 'async_update')) and (self.parallel_updates == 0)):
        entity.parallel_updates = None
    else:
        entity.parallel_updates = self._get_parallel_updates_semaphore()
    if update_before_add:
        try:
            (await entity.async_device_update(warning=False))
        except Exception:
            self.logger.exception('%s: Error on device update!', self.platform_name)
            return
    suggested_object_id = None
    if (entity.unique_id is not None):
        if (entity.entity_id is not None):
            suggested_object_id = split_entity_id(entity.entity_id)[1]
        else:
            suggested_object_id = entity.name
        if (self.entity_namespace is not None):
            suggested_object_id = '{} {}'.format(self.entity_namespace, suggested_object_id)
        if (self.config_entry is not None):
            config_entry_id = self.config_entry.entry_id
        else:
            config_entry_id = None
        device_info = entity.device_info
        device_id = None
        if ((config_entry_id is not None) and (device_info is not None)):
            processed_dev_info = {'config_entry_id': config_entry_id}
            for key in ('connections', 'identifiers', 'manufacturer', 'model', 'name', 'sw_version', 'via_hub'):
                if (key in device_info):
                    processed_dev_info[key] = device_info[key]
            device = device_registry.async_get_or_create(**processed_dev_info)
            if device:
                device_id = device.id
        entry = entity_registry.async_get_or_create(self.domain, self.platform_name, entity.unique_id, suggested_object_id=suggested_object_id, config_entry_id=config_entry_id, device_id=device_id, known_object_ids=self.entities.keys())
        if entry.disabled:
            self.logger.info("Not adding entity %s because it's disabled", (entry.name or entity.name or '"{} {}"'.format(self.platform_name, entity.unique_id)))
            return
        entity.entity_id = entry.entity_id
        entity.registry_name = entry.name
        entity.async_on_remove(entry.add_update_listener(entity))
    elif ((entity.entity_id is not None) and entity_registry.async_is_registered(entity.entity_id)):
        suggested_object_id = split_entity_id(entity.entity_id)[1]
        entity.entity_id = None
    if (entity.entity_id is None):
        suggested_object_id = (suggested_object_id or entity.name or DEVICE_DEFAULT_NAME)
        if (self.entity_namespace is not None):
            suggested_object_id = '{} {}'.format(self.entity_namespace, suggested_object_id)
        entity.entity_id = entity_registry.async_generate_entity_id(self.domain, suggested_object_id, self.entities.keys())
    if (not valid_entity_id(entity.entity_id)):
        raise HomeAssistantError('Invalid entity id: {}'.format(entity.entity_id))
    if ((entity.entity_id in self.entities) or (entity.entity_id in self.hass.states.async_entity_ids(self.domain))):
        msg = 'Entity id already exists: {}'.format(entity.entity_id)
        if (entity.unique_id is not None):
            msg += '. Platform {} does not generate unique IDs'.format(self.platform_name)
        raise HomeAssistantError(msg)
    entity_id = entity.entity_id
    self.entities[entity_id] = entity
    entity.async_on_remove((lambda : self.entities.pop(entity_id)))
    (await entity.async_added_to_hass())
    (await entity.async_update_ha_state())
Add an entity to the platform.
async def _async_add_entity(self, entity, update_before_add, entity_registry, device_registry):
    
    if (entity is None):
        raise ValueError('Entity cannot be None')
    entity.hass = self.hass
    entity.platform = self
    if (hasattr(entity, 'async_update') and (not self.parallel_updates)):
        entity.parallel_updates = None
    elif ((not hasattr(entity, 'async_update')) and (self.parallel_updates == 0)):
        entity.parallel_updates = None
    else:
        entity.parallel_updates = self._get_parallel_updates_semaphore()
    if update_before_add:
        try:
            (await entity.async_device_update(warning=False))
        except Exception:
            self.logger.exception('%s: Error on device update!', self.platform_name)
            return
    suggested_object_id = None
    if (entity.unique_id is not None):
        if (entity.entity_id is not None):
            suggested_object_id = split_entity_id(entity.entity_id)[1]
        else:
            suggested_object_id = entity.name
        if (self.entity_namespace is not None):
            suggested_object_id = '{} {}'.format(self.entity_namespace, suggested_object_id)
        if (self.config_entry is not None):
            config_entry_id = self.config_entry.entry_id
        else:
            config_entry_id = None
        device_info = entity.device_info
        device_id = None
        if ((config_entry_id is not None) and (device_info is not None)):
            processed_dev_info = {'config_entry_id': config_entry_id}
            for key in ('connections', 'identifiers', 'manufacturer', 'model', 'name', 'sw_version', 'via_hub'):
                if (key in device_info):
                    processed_dev_info[key] = device_info[key]
            device = device_registry.async_get_or_create(**processed_dev_info)
            if device:
                device_id = device.id
        entry = entity_registry.async_get_or_create(self.domain, self.platform_name, entity.unique_id, suggested_object_id=suggested_object_id, config_entry_id=config_entry_id, device_id=device_id, known_object_ids=self.entities.keys())
        if entry.disabled:
            self.logger.info("Not adding entity %s because it's disabled", (entry.name or entity.name or '"{} {}"'.format(self.platform_name, entity.unique_id)))
            return
        entity.entity_id = entry.entity_id
        entity.registry_name = entry.name
        entity.async_on_remove(entry.add_update_listener(entity))
    elif ((entity.entity_id is not None) and entity_registry.async_is_registered(entity.entity_id)):
        suggested_object_id = split_entity_id(entity.entity_id)[1]
        entity.entity_id = None
    if (entity.entity_id is None):
        suggested_object_id = (suggested_object_id or entity.name or DEVICE_DEFAULT_NAME)
        if (self.entity_namespace is not None):
            suggested_object_id = '{} {}'.format(self.entity_namespace, suggested_object_id)
        entity.entity_id = entity_registry.async_generate_entity_id(self.domain, suggested_object_id, self.entities.keys())
    if (not valid_entity_id(entity.entity_id)):
        raise HomeAssistantError('Invalid entity id: {}'.format(entity.entity_id))
    if ((entity.entity_id in self.entities) or (entity.entity_id in self.hass.states.async_entity_ids(self.domain))):
        msg = 'Entity id already exists: {}'.format(entity.entity_id)
        if (entity.unique_id is not None):
            msg += '. Platform {} does not generate unique IDs'.format(self.platform_name)
        raise HomeAssistantError(msg)
    entity_id = entity.entity_id
    self.entities[entity_id] = entity
    entity.async_on_remove((lambda : self.entities.pop(entity_id)))
    (await entity.async_added_to_hass())
    (await entity.async_update_ha_state())