Exemplo n.º 1
0
    def test_arm_home_with_pending(self):
        """Test arm home method."""
        self.assertTrue(alarm_control_panel.setup(self.hass, {
            'alarm_control_panel': {
                'platform': 'virtual',
                'name': 'test',
                'code': CODE,
                'pending_time': 1
            }}))

        entity_id = 'alarm_control_panel.test'

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

        alarm_control_panel.alarm_arm_home(self.hass, CODE, entity_id)
        self.hass.pool.block_till_done()

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

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

        self.assertEqual(STATE_ALARM_ARMED_HOME,
                         self.hass.states.get(entity_id).state)
Exemplo n.º 2
0
    def test_arm_home_with_pending(self):
        """Test arm home method."""
        self.assertTrue(
            alarm_control_panel.setup(
                self.hass, {
                    'alarm_control_panel': {
                        'platform': 'virtual',
                        'name': 'test',
                        'code': CODE,
                        'pending_time': 1
                    }
                }))

        entity_id = 'alarm_control_panel.test'

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

        alarm_control_panel.alarm_arm_home(self.hass, CODE, entity_id)
        self.hass.pool.block_till_done()

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

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

        self.assertEqual(STATE_ALARM_ARMED_HOME,
                         self.hass.states.get(entity_id).state)
Exemplo n.º 3
0
    def test_disarm_during_trigger_with_invalid_code(self):
        """Test disarming while code is invalid."""
        self.assertTrue(alarm_control_panel.setup(self.hass, {
            'alarm_control_panel': {
                'platform': 'virtual',
                'name': 'test',
                'pending_time': 5,
                'code': CODE + '2'
            }}))

        entity_id = 'alarm_control_panel.test'

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

        alarm_control_panel.alarm_trigger(self.hass)
        self.hass.pool.block_till_done()

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

        alarm_control_panel.alarm_disarm(self.hass, entity_id=entity_id)
        self.hass.pool.block_till_done()

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

        future = dt_util.utcnow() + timedelta(seconds=5)
        with patch(('blumate.components.alarm_control_panel.virtual.'
                    'dt_util.utcnow'), return_value=future):
            fire_time_changed(self.hass, future)
            self.hass.pool.block_till_done()

        self.assertEqual(STATE_ALARM_TRIGGERED,
                         self.hass.states.get(entity_id).state)
Exemplo n.º 4
0
    def test_trigger_no_pending(self):
        """Test arm home method."""
        self.assertTrue(alarm_control_panel.setup(self.hass, {
            'alarm_control_panel': {
                'platform': 'virtual',
                'name': 'test',
                'trigger_time': 0
            }}))

        entity_id = 'alarm_control_panel.test'

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

        alarm_control_panel.alarm_trigger(self.hass, entity_id=entity_id)
        self.hass.pool.block_till_done()

        self.assertEqual(STATE_ALARM_TRIGGERED,
                         self.hass.states.get(entity_id).state)
Exemplo n.º 5
0
    def test_arm_away_no_pending(self):
        """Test arm home method."""
        self.assertTrue(alarm_control_panel.setup(self.hass, {
            'alarm_control_panel': {
                'platform': 'virtual',
                'name': 'test',
                'code': CODE,
                'pending_time': 0
            }}))

        entity_id = 'alarm_control_panel.test'

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

        alarm_control_panel.alarm_arm_away(self.hass, CODE, entity_id)
        self.hass.pool.block_till_done()

        self.assertEqual(STATE_ALARM_ARMED_AWAY,
                         self.hass.states.get(entity_id).state)
Exemplo n.º 6
0
    def test_arm_home_with_invalid_code(self):
        """Attempt to arm home without a valid code."""
        self.assertTrue(alarm_control_panel.setup(self.hass, {
            'alarm_control_panel': {
                'platform': 'virtual',
                'name': 'test',
                'code': CODE,
                'pending_time': 1
            }}))

        entity_id = 'alarm_control_panel.test'

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

        alarm_control_panel.alarm_arm_home(self.hass, CODE + '2')
        self.hass.pool.block_till_done()

        self.assertEqual(STATE_ALARM_DISARMED,
                         self.hass.states.get(entity_id).state)
Exemplo n.º 7
0
    def test_disarm_during_trigger_with_invalid_code(self):
        """Test disarming while code is invalid."""
        self.assertTrue(
            alarm_control_panel.setup(
                self.hass, {
                    'alarm_control_panel': {
                        'platform': 'virtual',
                        'name': 'test',
                        'pending_time': 5,
                        'code': CODE + '2'
                    }
                }))

        entity_id = 'alarm_control_panel.test'

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

        alarm_control_panel.alarm_trigger(self.hass)
        self.hass.pool.block_till_done()

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

        alarm_control_panel.alarm_disarm(self.hass, entity_id=entity_id)
        self.hass.pool.block_till_done()

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

        future = dt_util.utcnow() + timedelta(seconds=5)
        with patch(('blumate.components.alarm_control_panel.virtual.'
                    'dt_util.utcnow'),
                   return_value=future):
            fire_time_changed(self.hass, future)
            self.hass.pool.block_till_done()

        self.assertEqual(STATE_ALARM_TRIGGERED,
                         self.hass.states.get(entity_id).state)
Exemplo n.º 8
0
    def test_trigger_no_pending(self):
        """Test arm home method."""
        self.assertTrue(
            alarm_control_panel.setup(
                self.hass, {
                    'alarm_control_panel': {
                        'platform': 'virtual',
                        'name': 'test',
                        'trigger_time': 0
                    }
                }))

        entity_id = 'alarm_control_panel.test'

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

        alarm_control_panel.alarm_trigger(self.hass, entity_id=entity_id)
        self.hass.pool.block_till_done()

        self.assertEqual(STATE_ALARM_TRIGGERED,
                         self.hass.states.get(entity_id).state)
Exemplo n.º 9
0
    def test_arm_home_with_invalid_code(self):
        """Attempt to arm home without a valid code."""
        self.assertTrue(
            alarm_control_panel.setup(
                self.hass, {
                    'alarm_control_panel': {
                        'platform': 'virtual',
                        'name': 'test',
                        'code': CODE,
                        'pending_time': 1
                    }
                }))

        entity_id = 'alarm_control_panel.test'

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

        alarm_control_panel.alarm_arm_home(self.hass, CODE + '2')
        self.hass.pool.block_till_done()

        self.assertEqual(STATE_ALARM_DISARMED,
                         self.hass.states.get(entity_id).state)
Exemplo n.º 10
0
    def test_arm_home_no_pending(self):
        """Test arm home method."""
        self.assertTrue(
            alarm_control_panel.setup(
                self.hass, {
                    'alarm_control_panel': {
                        'platform': 'virtual',
                        'name': 'test',
                        'code': CODE,
                        'pending_time': 0
                    }
                }))

        entity_id = 'alarm_control_panel.test'

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

        alarm_control_panel.alarm_arm_home(self.hass, CODE)
        self.hass.pool.block_till_done()

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