mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Remove unused entity_sources argument from shared_attrs_bytes_from_event (#108210)
This commit is contained in:
parent
2cd828b2d0
commit
15384f4661
@ -40,7 +40,6 @@ from homeassistant.const import (
|
||||
MAX_LENGTH_STATE_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
|
||||
import homeassistant.util.dt as dt_util
|
||||
from homeassistant.util.json import (
|
||||
@ -563,7 +562,6 @@ class StateAttributes(Base):
|
||||
@staticmethod
|
||||
def shared_attrs_bytes_from_event(
|
||||
event: Event,
|
||||
entity_sources: dict[str, EntityInfo],
|
||||
dialect: SupportedDialect | None,
|
||||
) -> bytes:
|
||||
"""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
|
||||
if state is None:
|
||||
return b"{}"
|
||||
exclude_attrs = set(ALL_DOMAIN_EXCLUDE_ATTRS)
|
||||
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
|
||||
bytes_result = encoder(
|
||||
{k: v for k, v in state.attributes.items() if k not in exclude_attrs}
|
||||
|
@ -8,7 +8,6 @@ from typing import TYPE_CHECKING, cast
|
||||
from sqlalchemy.orm.session import Session
|
||||
|
||||
from homeassistant.core import Event
|
||||
from homeassistant.helpers.entity import entity_sources
|
||||
from homeassistant.util.json import JSON_ENCODE_EXCEPTIONS
|
||||
|
||||
from ..db_schema import StateAttributes
|
||||
@ -37,15 +36,12 @@ class StateAttributesManager(BaseLRUTableManager[StateAttributes]):
|
||||
"""Initialize the event type manager."""
|
||||
super().__init__(recorder, CACHE_SIZE)
|
||||
self.active = True # always active
|
||||
self._entity_sources = entity_sources(recorder.hass)
|
||||
|
||||
def serialize_from_event(self, event: Event) -> bytes | None:
|
||||
"""Serialize event data."""
|
||||
try:
|
||||
return StateAttributes.shared_attrs_bytes_from_event(
|
||||
event,
|
||||
self._entity_sources,
|
||||
self.recorder.dialect_name,
|
||||
event, self.recorder.dialect_name
|
||||
)
|
||||
except JSON_ENCODE_EXCEPTIONS as ex:
|
||||
_LOGGER.warning(
|
||||
|
@ -77,7 +77,7 @@ def test_from_event_to_db_state_attributes() -> None:
|
||||
dialect = SupportedDialect.MYSQL
|
||||
|
||||
db_attrs.shared_attrs = StateAttributes.shared_attrs_bytes_from_event(
|
||||
event, {}, dialect
|
||||
event, dialect
|
||||
)
|
||||
assert db_attrs.to_native() == attrs
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user