home-assistant / intents

Intents to be used with Home Assistant
https://developers.home-assistant.io/docs/voice/overview/
Creative Commons Attribution 4.0 International
445 stars 508 forks source link

AssertionError due to lower case transformation #952

Open dontinelli opened 1 year ago

dontinelli commented 1 year ago

While testing around I noticed that entity names are apparently used in lower case only. At least in the following use case I got the following error:

E                   AssertionError: Incorrect response for: Zünd d Schlafzimmer-Lampe a
E                   assert 'Ha ds Liecht schlafzimmer-lampe igschalte.' in {'Ha ds Liecht Schlafzimmer-Lampe igschalte.'}

tests/test_language_sentences.py:157: AssertionError
=========================================================================== short test summary info ============================================================================
FAILED tests/test_language_sentences.py::test_light_HassTurnOn[de-CH] - AssertionError: Incorrect response for: Zünd d Schlafzimmer-Lampe a
================================================================== 1 failed, 1 passed, 17 deselected in 0.25s ==================================================================

test/light_HassTurnOn.yaml:

tests:
  - sentences:
      - "Zünd d Schlafzimmer-Lampe a"
      - "Schaut d Schlafzimmer-Lampe y"
    intent:
      name: HassTurnOn
      slots:
        name: light.bedroom_lamp
        domain: light
    response:
      - "Ha ds Liecht Schlafzimmer-Lampe igschalte."

-fixtures.yaml

entities:
  - name: "Schlafzimmer-Lampe"
    id: "light.bedroom_lamp"
    area: "bedroom"

responses/HassTurnOn.yaml

responses:
  intents:
    HassTurnOn:
      light: "Ha ds Liecht {{slots.name}} igschalte."

When I change the response in the test-file to "Ha ds Liecht schlafzimmer-lampe igschalte.", I don't get this error. I'm not sure where in the code the name is set to lower case, but in my view this only makes sense for testing but not for the response. I further assume that also the response in the console would the be lower case, which definitively would be wrong.

synesthesiam commented 1 year ago

This was a bug in hassil, and has been fixed now in 1.0.4. Thanks!

dontinelli commented 1 year ago

I just tried it out and it seems that in my codespace the error persists. I updated with script/setup and in terminal it is confirmed that hassil has version 1.0.4. Are there other dependencies that need to be processed first?

synesthesiam commented 1 year ago

Another version of hassil has been merged. Can you please check again with this @dontinelli ?

dontinelli commented 1 year ago

I checked with hassil version in codespace (1.0.5) and still have the same problem.

An other problem I ran over is related to states (not sure if this is in the same context or a total different problem). In the test sentences I can use the localized states (e.g. "offe" for "open") to check on the state. In the test response this throws an error. If I use the English state, though, test passes. It seems to be the same as reported in #1070. So it seems that not only in the conversion of the entity name but also the state for the response something is not working yet.

synesthesiam commented 1 year ago

You will need to translate the state names for your test fixtures, like this:

entities:
  - name: "..."
    state:
      - in: "offe"
      - out: "open"

I responded in https://github.com/home-assistant/intents/issues/1070 just now that in HA the state names will be automatically translated using the existing strings.json files.

dontinelli commented 1 year ago

You will need to translate the state names for your test fixtures, like this:

entities:
  - name: "..."
    state:
      - in: "offe"
      - out: "open"

I responded in #1070 just now that in HA the state names will be automatically translated using the existing strings.json files.

Ok, so the definition in fixtures is needed on top of the definitions in common.yaml, correct?

dontinelli commented 1 year ago

Just tried it out:


entities:
  - name: "Deck(e|i|ä)-Venti[lator]"
    id: fan.ceiling
    area: living_room
    state:
      - in: "an"
      - out: "on"

I got the following error:

Language: de-CH
[ERROR] tests/de-CH/_fixtures.yaml: invalid format: expected str for dictionary value @ data['entities'][0]['state']. Got [{'in': 'an'}, {'out': 'on'}]
dontinelli commented 1 year ago

Update on the above: I saw in the NL-files that one could/should use a capitalize-filter in the response-yaml: {{ slots.name | capitalize }} With this, I can use capital letters at the beginning of the word and the test passes. However, capital letter in the middle of a word such as "Decke-Ventilator". "Decke-ventilator" would be recognized, "Decke-Ventilator" is not.

Also the localized states in the response do not yet work for me (cf. error above). Is this a bug or did I try to define it the wrong way?