async def test_arm_home_with_pending(hass):
    """Test arm home method."""
    assert await async_setup_component(
        hass, alarm_control_panel.DOMAIN,
        {'alarm_control_panel': {
            'platform': 'manual',
            'name': 'test',
            'code': CODE,
            'pending_time': 1,
            'disarm_after_trigger': False
        }})

    entity_id = 'alarm_control_panel.test'

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

    common.async_alarm_arm_home(hass, CODE, entity_id)
    await hass.async_block_till_done()

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

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

    future = dt_util.utcnow() + timedelta(seconds=1)
    with patch(('homeassistant.components.manual.alarm_control_panel.'
                'dt_util.utcnow'), return_value=future):
        async_fire_time_changed(hass, future)
        await hass.async_block_till_done()

    state = hass.states.get(entity_id)
    assert state.state == STATE_ALARM_ARMED_HOME
async def test_armed_home_with_specific_pending(hass):
    """Test arm home method."""
    assert await async_setup_component(
        hass, alarm_control_panel.DOMAIN,
        {'alarm_control_panel': {
            'platform': 'manual',
            'name': 'test',
            'pending_time': 10,
            'armed_home': {
                'pending_time': 2
            }
        }})

    entity_id = 'alarm_control_panel.test'

    common.async_alarm_arm_home(hass)
    await hass.async_block_till_done()

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

    future = dt_util.utcnow() + timedelta(seconds=2)
    with patch(('homeassistant.components.manual.alarm_control_panel.'
                'dt_util.utcnow'), return_value=future):
        async_fire_time_changed(hass, future)
        await hass.async_block_till_done()

    assert STATE_ALARM_ARMED_HOME == \
        hass.states.get(entity_id).state
async def test_disarm_with_template_code(hass):
    """Attempt to disarm with a valid or invalid template-based code."""
    assert await async_setup_component(
        hass, alarm_control_panel.DOMAIN,
        {'alarm_control_panel': {
            'platform': 'manual',
            'name': 'test',
            'code_template':
                '{{ "" if from_state == "disarmed" else "abc" }}',
            'pending_time': 0,
            'disarm_after_trigger': False
        }})

    entity_id = 'alarm_control_panel.test'

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

    common.async_alarm_arm_home(hass, 'def')
    await hass.async_block_till_done()

    state = hass.states.get(entity_id)
    assert STATE_ALARM_ARMED_HOME == state.state

    common.async_alarm_disarm(hass, 'def')
    await hass.async_block_till_done()

    state = hass.states.get(entity_id)
    assert STATE_ALARM_ARMED_HOME == state.state

    common.async_alarm_disarm(hass, 'abc')
    await hass.async_block_till_done()

    state = hass.states.get(entity_id)
    assert STATE_ALARM_DISARMED == state.state
Example #4
0
async def test_armed_home_with_specific_pending(hass):
    """Test arm home method."""
    assert await async_setup_component(
        hass, alarm_control_panel.DOMAIN, {
            'alarm_control_panel': {
                'platform': 'manual',
                'name': 'test',
                'pending_time': 10,
                'armed_home': {
                    'pending_time': 2
                }
            }
        })

    entity_id = 'alarm_control_panel.test'

    common.async_alarm_arm_home(hass)
    await hass.async_block_till_done()

    assert STATE_ALARM_PENDING == \
        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):
        async_fire_time_changed(hass, future)
        await hass.async_block_till_done()

    assert STATE_ALARM_ARMED_HOME == \
        hass.states.get(entity_id).state
async def test_arm_home_with_invalid_code(hass):
    """Attempt to arm home without a valid code."""
    assert await async_setup_component(
        hass, alarm_control_panel.DOMAIN,
        {'alarm_control_panel': {
            'platform': 'manual',
            'name': 'test',
            'code': CODE,
            'pending_time': 1,
            'disarm_after_trigger': False
        }})

    entity_id = 'alarm_control_panel.test'

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

    common.async_alarm_arm_home(hass, CODE + '2')
    await hass.async_block_till_done()

    assert STATE_ALARM_DISARMED == \
        hass.states.get(entity_id).state
async def test_arm_home_no_pending(hass):
    """Test arm home method."""
    assert await async_setup_component(
        hass, alarm_control_panel.DOMAIN,
        {'alarm_control_panel': {
            'platform': 'manual',
            'name': 'test',
            'code': CODE,
            'pending_time': 0,
            'disarm_after_trigger': False
        }})

    entity_id = 'alarm_control_panel.test'

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

    common.async_alarm_arm_home(hass, CODE)
    await hass.async_block_till_done()

    assert STATE_ALARM_ARMED_HOME == \
        hass.states.get(entity_id).state
Example #7
0
async def test_arm_home_with_invalid_code(hass):
    """Attempt to arm home without a valid code."""
    assert await async_setup_component(
        hass, alarm_control_panel.DOMAIN, {
            'alarm_control_panel': {
                'platform': 'manual',
                'name': 'test',
                'code': CODE,
                'pending_time': 1,
                'disarm_after_trigger': False
            }
        })

    entity_id = 'alarm_control_panel.test'

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

    common.async_alarm_arm_home(hass, CODE + '2')
    await hass.async_block_till_done()

    assert STATE_ALARM_DISARMED == \
        hass.states.get(entity_id).state
Example #8
0
async def test_arm_home_no_pending(hass):
    """Test arm home method."""
    assert await async_setup_component(
        hass, alarm_control_panel.DOMAIN, {
            'alarm_control_panel': {
                'platform': 'manual',
                'name': 'test',
                'code': CODE,
                'pending_time': 0,
                'disarm_after_trigger': False
            }
        })

    entity_id = 'alarm_control_panel.test'

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

    common.async_alarm_arm_home(hass, CODE)
    await hass.async_block_till_done()

    assert STATE_ALARM_ARMED_HOME == \
        hass.states.get(entity_id).state
Example #9
0
async def test_arm_home_with_template_code(hass):
    """Attempt to arm with a template-based code."""
    assert await async_setup_component(
        hass, alarm_control_panel.DOMAIN, {
            'alarm_control_panel': {
                'platform': 'manual',
                'name': 'test',
                'code_template': '{{ "abc" }}',
                'pending_time': 0,
                'disarm_after_trigger': False
            }
        })

    entity_id = 'alarm_control_panel.test'

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

    common.async_alarm_arm_home(hass, 'abc')
    await hass.async_block_till_done()

    state = hass.states.get(entity_id)
    assert STATE_ALARM_ARMED_HOME == state.state
Example #10
0
async def test_arm_home_with_pending(hass):
    """Test arm home method."""
    assert await async_setup_component(
        hass, alarm_control_panel.DOMAIN, {
            'alarm_control_panel': {
                'platform': 'manual',
                'name': 'test',
                'code': CODE,
                'pending_time': 1,
                'disarm_after_trigger': False
            }
        })

    entity_id = 'alarm_control_panel.test'

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

    common.async_alarm_arm_home(hass, CODE, entity_id)
    await hass.async_block_till_done()

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

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

    future = dt_util.utcnow() + timedelta(seconds=1)
    with patch(('homeassistant.components.alarm_control_panel.manual.'
                'dt_util.utcnow'),
               return_value=future):
        async_fire_time_changed(hass, future)
        await hass.async_block_till_done()

    state = hass.states.get(entity_id)
    assert state.state == STATE_ALARM_ARMED_HOME