For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /developers/blog/2024-06-22-excluding-state-attributes-from-recording-match-all.md.

使用 MATCH_ALL 从 recording 中排除所有 state attribute

从 recording 中排除 state attribute 的方式在 2023 年 9 月之前已经更改过。

之前的实现存在局限性,因为没有方法可以处理动态 attribute,也没有简单的方法来简单地排除所有 attribute,而不是逐一列出它们。

现在可以在集成中使用 MATCH_ALL 常量来告诉 recording 不要记录任何 attribute,这将自动从 recording 中移除所有 attribute,但 device_classstate_classunit_of_measurementfriendly_name 除外。

from homeassistant.const import MATCH_ALL

class ExampleEntity(Entity):
    """一个 entity 的实现。"""

    _unrecorded_attributes = frozenset({MATCH_ALL})

更多详情请参阅 entity 文档

原始更改的背景在 architecture discussion #964 中。