async def test_armed_away_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_away': { 'pending_time': 2 } }}) entity_id = 'alarm_control_panel.test' common.async_alarm_arm_away(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_AWAY == \ hass.states.get(entity_id).state
async def test_armed_away_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_away': { 'pending_time': 2 } } }) entity_id = 'alarm_control_panel.test' common.async_alarm_arm_away(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_AWAY == \ hass.states.get(entity_id).state
async def test_arm_away_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_away(hass, CODE) 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_AWAY 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_AWAY
async def test_trigger_with_pending_and_specific_delay(hass): """Test trigger method and switch from pending to triggered.""" assert await async_setup_component( 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 == \ hass.states.get(entity_id).state common.async_alarm_arm_away(hass, CODE) await hass.async_block_till_done() assert STATE_ALARM_ARMED_AWAY == \ hass.states.get(entity_id).state common.async_alarm_trigger(hass, entity_id=entity_id) await hass.async_block_till_done() state = 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): async_fire_time_changed(hass, future) await hass.async_block_till_done() state = 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): async_fire_time_changed(hass, future) await hass.async_block_till_done() state = hass.states.get(entity_id) assert state.state == STATE_ALARM_TRIGGERED
async def test_back_to_back_trigger_with_no_disarm_after_trigger(hass): """Test disarm after trigger.""" assert await async_setup_component( 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' assert STATE_ALARM_DISARMED == \ hass.states.get(entity_id).state common.async_alarm_arm_away(hass, CODE, entity_id) await hass.async_block_till_done() assert STATE_ALARM_ARMED_AWAY == \ hass.states.get(entity_id).state common.async_alarm_trigger(hass, entity_id=entity_id) await hass.async_block_till_done() assert STATE_ALARM_TRIGGERED == \ 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): async_fire_time_changed(hass, future) await hass.async_block_till_done() assert STATE_ALARM_ARMED_AWAY == \ hass.states.get(entity_id).state common.async_alarm_trigger(hass, entity_id=entity_id) await hass.async_block_till_done() assert STATE_ALARM_TRIGGERED == \ 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): async_fire_time_changed(hass, future) await hass.async_block_till_done() assert STATE_ALARM_ARMED_AWAY == \ hass.states.get(entity_id).state
async def test_back_to_back_trigger_with_no_disarm_after_trigger(hass): """Test disarm after trigger.""" assert await async_setup_component( 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' assert STATE_ALARM_DISARMED == \ hass.states.get(entity_id).state common.async_alarm_arm_away(hass, CODE, entity_id) await hass.async_block_till_done() assert STATE_ALARM_ARMED_AWAY == \ hass.states.get(entity_id).state common.async_alarm_trigger(hass, entity_id=entity_id) await hass.async_block_till_done() assert STATE_ALARM_TRIGGERED == \ hass.states.get(entity_id).state future = dt_util.utcnow() + timedelta(seconds=5) 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_AWAY == \ hass.states.get(entity_id).state common.async_alarm_trigger(hass, entity_id=entity_id) await hass.async_block_till_done() assert STATE_ALARM_TRIGGERED == \ hass.states.get(entity_id).state future = dt_util.utcnow() + timedelta(seconds=5) 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_AWAY == \ hass.states.get(entity_id).state
async def test_trigger_with_unused_specific_delay(hass): """Test trigger method and switch from pending to triggered.""" assert await async_setup_component( hass, alarm_control_panel.DOMAIN, {'alarm_control_panel': { 'platform': 'manual', 'name': 'test', 'code': CODE, 'delay_time': 5, 'pending_time': 0, 'armed_home': { 'delay_time': 10 }, 'disarm_after_trigger': False }}) entity_id = 'alarm_control_panel.test' assert STATE_ALARM_DISARMED == \ hass.states.get(entity_id).state common.async_alarm_arm_away(hass, CODE) await hass.async_block_till_done() assert STATE_ALARM_ARMED_AWAY == \ hass.states.get(entity_id).state common.async_alarm_trigger(hass, entity_id=entity_id) await hass.async_block_till_done() state = hass.states.get(entity_id) assert STATE_ALARM_PENDING == state.state assert STATE_ALARM_TRIGGERED == \ state.attributes['post_pending_state'] future = dt_util.utcnow() + timedelta(seconds=5) 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_TRIGGERED
async def test_arm_away_with_invalid_code(hass): """Attempt to arm away 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_away(hass, CODE + '2') await hass.async_block_till_done() assert STATE_ALARM_DISARMED == \ hass.states.get(entity_id).state
async def test_arm_away_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_away(hass, CODE, entity_id) await hass.async_block_till_done() assert STATE_ALARM_ARMED_AWAY == \ hass.states.get(entity_id).state
async def test_arm_away_with_invalid_code(hass): """Attempt to arm away 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_away(hass, CODE + '2') await hass.async_block_till_done() assert STATE_ALARM_DISARMED == \ hass.states.get(entity_id).state
async def test_arm_away_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_away(hass, CODE, entity_id) await hass.async_block_till_done() assert STATE_ALARM_ARMED_AWAY == \ hass.states.get(entity_id).state