Skip to content
This repository has been archived by the owner on Aug 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request #234 from devkid/patch-1
Browse files Browse the repository at this point in the history
Enable speech response for Home Assistant intent handler
  • Loading branch information
synesthesiam authored Jun 2, 2020
2 parents 3133666 + 3a88488 commit cf8f231
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion rhasspy/intent_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ def __init__(self):
self.event_type_format = ""
self.pem_file = ""
self.handle_type: HomeAssistantHandleType = HomeAssistantHandleType.EVENT
self.speech_actor: Optional[RhasspyActor] = None

def to_started(self, from_state: str) -> None:
"""Transition to started state."""
self.hass_config = self.profile.get("home_assistant", {})
self.speech_actor = self.config.get("speech")

# Python format string for generating event type name
self.event_type_format = self.hass_config.get(
Expand Down Expand Up @@ -170,6 +172,15 @@ def forward_intent(self, intent_name: str, event_type: str, slots: Dict[str, Any
kwargs["verify"] = self.pem_file

response = requests.post(post_url, **kwargs)
response.raise_for_status()

intent = response.json()
self._logger.debug(intent)

# Check for speech
speech_text = intent.get("speech", {}).get("plain", {}).get("speech", "")
if speech_text and self.speech_actor:
self.send(self.speech_actor, SpeakSentence(speech_text))
else:
# Send event
post_url = urljoin(self.hass_config["url"], "api/events/" + event_type)
Expand All @@ -184,7 +195,7 @@ def forward_intent(self, intent_name: str, event_type: str, slots: Dict[str, Any
response = requests.post(post_url, **kwargs)
self._logger.debug("POSTed intent to %s", post_url)

response.raise_for_status()
response.raise_for_status()

# -------------------------------------------------------------------------

Expand Down

0 comments on commit cf8f231

Please sign in to comment.