Fix unneeded dict values for MATCH_ALL recorder attrs exclude (#120804)

* Small cleanup to handling MATCH_ALL recorder attrs exclude

* Fix unneeded dict values for MATCH_ALL recorder attrs exclude

The exclude is a set so the dict values were not needed

* Fix unneeded dict values for MATCH_ALL recorder attrs exclude

The exclude is a set so the dict values were not needed

* Fix unneeded dict values for MATCH_ALL recorder attrs exclude

The exclude is a set so the dict values were not needed
This commit is contained in:
J. Nick Koston 2024-06-29 00:42:08 -05:00 committed by Franck Nijhof
parent 0ec07001bd
commit 66932e3d9a
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3

View File

@ -142,6 +142,13 @@ _DEFAULT_TABLE_ARGS = {
"mariadb_engine": MYSQL_ENGINE,
}
_MATCH_ALL_KEEP = {
ATTR_DEVICE_CLASS,
ATTR_STATE_CLASS,
ATTR_UNIT_OF_MEASUREMENT,
ATTR_FRIENDLY_NAME,
}
class UnusedDateTime(DateTime):
"""An unused column type that behaves like a datetime."""
@ -597,19 +604,8 @@ class StateAttributes(Base):
if MATCH_ALL in unrecorded_attributes:
# Don't exclude device class, state class, unit of measurement
# or friendly name when using the MATCH_ALL exclude constant
_exclude_attributes = {
k: v
for k, v in state.attributes.items()
if k
not in (
ATTR_DEVICE_CLASS,
ATTR_STATE_CLASS,
ATTR_UNIT_OF_MEASUREMENT,
ATTR_FRIENDLY_NAME,
)
}
exclude_attrs.update(_exclude_attributes)
exclude_attrs.update(state.attributes)
exclude_attrs -= _MATCH_ALL_KEEP
else:
exclude_attrs = ALL_DOMAIN_EXCLUDE_ATTRS
encoder = json_bytes_strip_null if dialect == PSQL_DIALECT else json_bytes