Skip to content

Commit

Permalink
Turn off not cancellable scripts automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
quthla committed Oct 25, 2018
1 parent 9c7d3c2 commit a043e94
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions homeassistant/components/homekit/type_switches.py
Expand Up @@ -9,6 +9,7 @@
from homeassistant.const import (
ATTR_ENTITY_ID, CONF_TYPE, SERVICE_TURN_ON, SERVICE_TURN_OFF, STATE_ON)
from homeassistant.core import split_entity_id
from homeassistant.helpers.event import async_call_later

from . import TYPES
from .accessories import HomeAccessory
Expand Down Expand Up @@ -84,6 +85,14 @@ def set_state(self, value):
service = SERVICE_TURN_ON if value else SERVICE_TURN_OFF
self.call_service(self._domain, service, params)

state = self.hass.states.get(self.entity_id)
if (service == SERVICE_TURN_ON and
state.domain == 'script' and
not state.attributes.get('can_cancel')):
async def async_turn_off(_):
self.char_on.set_value(False)
self.hass.add_job(async_call_later, self.hass, 1, async_turn_off)

def update_state(self, new_state):
"""Update switch state after state changed."""
current_state = (new_state.state == STATE_ON)
Expand Down

0 comments on commit a043e94

Please sign in to comment.