Home Assistant Unofficial Reference 2024.12.1
error.py
Go to the documentation of this file.
1 """Errors for Google Assistant."""
2 
3 from .const import ERR_CHALLENGE_NEEDED
4 
5 
6 class SmartHomeError(Exception):
7  """Google Assistant Smart Home errors.
8 
9  https://developers.google.com/actions/smarthome/create-app#error_responses
10  """
11 
12  def __init__(self, code, msg):
13  """Log error code."""
14  super().__init__(msg)
15  self.codecode = code
16 
17  def to_response(self):
18  """Convert to a response format."""
19  return {"errorCode": self.codecode}
20 
21 
23  """Google Assistant Smart Home errors.
24 
25  https://developers.google.com/actions/smarthome/create-app#error_responses
26  """
27 
28  def __init__(self, challenge_type):
29  """Initialize challenge needed error."""
30  super().__init__(ERR_CHALLENGE_NEEDED, f"Challenge needed: {challenge_type}")
31  self.challenge_typechallenge_type = challenge_type
32 
33  def to_response(self):
34  """Convert to a response format."""
35  return {
36  "errorCode": self.codecode,
37  "challengeNeeded": {"type": self.challenge_typechallenge_type},
38  }