Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: fix google_assistant 'allow_unlock' config option #18874

Merged
merged 1 commit into from
Dec 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ def should_expose(entity):

self._gactions_config = ga_h.Config(
should_expose=should_expose,
allow_unlock=self.prefs.google_allow_unlock,
agent_user_id=self.claims['cognito:username'],
entity_config=conf.get(CONF_ENTITY_CONFIG),
allow_unlock=self.prefs.google_allow_unlock,
)

return self._gactions_config
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/google_assistant/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def __init__(self, code, msg):
class Config:
"""Hold the configuration for Google Assistant."""

def __init__(self, should_expose, agent_user_id, entity_config=None,
allow_unlock=False):
def __init__(self, should_expose, allow_unlock, agent_user_id,
entity_config=None):
"""Initialize the configuration."""
self.should_expose = should_expose
self.agent_user_id = agent_user_id
Expand Down
8 changes: 6 additions & 2 deletions homeassistant/components/google_assistant/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from .const import (
GOOGLE_ASSISTANT_API_ENDPOINT,
CONF_ALLOW_UNLOCK,
CONF_EXPOSE_BY_DEFAULT,
CONF_EXPOSED_DOMAINS,
CONF_ENTITY_CONFIG,
Expand All @@ -32,6 +33,7 @@ def async_register_http(hass, cfg):
expose_by_default = cfg.get(CONF_EXPOSE_BY_DEFAULT)
exposed_domains = cfg.get(CONF_EXPOSED_DOMAINS)
entity_config = cfg.get(CONF_ENTITY_CONFIG) or {}
allow_unlock = cfg.get(CONF_ALLOW_UNLOCK, False)

def is_exposed(entity) -> bool:
"""Determine if an entity should be exposed to Google Assistant."""
Expand All @@ -57,7 +59,7 @@ def is_exposed(entity) -> bool:
return is_default_exposed or explicit_expose

hass.http.register_view(
GoogleAssistantView(is_exposed, entity_config))
GoogleAssistantView(is_exposed, entity_config, allow_unlock))


class GoogleAssistantView(HomeAssistantView):
Expand All @@ -67,15 +69,17 @@ class GoogleAssistantView(HomeAssistantView):
name = 'api:google_assistant'
requires_auth = True

def __init__(self, is_exposed, entity_config):
def __init__(self, is_exposed, entity_config, allow_unlock):
"""Initialize the Google Assistant request handler."""
self.is_exposed = is_exposed
self.entity_config = entity_config
self.allow_unlock = allow_unlock

async def post(self, request: Request) -> Response:
"""Handle Google Assistant requests."""
message = await request.json() # type: dict
config = Config(self.is_exposed,
self.allow_unlock,
request['hass_user'].id,
self.entity_config)
result = await async_handle_message(
Expand Down
2 changes: 2 additions & 0 deletions tests/components/google_assistant/test_smart_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

BASIC_CONFIG = helpers.Config(
should_expose=lambda state: True,
allow_unlock=False,
agent_user_id='test-agent',
)
REQ_ID = 'ff36a3cc-ec34-11e6-b1a0-64510650abcf'
Expand All @@ -35,6 +36,7 @@ async def test_sync_message(hass):

config = helpers.Config(
should_expose=lambda state: state.entity_id != 'light.not_expose',
allow_unlock=False,
agent_user_id='test-agent',
entity_config={
'light.demo_light': {
Expand Down
1 change: 1 addition & 0 deletions tests/components/google_assistant/test_trait.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

BASIC_CONFIG = helpers.Config(
should_expose=lambda state: True,
allow_unlock=False,
agent_user_id='test-agent',
)

Expand Down