diff --git a/tests/components/totalconnect/test_alarm_control_panel.py b/tests/components/totalconnect/test_alarm_control_panel.py index ed89f0b00cdac..eb2b849540c6a 100644 --- a/tests/components/totalconnect/test_alarm_control_panel.py +++ b/tests/components/totalconnect/test_alarm_control_panel.py @@ -40,7 +40,6 @@ from homeassistant.exceptions import HomeAssistantError, ServiceValidationError from homeassistant.helpers import entity_registry as er from homeassistant.helpers.entity_component import async_update_entity -from homeassistant.util import dt as dt_util from .common import ( LOCATION_ID, @@ -92,7 +91,9 @@ async def test_attributes( assert mock_request.call_count == 1 -async def test_arm_home_success(hass: HomeAssistant) -> None: +async def test_arm_home_success( + hass: HomeAssistant, freezer: FrozenDateTimeFactory +) -> None: """Test arm home method success.""" responses = [RESPONSE_DISARMED, RESPONSE_ARM_SUCCESS, RESPONSE_ARMED_STAY] await setup_platform(hass, ALARM_DOMAIN) @@ -108,7 +109,8 @@ async def test_arm_home_success(hass: HomeAssistant) -> None: ) assert mock_request.call_count == 2 - async_fire_time_changed(hass, dt_util.utcnow() + DELAY) + freezer.tick(DELAY) + async_fire_time_changed(hass) await hass.async_block_till_done() assert mock_request.call_count == 3 assert hass.states.get(ENTITY_ID).state == STATE_ALARM_ARMED_HOME @@ -148,7 +150,9 @@ async def test_arm_home_failure(hass: HomeAssistant) -> None: assert mock_request.call_count == 3 -async def test_arm_home_instant_success(hass: HomeAssistant) -> None: +async def test_arm_home_instant_success( + hass: HomeAssistant, freezer: FrozenDateTimeFactory +) -> None: """Test arm home instant method success.""" responses = [RESPONSE_DISARMED, RESPONSE_ARM_SUCCESS, RESPONSE_ARMED_STAY] await setup_platform(hass, ALARM_DOMAIN) @@ -164,7 +168,8 @@ async def test_arm_home_instant_success(hass: HomeAssistant) -> None: ) assert mock_request.call_count == 2 - async_fire_time_changed(hass, dt_util.utcnow() + DELAY) + freezer.tick(DELAY) + async_fire_time_changed(hass) await hass.async_block_till_done() assert mock_request.call_count == 3 assert hass.states.get(ENTITY_ID).state == STATE_ALARM_ARMED_HOME @@ -205,7 +210,9 @@ async def test_arm_home_instant_failure(hass: HomeAssistant) -> None: assert mock_request.call_count == 3 -async def test_arm_away_instant_success(hass: HomeAssistant) -> None: +async def test_arm_away_instant_success( + hass: HomeAssistant, freezer: FrozenDateTimeFactory +) -> None: """Test arm home instant method success.""" responses = [RESPONSE_DISARMED, RESPONSE_ARM_SUCCESS, RESPONSE_ARMED_AWAY] await setup_platform(hass, ALARM_DOMAIN) @@ -221,7 +228,8 @@ async def test_arm_away_instant_success(hass: HomeAssistant) -> None: ) assert mock_request.call_count == 2 - async_fire_time_changed(hass, dt_util.utcnow() + DELAY) + freezer.tick(DELAY) + async_fire_time_changed(hass) await hass.async_block_till_done() assert mock_request.call_count == 3 assert hass.states.get(ENTITY_ID).state == STATE_ALARM_ARMED_AWAY @@ -262,7 +270,9 @@ async def test_arm_away_instant_failure(hass: HomeAssistant) -> None: assert mock_request.call_count == 3 -async def test_arm_away_success(hass: HomeAssistant) -> None: +async def test_arm_away_success( + hass: HomeAssistant, freezer: FrozenDateTimeFactory +) -> None: """Test arm away method success.""" responses = [RESPONSE_DISARMED, RESPONSE_ARM_SUCCESS, RESPONSE_ARMED_AWAY] await setup_platform(hass, ALARM_DOMAIN) @@ -277,7 +287,8 @@ async def test_arm_away_success(hass: HomeAssistant) -> None: ) assert mock_request.call_count == 2 - async_fire_time_changed(hass, dt_util.utcnow() + DELAY) + freezer.tick(DELAY) + async_fire_time_changed(hass) await hass.async_block_till_done() assert mock_request.call_count == 3 assert hass.states.get(ENTITY_ID).state == STATE_ALARM_ARMED_AWAY @@ -315,7 +326,9 @@ async def test_arm_away_failure(hass: HomeAssistant) -> None: assert mock_request.call_count == 3 -async def test_disarm_success(hass: HomeAssistant) -> None: +async def test_disarm_success( + hass: HomeAssistant, freezer: FrozenDateTimeFactory +) -> None: """Test disarm method success.""" responses = [RESPONSE_ARMED_AWAY, RESPONSE_DISARM_SUCCESS, RESPONSE_DISARMED] await setup_platform(hass, ALARM_DOMAIN) @@ -330,7 +343,8 @@ async def test_disarm_success(hass: HomeAssistant) -> None: ) assert mock_request.call_count == 2 - async_fire_time_changed(hass, dt_util.utcnow() + DELAY) + freezer.tick(DELAY) + async_fire_time_changed(hass) await hass.async_block_till_done() assert mock_request.call_count == 3 assert hass.states.get(ENTITY_ID).state == STATE_ALARM_DISARMED @@ -410,7 +424,9 @@ async def test_disarm_code_required( assert hass.states.get(ENTITY_ID).state == STATE_ALARM_DISARMED -async def test_arm_night_success(hass: HomeAssistant) -> None: +async def test_arm_night_success( + hass: HomeAssistant, freezer: FrozenDateTimeFactory +) -> None: """Test arm night method success.""" responses = [RESPONSE_DISARMED, RESPONSE_ARM_SUCCESS, RESPONSE_ARMED_NIGHT] await setup_platform(hass, ALARM_DOMAIN) @@ -425,7 +441,8 @@ async def test_arm_night_success(hass: HomeAssistant) -> None: ) assert mock_request.call_count == 2 - async_fire_time_changed(hass, dt_util.utcnow() + DELAY) + freezer.tick(DELAY) + async_fire_time_changed(hass) await hass.async_block_till_done() assert mock_request.call_count == 3 assert hass.states.get(ENTITY_ID).state == STATE_ALARM_ARMED_NIGHT @@ -463,7 +480,7 @@ async def test_arm_night_failure(hass: HomeAssistant) -> None: assert mock_request.call_count == 3 -async def test_arming(hass: HomeAssistant) -> None: +async def test_arming(hass: HomeAssistant, freezer: FrozenDateTimeFactory) -> None: """Test arming.""" responses = [RESPONSE_DISARMED, RESPONSE_SUCCESS, RESPONSE_ARMING] await setup_platform(hass, ALARM_DOMAIN) @@ -478,13 +495,14 @@ async def test_arming(hass: HomeAssistant) -> None: ) assert mock_request.call_count == 2 - async_fire_time_changed(hass, dt_util.utcnow() + DELAY) + freezer.tick(DELAY) + async_fire_time_changed(hass) await hass.async_block_till_done() assert mock_request.call_count == 3 assert hass.states.get(ENTITY_ID).state == STATE_ALARM_ARMING -async def test_disarming(hass: HomeAssistant) -> None: +async def test_disarming(hass: HomeAssistant, freezer: FrozenDateTimeFactory) -> None: """Test disarming.""" responses = [RESPONSE_ARMED_AWAY, RESPONSE_SUCCESS, RESPONSE_DISARMING] await setup_platform(hass, ALARM_DOMAIN) @@ -499,7 +517,8 @@ async def test_disarming(hass: HomeAssistant) -> None: ) assert mock_request.call_count == 2 - async_fire_time_changed(hass, dt_util.utcnow() + DELAY) + freezer.tick(DELAY) + async_fire_time_changed(hass) await hass.async_block_till_done() assert mock_request.call_count == 3 assert hass.states.get(ENTITY_ID).state == STATE_ALARM_DISARMING @@ -566,7 +585,9 @@ async def test_unknown(hass: HomeAssistant) -> None: assert mock_request.call_count == 1 -async def test_other_update_failures(hass: HomeAssistant) -> None: +async def test_other_update_failures( + hass: HomeAssistant, freezer: FrozenDateTimeFactory +) -> None: """Test other failures seen during updates.""" responses = [ RESPONSE_DISARMED, @@ -585,31 +606,36 @@ async def test_other_update_failures(hass: HomeAssistant) -> None: assert mock_request.call_count == 1 # then an error: ServiceUnavailable --> UpdateFailed - async_fire_time_changed(hass, dt_util.utcnow() + SCAN_INTERVAL) + freezer.tick(SCAN_INTERVAL) + async_fire_time_changed(hass) await hass.async_block_till_done(wait_background_tasks=True) assert hass.states.get(ENTITY_ID).state == STATE_UNAVAILABLE assert mock_request.call_count == 2 # works again - async_fire_time_changed(hass, dt_util.utcnow() + SCAN_INTERVAL * 2) + freezer.tick(SCAN_INTERVAL) + async_fire_time_changed(hass) await hass.async_block_till_done(wait_background_tasks=True) assert hass.states.get(ENTITY_ID).state == STATE_ALARM_DISARMED assert mock_request.call_count == 3 # then an error: TotalConnectError --> UpdateFailed - async_fire_time_changed(hass, dt_util.utcnow() + SCAN_INTERVAL * 3) + freezer.tick(SCAN_INTERVAL) + async_fire_time_changed(hass) await hass.async_block_till_done(wait_background_tasks=True) assert hass.states.get(ENTITY_ID).state == STATE_UNAVAILABLE assert mock_request.call_count == 4 # works again - async_fire_time_changed(hass, dt_util.utcnow() + SCAN_INTERVAL * 4) + freezer.tick(SCAN_INTERVAL) + async_fire_time_changed(hass) await hass.async_block_till_done(wait_background_tasks=True) assert hass.states.get(ENTITY_ID).state == STATE_ALARM_DISARMED assert mock_request.call_count == 5 # unknown TotalConnect status via ValueError - async_fire_time_changed(hass, dt_util.utcnow() + SCAN_INTERVAL * 5) + freezer.tick(SCAN_INTERVAL) + async_fire_time_changed(hass) await hass.async_block_till_done(wait_background_tasks=True) assert hass.states.get(ENTITY_ID).state == STATE_UNAVAILABLE assert mock_request.call_count == 6