blob: 34c0a41723765d80271a0e7d363cd9beda8dd8af (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
import yaml
from pathlib import Path
from ..config import Config
from ..responses.responses import Responses
from ..hassil.util import merge_dict
from .response_handler import ResponseHandler
from .libnotify import LibNotify
class ResponseManager:
def __init__(self, config: Config):
response_dict = {"responses": {}}
response_yaml_path = Path(config.responses_dir)
response_yaml_file_paths = response_yaml_path.glob("*.yaml")
for yaml_file_path in response_yaml_file_paths:
with open(yaml_file_path, "r", encoding="utf-8") as yaml_file:
merge_dict(response_dict, yaml.safe_load(yaml_file))
self.responses = Responses.from_dict(response_dict)
self.respond_handlers: list[ResponseHandler] = [LibNotify(config)]
def respond(self, response: str, intent_name: str):
response_key = intent_name if response == "default" else response
if response_key not in self.responses.responses:
print(f"No response found for: {response_key}")
return
response_text = self.responses.responses[response_key].sentence_texts[0]
for handler in self.respond_handlers:
handler.respond(response_text)
|