async def async_device_message_received(topic, payload, qos):
    'Process the received message.'
    match = TOPIC_MATCHER.match(topic)
    if (not match):
        return
    (_prefix_topic, component, node_id, object_id) = match.groups()
    if (component not in SUPPORTED_COMPONENTS):
        _LOGGER.warning('Component %s is not supported', component)
        return
    if payload:
        try:
            payload = json.loads(payload)
        except ValueError:
            _LOGGER.warning("Unable to parse JSON %s: '%s'", object_id, payload)
            return
    payload = dict(payload)
    for key in list(payload.keys()):
        abbreviated_key = key
        key = ABBREVIATIONS.get(key, key)
        payload[key] = payload.pop(abbreviated_key)
    if (TOPIC_BASE in payload):
        base = payload[TOPIC_BASE]
        for (key, value) in payload.items():
            if (isinstance(value, str) and value):
                if ((value[0] == TOPIC_BASE) and key.endswith('_topic')):
                    payload[key] = '{}{}'.format(base, value[1:])
                if ((value[(- 1)] == TOPIC_BASE) and key.endswith('_topic')):
                    payload[key] = '{}{}'.format(value[:(- 1)], base)
    discovery_id = (' '.join((node_id, object_id)) if node_id else object_id)
    discovery_hash = (component, discovery_id)
    if payload:
        if ((CONF_PLATFORM in payload) and ('schema' not in payload)):
            platform = payload[CONF_PLATFORM]
            if ((component in DEPRECATED_PLATFORM_TO_SCHEMA) and (platform in DEPRECATED_PLATFORM_TO_SCHEMA[component])):
                schema = DEPRECATED_PLATFORM_TO_SCHEMA[component][platform]
                payload['schema'] = schema
                _LOGGER.warning('"platform": "%s" is deprecated, replace with "schema":"%s"', platform, schema)
        payload[CONF_PLATFORM] = 'mqtt'
        if (CONF_STATE_TOPIC not in payload):
            payload[CONF_STATE_TOPIC] = '{}/{}/{}{}/state'.format(discovery_topic, component, (('%s/' % node_id) if node_id else ''), object_id)
        payload[ATTR_DISCOVERY_HASH] = discovery_hash
    if (ALREADY_DISCOVERED not in hass.data):
        hass.data[ALREADY_DISCOVERED] = {}
    if (discovery_hash in hass.data[ALREADY_DISCOVERED]):
        _LOGGER.info('Component has already been discovered: %s %s, sending update', component, discovery_id)
        async_dispatcher_send(hass, MQTT_DISCOVERY_UPDATED.format(discovery_hash), payload)
    elif payload:
        _LOGGER.info('Found new component: %s %s', component, discovery_id)
        hass.data[ALREADY_DISCOVERED][discovery_hash] = None
        if (component not in CONFIG_ENTRY_COMPONENTS):
            (await async_load_platform(hass, component, 'mqtt', payload, hass_config))
            return
        config_entries_key = '{}.{}'.format(component, 'mqtt')
        async with hass.data[DATA_CONFIG_ENTRY_LOCK]:
            if (config_entries_key not in hass.data[CONFIG_ENTRY_IS_SETUP]):
                (await hass.config_entries.async_forward_entry_setup(config_entry, component))
                hass.data[CONFIG_ENTRY_IS_SETUP].add(config_entries_key)
        async_dispatcher_send(hass, MQTT_DISCOVERY_NEW.format(component, 'mqtt'), payload)
Process the received message.
async def async_device_message_received(topic, payload, qos):
    
    match = TOPIC_MATCHER.match(topic)
    if (not match):
        return
    (_prefix_topic, component, node_id, object_id) = match.groups()
    if (component not in SUPPORTED_COMPONENTS):
        _LOGGER.warning('Component %s is not supported', component)
        return
    if payload:
        try:
            payload = json.loads(payload)
        except ValueError:
            _LOGGER.warning("Unable to parse JSON %s: '%s'", object_id, payload)
            return
    payload = dict(payload)
    for key in list(payload.keys()):
        abbreviated_key = key
        key = ABBREVIATIONS.get(key, key)
        payload[key] = payload.pop(abbreviated_key)
    if (TOPIC_BASE in payload):
        base = payload[TOPIC_BASE]
        for (key, value) in payload.items():
            if (isinstance(value, str) and value):
                if ((value[0] == TOPIC_BASE) and key.endswith('_topic')):
                    payload[key] = '{}{}'.format(base, value[1:])
                if ((value[(- 1)] == TOPIC_BASE) and key.endswith('_topic')):
                    payload[key] = '{}{}'.format(value[:(- 1)], base)
    discovery_id = (' '.join((node_id, object_id)) if node_id else object_id)
    discovery_hash = (component, discovery_id)
    if payload:
        if ((CONF_PLATFORM in payload) and ('schema' not in payload)):
            platform = payload[CONF_PLATFORM]
            if ((component in DEPRECATED_PLATFORM_TO_SCHEMA) and (platform in DEPRECATED_PLATFORM_TO_SCHEMA[component])):
                schema = DEPRECATED_PLATFORM_TO_SCHEMA[component][platform]
                payload['schema'] = schema
                _LOGGER.warning('"platform": "%s" is deprecated, replace with "schema":"%s"', platform, schema)
        payload[CONF_PLATFORM] = 'mqtt'
        if (CONF_STATE_TOPIC not in payload):
            payload[CONF_STATE_TOPIC] = '{}/{}/{}{}/state'.format(discovery_topic, component, (('%s/' % node_id) if node_id else ), object_id)
        payload[ATTR_DISCOVERY_HASH] = discovery_hash
    if (ALREADY_DISCOVERED not in hass.data):
        hass.data[ALREADY_DISCOVERED] = {}
    if (discovery_hash in hass.data[ALREADY_DISCOVERED]):
        _LOGGER.info('Component has already been discovered: %s %s, sending update', component, discovery_id)
        async_dispatcher_send(hass, MQTT_DISCOVERY_UPDATED.format(discovery_hash), payload)
    elif payload:
        _LOGGER.info('Found new component: %s %s', component, discovery_id)
        hass.data[ALREADY_DISCOVERED][discovery_hash] = None
        if (component not in CONFIG_ENTRY_COMPONENTS):
            (await async_load_platform(hass, component, 'mqtt', payload, hass_config))
            return
        config_entries_key = '{}.{}'.format(component, 'mqtt')
        async with hass.data[DATA_CONFIG_ENTRY_LOCK]:
            if (config_entries_key not in hass.data[CONFIG_ENTRY_IS_SETUP]):
                (await hass.config_entries.async_forward_entry_setup(config_entry, component))
                hass.data[CONFIG_ENTRY_IS_SETUP].add(config_entries_key)
        async_dispatcher_send(hass, MQTT_DISCOVERY_NEW.format(component, 'mqtt'), payload)