async def test_arm(hass, mock_auth, code, alarm_service, alarm_state): """Test the alarm control panel can be set to away.""" install = AsyncMock() install.arm = AsyncMock(return_value=False) install.arm_partially = AsyncMock(return_value=True) install.disarm = AsyncMock(return_value=True) install.status = code with patch("pyprosegur.installation.Installation.retrieve", return_value=install): await setup_platform(hass) await hass.services.async_call( ALARM_DOMAIN, alarm_service, {ATTR_ENTITY_ID: PROSEGUR_ALARM_ENTITY}, blocking=True, ) await hass.async_block_till_done() state = hass.states.get(PROSEGUR_ALARM_ENTITY) assert state.state == alarm_state
async def test_connection_error(hass, mock_auth): """Test the alarm control panel when connection can't be made to the cloud service.""" install = AsyncMock() install.arm = AsyncMock(return_value=False) install.arm_partially = AsyncMock(return_value=True) install.disarm = AsyncMock(return_value=True) install.status = Status.ARMED with patch("pyprosegur.installation.Installation.retrieve", return_value=install): await setup_platform(hass) await hass.async_block_till_done() with patch("pyprosegur.installation.Installation.retrieve", side_effect=ConnectionError): await entity_component.async_update_entity(hass, PROSEGUR_ALARM_ENTITY) state = hass.states.get(PROSEGUR_ALARM_ENTITY) assert state.state == STATE_UNAVAILABLE