Fix Cloud UI bug preventing managing Google 2FA (#34241)
* Fix Cloud UI bug preventing managing Google 2FA * Update comment
This commit is contained in:
1 parent
5f97937ba0
commit
0afb849e7f
5 files changed
+28
-10
No files matched your search
@@ -687,20 +687,30 @@ async def test_list_google_entities(hass, hass_ws_client, setup_api, mock_cloud_
|
||||
entity = GoogleEntity(
|
||||
hass, MockConfig(should_expose=lambda *_: False), State("light.kitchen", "on")
|
||||
)
|
||||
entity2 = GoogleEntity(
|
||||
hass,
|
||||
MockConfig(should_expose=lambda *_: True, should_2fa=lambda *_: False),
|
||||
State("cover.garage", "open", {"device_class": "garage"}),
|
||||
)
|
||||
with patch(
|
||||
"homeassistant.components.google_assistant.helpers.async_get_entities",
|
||||
return_value=[entity],
|
||||
return_value=[entity, entity2],
|
||||
):
|
||||
await client.send_json({"id": 5, "type": "cloud/google_assistant/entities"})
|
||||
response = await client.receive_json()
|
||||
|
||||
assert response["success"]
|
||||
assert len(response["result"]) == 1
|
||||
assert len(response["result"]) == 2
|
||||
assert response["result"][0] == {
|
||||
"entity_id": "light.kitchen",
|
||||
"might_2fa": False,
|
||||
"traits": ["action.devices.traits.OnOff"],
|
||||
}
|
||||
assert response["result"][1] == {
|
||||
"entity_id": "cover.garage",
|
||||
"might_2fa": True,
|
||||
"traits": ["action.devices.traits.OpenClose"],
|
||||
}
|
||||
|
||||
|
||||
async def test_update_google_entity(hass, hass_ws_client, setup_api, mock_cloud_login):
|
||||
|
||||
@@ -33,6 +33,7 @@ class MockConfig(helpers.AbstractConfig):
|
||||
"""Initialize config."""
|
||||
super().__init__(hass)
|
||||
self._should_expose = should_expose
|
||||
self._should_2fa = should_2fa
|
||||
self._secure_devices_pin = secure_devices_pin
|
||||
self._entity_config = entity_config or {}
|
||||
self._local_sdk_webhook_id = local_sdk_webhook_id
|
||||
@@ -73,6 +74,10 @@ class MockConfig(helpers.AbstractConfig):
|
||||
"""Expose it all."""
|
||||
return self._should_expose is None or self._should_expose(state)
|
||||
|
||||
def should_2fa(self, state):
|
||||
"""Expose it all."""
|
||||
return self._should_2fa is None or self._should_2fa(state)
|
||||
|
||||
|
||||
BASIC_CONFIG = MockConfig()
|
||||
|
||||
|
||||
@@ -845,10 +845,8 @@ async def test_lock_unlock_unlock(hass):
|
||||
assert err.value.code == const.ERR_CHALLENGE_NOT_SETUP
|
||||
|
||||
# Test with 2FA override
|
||||
with patch(
|
||||
"homeassistant.components.google_assistant.helpers"
|
||||
".AbstractConfig.should_2fa",
|
||||
return_value=False,
|
||||
with patch.object(
|
||||
BASIC_CONFIG, "should_2fa", return_value=False,
|
||||
):
|
||||
await trt.execute(trait.COMMAND_LOCKUNLOCK, BASIC_DATA, {"lock": False}, {})
|
||||
assert len(calls) == 2
|
||||
|
||||
Reference in new issue
Block a user