mirror of
https://github.com/home-assistant/core.git
synced 2026-09-24 15:31:52 -05:00
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:
@@ -22,6 +22,7 @@ class MockConfig(helpers.AbstractConfig):
|
||||
*,
|
||||
secure_devices_pin=None,
|
||||
should_expose=None,
|
||||
should_2fa=None,
|
||||
entity_config=None,
|
||||
hass=None,
|
||||
local_sdk_webhook_id=None,
|
||||
|
||||
@@ -82,6 +82,7 @@ async def test_sync_message(hass):
|
||||
config,
|
||||
"test-agent",
|
||||
{"requestId": REQ_ID, "inputs": [{"intent": "action.devices.SYNC"}]},
|
||||
const.SOURCE_CLOUD,
|
||||
)
|
||||
|
||||
assert result == {
|
||||
@@ -115,7 +116,7 @@ async def test_sync_message(hass):
|
||||
|
||||
assert len(events) == 1
|
||||
assert events[0].event_type == EVENT_SYNC_RECEIVED
|
||||
assert events[0].data == {"request_id": REQ_ID}
|
||||
assert events[0].data == {"request_id": REQ_ID, "source": "cloud"}
|
||||
|
||||
|
||||
# pylint: disable=redefined-outer-name
|
||||
@@ -148,6 +149,7 @@ async def test_sync_in_area(hass, registries):
|
||||
config,
|
||||
"test-agent",
|
||||
{"requestId": REQ_ID, "inputs": [{"intent": "action.devices.SYNC"}]},
|
||||
const.SOURCE_CLOUD,
|
||||
)
|
||||
|
||||
assert result == {
|
||||
@@ -181,7 +183,7 @@ async def test_sync_in_area(hass, registries):
|
||||
|
||||
assert len(events) == 1
|
||||
assert events[0].event_type == EVENT_SYNC_RECEIVED
|
||||
assert events[0].data == {"request_id": REQ_ID}
|
||||
assert events[0].data == {"request_id": REQ_ID, "source": "cloud"}
|
||||
|
||||
|
||||
async def test_query_message(hass):
|
||||
@@ -220,6 +222,7 @@ async def test_query_message(hass):
|
||||
}
|
||||
],
|
||||
},
|
||||
const.SOURCE_CLOUD,
|
||||
)
|
||||
|
||||
assert result == {
|
||||
@@ -247,11 +250,23 @@ async def test_query_message(hass):
|
||||
|
||||
assert len(events) == 3
|
||||
assert events[0].event_type == EVENT_QUERY_RECEIVED
|
||||
assert events[0].data == {"request_id": REQ_ID, "entity_id": "light.demo_light"}
|
||||
assert events[0].data == {
|
||||
"request_id": REQ_ID,
|
||||
"entity_id": "light.demo_light",
|
||||
"source": "cloud",
|
||||
}
|
||||
assert events[1].event_type == EVENT_QUERY_RECEIVED
|
||||
assert events[1].data == {"request_id": REQ_ID, "entity_id": "light.another_light"}
|
||||
assert events[1].data == {
|
||||
"request_id": REQ_ID,
|
||||
"entity_id": "light.another_light",
|
||||
"source": "cloud",
|
||||
}
|
||||
assert events[2].event_type == EVENT_QUERY_RECEIVED
|
||||
assert events[2].data == {"request_id": REQ_ID, "entity_id": "light.non_existing"}
|
||||
assert events[2].data == {
|
||||
"request_id": REQ_ID,
|
||||
"entity_id": "light.non_existing",
|
||||
"source": "cloud",
|
||||
}
|
||||
|
||||
|
||||
async def test_execute(hass):
|
||||
@@ -300,6 +315,7 @@ async def test_execute(hass):
|
||||
}
|
||||
],
|
||||
},
|
||||
const.SOURCE_CLOUD,
|
||||
)
|
||||
|
||||
assert result == {
|
||||
@@ -341,6 +357,7 @@ async def test_execute(hass):
|
||||
"command": "action.devices.commands.OnOff",
|
||||
"params": {"on": True},
|
||||
},
|
||||
"source": "cloud",
|
||||
}
|
||||
assert events[1].event_type == EVENT_COMMAND_RECEIVED
|
||||
assert events[1].data == {
|
||||
@@ -350,6 +367,7 @@ async def test_execute(hass):
|
||||
"command": "action.devices.commands.BrightnessAbsolute",
|
||||
"params": {"brightness": 20},
|
||||
},
|
||||
"source": "cloud",
|
||||
}
|
||||
assert events[2].event_type == EVENT_COMMAND_RECEIVED
|
||||
assert events[2].data == {
|
||||
@@ -359,6 +377,7 @@ async def test_execute(hass):
|
||||
"command": "action.devices.commands.OnOff",
|
||||
"params": {"on": True},
|
||||
},
|
||||
"source": "cloud",
|
||||
}
|
||||
assert events[3].event_type == EVENT_COMMAND_RECEIVED
|
||||
assert events[3].data == {
|
||||
@@ -368,6 +387,7 @@ async def test_execute(hass):
|
||||
"command": "action.devices.commands.BrightnessAbsolute",
|
||||
"params": {"brightness": 20},
|
||||
},
|
||||
"source": "cloud",
|
||||
}
|
||||
|
||||
assert len(service_events) == 2
|
||||
@@ -424,6 +444,7 @@ async def test_raising_error_trait(hass):
|
||||
}
|
||||
],
|
||||
},
|
||||
const.SOURCE_CLOUD,
|
||||
)
|
||||
|
||||
assert result == {
|
||||
@@ -448,6 +469,7 @@ async def test_raising_error_trait(hass):
|
||||
"command": "action.devices.commands.ThermostatTemperatureSetpoint",
|
||||
"params": {"thermostatTemperatureSetpoint": 10},
|
||||
},
|
||||
"source": "cloud",
|
||||
}
|
||||
|
||||
|
||||
@@ -483,6 +505,7 @@ async def test_unavailable_state_does_sync(hass):
|
||||
BASIC_CONFIG,
|
||||
"test-agent",
|
||||
{"requestId": REQ_ID, "inputs": [{"intent": "action.devices.SYNC"}]},
|
||||
const.SOURCE_CLOUD,
|
||||
)
|
||||
|
||||
assert result == {
|
||||
@@ -515,7 +538,7 @@ async def test_unavailable_state_does_sync(hass):
|
||||
|
||||
assert len(events) == 1
|
||||
assert events[0].event_type == EVENT_SYNC_RECEIVED
|
||||
assert events[0].data == {"request_id": REQ_ID}
|
||||
assert events[0].data == {"request_id": REQ_ID, "source": "cloud"}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -545,6 +568,7 @@ async def test_device_class_switch(hass, device_class, google_type):
|
||||
BASIC_CONFIG,
|
||||
"test-agent",
|
||||
{"requestId": REQ_ID, "inputs": [{"intent": "action.devices.SYNC"}]},
|
||||
const.SOURCE_CLOUD,
|
||||
)
|
||||
|
||||
assert result == {
|
||||
@@ -589,6 +613,7 @@ async def test_device_class_binary_sensor(hass, device_class, google_type):
|
||||
BASIC_CONFIG,
|
||||
"test-agent",
|
||||
{"requestId": REQ_ID, "inputs": [{"intent": "action.devices.SYNC"}]},
|
||||
const.SOURCE_CLOUD,
|
||||
)
|
||||
|
||||
assert result == {
|
||||
@@ -629,6 +654,7 @@ async def test_device_class_cover(hass, device_class, google_type):
|
||||
BASIC_CONFIG,
|
||||
"test-agent",
|
||||
{"requestId": REQ_ID, "inputs": [{"intent": "action.devices.SYNC"}]},
|
||||
const.SOURCE_CLOUD,
|
||||
)
|
||||
|
||||
assert result == {
|
||||
@@ -669,6 +695,7 @@ async def test_device_media_player(hass, device_class, google_type):
|
||||
BASIC_CONFIG,
|
||||
"test-agent",
|
||||
{"requestId": REQ_ID, "inputs": [{"intent": "action.devices.SYNC"}]},
|
||||
const.SOURCE_CLOUD,
|
||||
)
|
||||
|
||||
assert result == {
|
||||
@@ -702,6 +729,7 @@ async def test_query_disconnect(hass):
|
||||
config,
|
||||
"test-agent",
|
||||
{"inputs": [{"intent": "action.devices.DISCONNECT"}], "requestId": REQ_ID},
|
||||
const.SOURCE_CLOUD,
|
||||
)
|
||||
assert result is None
|
||||
assert len(mock_disconnect.mock_calls) == 1
|
||||
@@ -751,6 +779,7 @@ async def test_trait_execute_adding_query_data(hass):
|
||||
}
|
||||
],
|
||||
},
|
||||
const.SOURCE_CLOUD,
|
||||
)
|
||||
|
||||
assert result == {
|
||||
@@ -817,6 +846,7 @@ async def test_identify(hass):
|
||||
}
|
||||
],
|
||||
},
|
||||
const.SOURCE_CLOUD,
|
||||
)
|
||||
|
||||
assert result == {
|
||||
@@ -851,8 +881,11 @@ async def test_reachable_devices(hass):
|
||||
# Not passed in as google_id
|
||||
hass.states.async_set("light.not_mentioned", "on")
|
||||
|
||||
# Has 2FA
|
||||
hass.states.async_set("lock.has_2fa", "on")
|
||||
|
||||
config = MockConfig(
|
||||
should_expose=lambda state: state.entity_id != "light.not_expose"
|
||||
should_expose=lambda state: state.entity_id != "light.not_expose",
|
||||
)
|
||||
|
||||
user_agent_id = "mock-user-id"
|
||||
@@ -898,9 +931,19 @@ async def test_reachable_devices(hass):
|
||||
"webhookId": "dde3b9800a905e886cc4d38e226a6e7e3f2a6993d2b9b9f63d13e42ee7de3219",
|
||||
},
|
||||
},
|
||||
{
|
||||
"id": "lock.has_2fa",
|
||||
"customData": {
|
||||
"httpPort": 8123,
|
||||
"httpSSL": False,
|
||||
"proxyDeviceId": proxy_device_id,
|
||||
"webhookId": "dde3b9800a905e886cc4d38e226a6e7e3f2a6993d2b9b9f63d13e42ee7de3219",
|
||||
},
|
||||
},
|
||||
{"id": proxy_device_id, "customData": {}},
|
||||
],
|
||||
},
|
||||
const.SOURCE_CLOUD,
|
||||
)
|
||||
|
||||
assert result == {
|
||||
|
||||
@@ -51,11 +51,15 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
REQ_ID = "ff36a3cc-ec34-11e6-b1a0-64510650abcf"
|
||||
|
||||
BASIC_DATA = helpers.RequestData(BASIC_CONFIG, "test-agent", REQ_ID, None)
|
||||
BASIC_DATA = helpers.RequestData(
|
||||
BASIC_CONFIG, "test-agent", const.SOURCE_CLOUD, REQ_ID, None
|
||||
)
|
||||
|
||||
PIN_CONFIG = MockConfig(secure_devices_pin="1234")
|
||||
|
||||
PIN_DATA = helpers.RequestData(PIN_CONFIG, "test-agent", REQ_ID, None)
|
||||
PIN_DATA = helpers.RequestData(
|
||||
PIN_CONFIG, "test-agent", const.SOURCE_CLOUD, REQ_ID, None
|
||||
)
|
||||
|
||||
|
||||
async def test_brightness_light(hass):
|
||||
|
||||
Reference in New Issue
Block a user