async def test_armed_night_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_night': {
                'pending_time': 2
            }
        }})

    entity_id = 'alarm_control_panel.test'

    common.async_alarm_arm_night(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_NIGHT == \
        hass.states.get(entity_id).state
Exemple #2
0
async def test_armed_night_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_night': {
                    'pending_time': 2
                }
            }
        })

    entity_id = 'alarm_control_panel.test'

    common.async_alarm_arm_night(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_NIGHT == \
        hass.states.get(entity_id).state
Exemple #3
0
async def test_arm_night_with_pending(hass):
    """Test arm night 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_night(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_NIGHT

    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_NIGHT

    # Do not go to the pending state when updating to the same state
    common.async_alarm_arm_night(hass, CODE, entity_id)
    await hass.async_block_till_done()

    assert STATE_ALARM_ARMED_NIGHT == \
        hass.states.get(entity_id).state
async def test_arm_night_with_pending(hass):
    """Test arm night 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_night(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_NIGHT

    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_NIGHT

    # Do not go to the pending state when updating to the same state
    common.async_alarm_arm_night(hass, CODE, entity_id)
    await hass.async_block_till_done()

    assert STATE_ALARM_ARMED_NIGHT == \
        hass.states.get(entity_id).state
async def test_arm_night_with_invalid_code(hass):
    """Attempt to night 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_night(hass, CODE + '2')
    await hass.async_block_till_done()

    assert STATE_ALARM_DISARMED == \
        hass.states.get(entity_id).state
async def test_arm_night_no_pending(hass):
    """Test arm night 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_night(hass, CODE)
    await hass.async_block_till_done()

    assert STATE_ALARM_ARMED_NIGHT == \
        hass.states.get(entity_id).state
Exemple #7
0
async def test_arm_night_with_invalid_code(hass):
    """Attempt to night 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_night(hass, CODE + '2')
    await hass.async_block_till_done()

    assert STATE_ALARM_DISARMED == \
        hass.states.get(entity_id).state
Exemple #8
0
async def test_arm_night_no_pending(hass):
    """Test arm night 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_night(hass, CODE)
    await hass.async_block_till_done()

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