Fix regression manual alarm

This commit is contained in:
Paulus Schoutsen 2015-10-14 23:38:42 -07:00
parent 8d99c4a0cc
commit 7ba4263284
2 changed files with 25 additions and 4 deletions

View File

@ -40,7 +40,13 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=too-many-arguments, too-many-instance-attributes
# pylint: disable=abstract-method
class ManualAlarm(alarm.AlarmControlPanel):
""" Represents an alarm status. """
"""
Represents an alarm status.
When armed, will be pending for 'pending_time', after that armed.
When triggered, will be pending for 'trigger_time'. After that will be
triggered for 'trigger_time', after that we return to disarmed.
"""
def __init__(self, hass, name, code, pending_time, trigger_time):
self._state = STATE_ALARM_DISARMED
@ -69,9 +75,11 @@ class ManualAlarm(alarm.AlarmControlPanel):
dt_util.utcnow():
return STATE_ALARM_PENDING
if self._state == STATE_ALARM_TRIGGERED and self._trigger_time and \
self._state_ts + self._trigger_time > dt_util.utcnow():
return STATE_ALARM_PENDING
if self._state == STATE_ALARM_TRIGGERED and self._trigger_time:
if self._state_ts + self._trigger_time > dt_util.utcnow():
return STATE_ALARM_PENDING
elif dt_util.utcnow() >= self._state_ts + (2 * self._trigger_time):
return STATE_ALARM_DISARMED
return self._state
@ -128,6 +136,10 @@ class ManualAlarm(alarm.AlarmControlPanel):
self._hass, self.update_ha_state,
self._state_ts + self._trigger_time)
track_point_in_time(
self._hass, self.update_ha_state,
self._state_ts + 2 * self._trigger_time)
def _validate_code(self, code, state):
""" Validate given code. """
check = self._code is None or code == self._code

View File

@ -223,6 +223,15 @@ class TestAlarmControlPanelManual(unittest.TestCase):
self.assertEqual(STATE_ALARM_TRIGGERED,
self.hass.states.get(entity_id).state)
future = dt_util.utcnow() + timedelta(seconds=2)
with patch(('homeassistant.components.alarm_control_panel.manual.'
'dt_util.utcnow'), return_value=future):
fire_time_changed(self.hass, future)
self.hass.pool.block_till_done()
self.assertEqual(STATE_ALARM_DISARMED,
self.hass.states.get(entity_id).state)
def test_disarm_while_pending_trigger(self):
self.assertTrue(alarm_control_panel.setup(self.hass, {
'alarm_control_panel': {