Guard bad supported features for Google (#42163)

This commit is contained in:
Paulus Schoutsen 2020-10-21 16:37:42 +02:00 committed by GitHub
parent d8577a1550
commit 5626a379de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -343,6 +343,15 @@ class GoogleEntity:
state = self.state
domain = state.domain
features = state.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
if not isinstance(features, int):
_LOGGER.warning(
"Entity %s contains invalid supported_features value %s",
self.entity_id,
features,
)
return []
device_class = state.attributes.get(ATTR_DEVICE_CLASS)
self._traits = [

View File

@ -9,6 +9,7 @@ from homeassistant.components.google_assistant.const import ( # noqa: F401
NOT_EXPOSE_LOCAL,
)
from homeassistant.config import async_process_ha_core_config
from homeassistant.core import State
from homeassistant.setup import async_setup_component
from homeassistant.util import dt
@ -242,3 +243,12 @@ async def test_sync_entities_all(agents, result):
res = await config.async_sync_entities_all()
assert sorted(mock.mock_calls) == sorted([call(agent) for agent in agents])
assert res == result
def test_supported_features_string(caplog):
"""Test bad supported features."""
entity = helpers.GoogleEntity(
None, None, State("test.entity_id", "on", {"supported_features": "invalid"})
)
assert entity.is_supported() is False
assert "Entity test.entity_id contains invalid supported_features value invalid"