阀门实体

阀门实体控制阀门设备,例如家中的水阀或燃气阀。平台实体派生自homeassistant.components.valve.ValveEntity

特性

Tip

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

名称类型默认值说明
current_valve_positionint | NoneNone阀门的当前位置,其中 0 表示关闭,100 表示完全打开。具有 reports_position = True 的阀门需要此属性,用于确定状态。
is_closedbool | NoneNone阀门是否关闭。用于确定不报告位置的阀门的 state
is_closingbool | NoneNone阀门是否关闭。用于确定 state
is_openingbool | NoneNone阀门是否打开。用于确定 state
reports_positionboolRequired阀门是否知道其位置。

设备类别

常量说明
ValveDeviceClass.WATER水阀的控制。
ValveDeviceClass.GAS燃气阀的控制。

状态

状态是通过设置其属性来定义的。结果状态是使用 ValveState 枚举返回以下成员之一。

说明
OPENING阀门正在打开以到达设定位置。
OPEN阀门已到达打开位置。
CLOSING阀门正在关闭以达到设定位置。
CLOSED阀门已到达关闭位置。

支持的功能

支持的功能通过使用 ValveEntityFeature 枚举中的值来定义 和 使用按位或 (|) 运算符进行组合。

说明
OPEN阀门支持开启。
CLOSE阀门支持关闭。
SET_POSITION阀门支持移动到打开和关闭之间的特定位置。
STOP阀门支持停止当前动作(开、关、设定位置)

方法

打开阀门

仅当设置了标志 SUPPORT_OPEN 时才实现此方法。对于阀门来说 可以设置位置,该方法不应该实现,只需要set_valve_position

class MyValve(ValveEntity):
    # Implement one of these methods.

    def open_valve(self) -> None:
        """Open the valve."""

    async def async_open_valve(self) -> None:
        """Open the valve."""

关闭阀门

仅当设置了标志 SUPPORT_CLOSE 时才实现此方法。 对于阀门来说 可以设置位置,该方法不应该实现,只需要set_valve_position

class MyValve(ValveEntity):
    # Implement one of these methods.

    def close_valve(self) -> None:
        """Close valve."""

    async def async_close_valve(self) -> None:
        """Close valve."""

设置阀门位置

仅当设置了标志 SUPPORT_SET_POSITION 时才实现此方法。此方法必须在可设定位置的阀门中实施。

class MyValve(ValveEntity):
    # Implement one of these methods.

    def set_valve_position(self, position: int) -> None:
        """Move the valve to a specific position."""

    async def async_set_valve_position(self, position: int) -> None:
        """Move the valve to a specific position."""

截止阀

仅当设置了标志 SUPPORT_STOP 时才实现此方法。

class MyValve(ValveEntity):
    # Implement one of these methods.

    def stop_valve(self) -> None:
        """Stop the valve."""

    async def async_stop_valve(self) -> None:
        """Stop the valve."""