Exemplo n.º 1
0
    def test_trigger_with_zero_specific_trigger_time(self):
        """Test trigger method."""
        assert setup_component(
            self.hass, alarm_control_panel.DOMAIN,
            {'alarm_control_panel': {
                'platform': 'manual',
                'name': 'test',
                'trigger_time': 5,
                'disarmed': {
                    'trigger_time': 0
                },
                'pending_time': 0,
                'disarm_after_trigger': True
            }})

        entity_id = 'alarm_control_panel.test'

        assert STATE_ALARM_DISARMED == \
            self.hass.states.get(entity_id).state

        common.alarm_trigger(self.hass, entity_id=entity_id)
        self.hass.block_till_done()

        assert STATE_ALARM_DISARMED == \
            self.hass.states.get(entity_id).state
Exemplo n.º 2
0
    def test_trigger_with_specific_trigger_time(self):
        """Test disarm after trigger."""
        assert setup_component(
            self.hass, alarm_control_panel.DOMAIN,
            {'alarm_control_panel': {
                'platform': 'manual',
                'name': 'test',
                'disarmed': {
                    'trigger_time': 5
                },
                'pending_time': 0,
                'disarm_after_trigger': True
            }})

        entity_id = 'alarm_control_panel.test'

        assert STATE_ALARM_DISARMED == \
            self.hass.states.get(entity_id).state

        common.alarm_trigger(self.hass, entity_id=entity_id)
        self.hass.block_till_done()

        assert STATE_ALARM_TRIGGERED == \
            self.hass.states.get(entity_id).state

        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)
            self.hass.block_till_done()

        assert STATE_ALARM_DISARMED == \
            self.hass.states.get(entity_id).state
Exemplo n.º 3
0
    def test_trigger_no_pending(self):
        """Test triggering when no pending submitted method."""
        assert setup_component(
            self.hass, alarm_control_panel.DOMAIN,
            {'alarm_control_panel': {
                'platform': 'manual',
                'name': 'test',
                'trigger_time': 1,
                'disarm_after_trigger': False
            }})

        entity_id = 'alarm_control_panel.test'

        assert STATE_ALARM_DISARMED == \
            self.hass.states.get(entity_id).state

        common.alarm_trigger(self.hass, entity_id=entity_id)
        self.hass.block_till_done()

        assert STATE_ALARM_PENDING == \
            self.hass.states.get(entity_id).state

        future = dt_util.utcnow() + timedelta(seconds=60)
        with patch(('homeassistant.components.alarm_control_panel.manual.'
                    'dt_util.utcnow'), return_value=future):
            fire_time_changed(self.hass, future)
            self.hass.block_till_done()

        assert STATE_ALARM_TRIGGERED == \
            self.hass.states.get(entity_id).state
Exemplo n.º 4
0
    def test_trigger_with_pending_and_specific_delay(self):
        """Test trigger method and switch from pending to triggered."""
        assert setup_component(
            self.hass, alarm_control_panel.DOMAIN,
            {'alarm_control_panel': {
                'platform': 'manual',
                'name': 'test',
                'code': CODE,
                'delay_time': 10,
                'pending_time': 0,
                'armed_away': {
                    'delay_time': 1
                },
                'triggered': {
                    'pending_time': 1
                },
                'disarm_after_trigger': False
            }})

        entity_id = 'alarm_control_panel.test'

        assert STATE_ALARM_DISARMED == \
            self.hass.states.get(entity_id).state

        common.alarm_arm_away(self.hass, CODE)
        self.hass.block_till_done()

        assert STATE_ALARM_ARMED_AWAY == \
            self.hass.states.get(entity_id).state

        common.alarm_trigger(self.hass, entity_id=entity_id)
        self.hass.block_till_done()

        state = self.hass.states.get(entity_id)
        assert state.state == STATE_ALARM_PENDING
        assert state.attributes['post_pending_state'] == STATE_ALARM_TRIGGERED

        future = dt_util.utcnow() + timedelta(seconds=1)
        with patch(('homeassistant.components.alarm_control_panel.manual.'
                    'dt_util.utcnow'), return_value=future):
            fire_time_changed(self.hass, future)
            self.hass.block_till_done()

        state = self.hass.states.get(entity_id)
        assert state.state == STATE_ALARM_PENDING
        assert state.attributes['post_pending_state'] == STATE_ALARM_TRIGGERED

        future += timedelta(seconds=1)
        with patch(('homeassistant.components.alarm_control_panel.manual.'
                    'dt_util.utcnow'), return_value=future):
            fire_time_changed(self.hass, future)
            self.hass.block_till_done()

        state = self.hass.states.get(entity_id)
        assert state.state == STATE_ALARM_TRIGGERED
Exemplo n.º 5
0
    def test_back_to_back_trigger_with_no_disarm_after_trigger(self):
        """Test disarm after trigger."""
        self.assertTrue(setup_component(
            self.hass, alarm_control_panel.DOMAIN,
            {'alarm_control_panel': {
                'platform': 'manual',
                'name': 'test',
                'trigger_time': 5,
                'pending_time': 0,
                'disarm_after_trigger': False
            }}))

        entity_id = 'alarm_control_panel.test'

        self.assertEqual(STATE_ALARM_DISARMED,
                         self.hass.states.get(entity_id).state)

        common.alarm_arm_away(self.hass, CODE, entity_id)
        self.hass.block_till_done()

        self.assertEqual(STATE_ALARM_ARMED_AWAY,
                         self.hass.states.get(entity_id).state)

        common.alarm_trigger(self.hass, entity_id=entity_id)
        self.hass.block_till_done()

        self.assertEqual(STATE_ALARM_TRIGGERED,
                         self.hass.states.get(entity_id).state)

        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)
            self.hass.block_till_done()

        self.assertEqual(STATE_ALARM_ARMED_AWAY,
                         self.hass.states.get(entity_id).state)

        common.alarm_trigger(self.hass, entity_id=entity_id)
        self.hass.block_till_done()

        self.assertEqual(STATE_ALARM_TRIGGERED,
                         self.hass.states.get(entity_id).state)

        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)
            self.hass.block_till_done()

        self.assertEqual(STATE_ALARM_ARMED_AWAY,
                         self.hass.states.get(entity_id).state)
Exemplo n.º 6
0
    def test_trigger_with_pending(self):
        """Test arm home method."""
        assert setup_component(
            self.hass, alarm_control_panel.DOMAIN,
            {'alarm_control_panel': {
                'platform': 'manual',
                'name': 'test',
                'pending_time': 2,
                'trigger_time': 3,
                'disarm_after_trigger': False
            }})

        entity_id = 'alarm_control_panel.test'

        assert STATE_ALARM_DISARMED == \
            self.hass.states.get(entity_id).state

        common.alarm_trigger(self.hass)
        self.hass.block_till_done()

        assert STATE_ALARM_PENDING == \
            self.hass.states.get(entity_id).state

        state = self.hass.states.get(entity_id)
        assert state.attributes['post_pending_state'] == STATE_ALARM_TRIGGERED

        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.block_till_done()

        state = self.hass.states.get(entity_id)
        assert state.state == STATE_ALARM_TRIGGERED

        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)
            self.hass.block_till_done()

        state = self.hass.states.get(entity_id)
        assert state.state == STATE_ALARM_DISARMED
Exemplo n.º 7
0
    def test_trigger_with_specific_pending(self):
        """Test arm home method."""
        self.assertTrue(setup_component(
            self.hass, alarm_control_panel.DOMAIN,
            {'alarm_control_panel': {
                'platform': 'manual',
                'name': 'test',
                'pending_time': 10,
                'triggered': {
                    'pending_time': 2
                },
                'trigger_time': 3,
                'disarm_after_trigger': False
            }}))

        entity_id = 'alarm_control_panel.test'

        common.alarm_trigger(self.hass)
        self.hass.block_till_done()

        self.assertEqual(STATE_ALARM_PENDING,
                         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.block_till_done()

        self.assertEqual(STATE_ALARM_TRIGGERED,
                         self.hass.states.get(entity_id).state)

        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)
            self.hass.block_till_done()

        self.assertEqual(STATE_ALARM_DISARMED,
                         self.hass.states.get(entity_id).state)
Exemplo n.º 8
0
    def test_trigger_zero_trigger_time_with_pending(self):
        """Test disabled trigger."""
        assert setup_component(
            self.hass, alarm_control_panel.DOMAIN,
            {'alarm_control_panel': {
                'platform': 'manual',
                'name': 'test',
                'pending_time': 2,
                'trigger_time': 0,
                'disarm_after_trigger': False
            }})

        entity_id = 'alarm_control_panel.test'

        assert STATE_ALARM_DISARMED == \
            self.hass.states.get(entity_id).state

        common.alarm_trigger(self.hass)
        self.hass.block_till_done()

        assert STATE_ALARM_DISARMED == \
            self.hass.states.get(entity_id).state
Exemplo n.º 9
0
    def test_trigger_zero_trigger_time(self):
        """Test disabled trigger."""
        self.assertTrue(setup_component(
            self.hass, alarm_control_panel.DOMAIN,
            {'alarm_control_panel': {
                'platform': 'manual',
                'name': 'test',
                'pending_time': 0,
                'trigger_time': 0,
                'disarm_after_trigger': False
            }}))

        entity_id = 'alarm_control_panel.test'

        self.assertEqual(STATE_ALARM_DISARMED,
                         self.hass.states.get(entity_id).state)

        common.alarm_trigger(self.hass)
        self.hass.block_till_done()

        self.assertEqual(STATE_ALARM_DISARMED,
                         self.hass.states.get(entity_id).state)
Exemplo n.º 10
0
    def test_disarm_during_trigger_with_invalid_code(self):
        """Test disarming while code is invalid."""
        assert setup_component(
            self.hass, alarm_control_panel.DOMAIN,
            {'alarm_control_panel': {
                'platform': 'manual',
                'name': 'test',
                'pending_time': 5,
                'code': CODE + '2',
                'disarm_after_trigger': False
            }})

        entity_id = 'alarm_control_panel.test'

        assert STATE_ALARM_DISARMED == \
            self.hass.states.get(entity_id).state

        common.alarm_trigger(self.hass)
        self.hass.block_till_done()

        assert STATE_ALARM_PENDING == \
            self.hass.states.get(entity_id).state

        common.alarm_disarm(self.hass, entity_id=entity_id)
        self.hass.block_till_done()

        assert STATE_ALARM_PENDING == \
            self.hass.states.get(entity_id).state

        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)
            self.hass.block_till_done()

        assert STATE_ALARM_TRIGGERED == \
            self.hass.states.get(entity_id).state
Exemplo n.º 11
0
    def test_arm_away_after_disabled_disarmed(self):
        """Test pending state with and without zero trigger time."""
        self.assertTrue(setup_component(
            self.hass, alarm_control_panel.DOMAIN,
            {'alarm_control_panel': {
                'platform': 'manual',
                'name': 'test',
                'code': CODE,
                'pending_time': 0,
                'delay_time': 1,
                'armed_away': {
                    'pending_time': 1,
                },
                'disarmed': {
                    'trigger_time': 0
                },
                'disarm_after_trigger': False
            }}))

        entity_id = 'alarm_control_panel.test'

        self.assertEqual(STATE_ALARM_DISARMED,
                         self.hass.states.get(entity_id).state)

        common.alarm_arm_away(self.hass, CODE)
        self.hass.block_till_done()

        state = self.hass.states.get(entity_id)
        self.assertEqual(STATE_ALARM_PENDING, state.state)
        self.assertEqual(STATE_ALARM_DISARMED,
                         state.attributes['pre_pending_state'])
        self.assertEqual(STATE_ALARM_ARMED_AWAY,
                         state.attributes['post_pending_state'])

        common.alarm_trigger(self.hass, entity_id=entity_id)
        self.hass.block_till_done()

        state = self.hass.states.get(entity_id)
        self.assertEqual(STATE_ALARM_PENDING, state.state)
        self.assertEqual(STATE_ALARM_DISARMED,
                         state.attributes['pre_pending_state'])
        self.assertEqual(STATE_ALARM_ARMED_AWAY,
                         state.attributes['post_pending_state'])

        future = dt_util.utcnow() + timedelta(seconds=1)
        with patch(('homeassistant.components.alarm_control_panel.manual.'
                    'dt_util.utcnow'), return_value=future):
            fire_time_changed(self.hass, future)
            self.hass.block_till_done()

            state = self.hass.states.get(entity_id)
            self.assertEqual(STATE_ALARM_ARMED_AWAY, state.state)

            common.alarm_trigger(self.hass, entity_id=entity_id)
            self.hass.block_till_done()

            state = self.hass.states.get(entity_id)
            self.assertEqual(STATE_ALARM_PENDING, state.state)
            self.assertEqual(STATE_ALARM_ARMED_AWAY,
                             state.attributes['pre_pending_state'])
            self.assertEqual(STATE_ALARM_TRIGGERED,
                             state.attributes['post_pending_state'])

        future += timedelta(seconds=1)
        with patch(('homeassistant.components.alarm_control_panel.manual.'
                    'dt_util.utcnow'), return_value=future):
            fire_time_changed(self.hass, future)
            self.hass.block_till_done()

        state = self.hass.states.get(entity_id)
        self.assertEqual(STATE_ALARM_TRIGGERED, state.state)