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/core/entity/text.md.

文本实体

Text 实体是一种允许用户向集成输入文本值的实体。从 homeassistant.components.text.TextEntity 派生实体平台。

属性

Tip

属性应始终仅返回内存中的信息,而不是执行 I/O(如网络请求)。实现 update()async_update() 来获取数据,或构建一种机制将状态更新推送到实体类实例。

名称类型默认值描述
modestringtext定义文本在 UI 中应如何显示。可以是 textpassword
native_maxint255文本值中字符的最大数量(含)。
native_minint0文本值中字符的最小数量(含)。
patternstrNone文本值必须匹配的 regex 模式。
native_valuestr必填文本的值。

所有实体共有的其他属性(如 iconname 等)也适用。

方法

设置值

class MyTextEntity(TextEntity):
    # 实现以下方法之一。

    def set_value(self, value: str) -> None:
        """Set the text value."""

    async def async_set_value(self, value: str) -> None:
        """Set the text value."""