コード例 #1
0
async def test_multi_level_wildcard_topic_not_matching(hass):
    """Test not matching multi level wildcard topic."""
    dev_id = 'zanzito'
    entity_id = ENTITY_ID_FORMAT.format(dev_id)
    subscription = 'location/#'
    topic = 'somewhere/zanzito'
    location = json.dumps(LOCATION_MESSAGE)

    assert await async_setup_component(hass, DT_DOMAIN, {
        DT_DOMAIN: {
            CONF_PLATFORM: 'mqtt_json',
            'devices': {
                dev_id: subscription
            }
        }
    })
    async_fire_mqtt_message(hass, topic, location)
    await hass.async_block_till_done()
    assert hass.states.get(entity_id) is None
コード例 #2
0
async def test_single_level_wildcard_topic_not_matching(hass):
    """Test not matching single level wildcard topic."""
    dev_id = "zanzito"
    entity_id = ENTITY_ID_FORMAT.format(dev_id)
    subscription = "location/+/zanzito"
    topic = "location/zanzito"
    location = json.dumps(LOCATION_MESSAGE)

    assert await async_setup_component(
        hass,
        DT_DOMAIN,
        {
            DT_DOMAIN: {
                CONF_PLATFORM: "mqtt_json",
                "devices": {
                    dev_id: subscription
                }
            }
        },
    )
    async_fire_mqtt_message(hass, topic, location)
    await hass.async_block_till_done()
    assert hass.states.get(entity_id) is None