Google Assistant: Track if request is local (#31226)

* Track if request is local

* Cancel early if 2FA disabled

* Allow disabling 2FA for ack

* Do not mark devices with 2FA as reachable

* Add request source to GA events
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2020-01-28 10:54:39 -08:00
1 parent 03954be12d
commit 8ceef72853
9 files changed
+99 -19

No files matched your search

@@ -28,6 +28,7 @@ from .const import (
DOMAIN,
DOMAIN_TO_GOOGLE_TYPES,
ERR_FUNCTION_NOT_SUPPORTED,
SOURCE_LOCAL,
STORE_AGENT_USER_IDS,
)
from .error import SmartHomeError
@@ -232,7 +233,7 @@ class AbstractConfig(ABC):
return json_response(smart_home.turned_off_response(payload))
result = await smart_home.async_handle_message(
self.hass, self, self.local_sdk_user_id, payload
self.hass, self, self.local_sdk_user_id, payload, SOURCE_LOCAL
)
if _LOGGER.isEnabledFor(logging.DEBUG):
@@ -286,15 +287,22 @@ class RequestData:
self,
config: AbstractConfig,
user_id: str,
source: str,
request_id: str,
devices: Optional[List[dict]],
):
"""Initialize the request data."""
self.config = config
self.source = source
self.request_id = request_id
self.context = Context(user_id=user_id)
self.devices = devices
@property
def is_local_request(self):
"""Return if this is a local request."""
return self.source == SOURCE_LOCAL
def get_google_type(domain, device_class):
"""Google type based on domain and device class."""
@@ -354,6 +362,9 @@ class GoogleEntity:
features = state.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
device_class = state.attributes.get(ATTR_DEVICE_CLASS)
if not self.config.should_2fa(state):
return False
return any(
trait.might_2fa(domain, features, device_class) for trait in self.traits()
)