Google Assistant: Remove speaker type and earlier filter out devices from being locally exposed (#31830)
* Remove speaker type * Do not expose locks or alarms to Google Localpull/31847/head
parent
52b045ed30
commit
4501471b8c
|
@ -133,7 +133,6 @@ DEVICE_CLASS_TO_GOOGLE_TYPES = {
|
||||||
(binary_sensor.DOMAIN, binary_sensor.DEVICE_CLASS_OPENING): TYPE_SENSOR,
|
(binary_sensor.DOMAIN, binary_sensor.DEVICE_CLASS_OPENING): TYPE_SENSOR,
|
||||||
(binary_sensor.DOMAIN, binary_sensor.DEVICE_CLASS_WINDOW): TYPE_SENSOR,
|
(binary_sensor.DOMAIN, binary_sensor.DEVICE_CLASS_WINDOW): TYPE_SENSOR,
|
||||||
(media_player.DOMAIN, media_player.DEVICE_CLASS_TV): TYPE_TV,
|
(media_player.DOMAIN, media_player.DEVICE_CLASS_TV): TYPE_TV,
|
||||||
(media_player.DOMAIN, media_player.DEVICE_CLASS_SPEAKER): TYPE_SPEAKER,
|
|
||||||
(sensor.DOMAIN, sensor.DEVICE_CLASS_TEMPERATURE): TYPE_SENSOR,
|
(sensor.DOMAIN, sensor.DEVICE_CLASS_TEMPERATURE): TYPE_SENSOR,
|
||||||
(sensor.DOMAIN, sensor.DEVICE_CLASS_HUMIDITY): TYPE_SENSOR,
|
(sensor.DOMAIN, sensor.DEVICE_CLASS_HUMIDITY): TYPE_SENSOR,
|
||||||
}
|
}
|
||||||
|
@ -146,3 +145,5 @@ STORE_AGENT_USER_IDS = "agent_user_ids"
|
||||||
|
|
||||||
SOURCE_CLOUD = "cloud"
|
SOURCE_CLOUD = "cloud"
|
||||||
SOURCE_LOCAL = "local"
|
SOURCE_LOCAL = "local"
|
||||||
|
|
||||||
|
NOT_EXPOSE_LOCAL = {TYPE_ALARM, TYPE_LOCK}
|
||||||
|
|
|
@ -28,6 +28,7 @@ from .const import (
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
DOMAIN_TO_GOOGLE_TYPES,
|
DOMAIN_TO_GOOGLE_TYPES,
|
||||||
ERR_FUNCTION_NOT_SUPPORTED,
|
ERR_FUNCTION_NOT_SUPPORTED,
|
||||||
|
NOT_EXPOSE_LOCAL,
|
||||||
SOURCE_LOCAL,
|
SOURCE_LOCAL,
|
||||||
STORE_AGENT_USER_IDS,
|
STORE_AGENT_USER_IDS,
|
||||||
)
|
)
|
||||||
|
@ -351,6 +352,18 @@ class GoogleEntity:
|
||||||
"""If entity should be exposed."""
|
"""If entity should be exposed."""
|
||||||
return self.config.should_expose(self.state)
|
return self.config.should_expose(self.state)
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def should_expose_local(self) -> bool:
|
||||||
|
"""Return if the entity should be exposed locally."""
|
||||||
|
return (
|
||||||
|
self.should_expose()
|
||||||
|
and get_google_type(
|
||||||
|
self.state.domain, self.state.attributes.get(ATTR_DEVICE_CLASS)
|
||||||
|
)
|
||||||
|
not in NOT_EXPOSE_LOCAL
|
||||||
|
and not self.might_2fa()
|
||||||
|
)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def is_supported(self) -> bool:
|
def is_supported(self) -> bool:
|
||||||
"""Return if the entity is supported by Google."""
|
"""Return if the entity is supported by Google."""
|
||||||
|
@ -401,7 +414,7 @@ class GoogleEntity:
|
||||||
if aliases:
|
if aliases:
|
||||||
device["name"]["nicknames"] = [name] + aliases
|
device["name"]["nicknames"] = [name] + aliases
|
||||||
|
|
||||||
if self.config.is_local_sdk_active:
|
if self.config.is_local_sdk_active and self.should_expose_local():
|
||||||
device["otherDeviceIds"] = [{"deviceId": self.entity_id}]
|
device["otherDeviceIds"] = [{"deviceId": self.entity_id}]
|
||||||
device["customData"] = {
|
device["customData"] = {
|
||||||
"webhookId": self.config.local_sdk_webhook_id,
|
"webhookId": self.config.local_sdk_webhook_id,
|
||||||
|
|
|
@ -243,9 +243,7 @@ async def async_devices_reachable(hass, data: RequestData, payload):
|
||||||
"devices": [
|
"devices": [
|
||||||
entity.reachable_device_serialize()
|
entity.reachable_device_serialize()
|
||||||
for entity in async_get_entities(hass, data.config)
|
for entity in async_get_entities(hass, data.config)
|
||||||
if entity.entity_id in google_ids
|
if entity.entity_id in google_ids and entity.should_expose_local()
|
||||||
and entity.should_expose()
|
|
||||||
and not entity.might_2fa()
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import pytest
|
||||||
from homeassistant.components.google_assistant import helpers
|
from homeassistant.components.google_assistant import helpers
|
||||||
from homeassistant.components.google_assistant.const import ( # noqa: F401
|
from homeassistant.components.google_assistant.const import ( # noqa: F401
|
||||||
EVENT_COMMAND_RECEIVED,
|
EVENT_COMMAND_RECEIVED,
|
||||||
|
NOT_EXPOSE_LOCAL,
|
||||||
)
|
)
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
from homeassistant.util import dt
|
from homeassistant.util import dt
|
||||||
|
@ -46,6 +47,15 @@ async def test_google_entity_sync_serialize_with_local_sdk(hass):
|
||||||
"webhookId": "mock-webhook-id",
|
"webhookId": "mock-webhook-id",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for device_type in NOT_EXPOSE_LOCAL:
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.google_assistant.helpers.get_google_type",
|
||||||
|
return_value=device_type,
|
||||||
|
):
|
||||||
|
serialized = await entity.sync_serialize(None)
|
||||||
|
assert "otherDeviceIds" not in serialized
|
||||||
|
assert "customData" not in serialized
|
||||||
|
|
||||||
|
|
||||||
async def test_config_local_sdk(hass, hass_client):
|
async def test_config_local_sdk(hass, hass_client):
|
||||||
"""Test the local SDK."""
|
"""Test the local SDK."""
|
||||||
|
|
|
@ -682,7 +682,6 @@ async def test_device_class_cover(hass, device_class, google_type):
|
||||||
"device_class,google_type",
|
"device_class,google_type",
|
||||||
[
|
[
|
||||||
("non_existing_class", "action.devices.types.SWITCH"),
|
("non_existing_class", "action.devices.types.SWITCH"),
|
||||||
("speaker", "action.devices.types.SPEAKER"),
|
|
||||||
("tv", "action.devices.types.TV"),
|
("tv", "action.devices.types.TV"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue