Google Assistant: Create and pass context to service calls (#21551)

* Google Assistant: Create and pass context to service calls

* Refactor request data into separate object and pass to execute.
This commit is contained in:
Penny Wood 2019-03-06 12:00:53 +08:00 committed by Paulus Schoutsen
parent fc1ee9be43
commit d1038ea79f
8 changed files with 345 additions and 265 deletions

View file

@ -1,4 +1,5 @@
"""Helper classes for Google Assistant integration."""
from homeassistant.core import Context
class SmartHomeError(Exception):
@ -16,10 +17,19 @@ class SmartHomeError(Exception):
class Config:
"""Hold the configuration for Google Assistant."""
def __init__(self, should_expose, allow_unlock, agent_user_id,
def __init__(self, should_expose, allow_unlock,
entity_config=None):
"""Initialize the configuration."""
self.should_expose = should_expose
self.agent_user_id = agent_user_id
self.entity_config = entity_config or {}
self.allow_unlock = allow_unlock
class RequestData:
"""Hold data associated with a particular request."""
def __init__(self, config, user_id, request_id):
"""Initialize the request data."""
self.config = config
self.request_id = request_id
self.context = Context(user_id=user_id)