예제 #1
0
async def test_snips_low_probability(hass, mqtt_mock, caplog):
    """Test intent via Snips."""
    caplog.set_level(logging.WARNING)
    result = await async_setup_component(hass, "snips", {
        "snips": {
            "probability_threshold": 0.5
        },
    })
    assert result
    payload = """
    {
        "input": "I am not sure what to say",
        "intent": {
            "intentName": "LightsMaybe",
            "probability": 0.49
        },
        "slots": []
    }
    """

    async_mock_intent(hass, 'LightsMaybe')
    async_fire_mqtt_message(hass, 'hermes/intent/LightsMaybe',
                            payload)
    await hass.async_block_till_done()
    assert 'Intent below probaility threshold 0.49 < 0.5' in caplog.text
예제 #2
0
async def test_snips_low_probability(hass, caplog):
    """Test intent via Snips."""
    await async_mock_mqtt_component(hass)

    caplog.set_level(logging.WARNING)
    result = await async_setup_component(
        hass, "snips", {"snips": {
            "probability_threshold": 0.5
        }})
    assert result
    payload = """
    {
        "input": "I am not sure what to say",
        "intent": {
            "intentName": "LightsMaybe",
            "confidenceScore": 0.49
        },
        "slots": []
    }
    """

    async_mock_intent(hass, "LightsMaybe")
    async_fire_mqtt_message(hass, "hermes/intent/LightsMaybe", payload)
    await hass.async_block_till_done()
    assert "Intent below probaility threshold 0.49 < 0.5" in caplog.text
예제 #3
0
async def test_calling_intent(hass):
    """Test calling an intent from a conversation."""
    intents = async_mock_intent(hass, 'OrderBeer')

    result = await component.async_setup(hass, {})
    assert result

    result = await async_setup_component(
        hass, 'conversation', {
            'conversation': {
                'intents': {
                    'OrderBeer': ['I would like the {type} beer']
                }
            }
        })
    assert result

    await hass.services.async_call(
        'conversation', 'process',
        {conversation.ATTR_TEXT: 'I would like the Grolsch beer'})
    await hass.async_block_till_done()

    assert len(intents) == 1
    intent = intents[0]
    assert intent.platform == 'conversation'
    assert intent.intent_type == 'OrderBeer'
    assert intent.slots == {'type': {'value': 'Grolsch'}}
    assert intent.text_input == 'I would like the Grolsch beer'
예제 #4
0
async def test_snips_intent_user(hass, mqtt_mock):
    """Test intentName format user_XXX__intentName."""
    result = await async_setup_component(hass, "snips", {
        "snips": {},
    })
    assert result
    payload = """
    {
        "input": "what to do",
        "intent": {
            "intentName": "user_ABCDEF123__Lights",
            "probability": 1
        },
        "slots": []
    }
    """
    intents = async_mock_intent(hass, 'Lights')
    async_fire_mqtt_message(hass, 'hermes/intent/user_ABCDEF123__Lights',
                            payload)
    await hass.async_block_till_done()

    assert len(intents) == 1
    intent = intents[0]
    assert intent.platform == 'snips'
    assert intent.intent_type == 'Lights'
예제 #5
0
async def test_snips_intent_username(hass, mqtt_mock):
    """Test intentName format username:intentName."""
    result = await async_setup_component(hass, "snips", {
        "snips": {},
    })
    assert result
    payload = """
    {
        "input": "what to do",
        "intent": {
            "intentName": "username:Lights",
            "probability": 1
        },
        "slots": []
    }
    """
    intents = async_mock_intent(hass, 'Lights')
    async_fire_mqtt_message(hass, 'hermes/intent/username:Lights',
                            payload)
    await hass.async_block_till_done()

    assert len(intents) == 1
    intent = intents[0]
    assert intent.platform == 'snips'
    assert intent.intent_type == 'Lights'
예제 #6
0
async def test_snips_intent_user(hass):
    """Test intentName format user_XXX__intentName."""
    await async_mock_mqtt_component(hass)

    result = await async_setup_component(hass, "snips", {
        "snips": {},
    })
    assert result
    payload = """
    {
        "input": "what to do",
        "intent": {
            "intentName": "user_ABCDEF123__Lights",
            "confidenceScore": 1
        },
        "slots": []
    }
    """
    intents = async_mock_intent(hass, 'Lights')
    async_fire_mqtt_message(hass, 'hermes/intent/user_ABCDEF123__Lights',
                            payload)
    await hass.async_block_till_done()

    assert len(intents) == 1
    intent = intents[0]
    assert intent.platform == 'snips'
    assert intent.intent_type == 'Lights'
예제 #7
0
async def test_snips_intent(hass, mqtt_mock):
    """Test intent via Snips."""
    result = await async_setup_component(hass, "snips", {
        "snips": {},
    })
    assert result
    payload = """
    {
        "input": "turn the lights green",
        "intent": {
            "intentName": "Lights",
            "probability": 1
        },
        "slots": [
            {
                "slotName": "light_color",
                "value": {
                    "kind": "Custom",
                    "value": "green"
                }
            }
        ]
    }
    """

    intents = async_mock_intent(hass, 'Lights')

    async_fire_mqtt_message(hass, 'hermes/intent/Lights', payload)
    await hass.async_block_till_done()
    assert len(intents) == 1
    intent = intents[0]
    assert intent.platform == 'snips'
    assert intent.intent_type == 'Lights'
    assert intent.slots == {'light_color': {'value': 'green'}}
    assert intent.text_input == 'turn the lights green'
예제 #8
0
async def test_calling_intent(hass):
    """Test calling an intent from a conversation."""
    intents = async_mock_intent(hass, "OrderBeer")

    result = await async_setup_component(hass, "homeassistant", {})
    assert result

    result = await async_setup_component(
        hass,
        "conversation",
        {
            "conversation": {
                "intents": {
                    "OrderBeer": ["I would like the {type} beer"]
                }
            }
        },
    )
    assert result

    await hass.services.async_call(
        "conversation",
        "process",
        {conversation.ATTR_TEXT: "I would like the Grolsch beer"},
    )
    await hass.async_block_till_done()

    assert len(intents) == 1
    intent = intents[0]
    assert intent.platform == "conversation"
    assert intent.intent_type == "OrderBeer"
    assert intent.slots == {"type": {"value": "Grolsch"}}
    assert intent.text_input == "I would like the Grolsch beer"
async def test_calling_intent(hass):
    """Test calling an intent from a conversation."""
    intents = async_mock_intent(hass, 'OrderBeer')

    result = await component.async_setup(hass, {})
    assert result

    result = await async_setup_component(hass, 'conversation', {
        'conversation': {
            'intents': {
                'OrderBeer': [
                    'I would like the {type} beer'
                ]
            }
        }
    })
    assert result

    await hass.services.async_call(
        'conversation', 'process', {
            conversation.ATTR_TEXT: 'I would like the Grolsch beer'
        })
    await hass.async_block_till_done()

    assert len(intents) == 1
    intent = intents[0]
    assert intent.platform == 'conversation'
    assert intent.intent_type == 'OrderBeer'
    assert intent.slots == {'type': {'value': 'Grolsch'}}
    assert intent.text_input == 'I would like the Grolsch beer'
예제 #10
0
async def test_snips_intent_user(hass):
    """Test intentName format user_XXX__intentName."""
    await async_mock_mqtt_component(hass)

    result = await async_setup_component(hass, "snips", {"snips": {}})
    assert result
    payload = """
    {
        "input": "what to do",
        "intent": {
            "intentName": "user_ABCDEF123__Lights",
            "confidenceScore": 1
        },
        "slots": []
    }
    """
    intents = async_mock_intent(hass, "Lights")
    async_fire_mqtt_message(hass, "hermes/intent/user_ABCDEF123__Lights",
                            payload)
    await hass.async_block_till_done()

    assert len(intents) == 1
    intent = intents[0]
    assert intent.platform == "snips"
    assert intent.intent_type == "Lights"
예제 #11
0
async def test_snips_intent_with_duration(hass, mqtt_mock):
    """Test intent with Snips duration."""
    result = await async_setup_component(hass, "snips", {
        "snips": {},
    })
    assert result
    payload = """
    {
      "input": "set a timer of five minutes",
      "intent": {
        "intentName": "SetTimer",
        "probability": 1
      },
      "slots": [
        {
          "rawValue": "five minutes",
          "value": {
            "kind": "Duration",
            "years": 0,
            "quarters": 0,
            "months": 0,
            "weeks": 0,
            "days": 0,
            "hours": 0,
            "minutes": 5,
            "seconds": 0,
            "precision": "Exact"
          },
          "range": {
            "start": 15,
            "end": 27
          },
          "entity": "snips/duration",
          "slotName": "timer_duration"
        }
      ]
    }
    """
    intents = async_mock_intent(hass, 'SetTimer')

    async_fire_mqtt_message(hass, 'hermes/intent/SetTimer', payload)
    await hass.async_block_till_done()
    assert len(intents) == 1
    intent = intents[0]
    assert intent.platform == 'snips'
    assert intent.intent_type == 'SetTimer'
    assert intent.slots == {
        'probability': {
            'value': 1
        },
        'site_id': {
            'value': None
        },
        'timer_duration': {
            'value': 300
        }
    }
예제 #12
0
async def test_snips_intent(hass):
    """Test intent via Snips."""
    await async_mock_mqtt_component(hass)

    result = await async_setup_component(hass, "snips", {"snips": {}})
    assert result
    payload = """
    {
        "siteId": "default",
        "sessionId": "1234567890ABCDEF",
        "input": "turn the lights green",
        "intent": {
            "intentName": "Lights",
            "confidenceScore": 1
        },
        "slots": [
            {
                "slotName": "light_color",
                "value": {
                    "kind": "Custom",
                    "value": "green"
                },
                "rawValue": "green"
            }
        ]
    }
    """

    intents = async_mock_intent(hass, "Lights")

    async_fire_mqtt_message(hass, "hermes/intent/Lights", payload)
    await hass.async_block_till_done()
    assert len(intents) == 1
    intent = intents[0]
    assert intent.platform == "snips"
    assert intent.intent_type == "Lights"
    assert intent
    assert intent.slots == {
        "light_color": {
            "value": "green"
        },
        "light_color_raw": {
            "value": "green"
        },
        "confidenceScore": {
            "value": 1
        },
        "site_id": {
            "value": "default"
        },
        "session_id": {
            "value": "1234567890ABCDEF"
        },
    }
    assert intent.text_input == "turn the lights green"
예제 #13
0
async def test_snips_intent_with_duration(hass):
    """Test intent with Snips duration."""
    await async_mock_mqtt_component(hass)

    result = await async_setup_component(hass, "snips", {
        "snips": {},
    })
    assert result
    payload = """
    {
      "input": "set a timer of five minutes",
      "intent": {
        "intentName": "SetTimer",
        "confidenceScore": 1
      },
      "slots": [
        {
          "rawValue": "five minutes",
          "value": {
            "kind": "Duration",
            "years": 0,
            "quarters": 0,
            "months": 0,
            "weeks": 0,
            "days": 0,
            "hours": 0,
            "minutes": 5,
            "seconds": 0,
            "precision": "Exact"
          },
          "range": {
            "start": 15,
            "end": 27
          },
          "entity": "snips/duration",
          "slotName": "timer_duration"
        }
      ]
    }
    """
    intents = async_mock_intent(hass, 'SetTimer')

    async_fire_mqtt_message(hass, 'hermes/intent/SetTimer',
                            payload)
    await hass.async_block_till_done()
    assert len(intents) == 1
    intent = intents[0]
    assert intent.platform == 'snips'
    assert intent.intent_type == 'SetTimer'
    assert intent.slots == {'confidenceScore': {'value': 1},
                            'site_id': {'value': None},
                            'session_id': {'value': None},
                            'timer_duration': {'value': 300},
                            'timer_duration_raw': {'value': 'five minutes'}}
예제 #14
0
async def test_snips_intent(hass):
    """Test intent via Snips."""
    await async_mock_mqtt_component(hass)

    result = await async_setup_component(hass, "snips", {
        "snips": {},
    })
    assert result
    payload = """
    {
        "siteId": "default",
        "sessionId": "1234567890ABCDEF",
        "input": "turn the lights green",
        "intent": {
            "intentName": "Lights",
            "confidenceScore": 1
        },
        "slots": [
            {
                "slotName": "light_color",
                "value": {
                    "kind": "Custom",
                    "value": "green"
                },
                "rawValue": "green"
            }
        ]
    }
    """

    intents = async_mock_intent(hass, 'Lights')

    async_fire_mqtt_message(hass, 'hermes/intent/Lights',
                            payload)
    await hass.async_block_till_done()
    assert len(intents) == 1
    intent = intents[0]
    assert intent.platform == 'snips'
    assert intent.intent_type == 'Lights'
    assert intent
    assert intent.slots == {'light_color': {'value': 'green'},
                            'light_color_raw': {'value': 'green'},
                            'confidenceScore': {'value': 1},
                            'site_id': {'value': 'default'},
                            'session_id': {'value': '1234567890ABCDEF'}}
    assert intent.text_input == 'turn the lights green'
예제 #15
0
def test_snips_call_action(hass, mqtt_mock):
    """Test calling action via Snips."""
    result = yield from async_setup_component(hass, "snips", {
        "snips": {},
    })
    assert result

    intents = async_mock_intent(hass, 'Lights')

    async_fire_mqtt_message(hass, 'hermes/intent/activateLights', EXAMPLE_MSG)
    yield from hass.async_block_till_done()
    assert len(intents) == 1
    intent = intents[0]
    assert intent.platform == 'snips'
    assert intent.intent_type == 'Lights'
    assert intent.slots == {'light_color': {'value': 'green'}}
    assert intent.text_input == 'turn the lights green'
예제 #16
0
async def test_snips_intent(hass):
    """Test intent via Snips."""
    await async_mock_mqtt_component(hass)

    result = await async_setup_component(hass, "snips", {
        "snips": {},
    })
    assert result
    payload = """
    {
        "siteId": "default",
        "sessionId": "1234567890ABCDEF",
        "input": "turn the lights green",
        "intent": {
            "intentName": "Lights",
            "probability": 1
        },
        "slots": [
            {
                "slotName": "light_color",
                "value": {
                    "kind": "Custom",
                    "value": "green"
                },
                "rawValue": "green"
            }
        ]
    }
    """

    intents = async_mock_intent(hass, 'Lights')

    async_fire_mqtt_message(hass, 'hermes/intent/Lights',
                            payload)
    await hass.async_block_till_done()
    assert len(intents) == 1
    intent = intents[0]
    assert intent.platform == 'snips'
    assert intent.intent_type == 'Lights'
    assert intent
    assert intent.slots == {'light_color': {'value': 'green'},
                            'light_color_raw': {'value': 'green'},
                            'probability': {'value': 1},
                            'site_id': {'value': 'default'},
                            'session_id': {'value': '1234567890ABCDEF'}}
    assert intent.text_input == 'turn the lights green'
예제 #17
0
async def test_register_before_setup(opp):
    """Test calling an intent from a conversation."""
    intents = async_mock_intent(opp, "OrderBeer")

    opp.components.conversation.async_register("OrderBeer",
                                               ["A {type} beer, please"])

    result = await async_setup_component(
        opp,
        "conversation",
        {
            "conversation": {
                "intents": {
                    "OrderBeer": ["I would like the {type} beer"]
                }
            }
        },
    )
    assert result

    await opp.services.async_call(
        "conversation", "process",
        {conversation.ATTR_TEXT: "A Grolsch beer, please"})
    await opp.async_block_till_done()

    assert len(intents) == 1
    intent = intents[0]
    assert intent.platform == "conversation"
    assert intent.intent_type == "OrderBeer"
    assert intent.slots == {"type": {"value": "Grolsch"}}
    assert intent.text_input == "A Grolsch beer, please"

    await opp.services.async_call(
        "conversation",
        "process",
        {conversation.ATTR_TEXT: "I would like the Grolsch beer"},
    )
    await opp.async_block_till_done()

    assert len(intents) == 2
    intent = intents[1]
    assert intent.platform == "conversation"
    assert intent.intent_type == "OrderBeer"
    assert intent.slots == {"type": {"value": "Grolsch"}}
    assert intent.text_input == "I would like the Grolsch beer"
예제 #18
0
def test_snips_call_action(hass, mqtt_mock):
    """Test calling action via Snips."""
    result = yield from async_setup_component(hass, "snips", {
        "snips": {},
    })
    assert result

    intents = async_mock_intent(hass, 'Lights')

    async_fire_mqtt_message(hass, 'hermes/nlu/intentParsed',
                            EXAMPLE_MSG)
    yield from hass.async_block_till_done()
    assert len(intents) == 1
    intent = intents[0]
    assert intent.platform == 'snips'
    assert intent.intent_type == 'Lights'
    assert intent.slots == {'light_color': {'value': 'green'}}
    assert intent.text_input == 'turn the lights green'
def test_register_before_setup(hass):
    """Test calling an intent from a conversation."""
    intents = async_mock_intent(hass, 'OrderBeer')

    hass.components.conversation.async_register('OrderBeer', [
        'A {type} beer, please'
    ])

    result = yield from async_setup_component(hass, 'conversation', {
        'conversation': {
            'intents': {
                'OrderBeer': [
                    'I would like the {type} beer'
                ]
            }
        }
    })
    assert result

    yield from hass.services.async_call(
        'conversation', 'process', {
            conversation.ATTR_TEXT: 'A Grolsch beer, please'
        })
    yield from hass.async_block_till_done()

    assert len(intents) == 1
    intent = intents[0]
    assert intent.platform == 'conversation'
    assert intent.intent_type == 'OrderBeer'
    assert intent.slots == {'type': {'value': 'Grolsch'}}
    assert intent.text_input == 'A Grolsch beer, please'

    yield from hass.services.async_call(
        'conversation', 'process', {
            conversation.ATTR_TEXT: 'I would like the Grolsch beer'
        })
    yield from hass.async_block_till_done()

    assert len(intents) == 2
    intent = intents[1]
    assert intent.platform == 'conversation'
    assert intent.intent_type == 'OrderBeer'
    assert intent.slots == {'type': {'value': 'Grolsch'}}
    assert intent.text_input == 'I would like the Grolsch beer'
예제 #20
0
def test_register_before_setup(hass):
    """Test calling an intent from a conversation."""
    intents = async_mock_intent(hass, 'OrderBeer')

    hass.components.conversation.async_register('OrderBeer', [
        'A {type} beer, please'
    ])

    result = yield from async_setup_component(hass, 'conversation', {
        'conversation': {
            'intents': {
                'OrderBeer': [
                    'I would like the {type} beer'
                ]
            }
        }
    })
    assert result

    yield from hass.services.async_call(
        'conversation', 'process', {
            conversation.ATTR_TEXT: 'A Grolsch beer, please'
        })
    yield from hass.async_block_till_done()

    assert len(intents) == 1
    intent = intents[0]
    assert intent.platform == 'conversation'
    assert intent.intent_type == 'OrderBeer'
    assert intent.slots == {'type': {'value': 'Grolsch'}}
    assert intent.text_input == 'A Grolsch beer, please'

    yield from hass.services.async_call(
        'conversation', 'process', {
            conversation.ATTR_TEXT: 'I would like the Grolsch beer'
        })
    yield from hass.async_block_till_done()

    assert len(intents) == 2
    intent = intents[1]
    assert intent.platform == 'conversation'
    assert intent.intent_type == 'OrderBeer'
    assert intent.slots == {'type': {'value': 'Grolsch'}}
    assert intent.text_input == 'I would like the Grolsch beer'
예제 #21
0
async def test_snips_intent(hass, mqtt_mock):
    """Test intent via Snips."""
    result = await async_setup_component(hass, "snips", {
        "snips": {},
    })
    assert result
    payload = """
    {
        "input": "turn the lights green",
        "intent": {
            "intentName": "Lights",
            "probability": 1
        },
        "slots": [
            {
                "slotName": "light_color",
                "value": {
                    "kind": "Custom",
                    "value": "green"
                }
            }
        ]
    }
    """

    intents = async_mock_intent(hass, 'Lights')

    async_fire_mqtt_message(hass, 'hermes/intent/Lights',
                            payload)
    await hass.async_block_till_done()
    assert len(intents) == 1
    intent = intents[0]
    assert intent.platform == 'snips'
    assert intent.intent_type == 'Lights'
    assert intent.slots == {'light_color': {'value': 'green'},
                            'probability': {'value': 1},
                            'site_id': {'value': None}}
    assert intent.text_input == 'turn the lights green'
예제 #22
0
def test_snips_intent_username(hass, mqtt_mock):
    """Test intentName format username:intentName."""
    result = yield from async_setup_component(hass, "snips", {
        "snips": {},
    })
    assert result
    payload = """
    {
        "input": "what to do",
        "intent": {
            "intentName": "username:Lights"
        },
        "slots": []
    }
    """
    intents = async_mock_intent(hass, 'Lights')
    async_fire_mqtt_message(hass, 'hermes/intent/username:Lights', payload)
    yield from hass.async_block_till_done()

    assert len(intents) == 1
    intent = intents[0]
    assert intent.platform == 'snips'
    assert intent.intent_type == 'Lights'
예제 #23
0
def test_snips_unknown_intent(hass, mqtt_mock):
    """Test calling unknown Intent via Snips."""
    event = 'call_service'
    events = []

    @callback
    def record_event(event):
        """Add recorded event to set."""
        events.append(event)
    result = yield from async_setup_component(hass, "snips", {
        "snips": {},
    })
    assert result
    payload = """
    {
        "input": "what to do",
        "intent": {
            "intentName": "unknownIntent"
        },
        "slots": []
    }
    """
    intents = async_mock_intent(hass, 'knownIntent')
    hass.bus.async_listen(event, record_event)
    async_fire_mqtt_message(hass, 'hermes/intent/unknownIntent',
                            payload)
    yield from hass.async_block_till_done()

    assert not intents
    assert len(events) == 1
    assert events[0].data['domain'] == 'mqtt'
    assert events[0].data['service'] == 'publish'
    payload = json.loads(events[0].data['service_data']['payload'])
    topic = events[0].data['service_data']['topic']
    assert payload['text'] == 'Unknown Intent'
    assert topic == 'hermes/dialogueManager/endSession'
예제 #24
0
async def test_snips_intent_with_duration(hass):
    """Test intent with Snips duration."""
    await async_mock_mqtt_component(hass)

    result = await async_setup_component(hass, "snips", {"snips": {}})
    assert result
    payload = """
    {
      "input": "set a timer of five minutes",
      "intent": {
        "intentName": "SetTimer",
        "confidenceScore": 1
      },
      "slots": [
        {
          "rawValue": "five minutes",
          "value": {
            "kind": "Duration",
            "years": 0,
            "quarters": 0,
            "months": 0,
            "weeks": 0,
            "days": 0,
            "hours": 0,
            "minutes": 5,
            "seconds": 0,
            "precision": "Exact"
          },
          "range": {
            "start": 15,
            "end": 27
          },
          "entity": "snips/duration",
          "slotName": "timer_duration"
        }
      ]
    }
    """
    intents = async_mock_intent(hass, "SetTimer")

    async_fire_mqtt_message(hass, "hermes/intent/SetTimer", payload)
    await hass.async_block_till_done()
    assert len(intents) == 1
    intent = intents[0]
    assert intent.platform == "snips"
    assert intent.intent_type == "SetTimer"
    assert intent.slots == {
        "confidenceScore": {
            "value": 1
        },
        "site_id": {
            "value": None
        },
        "session_id": {
            "value": None
        },
        "timer_duration": {
            "value": 300
        },
        "timer_duration_raw": {
            "value": "five minutes"
        },
    }