Fix another manual alarm regression
parent
2dd77f9477
commit
5dfd0d2502
|
@ -76,9 +76,10 @@ class ManualAlarm(alarm.AlarmControlPanel):
|
|||
return STATE_ALARM_PENDING
|
||||
|
||||
if self._state == STATE_ALARM_TRIGGERED and self._trigger_time:
|
||||
if self._state_ts + self._trigger_time > dt_util.utcnow():
|
||||
if self._state_ts + self._pending_time > dt_util.utcnow():
|
||||
return STATE_ALARM_PENDING
|
||||
elif dt_util.utcnow() >= self._state_ts + (2 * self._trigger_time):
|
||||
elif (self._state_ts + self._pending_time +
|
||||
self._trigger_time) < dt_util.utcnow():
|
||||
return STATE_ALARM_DISARMED
|
||||
|
||||
return self._state
|
||||
|
@ -134,11 +135,11 @@ class ManualAlarm(alarm.AlarmControlPanel):
|
|||
if self._trigger_time:
|
||||
track_point_in_time(
|
||||
self._hass, self.update_ha_state,
|
||||
self._state_ts + self._trigger_time)
|
||||
self._state_ts + self._pending_time)
|
||||
|
||||
track_point_in_time(
|
||||
self._hass, self.update_ha_state,
|
||||
self._state_ts + 2 * self._trigger_time)
|
||||
self._state_ts + self._pending_time + self._trigger_time)
|
||||
|
||||
def _validate_code(self, code, state):
|
||||
""" Validate given code. """
|
||||
|
|
|
@ -200,7 +200,8 @@ class TestAlarmControlPanelManual(unittest.TestCase):
|
|||
'alarm_control_panel': {
|
||||
'platform': 'manual',
|
||||
'name': 'test',
|
||||
'trigger_time': 1
|
||||
'pending_time': 2,
|
||||
'trigger_time': 3
|
||||
}}))
|
||||
|
||||
entity_id = 'alarm_control_panel.test'
|
||||
|
@ -214,7 +215,7 @@ class TestAlarmControlPanelManual(unittest.TestCase):
|
|||
self.assertEqual(STATE_ALARM_PENDING,
|
||||
self.hass.states.get(entity_id).state)
|
||||
|
||||
future = dt_util.utcnow() + timedelta(seconds=1)
|
||||
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)
|
||||
|
@ -223,7 +224,7 @@ class TestAlarmControlPanelManual(unittest.TestCase):
|
|||
self.assertEqual(STATE_ALARM_TRIGGERED,
|
||||
self.hass.states.get(entity_id).state)
|
||||
|
||||
future = dt_util.utcnow() + timedelta(seconds=2)
|
||||
future = dt_util.utcnow() + timedelta(seconds=5)
|
||||
with patch(('homeassistant.components.alarm_control_panel.manual.'
|
||||
'dt_util.utcnow'), return_value=future):
|
||||
fire_time_changed(self.hass, future)
|
||||
|
@ -271,7 +272,7 @@ class TestAlarmControlPanelManual(unittest.TestCase):
|
|||
'alarm_control_panel': {
|
||||
'platform': 'manual',
|
||||
'name': 'test',
|
||||
'trigger_time': 5,
|
||||
'pending_time': 5,
|
||||
'code': CODE + '2'
|
||||
}}))
|
||||
|
||||
|
|
Loading…
Reference in New Issue