选择实体

select 是一个实体,允许用户从集成提供的有限选项列表中选择一个选项。平台实体派生自homeassistant.components.select.SelectEntity

该实体仅应在没有更好的拟合选项可用的情况下使用。 例如,灯泡可以具有用户可选择的灯光效果。虽然这可以使用 select 实体来完成,但它实际上应该是 light 实体的一部分,该实体已经支持灯光效果。

特性

Tip

属性应该始终只从内存返回信息,而不执行 I/O(如网络请求)。实现 update()async_update() 来获取数据。

名称类型默认值说明
current_optionstrNone当前选择的选项
optionslistRequired可用选项列表(字符串形式)

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

方法

选择选项

当用户或自动化想要更改当前选定的选项时调用。

class MySelect(SelectEntity):
    # Implement one of these methods.

    def select_option(self, option: str) -> None:
        """Change the selected option."""

    async def async_select_option(self, option: str) -> None:
        """Change the selected option."""