Remove unused entity_sources argument from shared_attrs_bytes_from_event (#108210)

This commit is contained in:
J. Nick Koston 2024-01-17 03:45:04 -10:00 committed by GitHub
parent 2cd828b2d0
commit 15384f4661
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 10 deletions

View File

@ -40,7 +40,6 @@ from homeassistant.const import (
MAX_LENGTH_STATE_STATE, MAX_LENGTH_STATE_STATE,
) )
from homeassistant.core import Context, Event, EventOrigin, State from homeassistant.core import Context, Event, EventOrigin, State
from homeassistant.helpers.entity import EntityInfo
from homeassistant.helpers.json import JSON_DUMP, json_bytes, json_bytes_strip_null from homeassistant.helpers.json import JSON_DUMP, json_bytes, json_bytes_strip_null
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
from homeassistant.util.json import ( from homeassistant.util.json import (
@ -563,7 +562,6 @@ class StateAttributes(Base):
@staticmethod @staticmethod
def shared_attrs_bytes_from_event( def shared_attrs_bytes_from_event(
event: Event, event: Event,
entity_sources: dict[str, EntityInfo],
dialect: SupportedDialect | None, dialect: SupportedDialect | None,
) -> bytes: ) -> bytes:
"""Create shared_attrs from a state_changed event.""" """Create shared_attrs from a state_changed event."""
@ -571,9 +569,13 @@ class StateAttributes(Base):
# None state means the state was removed from the state machine # None state means the state was removed from the state machine
if state is None: if state is None:
return b"{}" return b"{}"
exclude_attrs = set(ALL_DOMAIN_EXCLUDE_ATTRS)
if state_info := state.state_info: if state_info := state.state_info:
exclude_attrs |= state_info["unrecorded_attributes"] exclude_attrs = {
*ALL_DOMAIN_EXCLUDE_ATTRS,
*state_info["unrecorded_attributes"],
}
else:
exclude_attrs = ALL_DOMAIN_EXCLUDE_ATTRS
encoder = json_bytes_strip_null if dialect == PSQL_DIALECT else json_bytes encoder = json_bytes_strip_null if dialect == PSQL_DIALECT else json_bytes
bytes_result = encoder( bytes_result = encoder(
{k: v for k, v in state.attributes.items() if k not in exclude_attrs} {k: v for k, v in state.attributes.items() if k not in exclude_attrs}

View File

@ -8,7 +8,6 @@ from typing import TYPE_CHECKING, cast
from sqlalchemy.orm.session import Session from sqlalchemy.orm.session import Session
from homeassistant.core import Event from homeassistant.core import Event
from homeassistant.helpers.entity import entity_sources
from homeassistant.util.json import JSON_ENCODE_EXCEPTIONS from homeassistant.util.json import JSON_ENCODE_EXCEPTIONS
from ..db_schema import StateAttributes from ..db_schema import StateAttributes
@ -37,15 +36,12 @@ class StateAttributesManager(BaseLRUTableManager[StateAttributes]):
"""Initialize the event type manager.""" """Initialize the event type manager."""
super().__init__(recorder, CACHE_SIZE) super().__init__(recorder, CACHE_SIZE)
self.active = True # always active self.active = True # always active
self._entity_sources = entity_sources(recorder.hass)
def serialize_from_event(self, event: Event) -> bytes | None: def serialize_from_event(self, event: Event) -> bytes | None:
"""Serialize event data.""" """Serialize event data."""
try: try:
return StateAttributes.shared_attrs_bytes_from_event( return StateAttributes.shared_attrs_bytes_from_event(
event, event, self.recorder.dialect_name
self._entity_sources,
self.recorder.dialect_name,
) )
except JSON_ENCODE_EXCEPTIONS as ex: except JSON_ENCODE_EXCEPTIONS as ex:
_LOGGER.warning( _LOGGER.warning(

View File

@ -77,7 +77,7 @@ def test_from_event_to_db_state_attributes() -> None:
dialect = SupportedDialect.MYSQL dialect = SupportedDialect.MYSQL
db_attrs.shared_attrs = StateAttributes.shared_attrs_bytes_from_event( db_attrs.shared_attrs = StateAttributes.shared_attrs_bytes_from_event(
event, {}, dialect event, dialect
) )
assert db_attrs.to_native() == attrs assert db_attrs.to_native() == attrs