From bd1d7bdbb78f862b99c5aafd152d03b03990ca43 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sun, 3 Apr 2022 20:37:13 +0200 Subject: [PATCH] Exclude more media player attributes from recorder (#69209) --- .../components/media_player/__init__.py | 3 ++- homeassistant/components/media_player/const.py | 1 + .../components/media_player/recorder.py | 17 +++++++++++++++-- tests/components/media_player/test_recorder.py | 10 ++++++++-- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/media_player/__init__.py b/homeassistant/components/media_player/__init__.py index 8cd8cad2956..0947d8057ed 100644 --- a/homeassistant/components/media_player/__init__.py +++ b/homeassistant/components/media_player/__init__.py @@ -70,6 +70,7 @@ from .browse_media import BrowseMedia, async_process_play_media_url # noqa: F40 from .const import ( # noqa: F401 ATTR_APP_ID, ATTR_APP_NAME, + ATTR_ENTITY_PICTURE_LOCAL, ATTR_GROUP_MEMBERS, ATTR_INPUT_SOURCE, ATTR_INPUT_SOURCE_LIST, @@ -954,7 +955,7 @@ class MediaPlayerEntity(Entity): state_attr[attr] = value if self.media_image_remotely_accessible: - state_attr["entity_picture_local"] = self.media_image_local + state_attr[ATTR_ENTITY_PICTURE_LOCAL] = self.media_image_local return state_attr diff --git a/homeassistant/components/media_player/const.py b/homeassistant/components/media_player/const.py index fcb706250cc..b12f0c4ae01 100644 --- a/homeassistant/components/media_player/const.py +++ b/homeassistant/components/media_player/const.py @@ -6,6 +6,7 @@ CONTENT_AUTH_EXPIRY_TIME = 3600 * 24 ATTR_APP_ID = "app_id" ATTR_APP_NAME = "app_name" +ATTR_ENTITY_PICTURE_LOCAL = "entity_picture_local" ATTR_GROUP_MEMBERS = "group_members" ATTR_INPUT_SOURCE = "source" ATTR_INPUT_SOURCE_LIST = "source_list" diff --git a/homeassistant/components/media_player/recorder.py b/homeassistant/components/media_player/recorder.py index 66bd61c72cd..8ced833ebec 100644 --- a/homeassistant/components/media_player/recorder.py +++ b/homeassistant/components/media_player/recorder.py @@ -4,10 +4,23 @@ from __future__ import annotations from homeassistant.const import ATTR_ENTITY_PICTURE from homeassistant.core import HomeAssistant, callback -from . import ATTR_INPUT_SOURCE_LIST, ATTR_SOUND_MODE_LIST +from . import ( + ATTR_ENTITY_PICTURE_LOCAL, + ATTR_INPUT_SOURCE_LIST, + ATTR_MEDIA_POSITION, + ATTR_MEDIA_POSITION_UPDATED_AT, + ATTR_SOUND_MODE_LIST, +) @callback def exclude_attributes(hass: HomeAssistant) -> set[str]: """Exclude static and token attributes from being recorded in the database.""" - return {ATTR_SOUND_MODE_LIST, ATTR_ENTITY_PICTURE, ATTR_INPUT_SOURCE_LIST} + return { + ATTR_ENTITY_PICTURE_LOCAL, + ATTR_ENTITY_PICTURE, + ATTR_INPUT_SOURCE_LIST, + ATTR_MEDIA_POSITION_UPDATED_AT, + ATTR_MEDIA_POSITION, + ATTR_SOUND_MODE_LIST, + } diff --git a/tests/components/media_player/test_recorder.py b/tests/components/media_player/test_recorder.py index 9532fe75cd0..df1c7cc8da0 100644 --- a/tests/components/media_player/test_recorder.py +++ b/tests/components/media_player/test_recorder.py @@ -5,7 +5,10 @@ from datetime import timedelta from homeassistant.components import media_player from homeassistant.components.media_player.const import ( + ATTR_ENTITY_PICTURE_LOCAL, ATTR_INPUT_SOURCE_LIST, + ATTR_MEDIA_POSITION, + ATTR_MEDIA_POSITION_UPDATED_AT, ATTR_SOUND_MODE_LIST, ) from homeassistant.components.recorder.models import StateAttributes, States @@ -42,7 +45,10 @@ async def test_exclude_attributes(hass): states: list[State] = await hass.async_add_executor_job(_fetch_states) assert len(states) > 1 for state in states: - assert ATTR_SOUND_MODE_LIST not in state.attributes assert ATTR_ENTITY_PICTURE not in state.attributes - assert ATTR_INPUT_SOURCE_LIST not in state.attributes + assert ATTR_ENTITY_PICTURE_LOCAL not in state.attributes assert ATTR_FRIENDLY_NAME in state.attributes + assert ATTR_INPUT_SOURCE_LIST not in state.attributes + assert ATTR_MEDIA_POSITION not in state.attributes + assert ATTR_MEDIA_POSITION_UPDATED_AT not in state.attributes + assert ATTR_SOUND_MODE_LIST not in state.attributes