当前位置: 首页>>代码示例>>Python>>正文


Python Script.async_stop方法代码示例

本文整理汇总了Python中homeassistant.helpers.script.Script.async_stop方法的典型用法代码示例。如果您正苦于以下问题:Python Script.async_stop方法的具体用法?Python Script.async_stop怎么用?Python Script.async_stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在homeassistant.helpers.script.Script的用法示例。


在下文中一共展示了Script.async_stop方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ScriptEntity

# 需要导入模块: from homeassistant.helpers.script import Script [as 别名]
# 或者: from homeassistant.helpers.script.Script import async_stop [as 别名]
class ScriptEntity(ToggleEntity):
    """Representation of a script entity."""

    def __init__(self, hass, object_id, name, sequence):
        """Initialize the script."""
        self.object_id = object_id
        self.entity_id = ENTITY_ID_FORMAT.format(object_id)
        self.script = Script(hass, sequence, name, self.async_update_ha_state)

    @property
    def should_poll(self):
        """No polling needed."""
        return False

    @property
    def name(self):
        """Return the name of the entity."""
        return self.script.name

    @property
    def state_attributes(self):
        """Return the state attributes."""
        attrs = {}
        attrs[ATTR_LAST_TRIGGERED] = self.script.last_triggered
        if self.script.can_cancel:
            attrs[ATTR_CAN_CANCEL] = self.script.can_cancel
        if self.script.last_action:
            attrs[ATTR_LAST_ACTION] = self.script.last_action
        return attrs

    @property
    def is_on(self):
        """Return true if script is on."""
        return self.script.is_running

    async def async_turn_on(self, **kwargs):
        """Turn the script on."""
        context = kwargs.get('context')
        self.async_set_context(context)
        self.hass.bus.async_fire(EVENT_SCRIPT_STARTED, {
            ATTR_NAME: self.script.name,
            ATTR_ENTITY_ID: self.entity_id,
        }, context=context)
        await self.script.async_run(
            kwargs.get(ATTR_VARIABLES), context)

    async def async_turn_off(self, **kwargs):
        """Turn script off."""
        self.script.async_stop()

    async def async_will_remove_from_hass(self):
        """Stop script and remove service when it will be removed from HASS."""
        if self.script.is_running:
            self.script.async_stop()

        # remove service
        self.hass.services.async_remove(DOMAIN, self.object_id)
开发者ID:boced66,项目名称:home-assistant,代码行数:59,代码来源:__init__.py

示例2: ScriptEntity

# 需要导入模块: from homeassistant.helpers.script import Script [as 别名]
# 或者: from homeassistant.helpers.script.Script import async_stop [as 别名]
class ScriptEntity(ToggleEntity):
    """Representation of a script entity."""

    def __init__(self, hass, object_id, name, sequence):
        """Initialize the script."""
        self.object_id = object_id
        self.entity_id = ENTITY_ID_FORMAT.format(object_id)
        self.script = Script(hass, sequence, name, self.async_update_ha_state)

    @property
    def should_poll(self):
        """No polling needed."""
        return False

    @property
    def name(self):
        """Return the name of the entity."""
        return self.script.name

    @property
    def state_attributes(self):
        """Return the state attributes."""
        attrs = {}
        attrs[ATTR_LAST_TRIGGERED] = self.script.last_triggered
        if self.script.can_cancel:
            attrs[ATTR_CAN_CANCEL] = self.script.can_cancel
        if self.script.last_action:
            attrs[ATTR_LAST_ACTION] = self.script.last_action
        return attrs

    @property
    def is_on(self):
        """Return true if script is on."""
        return self.script.is_running

    @asyncio.coroutine
    def async_turn_on(self, **kwargs):
        """Turn the script on."""
        yield from self.script.async_run(kwargs.get(ATTR_VARIABLES))

    @asyncio.coroutine
    def async_turn_off(self, **kwargs):
        """Turn script off."""
        self.script.async_stop()

    def async_remove(self):
        """Remove script from HASS.

        This method must be run in the event loop and returns a coroutine.
        """
        if self.script.is_running:
            self.script.async_stop()

        # remove service
        self.hass.services.async_remove(DOMAIN, self.object_id)

        return super().async_remove()
开发者ID:Khabi,项目名称:home-assistant,代码行数:59,代码来源:script.py

示例3: ScriptEntity

# 需要导入模块: from homeassistant.helpers.script import Script [as 别名]
# 或者: from homeassistant.helpers.script.Script import async_stop [as 别名]
class ScriptEntity(ToggleEntity):
    """Representation of a script entity."""

    def __init__(self, hass, object_id, name, sequence):
        """Initialize the script."""
        self.object_id = object_id
        self.entity_id = ENTITY_ID_FORMAT.format(object_id)
        self.script = Script(hass, sequence, name, self.async_update_ha_state)

    @property
    def should_poll(self):
        """No polling needed."""
        return False

    @property
    def name(self):
        """Return the name of the entity."""
        return self.script.name

    @property
    def state_attributes(self):
        """Return the state attributes."""
        attrs = {}
        if self.script.can_cancel:
            attrs[ATTR_CAN_CANCEL] = self.script.can_cancel
        if self.script.last_action:
            attrs[ATTR_LAST_ACTION] = self.script.last_action
        return attrs

    @property
    def is_on(self):
        """Return true if script is on."""
        return self.script.is_running

    @asyncio.coroutine
    def async_turn_on(self, **kwargs):
        """Turn the script on."""
        yield from self.script.async_run(kwargs.get(ATTR_VARIABLES))

    @asyncio.coroutine
    def async_turn_off(self, **kwargs):
        """Turn script off."""
        self.script.async_stop()
开发者ID:DavidLP,项目名称:home-assistant,代码行数:45,代码来源:script.py


注:本文中的homeassistant.helpers.script.Script.async_stop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。