Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few small fixes #2251

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions intents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -365,32 +365,32 @@ HassMediaNext:
description: "Name of an area"
required: false

HassSetVolume:
HassMediaPrevious:
supported: true
domain: media_player
description: "Sets the volume of a media player"
description: "Skips a media player back to the previous item"
slots:
name:
description: "Name of a device or entity"
required: false
area:
description: "Name of an area"
required: false
volume_level:
description: "Volume level from 0 to 100"
required: true

HassMediaPrevious:
supported: false
HassSetVolume:
supported: true
domain: media_player
description: "Skips a media player back to the previous item"
description: "Sets the volume of a media player"
slots:
name:
description: "Name of a device or entity"
required: false
area:
description: "Name of an area"
required: false
volume_level:
description: "Volume level from 0 to 100"
required: true

# -----------------------------------------------------------------------------
# timers
Expand Down
54 changes: 32 additions & 22 deletions script/intentfest/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import yaml
from hassil.intents import Intents
from hassil.recognize import recognize
from hassil.recognize import recognize_all
from hassil.util import merge_dict, normalize_whitespace

from shared import (
Expand Down Expand Up @@ -49,6 +49,11 @@ def get_arguments() -> argparse.Namespace:
metavar=("key", "value"),
help="Add key/value pair to context",
)
parser.add_argument(
"--all",
action="store_true",
help="List all possible matches instead of just the first one",
)
return parser.parse_args()


Expand Down Expand Up @@ -81,28 +86,33 @@ def run() -> int:

# Parse sentences
for sentence in args.sentence:
result = recognize(
for result in recognize_all(
sentence, intents, slot_lists=slot_lists, intent_context=intent_context
)
output_dict = {"text": sentence, "match": result is not None}
if result is not None:
output_dict["intent"] = result.intent.name
output_dict["slots"] = {
entity.name: entity.value for entity in result.entities_list
}
output_dict["context"] = result.context

# Response
matched, unmatched = get_matched_states(states, areas, result)
output_dict["response_key"] = result.response
response_template = responses.get(result.intent.name, {}).get(
result.response
)
output_dict["response"] = normalize_whitespace(
render_response(response_template, result, matched, unmatched)
).strip()

json.dump(output_dict, sys.stdout, ensure_ascii=False, indent=2)
):
output_dict = {"text": sentence, "match": result is not None}
if result is not None:
output_dict["intent"] = result.intent.name
output_dict["slots"] = {
entity.name: entity.value for entity in result.entities_list
}
output_dict["context"] = result.context
output_dict["text_chunks_matched"] = result.text_chunks_matched

# Response
matched, unmatched = get_matched_states(states, areas, result)
output_dict["response_key"] = result.response
response_template = responses.get(result.intent.name, {}).get(
result.response
)
output_dict["response"] = normalize_whitespace(
render_response(response_template, result, matched, unmatched)
).strip()

json.dump(output_dict, sys.stdout, ensure_ascii=False, indent=2)
print("")
if not args.all:
break

print("")

return 0
10 changes: 5 additions & 5 deletions sentences/en/homeassistant_HassStartTimer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ intents:
- "timer for <timer_duration>"
- "<timer_duration> timer for {timer_name:name}"
- "timer for <timer_duration> (named|called) {timer_name:name}"
- "<timer_set>[ a] <timer_duration> timer"
- "<timer_set>[ a] timer for <timer_duration>"
- "<timer_set>[ a] <timer_duration> timer (named|called|for) {timer_name:name}"
- "<timer_set>[ a] timer (named|called) {timer_name:name} for <timer_duration>"
- "<timer_set>[ a] timer for <timer_duration> (named|called) {timer_name:name}"
- "<timer_set>[ a| the| my] <timer_duration> timer"
- "<timer_set>[ a| the| my] timer for <timer_duration>"
- "<timer_set>[ a| the| my] <timer_duration> timer (named|called|for) {timer_name:name}"
- "<timer_set>[ a| the| my] timer (named|called) {timer_name:name} for <timer_duration>"
- "<timer_set>[ a| the| my] timer for <timer_duration> (named|called) {timer_name:name}"
requires_context:
area:
slot: false
Expand Down